CoolFace
Apppublic

umair894/quickstart-trackio

sourceHugging Faceupdated 11mo agoView on Hugging Face
0likes
deploy.cpython-312.pyc88 linesDownload Raw Back to __pycache__
12�1�h"��\�ddlZddlZddlZddlZddlmZddlmZddl	Z	ddl3Z4ddlmZm
Z
ddlmZddlmZddlmZddlZddlmZd	Zd5Zdefd�Z			dd
ede6j8dzdedzdedzfd�Z			dd
ede7j8dzdedzdedzddf8d�Zd
eddfd�Zded
eddfd�Z y)�N)�files)�Path)�Client�handle_file)�ReadTimeout)�RepositoryNotFoundError)�	HTTPError)�
SQLiteStoragez*https://{user_name}-{space_name}.hf.space/z(https://huggingface.co/spaces/{space_id}�returnc�r�	tj}d|vrytjj	d�}|j9r*t
|j10�}td�|D��}|ryy#ttjjtjjttf$rYywxYw)zCCheck if trackio is installed from source/editable install vs PyPI.z
site-packagesT�trackioc3�6K�|]}dt|�v���y�w)z.pthN)�str)�.0�fs  �9/usr/local/lib/python3.12/dist-packages/trackio/deploy.py�	<genexpr>z4_is_trackio_installed_from_source.<locals>.<genexpr> s����:�E�q�&�C��F�*�E�s�F)
r
�__file__�	importlib�metadata�distributionr�list�any�AttributeError�PackageNotFoundError�
MetadataError�11ValueError�	TypeError)�trackio_file�distr�has_pths    r�!_is_trackio_installed_from_sourcer"s�����'�'���,�.���!�!�.�.�y�9���:�:�����$�E��:�E�:�:�G���������/�/����(�(�������s�A-�AA-�-AB6�5B6�space_id�
space_storage�12dataset_id�privatec	���tjd�dk(rytd�}tj�}	tj13||d|dd��tt|d
�d�5}|j�}|jdt j"�}t%j&|j)d��}	|j+|	d
|d��ddd�t-�}14|15rd}ndt.j"�d�}t%j&|j)d��}|j+|d|d��tj0j3�|16r|j5|d|d
g��n;d}
t%j&|
j)d��}|j+|d|d��tj0j7�x}rtj8|d|�|�tj:|d|�tj<j?d�x}rtj:|d|�tj<j?d�x}rtj:|d|�tj<j?d�x}rtj:|d|�tj<j?d�x}rtj:|d|�yy#t$rn}|jjdvr=td	�tjd17��tj18||d|dd��ntd|����Yd}~���d}~wwxYw#1swY���xYw)N�SYSTEM�spacesr
�gradio�spaceT)r&�	space_sdkr$�	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_idr-z"pyarrow>=21.019plotly>=6.0.0,<7.0.0zpyarrow>=21.020trackio==z21plotly>=6.0.0,<7.0.0zrequirements.txt)r7r-�folder_path�ignore_patternszimport trackio22trackio.show()z23ui/main.py�HF_TOKEN�TRACKIO_DATASET_ID�TRACKIO_LOGO_LIGHT_URL�TRACKIO_LOGO_DARK_URL�TRACKIO_PLOT_ORDER�
TRACKIO_THEME) �os�getenvr�huggingface_hub�HfApi�create_repor	�response�status_code�print�loginr�openr�read�replacer*�__version__�io�BytesIO�encode�upload_filer"r
�utils�disable_progress_bars�
upload_folder�	get_token�add_space_secret�add_space_variable�environ�get)r#r$r%r&�trackio_path�hf_api�er�readme_content�
readme_buffer�is_source_install�requirements_content�requirements_buffer�app_file_content�app_file_buffer�hf_token�logo_light_url�
logo_dark_url�24plot_order�themes                    r�deploy_as_spacerh/s7��	�	�	�(��x�'����#�L�
�
"�
"�
$�F�=��#�#����'���
	25�.26�d�<��-�s�	3�q������'�/�/�0B�F�DV�DV�W���2728�>�#8�#8��#A�B�
����)�$���		�	29304�:�;��� ��$3132�33�34�	�� ���*�*�%9�%@�%@��%I�J��35���+�'���	�����/�/�1�������$�(�M�		�	36����*�*�%5�%<�%<�W�%E�F�����+�%���		�	37�#�(�(�2�2�4�4�x�4��(�(��:�x�H����*�*�8�5I�:�V������(@�A�A�~�A��*�*��.��	38��3940���'>�?�?�}�?��*�*��-�}�	41��Z�Z�^�^�$8�9�9�z�9��*�*�8�5I�:�V��4243����/�/�u�/��*�*�8�_�e�L�0��g�
=��:�:�!�!�Z�/��F�G��!�!��>��'�'���"�+�!��

