
    PiP                        d dl mZ d dlZd dlZd dlmZ d dlmZ d dlZd dl	m
Z
 d dlmZ d dlmZmZ d dlmZmZ d dlZd d	lmZ d
dlmZ ddlmZ ddlmZmZ 	 	 	 	 	 	 	 	 d&d'd%ZdS )(    )annotationsN)Path)	Annotated)print)Panel)ConfirmPrompt)dumpparse)custom_component_analytics   )LivePanelDisplay   )_create_utils)_get_npm_install_command Tnpm installFnamegAnnotated[str, typer.Argument(help='Name of the component. Preferably in camel case, i.e. MyTextBox.')]	directoryAnnotated[Path | None, typer.Option(help='Directory to create the component in. Default is None. If None, will be created in <component-name> directory in the current directory.')]package_nameaAnnotated[str | None, typer.Option(help='Name of the package. Default is gradio_{name.lower()}')]templatekAnnotated[str, typer.Option(help='Component to use as a template. Should use exact name of python class.')]installAnnotated[bool, typer.Option(help='Whether to install the component in your current environment as a development install. Recommended for development.')]npm_installZAnnotated[str, typer.Option(help="NPM install command to use. Default is 'npm install'.")]pip_pathAnnotated[str | None, typer.Option(help='Path to pip executable. If None, will use the default path found by `which pip3`. If pip3 is not found, `which pip` will be tried. If both fail an error will be raised.')]	overwrite_Annotated[bool, typer.Option(help='Whether to overwrite the existing component if it exists.')]configure_metadatamAnnotated[bool, typer.Option(help='Whether to interactively configure project metadata based on user input')]c	                 
   t          d|d d d |           |s!t          |                                           }|sd|                                  }|                                r'|s%t	          d|                                 d          |                                r|rt          j        |           |                    |           t          j	                    rt          j        d           d}nt          |          }t                      5 }	|	                    d	|  d
| dd           |r|	                    d| d           n|	                    d           t          j        |          }
t          j        | |
||           |	                    dd           t          t#          j        t&                              j        }|dz  }|                                s|	                    dd           t          j        |                                 |
||           |	                    dd           |rt-          ||	||           |	j                                         d}g }|rt3          t5          d                     t7          j        d          }t;          |dz                                            }|r@|d         d         } t?          j        d          }|r||d         d<   t?          j        d          pd}t3          d| d            ||d         d!<   t?          j        d"          }|pd#}t3          d$| d            |pd#|d         d%<   t3          d&           	 t?          j        d(          }|r|                     |           nn.|d         !                    d)g           }||z   |d         d)<   tE          |dz  d*d+,          5 }tG          ||           d d d            n# 1 swxY w Y   |d-z  d.z  $                    |           t          tJ                    j        d/z  d0z  }|                                }|rd1d1&                    |           nd2}d1| }|'                    d3|          '                    d4|          '                    d5|          '                    d6|          }|d0z  $                    |           t3          d7           d d d            d S # 1 swxY w Y   d S )8Ncreate)r   gradio_zThe directory z already exists. Please set --overwrite flag or pass in the name of a directory that does not already exist via the --directory option.)exist_okpnpmz i --ignore-scriptsz5:building_construction:  Creating component [orange3]z[/] in directory [orange3]z[/]g?)	add_sleepz&:fax: Starting from template [orange3]z7:page_facing_up: Creating a new component from scratch.z:snake: Created backend code_frontend_codez~:fast_down_button: Downloading frontend code from Hugging Face Hub. Set HF_HUB_DISABLE_PROGRESS_BARS to disable progress bars.)r   r   z:art: Created frontend codezA gradio custom componentzIt is recommended to answer the following [bold][magenta]4 questions[/][/] to finish configuring your custom component's metadata.
You can also answer them later by editing the [bold][magenta]pyproject.toml[/][/] file in your component directory.z 
Do you want to answer them now?zpyproject.tomlprojectr   zY
:pencil: Please enter a one sentence [bold][magenta]description[/][/] for your componentdescriptionzv
:bookmark_tabs: Please enter a [bold][magenta]software license[/][/] for your component. Leave blank for 'apache-2.0'z
apache-2.0z-:bookmark_tabs: Using license [bold][magenta]z[/][/]licensezs
:snake: Please enter the [bold][magenta]allowed python[/][/] versions for your component. Leave blank for '>=3.10'z>=3.10z0:snake: Using requires-python of [bold][magenta]zrequires-pythonzI
:label: Please add some keywords to help others discover your component.Tz+:label: Leave blank to stop adding keywordskeywordswzutf-8)encodingdemozrequirements.txtfilesz	README.mdz, r   z	<<title>>z<<short-description>>z<<tags>>z<<template>>z2
Component creation [bold][magenta]complete[/][/]!)(r   r   lowerexists
ValueErrorresolver   delete_contentsmkdir_in_test_dirshutilwhichr   r   update_get_component_code_create_backendinspectgetfilegradioparent_create_frontendr   _panelstopr   r   r   askr   	read_textr	   appendgetopenr
   
write_text__file__joinreplace)r   r   r   r   r   r   r!   r#   r%   live	componentpcomponent_sourcer/   r1   	answer_qspyproject_tomllicense_requires_pythonkeywordcurrent_keywordsfreadme_pathreadme_contentstagss                            y/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/gradio/cli/commands/components/create.py_createra      s   d      '&&	 0/// 1) 1UY..00 U U U
 
 	

 
				 1	 1%i000OOYO'''!## ,f--BBB{++			 gEtrDrrdmrrr 	 	
 	
 	
  	SKKNNNNOOOOKKQRRR!5h??	%dIy,OOO2cBBB(())0//&&(( 	KK Q     	&JJLL)y|	
 	
 	
 	
 	1SAAA 	EYk8DDD1 5	,L     $GHHI"I0@$@#K#K#M#MNNN ),%i08$jp   K?JN9-m< J R  $ $	  VhVVVWWW7?y))4"(* K# # #2"=X^^^^   $/x y)*;< `  $j)VWWG  0000 $2)#<#@#@R#P#P 8H88Sy)*5)&66gNNN ,RS+++, , , , , , , , , , , , , , , 
V	0	0<<\JJJ8nn+g5C%//11-5=)DIIh'')))2"??##K>>W,k::WZ&&W^X..	 	 
[	 ,,_===CDDDOgE gE gE gE gE gE gE gE gE gE gE gE gE gE gE gE gE gEs8   KT&P7TP	T
P	C+TT
T)NNr   Tr   NFT)r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   )
__future__r   rB   r=   pathlibr   typingr   typerrichr   
rich.panelr   rich.promptr   r	   tomlkitr
   r   rD   gradio.analyticsr   displayr   r   r   install_componentr   r   ra        r`   <module>ro      s[   " " " " " "                            ' ' ' ' ' ' ' '          7 7 7 7 7 7 & & & & & &       9 9 9 9 9 9 9 9 	 	 	 	 	 	 	 	avE vE vE vE vE vE vErn   