Team Ai
Apppublic

delsj/function-gemma

sourceHugging Faceupdated 10mo agoView on Hugging Face
0likes
deploy.cpython-312.pyc127 linesDownload Raw Back to __pycache__
1�

2LIiO1�
��ddlZddlZddlZddlZddlZddlmZddlm	Z	ddl3Z4ddlZddlm
Z
mZddlmZddlmZmZddlZddlmZddlmZmZd	Zd5Zdefd�Z			dd
edej>dzdedzdedzfd�Z 			dd
edej>dzdedzdedzddf6d�Z!d
eddfd�Z"dded
ededdfd�Z#				dded
edzdedzdededefd�Z$y)�N)�files)�Path)�Client�handle_file)�ReadTimeout)�HfHubHTTPError�RepositoryNotFoundError)�
SQLiteStorage)�get_or_create_project_hash� preprocess_space_and_dataset_idsz*https://{user_name}-{space_name}.hf.space/z(https://huggingface.co/spaces/{space_id}�returnc�r�	tj}d|vrytjj	d�}|j7r*t
|j8�}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�9ValueError�	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�10dataset_id�privatec	���tjd�dk(rytd�}tj�}	tj11||d|dd��tt|d
�d�5}|j�}|jdt j"�}t%j&|j)d��}	|j+|	d
|d��ddd�t-�}12|13rd}ndt.j"�d�}t%j&|j)d��}|j+|d|d��tj0j3�|14r|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|�tj:|dd �y#t$rn}|jjdvr=td	�tjd15��tj16||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.017plotly>=6.0.0,<7.0.0zpyarrow>=21.018trackio==z19plotly>=6.0.0,<7.0.0zrequirements.txt)r9r/�folder_path�ignore_patternszimport trackio20trackio.show()z21ui/main.py�HF_TOKEN�TRACKIO_DATASET_ID�TRACKIO_LOGO_LIGHT_URL�TRACKIO_LOGO_DARK_URL�TRACKIO_PLOT_ORDER�
TRACKIO_THEME�GRADIO_MCP_SERVER�True) �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�22plot_order�themes                    r�deploy_as_spacerl0sE��	�	�	�(��x�'����#�L�
�
"�
"�
$�F�=��#�#����'���
	23�.24�d�<��-�s�	3�q������'�/�/�0B�F�DV�DV�W���25�26�>�#8�#8��#A�B�
����)�$���		�	27�	284�:�;��� ��$29�30�31�32�	�� ���*�*�%9�%@�%@��%I�J��33���+�'���	�����/�/�1�������$�(�M�		�	34����*�*�%5�%<�%<�W�%E�F�����+�%���		�	35�#�(�(�2�2�4�4�x�4��(�(��:�x�H����*�*�8�5I�:�V������(@�A�A�~�A��*�*��.��	36��37�38���'>�?�?�}�?��*�*��-�}�	39��Z�Z�^�^�$8�9�9�z�9��*�*�8�5I�:�V��40�41����/�/�u�/��*�*�8�_�e�L��&�&�x�1D�f�M��m�
=��:�:�!�!�Z�/��F�G��!�!��>��'�'���"�+�!��

