CoolFace
Apppublic

umair894/quickstart-trackio

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

2�1�h�1����ddlZddlZddlZddlZddlZddlZddlmZddlm	Z	ddl3mZddlm
ZddlmZddlmZddlmZdd	lmZmZmZdd4lmZddlmZmZddlmZmZdd
l m!Z!ddl"m#Z#ddl$m%Z%ddl&m'Z'ddl(m)Z)m*Z*ejVd�jYejZ�ej\dde/d��ej`ee1�jdjgd�ji��dZ5gd�Z6eZ7eZ8iZ9dZ:										d/de;de;dzde;dzde;dzdedzd e;dzd!e<dzd"e;d#e	d$e=dzd%e=d&e!fd'�Z>d0d(e<d)e?dzd&dfd*�Z@d+�ZA			d1de;dzd,e;ezdzd-e=dzfd.�ZBy)2�N)�Path)�Any)�BUILT_IN_THEMES)�Default)�5ThemeClass)�Client)�SpaceStorage)�context_vars�deploy�utils)�	Histogram)�6import_csv�import_tf_events)�TrackioImage�TrackioVideo)�Run)�
SQLiteStorage)�Table)�demo)�TRACKIO_DIR�TRACKIO_LOGO_DIR�httpx�ignorez4Empty session being created. Install gradio\[oauth\]zgradio.helpers)�message�category�modulezpackage.json�version)7�init�log�finish�showrr�Image�Videorr
�default�project�name�group�space_id�
space_storage�8dataset_id�config�resume�settings�private�embed�returnc9��|�tjd�|�
|�td��tj||�\}}t10jj�}t11jj�}|�v|�2tjdddddtdzttg��\}
}}n|}d}t12jj|�t13jj|�t14jj��"t15jj�|k7�r<td|���|�!|t j"d	<td16|���|��tdt���tj$�rG|17rE|r|dzn|}tj&||tj(�
�}tj*|�n�tj,|�n�t/j0||||	�|j3d�\}}t.j4j7||��}td|���tj$�r|18rtj*|�t19jj|�d}|s
t9|d��}|dk(r9|�td��|t;j<|�vrtd|�d|�d���d}nm|dk(r|duxr|t;j<|�v}nJ|dk(r:|�5|t;j<|�vrtjd|�d|�d��d}d}ntd��t?|||||||��}|rtd|j@���ntd|j@���t20jBj|�|jDtG�d<|S) a�21    Creates a new Trackio project and returns a [`Run`] object.22 23    Args:24        project (`str`):25            The name of the project (can be an existing project to continue tracking or26            a new project to start tracking from scratch).27        name (`str`, *optional*):28            The name of the run (if not provided, a default name will be generated).29        group (`str`, *optional*):30            The name of the group which this run belongs to in order to help organize31            related runs together. You can toggle the entire group's visibilitiy in the32            dashboard.33        space_id (`str`, *optional*):34            If provided, the project will be logged to a Hugging Face Space instead of35            a local directory. Should be a complete Space name like36            `"username/reponame"` or `"orgname/reponame"`, or just `"reponame"` in which37            case the Space will be created in the currently-logged-in Hugging Face38            user's namespace. If the Space does not exist, it will be created. If the39            Space already exists, the project will be logged to it.40        space_storage ([`~huggingface_hub.SpaceStorage`], *optional*):41            Choice of persistent storage tier.42        dataset_id (`str`, *optional*):43            If a `space_id` is provided, a persistent Hugging Face Dataset will be44            created and the metrics will be synced to it every 5 minutes. Specify a45            Dataset with name like `"username/datasetname"` or `"orgname/datasetname"`,46            or `"datasetname"` (uses currently-logged-in Hugging Face user's namespace),47            or `None` (uses the same name as the Space but with the `"_dataset"`48            suffix). If the Dataset does not exist, it will be created. If the Dataset49            already exists, the project will be appended to it.50        config (`dict`, *optional*):51            A dictionary of configuration options. Provided for compatibility with52            `wandb.init()`.53        resume (`str`, *optional*, defaults to `"never"`):54            Controls how to handle resuming a run. Can be one of:55 56            - `"must"`: Must resume the run with the given name, raises error if run57              doesn't exist58            - `"allow"`: Resume the run if it exists, otherwise create a new run59            - `"never"`: Never resume a run, always create a new one60        private (`bool`, *optional*):61            Whether to make the Space private. If None (default), the repo will be62            public unless the organization's default is private. This value is ignored63            if the repo already exists.64        settings (`Any`, *optional*):65            Not used. Provided for compatibility with `wandb.init()`.66        embed (`bool`, *optional*, defaults to `True`):67            If running inside a jupyter/Colab notebook, whether the dashboard should68            automatically be embedded in the cell when trackio.init() is called.69 70    Returns:71        `Run`: A [`Run`] object that can be used to log metrics and finish the run.72    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.FT�trackio_logo_light.png)�show_api�inline�quiet�prevent_thread_lock�73show_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)�	user_name�74space_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'r+r(z* Resumed existing run: z* Created new run: r+)$�warnings�warn�75ValueErrorr� preprocess_space_and_dataset_idsr76�current_server�get�current_share_serverr�launchrr�set�current_project�print�os�environ�is_in_notebook�get_full_urlr=�embed_url_in_notebook�print_dashboard_instructionsr�create_space_if_not_exists�split�SPACE_HOST_URL�formatrr�get_runsrr&�current_runr+�globals)r%r&r'r(r)r*r+r,r-r.r/rE�	share_url�_�base_url�full_urlr>r?�	space_urlrF�resumed�runs                      �;/usr/local/lib/python3.12/dist-packages/trackio/__init__.pyrr=s���D���
�
�
Q�	77���J�2��S�T�T� �A�A�(�J�W��H�j�78�79%�80%�81)�82)�83+�C��1�1�5�5�7�I�84�{��� $������$(��-�0H�H�/��=�!��A�s�I��C��I��#�#�'�'��,��)�)�-�-�i�8��$�$�(�(�*�2��'�'�+�+�-��8�
�/��y�9�:��!�/9�B�J�J�+�,��L�Z�L�Y�
����1�+��?�@��#�#�%�%�.7�9�s�?�S�� �-�-��g�4�;K�;K����+�+�H�5��2�2�7�;��-�-��-��W�
�%-�N�N�3�$7�!�I�z��-�-�4�4�#�85�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�
�86�D����M�N�N�87
����
�����C��
�(����88�3�4�
�#�C�H�H�:�.�/���� � ��%��*�*�G�I�h���J��metrics�stepc��tjj�}|�td��|j	||��y)a89    Logs metrics to the current run.90 91    Args:92        metrics (`dict`):93            A dictionary of metrics to log.94        step (`int`, *optional*):95            The step number. If not provided, the step will be incremented96            automatically.97    Nz)Call trackio.init() before trackio.log().)rhri)r98r]rL�RuntimeErrorr)rhrires   rfrr�s@���99"�100"�101&�102&�103(�C�104�{��F�G�G��G�G��
��rgc�z�tjj�}|�td��|j	�y)z#105    Finishes the current run.106    Nz,Call trackio.init() before trackio.finish().)r107r]rLrkr )res rfr r �s2���108"�109"�110&�111&�112(�C�113�{��I�J�J��J�J�Lrg�theme�114mcp_serverc	���|xs$tjjdt�}|tk7�rt	|t115�rD|j
�tvrt|j
�}n	tj|�}t	|t�stjd�t�}|t_|j!�t_|j$t_t)j*�}|j-tj"j/d��|j1�t_|�|n"tjjdd�d	k(}tj4|d116dd117t6dzt6t8g|�
�\}}}|r|dzn|}	t;j<|	|tj>��}118t;j@�s8tCd|119���tEjF|120�t;jH�yt;jJ|121�y#t$r9}tjd|�dt|����t�}Yd}~���d}~wwxYw)a)122    Launches the Trackio dashboard.123 124    Args:125        project (`str`, *optional*):126            The name of the project whose runs to show. If not provided, all projects127            will be shown and the user can select one.128        theme (`str` or `ThemeClass`, *optional*):129            A Gradio Theme to use for the dashboard instead of the default Gradio theme,130            can be a built-in theme (e.g. `'soft'`, `'citrus'`), a theme from the Hub131            (e.g. `"gstaff/xkcd"`), or a custom Theme class. If not provided, the132            `TRACKIO_THEME` environment variable will be used, or if that is not set, the133            default Gradio theme will be used.134        mcp_server (`bool`, *optional*):135            If `True`, the Trackio dashboard will be set up as an MCP server and certain136            functions will be added as MCP tools. If `None` (default behavior), then the137            `GRADIO_MCP_SERVER` environment variable will be used to determine if the138            MCP server should be enabled (which is `"True"` on Hugging Face Spaces).139    �
TRACKIO_THEMEzCannot load z. Caught Exception: Nz1Theme should be a class loaded from gradio.themeszutf-8�GRADIO_MCP_SERVER�False�TrueTFr2)r3r5r4r6r8r9rnr;r<z* Trackio UI launched at: )&rRrSrL�
DEFAULT_THEME�140isinstance�str�lowerrr�from_hub�	ExceptionrGrH�DefaultThemerrm�_get_theme_css�	theme_css�_stylesheets�stylesheets�hashlib�sha256�update�encode�	hexdigest�141theme_hashrNrrrrUr=rTrQ�142webbrowser�open�*block_main_thread_until_keyboard_interruptrV)r%rmrn�e�theme_hasher�_mcp_serverr`rEr_rarbs           rfr!r!s���0
�C�R�Z�Z�^�^�O�]�C�E��
���e�S�!��{�{�}��/�'����
�6��+�&�/�/��6�E��%��,��M�M�M�N� �N�E�!&��143��-�-�/��� �-�-����~�~�'�����D�N�N�1�1�'�:�;�&�0�0�2����!�	�
�Z�Z�^�^�/��
9�V�
C�������� �%�(@�@�'��5����A�s�I�#,�y�3���H��!�!��'�t�/?�/?��H����!�
�*�8�*�5�6�����!�
�8�8�:�
�#�#�H�-��O!�+��M�M�L���7K�C�PQ�F�8�"T�U�(�N�E��+�s�2H3�3	I5�<.I0�0I5)144NNNNNNrDNNT)N)NNN)Cr�json�loggingrRrGr��pathlibr�typingr�
gradio.blocksr�
gradio.themesrrzr�
gradio_clientr�huggingface_hubr	�trackior145rr�trackio.histogramr
�trackio.importsrr�
trackio.mediarr�trackio.runr�trackio.sqlite_storager�
trackio.tabler�trackio.ui.mainr�
trackio.utilsrr�	getLogger�setLevel�WARNING�filterwarnings�UserWarning�loads�__file__�parent�joinpath�	read_text�__version__�__all__r"r#r+rtrv�dict�boolr�intrr r!�rgrf�<module>r�s�����	�����)�1�$� �(�/�/�'�8�4��0�� �7�����'��#�#�G�O�O�4������D�
��	��d�j�j��h��.�.�7�7��G�Q�Q�S�T�
�����	����146���
�147���)-�!������h�
�h�148
��*�h���:�h��D�j�	h�149 �$�&�h��d�150�
h�
�4�K�h�
�h��h��D�[�h��h�	�h�V���S�4�Z��4��(��%)�"�K.�
�4�Z�K.����d�"�K.��t��K.rg