
    ;3h                        d dl mZ d dlZd dl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mZ d dlmZm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y)    )annotationsN)Path)	AnnotatedOptional)print)Panel)ConfirmPrompt)dumpparse)custom_component_analytics   )LivePanelDisplay   )_create_utils)_get_npm_install_commandc	                $   t        d|d d d |       |st        | j                               }|sd| j                          }|j                         r|st	        d|j                          d      |j                         r|rt        j                  |       |j                  |       t        j                         rt        j                  d       d}nt        |      }t               5 }	|	j                  d	|  d
| dd       |r|	j                  d| d       n|	j                  d       t        j                  |      }
t        j                   | |
||       |	j                  dd       t        j"                  | j                         |
||       |	j                  dd       |rt%        ||	||       |	j&                  j)                          d}g }|rRt+        t-        d             t/        j0                  d      }t3        |dz  j5                               }|r
|d   d   } t7        j0                  d      }|r||d   d<   t7        j0                  d      xs d}t+        d| d       ||d   d<   t7        j0                  d       }|xs d!}t+        d"| d       |xs d!|d   d#<   t+        d$       	 t7        j0                  d%      }|r|j9                  |       nn+|d   j;                  d&g       }||z   |d   d&<   t=        |dz  d'd()      5 }t?        ||       d d d        |d*z  d+z  jA                  |       t        tB              jD                  d,z  d-z  }|j5                         }|rd.d.jG                  |       nd/}d.| }|jI                  d0|      jI                  d1|      jI                  d2|      jI                  d3|      }|d-z  jA                  |       t+        d4       d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)5Ncreate)npm_install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)	directorypackage_namez: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projectnamezY
: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.z+:label: Leave blank to stop adding keywordskeywordswzutf-8)encodingdemozrequirements.txtfilesz	README.mdz,  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_create_frontendr   _panelstopr   r   r	   askr   	read_textr
   appendgetopenr   
write_text__file__parentjoinreplace)r   r   r   templateinstallr   pip_path	overwriteconfigure_metadatalive	componentr   r!   	answer_qspyproject_tomllicense_requires_pythonkeywordcurrent_keywordsfreadme_pathreadme_contentstagss                          e/var/www/html/audio-gradio/venv/lib/python3.12/site-packages/gradio/cli/commands/components/create.py_createrR      sT   d  &	 /)Y..01 2U U
 	

 
				%%i0OOYO'!!#f-..AB{+		 aEtCD6Icdmcnnqr 	 	
 KK@
#NOKKQR!55h?	%%dIy,O2cB&&JJL)y|	
 	1SAYk8D1L  $GHI"I0@$@#K#K#MNN%i08$jjp ?JN9-m< JJ R $ $	  EhZvVW7?y))4"(** K# #2"=XFFWW]^ $/x y)*;< ` $jj)VWG 0  $2)#<#@#@R#P 8H88Sy)*5)&66gN ,RS+, 
V	0	0<<\J8n++g5C%//1-5DIIh'()2z?##K>W,k:WZ&W^X.	 	 
[	 ,,_=CDCaE aE`, ,aaE aEs&   ,H,PO:%CP:P	?PP)NNr&   Tznpm installNFT)r   zgAnnotated[str, typer.Argument(help='Name of the component. Preferably in camel case, i.e. MyTextBox.')]r   zAnnotated[Optional[Path], 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.')]r   zdAnnotated[Optional[str], typer.Option(help='Name of the package. Default is gradio_{name.lower()}')]r@   zkAnnotated[str, typer.Option(help='Component to use as a template. Should use exact name of python class.')]rA   zAnnotated[bool, typer.Option(help='Whether to install the component in your current environment as a development install. Recommended for development.')]r   zZAnnotated[str, typer.Option(help="NPM install command to use. Default is 'npm install'.")]rB   zAnnotated[Optional[str], 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.')]rC   z_Annotated[bool, typer.Option(help='Whether to overwrite the existing component if it exists.')]rD   zmAnnotated[bool, typer.Option(help='Whether to interactively configure project metadata based on user input')])
__future__r   r.   pathlibr   typingr   r   typerrichr   
rich.panelr   rich.promptr	   r
   tomlkitr   r   gradio.analyticsr   displayr   r&   r   install_componentr   r   rR        rQ   <module>r`      s    "   &    '  7 &  9 	 	 	 	 	 	 	 	apEpEpEpE"#pE./pE:;pEBCpENOpEVWpEr_   