��7��s�;�<�<�
��	
=��424�	3�s%�K3�+A*M-�3	M*�<A#M%�%M*�-M7c��d|vrtd|�d���|�d|vrtd|�d���	tj|d��td	tj|�43����|�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|�44����t||||�y)a�45    Creates a new Hugging Face Space if it does not exist.46 47    Args:48        space_id (`str`):49            The ID of the Space to create.50        space_storage ([`~huggingface_hub.SpaceStorage`], *optional*):51            Choice of persistent storage tier for the Space.52        dataset_id (`str`, *optional*):53            The ID of the Dataset to add to the Space as a space variable.54        private (`bool`, *optional*):55            Whether to make the Space private. If `None` (default), the repo will be56            public unless the organization's default is private. This value is ignored57            if the repo already exists.58    �/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@rAr1r2Fr3r5z* Creating new space: )rrF�	repo_inforK�	SPACE_URL�formatrZrDr[r\r	rrIrJrLrl)	r%r&r'r(rhrirjrkr_s	         r�create_space_if_not_existsrs�s��*�(��� ��59�*i�j�60�	61���#�Z�"7��"�:�,�.s�t�62�	63�"=��!�!�(�g�>�
�(��)9�)9�8�)9�)L�(M�N�O��!��.�.��.�64�
� �Z�Z�^�^�,D�E�E�>�E��.�.��2�N�
��J�J�N�N�+B�C�C�=�C��.�.��1�=�
������(<�=�=�:�=��.�.��.�65�
��J�J�N�N�?�3�3�5�3��.�.�x��%�P���"�
���=��:�:�!�!�Z�/��F�G��!�!��>��.�.��.�66�
��7��s�;�<�<�	
��	=��67�"�9�#3�#3�X�#3�#F�"G�68H�I��H�m�Z��As�D2E�	G�(G�0AG�Gc�$�tj�}d}td�D]}	|j|�ytd��#tjj69tf$r'tj|�t|dzd�}Y�lwxYw)z�70    Blocks the current thread until the Space exists.71 72    Args:73        space_id (`str`):74            The ID of the Space to wait for.75 76    Raises:77        `TimeoutError`: If waiting for the Space takes longer than expected.78    ��N��<z4Waiting for space to exist took longer than expected)rFrG�range�79space_inforUrr�time�sleep�min�TimeoutError)r%r^�delay�_s    r�wait_until_space_existsr��s����
"�
"�
$�F�
�E�
�2�Y��	'����h�'����M�80N�N�� �%�%�4�4�k�B�	'��J�J�u�����	�2�&�E�	'�s�A�AB�B�project�forcec��tj|�}t|dddi��}|sG	|jd��}||vr0t	d|�d|�d	��}|j�d81vrt
d�y|jd|t|�tjj���y#t$r#}t
d
|���t
d�Yd}~�bd}~wwxYw)aI82    Uploads the database of a local Trackio project to a Hugging Face Space.83 84    This uses the Gradio Client to upload since we do not want to trigger a new build of85    the Space, which would happen if we used `huggingface_hub.upload_file`.86 87    Args:88        project (`str`):89            The name of the project to upload.90        space_id (`str`):91            The ID of the Space to upload to.92        force (`bool`, *optional*, defaults to `False`):93            If `True`, overwrites the existing database without prompting. If `False`,94            prompts for confirmation.95    F�timeout�Z)�verbose�httpx_kwargsz/get_all_projects)�api_namezDatabase for project 'z' already exists on Space 'z'. Overwrite it? (y/N): )�y�yesz* Upload cancelled.Nz7* Warning: Could not check if project exists on Space: z* Proceeding with upload...z/upload_db_to_space)r�r��uploaded_dbrg)r96�get_project_db_pathr�predict�input�lowerrK�	ExceptionrrFrUrX)r�r%r��db_path�client�existing_projectsrIr_s        r�upload_db_to_spacer��s��� �/�/��8�G�
�H�e�9�b�/�
J�F��	1� &���8K�� L���+�+� �,�W�I�5P�QY�PZ�[,�-����>�>�#�<�7��/�0��97�N�N�&����(� �&�&�0�0�2�	���	�	1��K�A�3�O�P��/�0�0��	1�s�AB*�*	C�3C�C�run_in_backgroundc����|���dt����}t|d�\}}	ddtdtdzdtf�fd�
}|r*t	j98||||f��j
�|S||||�|S)	a�99    Syncs a local Trackio project's database to a Hugging Face Space.100    If the Space does not exist, it will be created.101 102    Args:103        project (`str`): The name of the project to upload.104        space_id (`str`, *optional*): The ID of the Space to upload to (e.g., `"username/space_id"`).105            If not provided, a random space_id (e.g. "username/project-2ac3z2aA") will be used.106        private (`bool`, *optional*):107            Whether to make the Space private. If None (default), the repo will be108            public unless the organization's default is private. This value is ignored109            if the repo already exists.110        force (`bool`, *optional*, defaults to `False`):111            If `True`, overwrite the existing database without prompting for confirmation.112            If `False`, prompt the user before overwriting an existing database.113        run_in_background (`bool`, *optional*, defaults to `False`):114            If `True`, the Space creation and database upload will be run in a background thread.115            If `False`, all the steps will be run synchronously.116    Returns:117        `str`: The Space ID of the synced project.118    N�-r%r(r�c����tdtj|���d��t||��t	|�t�||��tdtj|�����y)Nz$* Syncing local Trackio project to: roz (please wait...))r()r�z * Synced successfully to space: )rKrqrrrsr�r�)r%r(r�r�s   �r�space_creation_and_uploadz'sync.<locals>.space_creation_and_uploadIsh���	�2�9�3C�3C�X�3C�3V�2W�Wh�i�	119�	#�8�W�=���)��7�H�E�:�
�0��1A�1A�8�1A�1T�0U�V�W�)�target�args)NF)rrr�bool�	threading�Thread�start)r�r%r(r�r�r�r�s`      r�syncr�)s����8���Y�a� :�7� C�D�E��2�8�T�B�K�H�a�CH�	X��	X� $�t��	X�;?�	X�����,�H�g�u�3M�	120�121�%�'��O�	"�(�G�U�;��Or�)NNN)F)NNFF)%�importlib.metadatarrQrDr�r{�importlib.resourcesr�pathlibrr,rF�
gradio_clientrr�httpxr�huggingface_hub.errorsrr	r�trackio.sqlite_storager122�
trackio.utilsrr�SPACE_HOST_URLrqr�r$r�SpaceStoragerlrsr�r�r��r�r�<module>r�s����	�	���%��
��-��J��0�V�=��6�	��4��6:>�!��	nN��nN�"�/�/�$�6�nN��d�123�nN��D�[�	nN�f:>�!��	BB��BB�"�/�/�$�6�BB��d�124�BB��D�[�	BB�125126�BB�JO��O�	�O�2'��'�s�'�4�'�D�'�X ���#�1�
�1��D�j�1��D�[�1��	1�127�1�	�
1r