o
    e                     @  s   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 Z	ej
e	dZej
ej
edZdd
dZdddZdd ZdS )    )annotationsNz	README.mdzdeploy_space_action.yamltitle
str | Noneapp_filereturndictc              	   C  s  i }t jt}| d u rtd| dp|} t| }|| kr&td| d ||d< |d u rt tD ]?}t jt|}t j	|rG|
dsHq3t|ddd	}| }d
|v rc|}	 W d     nW d    n1 smw   Y  q3td|r}d| dnd dp|}|rt j|std||d< d|d< tj|d< tt| tdddd tjD  dpd|d< i }	tddkr	 td}
|
sntd |
 d}||	|
< q|	|d!< t jtd"}t j|std# dkr	 td$}|snt|d%}||d&  W d    n	1 sw   Y  qtd' dkrwtd(p&d)}t jtd*}t jt j|dd+ tt}| }W d    n	1 sMw   Y  |d,|}t|d-}|| W d    n	1 snw   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   gradioZsdkZsdk_versionzEnter Spaces hardware (z, c                 s  s    | ]}|j V  qd S )N)value).0hardware r   CD:\Projects\ConvertPro\env\Lib\site-packages\gradio/deploy_space.py	<genexpr>:   s    z.add_configuration_to_readme.<locals>.<genexpr>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_hubZmetadata_savereadme_fileZSpaceHardwarelowerwritemakedirsdirnamegithub_action_templatereplace)r   r   configurationdir_nameZformatted_titlefile	file_pathfcontentr   secret_namesecret_valueZrequirements_filerequirementtrack_branchZgithub_action_fileZgithub_action_contentr   r   r   add_configuration_to_readme   s    



r?   strc                 C  sL   |  dd} tdd| } tdd| } | dr$| dd  } | ds| S )	N _z[^a-zA-Z0-9\-._]r   z-+-.   )r4   resub
startswith)r   r   r   r   r!   m   s   

r!   c            	      C  s  t ddkr	d S tjdd} | d | jdtdd | jd	td
d |  }t }d }d}z|	 }|d d d dkrAd}W n t
yM   d}Y nw |r^td tjdd |	 }d }t jtrwztt}W n	 tyv   Y nw |d u rtdt d t|j|j}tj|d ddd|ddj}|j|dtd |dr|d  D ]\}}t||| qtd|  d S )NZSYSTEMspaceszDeploy to Spaces)descriptiondeployz--titlezSpaces app title)typehelpz
--app-filezFile containing the Gradio appFauthZaccessTokenZroler0   Tz2Need 'write' access token to create a Spaces repo.)Zadd_to_git_credentialzCreating new Spaces Repo in 'z<'. Collecting metadata, press Enter to accept default value.r   r   spacer   )Z	space_sdk	repo_typer   Zspace_hardware)repo_idrP   Zfolder_pathr   z1Space available at https://huggingface.co/spaces/)r   getenvargparseArgumentParseradd_argumentr@   
parse_argsr-   ZHfApiwhoamiOSErrorr"   loginr   r)   r.   Zmetadata_load
ValueErrorr   r?   r   r   Zcreate_repogetrQ   Zupload_folderitemsZadd_space_secret)	parserargsZhf_apirW   rY   r5   Zspace_idr;   r<   r   r   r   rK   v   sn   


rK   )r   r   r   r   r   r   )r   r@   )
__future__r   rS   r   rF   r-   r   r+   getcwdr   r   r$   r.   r2   __file__r3   r?   r!   rK   r   r   r   r   <module>   s    

[	