CoolFace
Apppublic

Tonic/l-android-control

sourceHugging Faceupdated 1y agoView on Hugging Face
1likes
deploy.cpython-311.pyc92 linesDownload Raw Back to __pycache__
12�#�h�����ddlZddlZddlZddlmZddlmZddlZddlZddl	m3Z4mZddlm
Z
ddlmZddlmZddlmZd	Z	dd5ededzfd�Z	dd6ededzd
dfd�Zd7ed
dfd�Zded8ed
dfd�ZdS)�N)�files)�Path)�Client�handle_file)�ReadTimeout)�RepositoryNotFoundError)�	HTTPError)�
SQLiteStoragez(https://huggingface.co/spaces/{space_id}�space_id�9dataset_idc��tjd��dkrdStd��}tj��}	tj|ddd���nt#t$rg}|jjdvr=td	��tj10d11���tj|ddd���ntd|�����Yd}~nd}~wwxYwtt|d
��d��5}|���}|�dt j��}t%j|�d����}|�|d
|d���ddd��n#1swxYwYd}t%j|�d����}	|�|	d|d���tj���|�|d|d
g���tj���}12|13�tj|d|14��|�tj|d|��dSdS)N�SYSTEM�spaces�trackio�gradio�spaceT)�	space_sdk�	repo_type�exist_ok�i�i��2Need 'write' access token to create a Spaces repo.F��add_to_git_credential�Failed to create Space: z	README.md�rz{GRADIO_VERSION}zutf-8)�path_or_fileobj�path_in_repo�repo_idrz15pyarrow>=21.016    zrequirements.txt)rr�folder_path�ignore_patterns�HF_TOKEN�TRACKIO_DATASET_ID)�os�getenvr�huggingface_hub�HfApi�create_repor	�response�status_code�print�login�17ValueError�openr�read�replacer�__version__�io�BytesIO�encode�upload_file�utils�disable_progress_bars�
upload_folder�	get_token�add_space_secret�add_space_variable)rr�trackio_path�hf_api�e�f�readme_content�
readme_buffer�requirements_content�requirements_buffer�hf_tokens           �I/opt/conda/envs/codecanvas/lib/python3.11/site-packages/trackio/deploy.py�deploy_as_spacerEs���18	�	�(���x�'�'�����#�#�L�
�
"�
$�
$�F�=��#�����		19�	20�	21�	22�	23���=�=�=��:�!�Z�/�/��F�G�G�G��!��>�>�>�>��'��"�!��	
�
�
�
�
��;��;�;�<�<�<�
�
�
�
�
�����	=����24�d�<��-�-�s�	3�	3�	25�q�������'�/�/�0B�F�DV�W�W���26�>�#8�#8��#A�#A�B�B�
����)�$���		�	27�	28�	29�		30�	31�	32�	33�	34�	35�	36�	37�	38�	39�	40����	41�	42�	43�	44����*�%9�%@�%@��%I�%I�J�J��45���+�'���	������/�/�1�1�1�46����� �$�
�	�����$�.�.�0�0�H����(��:�x�H�H�H����*�8�5I�:�V�V�V�V�V��s+�A�47C�!AC�C�)A5E*�*E.�1E.�returnc��d|vrtd|�d����|�d|vrtd|�d����	tj|d���td	t�|�48������|�tj|d|��dS#t$rYnqt$re}|j	j49dvr;td
��tjd���tj|d|��ntd|�����Yd}~nd}~wwxYwtdt�|�50������t||��dS)z�51    Creates a new Hugging Face Space if it does not exist. If a dataset_id is provided, it will be added as a space variable.52 53    Args:54        space_id: The ID of the Space to create.55        dataset_id: The ID of the Dataset to add to the Space.56    �/zInvalid space ID: z?. Must be in the format: username/reponame or orgname/reponame.NzInvalid dataset ID: zE. Must be in the format: username/datasetname or orgname/datasetname.r)rz* Found existing space: )rr"rrFrrz* Creating new space: )
r,r%�	repo_infor*�	SPACE_URL�formatr:rr	r(r)r+rE)rrr=s   rD�create_space_if_not_existsrL[s����(����j��j�j�j�57�58�	59���#�Z�"7�"7��t�:�t�t�t�60�61�	62�=��!�(�g�>�>�>�>�
�N��)9�)9�8�)9�)L�)L�N�N�O�O�O��!��.��.�63�
�
�
�	���"�
�
�
����=�=�=��:�!�Z�/�/��F�G�G�G��!��>�>�>�>��.��.�64�
�
�
�
��;��;�;�<�<�<�	
�
�
�
�
�����	=����6566H�9�#3�#3�X�#3�#F�#F�67H�68H�I�I�I��H�j�)�)�)�)�)s�AB
�
69D�	D�"AD�Dc���d}td��D]T}	t|d���dS#ttf$r*t	j|��t
|dzd��}Y�QwxYwtd���)	z�70    Blocks the current thread until the space exists.71    May raise a TimeoutError if this takes quite a while.72 73    Args:74        space_id: The ID of the Space to wait for.75    ��76F��verboseN��z4Waiting for space to exist took longer than expected)�rangerrr,�time�sleep�min�TimeoutError)r�delay�_s   rD�wait_until_space_existsr[�s���
�E�
�2�Y�Y�'�'��	'��8�U�+�+�+�+��F�F���Z�(�	'�	'�	'��J�u�������	�2�&�&�E�E�E�	'�����M�77N�78N�Ns�)�8A$�#A$�projectc���tj|��}t|d���}|�d|t	|��t79j������dS)z�80    Uploads the database of a local Trackio project to a Hugging Face Space.81 82    Args:83        project: The name of the project to upload.84        space_id: The ID of the Space to upload to.85    FrPz/upload_db_to_space)�api_namer\�uploaded_dbrCN)r86�get_project_db_pathr�predictrr%r5r8)r\r�db_path�clients    rD�upload_db_to_spacerd�sn���/��8�8�G�
�H�e�
,�
,�
,�F�87�N�N�&����(�(� �&�0�0�2�2�	������)N)r1r#rU�importlib.resourcesr�pathlibrrr%�
gradio_clientrr�httpxr�huggingface_hub.errorsr�requestsr	�trackio.sqlite_storager88rJ�strrErLr[rd�rerD�<module>ros���	�	�	�	�	�	�	�	�����%�%�%�%�%�%�������
�
�
�
�����-�-�-�-�-�-�-�-�������:�:�:�:�:�:�������0�0�0�0�0�0�6�	�89"�EW�EW��EW��d�90�EW�EW�EW�EW�T"�(*�(*��(*��d�91�(*�92�(*�(*�(*�(*�VO��O�	�O�O�O�O�*���s��t������re