��7��s�;�<�<�
��	
=��444�	3�s%�K�+A*M�	M�&A#M�M�M!c��d|vrtd|�d���|�d|vrtd|�d���	tj|d��td	tj|�45����|�tj|d|�tjjd�x}rtj|d|�tjjd
�x}rtj|d
|�tjjd�x}rtj|d|�tjjd�x}rtj|d|�y#t$rYntt$ri}|jjdvr9td�tjd��tj|d|�ntd|����Yd}~nd}~wwxYwtdtj|�46����t||||�y)a�47    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.48 49    Args:50        space_id: The ID of the Space to create.51        dataset_id: The ID of the Dataset to add to the Space.52        private: Whether to make the Space private. If None (default), the repo will be53          public unless the organization's default is private. This value is ignored if54          the repo already exists.55    �/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+)r-z* Found existing space: )r#r;r<r=r>r?r/r0Fr1r3z* Creating new space: )rrB�	repo_inforG�	SPACE_URL�formatrVr@rWrXrr	rErFrHrh)	r#r$r%r&rdrerfrgr[s	         r�create_space_if_not_existsrn�s�� �(��� ��56�*i�j�57�	58���#�Z�"7��"�:�,�.s�t�59�	60�"=��!�!�(�g�>�
�(��)9�)9�8�)9�)L�(M�N�O��!��.�.��.�61�
� �Z�Z�^�^�,D�E�E�>�E��.�.��2�N�
��J�J�N�N�+B�C�C�=�C��.�.��1�=�
������(<�=�=�:�=��.�.��.�62�
��J�J�N�N�?�3�3�5�3��.�.�x��%�P���"�
���=��:�:�!�!�Z�/��F�G��!�!��>��.�.��.�63�
��7��s�;�<�<�	
��	=��64�"�9�#3�#3�X�#3�#F�"G�65H�I��H�m�Z��As�D2E�	G�(G�0AG�Gc���d}td�D]}	t|d��ytd��#ttf$r't	j66|�t
|dzd�}Y�TwxYw)	z�67    Blocks the current thread until the space exists.68    May raise a TimeoutError if this takes quite a while.69 70    Args:71        space_id: The ID of the Space to wait for.72    ��73F��verboseN��z4Waiting for space to exist took longer than expected)�rangerrr�time�sleep�min�TimeoutError)r#�delay�_s   r�wait_until_space_existsr}�si��
�E�
�2�Y��	'��8�U�+����M�74N�N���Z�(�	'��J�J�u�����	�2�&�E�	'�s�
-�3A#�"A#�projectc��tj|�}t|d��}|jd|t	|�t75jj���y)z�76    Uploads the database of a local Trackio project to a Hugging Face Space.77 78    Args:79        project: The name of the project to upload.80        space_id: The ID of the Space to upload to.81    Frrz/upload_db_to_space)�api_namer~�uploaded_dbrcN)r82�get_project_db_pathr�predictrrBrQrT)r~r#�db_path�clients    r�upload_db_to_spacer��sQ���/�/��8�G�
�H�e�
,�F�83�N�N�&����(� �&�&�0�0�2�	��)NNN)!�importlib.metadatarrMr@rw�importlib.resourcesr�pathlibrr*rB�
gradio_clientrr�httpxr�huggingface_hub.errorsr�requestsr	r
�trackio.sqlite_storager84�SPACE_HOST_URLrl�boolr"r�SpaceStoragerhrnr}r��r�r�<module>r�s!���	�	��%��
��-��:���0�=��6�	��4��6:>�!��	lM��lM�"�/�/�$�6�lM��d�85�lM��D�[�	lM�b:>�!��	=B��=B�"�/�/�$�6�=B��d�86�=B��D�[�	=B�8788�=B�@O��O�	�O�*���s��t�r