Team Ai
Apppublic

katira/function-gemma

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
__init__.cpython-312.pyc231 linesDownload Raw Back to __pycache__
1�

2�/Yi�L���ddlZddlZddlZddlZddlZddlZddlmZddlm	Z	ddl3Z4ddlmZddl
mZddlmZmZddl5mZddlmZdd	lmZmZmZdd6lmZddlmZddlmZmZdd
l m!Z!m"Z"m#Z#ddl$m%Z%ddl&m'Z'ddl(m)Z)ddl*m+Z+ddl,m-Z-m.Z.m/Z/ddl0m1Z1m2Z2ejfd�jiejj�ejldde7d��ejpee9�jtjwd�jy��dZ=gd�Z>e"Z?e#Z@e!ZAiZB										d:deCdeCdzdeCdzd eCdzd!edzd"eCdzd#eDdzd$eCd%e	d&eEdzd'eEd(e%fd)�ZFd;d*eDd+eGdzd(dfd,�ZHd-�ZId<deCd.eEd(eEfd/�ZJ	d;d0eCezdeCdzd(eCfd1�ZK	d;ddddddd2�deCdzd3eCezdzd4eEdzd5eEd6eLeCdzd7eEd8eEdzfd9�ZMy)=�N)�Path)�Any)�7ThemeClass)�TupleNoPrint)�Client�handle_file)�SpaceStorage)�LocalTokenNotFoundError)�context_vars�deploy�utils)�sync)�	Histogram)�8import_csv�import_tf_events)�TrackioAudio�TrackioImage�TrackioVideo)�Run)�
SQLiteStorage)�Table)�UploadEntry)�CSS�HEAD�demo)�TRACKIO_DIR�TRACKIO_LOGO_DIR�httpx�ignorez4Empty session being created. Install gradio\[oauth\]zgradio.helpers)�message�category�modulezpackage.json�version)�init�log�finish�showr�delete_projectrr�save�Image�Video�AudiorrT�project�name�group�space_id�
space_storage�9dataset_id�config�resume�settings�private�embed�returnc�h�|�tjd�|�
|�td��	tj||�\}}tjj�}tjj�}
|��|�]tjttddgddddtd	zttg�10�	\}}}
tj j#d�n#|}d}
tj j#|�tjj#|�tjj#|
�tj$j��"tj$j�|k7�r=t'd|���|�!|t(j*d<t'd
|���|��t'dt���tj,�rH|11rF|
r|
dzn|}tj.||tj0d��}tj2|�n�tj4|�n�t7j8||||	�|j;d�\}}t6j<j?||��}t'd|���tj,�r|12rtj2|�tj$j#|�d}|s
tA|d��}|dk(r9|�td��|tCjD|�vrtd|�d|�d���d}nm|dk(r|duxr|tCjD|�v}nJ|dk(r:|�5|tCjD|�vrtjd|�d|�d��d}d}ntd��tG|||||||��}|rt'd |jH���nt'd!|jH���tjJj#|�|jLtO�d"<|S#t13$r}td|���|�d}~wwxYw)#a�14    Creates a new Trackio project and returns a [`Run`] object.15 16    Args:17        project (`str`):18            The name of the project (can be an existing project to continue tracking or19            a new project to start tracking from scratch).20        name (`str`, *optional*):21            The name of the run (if not provided, a default name will be generated).22        group (`str`, *optional*):23            The name of the group which this run belongs to in order to help organize24            related runs together. You can toggle the entire group's visibilitiy in the25            dashboard.26        space_id (`str`, *optional*):27            If provided, the project will be logged to a Hugging Face Space instead of28            a local directory. Should be a complete Space name like29            `"username/reponame"` or `"orgname/reponame"`, or just `"reponame"` in which30            case the Space will be created in the currently-logged-in Hugging Face31            user's namespace. If the Space does not exist, it will be created. If the32            Space already exists, the project will be logged to it.33        space_storage ([`~huggingface_hub.SpaceStorage`], *optional*):34            Choice of persistent storage tier.35        dataset_id (`str`, *optional*):36            If a `space_id` is provided, a persistent Hugging Face Dataset will be37            created and the metrics will be synced to it every 5 minutes. Specify a38            Dataset with name like `"username/datasetname"` or `"orgname/datasetname"`,39            or `"datasetname"` (uses currently-logged-in Hugging Face user's namespace),40            or `None` (uses the same name as the Space but with the `"_dataset"`41            suffix). If the Dataset does not exist, it will be created. If the Dataset42            already exists, the project will be appended to it.43        config (`dict`, *optional*):44            A dictionary of configuration options. Provided for compatibility with45            `wandb.init()`.46        resume (`str`, *optional*, defaults to `"never"`):47            Controls how to handle resuming a run. Can be one of:48 49            - `"must"`: Must resume the run with the given name, raises error if run50              doesn't exist51            - `"allow"`: Resume the run if it exists, otherwise create a new run52            - `"never"`: Never resume a run, always create a new one53        private (`bool`, *optional*):54            Whether to make the Space private. If None (default), the repo will be55            public unless the organization's default is private. This value is ignored56            if the repo already exists.57        settings (`Any`, *optional*):58            Not used. Provided for compatibility with `wandb.init()`.59        embed (`bool`, *optional*, defaults to `True`):60            If running inside a jupyter/Colab notebook, whether the dashboard should61            automatically be embedded in the cell when trackio.init() is called.62 63    Returns:64        `Run`: A [`Run`] object that can be used to log metrics and finish the run.65    Nz�* Warning: settings is not used. Provided for compatibility with wandb.init(). Please create an issue at: https://github.com/gradio-app/trackio/issues if you need a specific feature implemented.z8Must provide a `space_id` when `dataset_id` is provided.z`You must be logged in to Hugging Face locally when `space_id` is provided to deploy to a Space. �gradior5FT�trackio_logo_light.png)	�css�head�footer_links�inline�quiet�prevent_thread_lock�66show_error�favicon_path�
allowed_pathsz* Trackio project initialized: �TRACKIO_DATASET_IDz:* Trackio metrics will be synced to Hugging Face Dataset: z* Trackio metrics logged to: �/�r-�write_token�footer)�	user_name�67space_namez* View dashboard by going to: )�verbose�mustz*Must provide a run name when resume='must'zRun 'z' does not exist in project '�'�allow�neverz%* Warning: resume='never' but a run 'z' already exists in project 'zw'. Generating a new name and instead. If you want to resume this run, call init() with resume='must' or resume='allow'.z2resume must be one of: 'must', 'allow', or 'never')�urlr-�clientr.r/r3r0z* Resumed existing run: z* Created new run: r3)(�warnings�warn�68ValueErrorr
� preprocess_space_and_dataset_idsr69r�current_server�get�current_share_serverr�launchrrrr�current_space_id�set�current_project�print�os�environ�is_in_notebook�get_full_urlrH�embed_url_in_notebook�print_dashboard_instructionsr�create_space_if_not_exists�split�SPACE_HOST_URL�formatrr�get_runsrr.�current_runr3�globals)r-r.r/r0r1r2r3r4r5r6r7�erQ�	share_url�_�base_url�full_urlrJrK�	space_urlrR�resumed�runs                       �;/usr/local/lib/python3.12/dist-packages/trackio/__init__.pyr$r$Cs��D���
�
�
Q�	70���J�2��S�T�T��$�E�E��j� 71���*��72%�73%�74)�75)�76+�C��1�1�5�5�7�I�77�{��� $�����&�78�3���$(��-�0H�H�/��=�79!��A�s�I�
�)�)�-�-�d�3��C��I��)�)�-�-�h�7��#�#�'�'��,��)�)�-�-�i�8��$�$�(�(�*�2��'�'�+�+�-��8�
�/��y�9�:��!�/9�B�J�J�+�,��L�Z�L�Y�
����1�+��?�@��#�#�%�%�.7�9�s�?�S�� �-�-��g�4�;K�;K�TX����+�+�H�5��2�2�7�;��-�-��-��W�
�%-�N�N�3�$7�!�I�z��-�-�4�4�#�80�5��I�
�2�9�+�>�?��#�#�%�%��+�+�I�6�� � �$�$�W�-�
�F����U�+��
����<��I�J�J��}�-�-�g�6�6��u�T�F�*G��y�PQ�R�S�S���	�7�	��d�"�N�t�}�/E�/E�g�/N�'N��	�7�	����
�(>�(>�w�(G� G��M�M�7��v�>�#�9�%X�X�
�81�D����M�N�N�82
����
�����C��
�(����83�3�4�
�#�C�H�H�:�.�/���� � ��%��*�*�G�I�h���J��O#��%�n�op�nq�r�84��	���s�P�	P1�P,�,P1�metrics�stepc��tjj�}|�td��|j	||��y)a85    Logs metrics to the current run.86 87    Args:88        metrics (`dict`):89            A dictionary of metrics to log.90        step (`int`, *optional*):91            The step number. If not provided, the step will be incremented92            automatically.93    Nz)Call trackio.init() before trackio.log().)rurv)rrjrX�RuntimeErrorr%)rurvrss   rtr%r%�s@���94"�95"�96&�97&�98(�C�99�{��F�G�G��G�G��
���c�z�tjj�}|�td��|j	�y)z#100    Finishes the current run.101    Nz,Call trackio.init() before trackio.finish().)rrjrXrxr&)rss rtr&r&s2���102"�103"�104&�105&�106(�C�107�{��I�J�J��J�J�Lry�forcec���tj|�}|j�std|�d��y|s-t	d|�d��}|j�dvrtd�y	|j
�dD]:}tt|�|z�}|j�s�+|j
��<td|�d	��y108#t$r}td|�d|���Yd
}~yd
}~wwxYw)a�109    Deletes a project by removing its local SQLite database.110 111    Args:112        project (`str`):113            The name of the project to delete.114        force (`bool`, *optional*, defaults to `False`):115            If `True`, deletes the project without prompting for confirmation.116            If `False`, prompts the user to confirm before deleting.117 118    Returns:119        `bool`: `True` if the project was deleted, `False` otherwise.120    z* Project 'z' does not exist.Fz)Are you sure you want to delete project 'z='? This will permanently delete all runs and metrics. (y/N): )�y�yesz* Deletion cancelled.)z-walz-shmz' has been deleted.Tz* Error deleting project 'z': N)121r�get_project_db_path�existsr^�input�lower�unlinkr�str�	Exception)r-r{�db_path�response�suffix�sidecarrls       rtr(r(s����/�/��8�G��>�>��
��G�9�$5�6�7����7��y�AI�
J�122���>�>��<�/��)�*�������&�F��3�w�<�&�0�1�G��~�~����� �'�123	��G�9�$7�8�9�����
�*�7�)�3�q�c�:�;����s�&<C�#!C�	C)�C$�$C)�glob_strc�@�|�+tjj�}|�td��t	|�}t	j124�j
�}g}|j�r|j
�g}n�t|�}|j�s.tt	j125�|zj
��}tj|d��D�cgc]4}t	|�j�rt	|�j
���6}}|std|����tjj�}tjj�}g}|D]j}		|	j|�}126|�)|j!|	dt|127j"�d���@|ddt|128�t%|	�d�}|j'|��l|rN|�td	��	t)|dd129di��}|j+d
|t,j.j1���tt.j8|zdz�Scc}w#t$rt	|	j�}130Y��wxYw#t2$r#}
t5j6d|
�d��Yd}
~
�od}
~
wwxYw)a�131    Saves files to a project (not linked to a specific run). If Trackio is running132    locally, the file(s) will be moved to the project's files directory. If Trackio is133    running in a Space, the file(s) will be uploaded to the Space's files directory.134 135    Args:136        glob_str (`str` or `Path`):137            The file path or glob pattern to save. Can be a single file or a pattern138            matching multiple files (e.g., `"*.py"`, `"models/**/*.pth"`).139        project (`str`, *optional*):140            The name of the project to save files to. If not provided, uses the current141            project from `trackio.init()`. If no project is initialized, raises an142            error.143 144    Returns:145        `str`: The path where the file(s) were saved (project's files directory).146 147    Example:148        ```python149        import trackio150 151        trackio.init(project="my-project")152        trackio.save("config.yaml")153        trackio.save("models/*.pth")154        ```155    NzhNo project specified. Either call trackio.init() first or provide a project parameter to trackio.save().T)�	recursivez!No files found matching pattern: F)rv�
relative_path�use_run_name)r-rsrvr��
uploaded_filezSNo server available. Call trackio.init() before trackio.save() to start the server.�timeout�Z)rL�httpx_kwargsz/bulk_upload_media)�api_name�uploads�hf_tokenzFailed to upload files: z.. Files may not be available in the dashboard.�files)rr]rXrxr�cwd�resolve�is_filer��is_absolute�globrUrWrj�relative_tor.�
_queue_upload�parentr�appendr�predict�huggingface_hubr
�	get_tokenr�rSrT�	MEDIA_DIR)r�r-�	base_path�
matched_files�pattern�frQrj�upload_entries�	file_path�relative_to_base�upload_entryrRrls              rtr)r)Ds���<���.�.�2�2�4���?��7��
�156�H�~�H����157�"�"�$�I��M�����!�)�)�+�,�
��h�-���#�#�%��4�8�8�:��0�9�9�;�<�G��Y�Y�w�$�7�158�7���A�w��� �
��G�O�O��7�	�159���<�X�J�G�H�H�160�161%�162%�163)�164)�165+�C��*�*�.�.�0�K��N�"�	�	4�(�4�4�Y�?���"�166
�%�%���!�"2�"9�"9�:�"�	
&�
�#���!$�%5�!6�!,�Y�!7�)�L�
�!�!�,�/�3#�6��;��e��
�	��C��i��_�M�F��N�N�-�&�(�.�.�8�8�:�
�
��u����(�7�2�3�3��y167��"�	4�#�I�N�N�3��	4��J�	��M�M�*�1�#�.?�?�
�
��	�s1�!9I�0I
�)AI1�
I.�-I.�1	J�:J�J)�theme�168mcp_serverrI�
color_palette�open_browser�block_threadr�r�rIr�r�r�c���|�"dj|�tjd<|xstjjd�}|�|n"tjjdd�dk(}t	j169ttddg|rd	gngzd170dd171tdzttg||�
�172\}}	}173|174r|175dzn|	}tj||tj|��}tj�s,td|���|rtj |�|�|nd176}ntj"|�|�|nd}|rtj$�t't|	|177|f�S)a178 179180    Launches the Trackio dashboard.181 182    Args:183        project (`str`, *optional*):184            The name of the project whose runs to show. If not provided, all projects185            will be shown and the user can select one.186        theme (`str` or `ThemeClass`, *optional*):187            A Gradio Theme to use for the dashboard instead of the default Gradio theme,188            can be a built-in theme (e.g. `'soft'`, `'citrus'`), a theme from the Hub189            (e.g. `"gstaff/xkcd"`), or a custom Theme class. If not provided, the190            `TRACKIO_THEME` environment variable will be used, or if that is not set,191            the default Gradio theme will be used.192        mcp_server (`bool`, *optional*):193            If `True`, the Trackio dashboard will be set up as an MCP server and certain194            functions will be added as MCP tools. If `None` (default behavior), then the195            `GRADIO_MCP_SERVER` environment variable will be used to determine if the196            MCP server should be enabled (which is `"True"` on Hugging Face Spaces).197        footer (`bool`, *optional*, defaults to `True`):198            Whether to show the Gradio footer. When `False`, the footer will be hidden.199            This can also be controlled via the `footer` query parameter in the URL.200        color_palette (`list[str]`, *optional*):201            A list of hex color codes to use for plot lines. If not provided, the202            `TRACKIO_COLOR_PALETTE` environment variable will be used (comma-separated203            hex codes), or if that is not set, the default color palette will be used.204            Example: `['#FF0000', '#00FF00', '#0000FF']`205        open_browser (`bool`, *optional*, defaults to `True`):206            If `True` and not in a notebook, a new browser tab will be opened with the207            dashboard. If `False`, the browser will not be opened.208        block_thread (`bool`, *optional*):209            If `True`, the main thread will be blocked until the dashboard is closed.210            If `None` (default behavior), then the main thread will not be blocked if the211            dashboard is launched in a notebook, otherwise the main thread will be blocked.212 213        Returns:214            `app`: The Gradio app object corresponding to the dashboard launched by Trackio.215            `url`: The local URL of the dashboard.216            `share_url`: The public share URL of the dashboard.217            `full_url`: The full URL of the dashboard including the write token (will use the public share URL if launched publicly, otherwise the local URL).218    �,�TRACKIO_COLOR_PALETTE�
TRACKIO_THEME�GRADIO_MCP_SERVER�False�Truer:r5�apiTFr;)219r<r=r>r@r?rArCrDr�r�rFrGz* Trackio UI launched at: )�joinr_r`rXrrZrrrrr
rbrHrar^�220webbrowser�openrc�*block_main_thread_until_keyboard_interruptr)
r-r�r�rIr�r�r��_mcp_server�apprQrmrorps
             rtr'r'�sX��d� �.1�h�h�}�.E��221�222�*�+��4�R�Z�Z�^�^�O�4�E��!�	�
�Z�Z�^�^�/��
9�V�
C���+�+��
��223�+�+��w�2�N��� �%�(@�@�'��5�����C��i�#,�y�3���H��!�!��'�t�/?�/?���H����!�
�*�8�*�5�6���O�O�H�%�'3�'?�|�T��
�#�#�H�-�'3�'?�|�U���
�8�8�:���s�I�x�8�9�9ry)224NNNNNNrPNNT)N)F)Nr��json�loggingr_rSr��pathlibr�typingrr��
gradio.themesr�gradio.utilsr�
gradio_clientrrr	�huggingface_hub.errorsr225�trackiorrr
�trackio.deployr�trackio.histogramr�trackio.importsrr�
trackio.mediarrr�trackio.runr�trackio.sqlite_storager�
trackio.tabler�trackio.typehintsr�trackio.ui.mainrrr�
trackio.utilsrr�	getLogger�setLevel�WARNING�filterwarnings�UserWarning�loads�__file__r��joinpath�	read_text�__version__�__all__r*r+r,r3r��dict�boolr$�intr%r&r(r)�listr'�ryrt�<module>r�s������	������$�%�-�(�:�/�/��'�8�B�B��0��)�+�+�7�����'��#�#�G�O�O�4������D�
��	��d�j�j��h��.�.�7�7��G�Q�Q�S�T�
�����"	������226��227���)-�!������t�
�t�228
��*�t���:�t��D�j�	t�229 �$�&�t��d�230�
t�
�4�K�t�
�t��t��D�[�t��t�	�t�n���S�4�Z��4��(�)�C�)��)��)�\�l4��D�j�l4�
�4�Z�l4�	�l4�`�Z:�&*�"��&*�� $�Z:�
�4�Z�Z:����d�"�Z:��t��	Z:�231
�Z:���9�t�#�
Z:��Z:���+�Z:ry