
    l0j                    
   d dl mZ d dlZd dlZd dlZd dlZd dlZ ej                    Z	ej
                            e	d          Zej
                            ej
                            e          d          Zdd
ZddZd ZdS )    )annotationsNz	README.mdzdeploy_space_action.yamltitle
str | Noneapp_filereturndictc                V   i }t           j                            t                    }| t	          d| d          p|} t          |           }|| k    rt          d| d           ||d<   |t          j        t                    D ]}t           j                            t          |          }t           j        	                    |          r|
                    d          s\t          |dd	          5 }|                                }d
|v r|}	 d d d             n	 d d d            n# 1 swxY w Y   t	          d|rd| dnd d          p|}|rt           j                            |          st          d          ||d<   d|d<   t          j        |d<   t#          j        t&          |           t	          dd                    d t"          j        D                        d          pd|d<   i }	t	          d          dk    r,	 t	          d          }
|
snt	          d|
 d          }||	|
<   +|	|d <   t           j                            t          d!          }t           j                            |          syt	          d"                                          dk    rT	 t	          d#          }|snAt          |d$          5 }|                    |d%z              d d d            n# 1 swxY w Y   St	          d&                                          dk    rt	          d'          pd(}t           j                            t          d)          }t          j        t           j                            |          d*           t          t2                    5 }|                                }d d d            n# 1 swxY w Y   |                    d+|          }t          |d,          5 }|                    |           d d d            n# 1 swxY w Y   t          d-           |S ).NzEnter Spaces app title [z]: zFormatted to z. r   z.pyzutf-8ignore)encodingerrorszimport gradiozEnter Gradio app file [] z: zFailed to find Gradio app file.r   gradiosdksdk_versionzEnter Spaces hardware (z, c              3  $   K   | ]}|j         V  d S )N)value).0hardwares     V/home/wildlama/miniconda3/envs/lam/lib/python3.11/site-packages/gradio/deploy_space.py	<genexpr>z.add_configuration_to_readme.<locals>.<genexpr>:   s$      /m/m8/m/m/m/m/m/m    z) [cpu-basic]: z	cpu-basicr   zAny Spaces secrets (y/n) [n]: yTz(Enter secret name (leave blank to end): zEnter secret value for secretszrequirements.txtz)Create requirements.txt file? (y/n) [n]: z)Enter a dependency (leave blank to end): a
zGCreate Github Action to automatically update Space on 'git push'? [n]: zEnter branch to track [main]: mainz".github/workflows/update_space.yml)exist_okz$branchwzGithub Action created. Add your Hugging Face write token (from https://huggingface.co/settings/tokens) as an Actions Secret named 'hf_token' to your GitHub repository. This can be set in your repository's settings page.)ospathbasenamerepo_directoryinputformat_titleprintlistdirjoinisfileendswithopenreadexistsFileNotFoundErrorgr__version__huggingface_hubmetadata_savereadme_fileSpaceHardwarelowerwritemakedirsdirnamegithub_action_templatereplace)r   r   configurationdir_nameformatted_titlefile	file_pathfcontentr   secret_namesecret_valuerequirements_filerequirementtrack_branchgithub_action_filegithub_action_contents                    r   add_configuration_to_readmerJ      sm    Mw//H}>>>>??K8"5))O%1o111222,M'J~.. 		 		D^T::I7>>),, DMM%4H4H i'(CCC q&&(("g--#H	       -               Rh+N?x????BRRRSS  	  C27>>(33 C ABBB (M*#M%#%>M- !+}=== 	~dii/m/mOl/m/m/m&m&m~~~	
 	
 	 	 * G-..#55	0 JKKK  !J;!J!J!JKKL#/GK 	0  'M)^5GHHGNN,--	,=>>DDFF#MM	, KLLK '-- ,d*+++, , , , , , , , , , , , , , ,		, 	U	
 	

%''	 	
 =>>H&W\\@
 
 	BGOO$677$GGGG()) 	-Q$%FFHH!	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 5 = =i V V$c** 	+aGG)***	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	 j	
 	
 	
 sH   4D**D.	1D.	K,,K03K0N<<O O -PPPstrc                    |                      dd          } t          j        dd|           } t          j        dd|           } |                     d          r| dd          } |                     d          | S )	N _z[^a-zA-Z0-9\-._]r   z-+-.   )r;   resub
startswith)r   s    r   r&   r&   m   s|    MM#s##EF&E22EF4e$$E


3

 abb	 

3

 Lr   c            	        t          j        d          dk    rd S t          j        d          } |                     d           |                     dt
          d           |                     d	t
          d
           |                                 }t          j                    }d }d}	 |	                                }|d         d         d         dk    rd}n# t          $ r d}Y nw xY w|r8t          d           t          j        d           |	                                }d }t           j                            t                    r+	 t          j        t                    }n# t"          $ r Y nw xY w|2t          dt$           d           t'          |j        |j                  }t          j        |d         ddd|                    d                    j        }|                    |dt$                     |                    d          r6|d                                         D ]\  }}t          j        |||           t          d|            d S )NSYSTEMspaceszDeploy to Spaces)descriptiondeployz--titlezSpaces app title)typehelpz
--app-filezFile containing the Gradio appFauthaccessTokenroler7   Tz2Need 'write' access token to create a Spaces repo.)add_to_git_credentialzCreating new Spaces Repo in 'z<'. Collecting metadata, press Enter to accept default value.r   r   spacer   )	space_sdk	repo_typer   space_hardware)repo_idrb   folder_pathr   z1Space available at https://huggingface.co/spaces/)r!   getenvargparseArgumentParseradd_argumentrK   
parse_argsr2   HfApiwhoamiOSErrorr'   loginr"   r.   r4   metadata_load
ValueErrorr$   rJ   r   r   create_repogetrd   upload_folderitemsadd_space_secret)	parserargshf_apirl   rn   r<   space_idrC   rD   s	            r   rY   rY   v   s   
	(x''$1CDDDF
!!!
	2DEEE
35UVVVD"$$FFE&>-(0G;;E    !BCCCE::::!%M	w~~k"" 	+9+FFMM 	 	 	D	 xNxxx	
 	
 	
 4JM
 

 *g$((44     "    
 ## R)6y)A)G)G)I)I 	R 	R%K,X{LQQQQ	
Hh
H
HIIIIIs$   +.C C)(C)E' '
E43E4)r   r   r   r   r   r   )r   rK   )
__future__r   rg   r!   rR   r2   r   r0   getcwdr$   r"   r)   r4   r9   __file__r:   rJ   r&   rY    r   r   <module>r~      s    " " " " " "  				 				        gll>;77GOOH9  
X X X Xv   9J 9J 9J 9J 9Jr   