Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
repocard.cpython-313.pyc487 linesDownload Raw Back to __pycache__
1�

2��j
�����SSKrSSKrSSKJr SSKJrJr SSKrSSKJ	r	 SSK3Jr SSKJ
r
JrJrJrJrJrJr SSKJrJrJrJrJr SS	KJr SS4KJr SSKJrJ r J!r! \ RD"\#5r$\"\%5RLS-S
-r'\"\%5RLS-S-r(\RR"S5r*"SS5r+"SS\+5r,"SS\+5r-"SS\+5r.S\/S\S4Sjr0S\/\-S\1S-4Sjr2S\/\-S\1SS4Sjr3SS SSSSS!.S"\/S#\/S$\/S%\/S&\/S'\S(\/S)\/S*\/S-S+\4S,\/S-S-\/S-S.\/S-S/\/S-S\14S0jjr5\!SS SSSSS SS1.S2\/S3\1S4\/S-S5\4S6\/S-S7\/S-S8\/S-S9\/S-S:\4S;\/S-S\/4S<jj5r6g)=�N)�Path)�Any�Literal)�hf_hub_download)�upload_file)�CardData�DatasetCardData�5EvalResult�
ModelCardData�
SpaceCardData�eval_results_to_model_index�model_index_to_eval_results)�HfHubHTTPError�get_session�hf_raise_for_status�is_jinja_available�	yaml_dump�)�	constants)�EntryNotFoundError)�SoftTemporaryDirectory�logging�validate_hf_hub_args�	templateszmodelcard_template.mdzdatasetcard_template.mdz1^(\s*---[\r\n]+)([\S\s]*?)([\r\n]+---(\r\n|\n|$))c�~�\rSrSr\r\rSrSS\	S\64Sjjr\S5r
\
RS\	4Sj5r
SrS	\\	-4S7jr\SS\	\-S
\	S-S\	S-S\84Sjj5rSS
\	S-4SjjrS S\	S\	S-S
\	S-S\	S-S\	S-S\	S-S\9S-S\	S-4Sjjr\S!S\S\	S-S\	S-4Sjj5rSrg)"�RepoCard�%�model�content�ignore_metadata_errorsc��X lXlg)a�Initialize a RepoCard from string content. The content should be a10Markdown file with a YAML block at the beginning and a Markdown body.11 12Args:13    content (`str`): The content of the Markdown file.14 15Example:16    ```python17    >>> from huggingface_hub.repocard import RepoCard18    >>> text = '''19    ... ---20    ... language: en21    ... license: mit22    ... ---23    ...24    ... # My repo25    ... '''26    >>> card = RepoCard(text)27    >>> card.data.to_dict()28    {'language': 'en', 'license': 'mit'}29    >>> card.text30    '\n# My repo\n'31 32    ```33> [!TIP]34> Raises the following error:35>36>     - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)37>       when the content of the repo card metadata is not a dictionary.38N)r r)�selfrr s   �^D:\code\apps\devtools\python\user_packages\Python313\site-packages\huggingface_hub/repocard.py�__init__�RepoCard.__init__*s��D'=�#���c��[UR5=(d SnSUURRXRS9USUUR393$)zLThe content of the RepoCard, including the YAML block and the Markdown body.�40�---)�41line_break�original_order)�_detect_line_ending�_content�data�to_yaml�_original_order�text)r"r*s  r#r�RepoCard.contentOsz��)����7�?�4�42��Z�L����!2�!2�j�Ym�Ym�!2�!n� o�pz�o{�{~�@J�K�LP�LU�LU�KV�W�	Wr&c���Xl[RU5nU(adURS5nXR	5SUl[R"U5nUc0n[U[5(d[S5eO[RS5 0nXlUR"S0UDSUR0D6Ul[!UR#55Ulg)z Set the content of the RepoCard.�N�)repo card metadata block should be a dictzBRepo card metadata block was not found. Setting CardData to empty.r �)r-�REGEX_YAML_BLOCK�search�group�endr1�yaml�	safe_load�43isinstance�dict�44ValueError�logger�warning�card_data_classr r.�list�keysr0)r"r�match�45yaml_block�	data_dicts     r#rr2Us��� �
� �'�'��0������Q��J��	�	��
�.�D�I����z�2�I�� ��	��i��.�.� �!L�M�M�/�
�N�N�_�`��I��I��(�(�i�9�i�T�Mh�Mh�i��	�#�I�N�N�$4�5��r&c��UR$�N)r)r"s r#�__str__�RepoCard.__str__ps���|�|�r&�filepathc���[U5nURRSSS9 [USSSS9nUR	[U55 SSS5 g!,(df   g=f)a3Save a RepoCard to a file.46 47Args:48    filepath (`Union[Path, str]`): Filepath to the markdown file to save.49 50Example:51    ```python52    >>> from huggingface_hub.repocard import RepoCard53    >>> card = RepoCard("---\nlanguage: en\n---\n# This is a test repo card")54    >>> card.save("/tmp/test.md")55 56    ```57T)�parents�exist_ok�w��utf-8��mode�newline�encodingN)r�parent�mkdir�open�write�str)r"rL�fs   r#�save�
RepoCard.savessQ����>�������d�T��:�
�(��b�7�
C�q�
�G�G�C��I��D�
C�
C�s�A�58A$N�repo_id_or_path�	repo_type�tokenc	��[U5R5(a[U5nO[[U[5(a7[[	U[59RU=(d URUS95nO[SUS35eURSSSS9nU"UR5US9sS	S	S	5 $!,(df   g	=f)60a�Initialize a RepoCard from a Hugging Face Hub repo's README.md or a local filepath.61 62Args:63    repo_id_or_path (`Union[str, Path]`):64        The repo ID associated with a Hugging Face Hub repo or a local filepath.65    repo_type (`str`, *optional*):66        The type of Hugging Face repo to push to. Defaults to None, which will use "model". Other options67        are "dataset" and "space". Not used when loading from a local filepath. If this is called from a child68        class, the default value will be the child class's `repo_type`.69    token (`str`, *optional*):70        Authentication token, obtained with `huggingface_hub.HfApi.login` method. Will default to the stored token.71    ignore_metadata_errors (`str`):72        If True, errors while parsing the metadata section will be ignored. Some information might be lost during73        the process. Use it at your own risk.74 75Returns:76    [`huggingface_hub.repocard.RepoCard`]: The RepoCard (or subclass) initialized from the repo's77        README.md file or filepath.78 79Example:80    ```python81    >>> from huggingface_hub.repocard import RepoCard82    >>> card = RepoCard.load("nateraw/food")83    >>> assert card.data.tags == ["generated_from_trainer", "image-classification", "pytorch"]84 85    ```86)r`raz.Cannot load RepoCard: path not found on disk (z).�rrQrRrS)r N)r�is_filer=r[rr�
REPOCARD_NAMEr`r?rY�read)�clsr_r`rar �	card_pathr\s       r#�load�
RepoCard.load�s���H�� �(�(�*�*��_�-�I�
���
-�
-���#��+�+�'�8�3�=�=��	��I��M�o�M^�^`�a�b�b��^�^��b�7�^�
C�q��q�v�v�x�8N�O�D�
C�
C�s�B6�687Cc��U=(d URnU[U5S.nSS0n[5RSX#S9n[	U5 g![88a,nWRS:Xa[UR5eUeSnAff=f)aValidates card against Hugging Face Hub's card validation logic.89Using this function requires access to the internet, so it is only called90internally by [`huggingface_hub.repocard.RepoCard.push_to_hub`].91 92Args:93    repo_type (`str`, *optional*, defaults to "model"):94        The type of Hugging Face repo to push to. Options are "model", "dataset", and "space".95        If this function is called from a child class, the default will be the child class's `repo_type`.96 97> [!TIP]98> Raises the following errors:99>100>     - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)101>       if the card fails validation checks.102>     - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)103>       if the request to the Hub API fails for any other reason.104)�repoTyper�Acceptz105text/plainz(https://huggingface.co/api/validate-yaml)�json�headersi�N)	r`r[r�postrr�status_coder?r1)r"r`�bodyro�response�excs      r#�validate�RepoCard.validate�s���(�/����	�"��4�y�106���\�*��	�"�}�)�)�*T�[_�)�q�H���)���	��#�#�s�*� ����/�/��	��		�s�#A
�
107B�'A>�>B�repo_id�commit_message�commit_description�revision�	create_pr�
parent_commitc	�T�U=(d URnURUS9 [5n	[U	5[R108-n109U110R
[U5SS9 [[U1115[R112UUUUUUUUS9113nSSS5 U$!,(df   W$=f)arPush a RepoCard to a Hugging Face Hub repo.114 115Args:116    repo_id (`str`):117        The repo ID of the Hugging Face Hub repo to push to. Example: "nateraw/food".118    token (`str`, *optional*):119        Authentication token, obtained with `huggingface_hub.HfApi.login` method. Will default to120        the stored token.121    repo_type (`str`, *optional*, defaults to "model"):122        The type of Hugging Face repo to push to. Options are "model", "dataset", and "space". If this123        function is called by a child class, it will default to the child class's `repo_type`.124    commit_message (`str`, *optional*):125        The summary / title / first line of the generated commit.126    commit_description (`str`, *optional*)127        The description of the generated commit.128    revision (`str`, *optional*):129        The git revision to commit from. Defaults to the head of the `"main"` branch.130    create_pr (`bool`, *optional*):131        Whether or not to create a Pull Request with this commit. Defaults to `False`.132    parent_commit (`str`, *optional*):133        The OID / SHA of the parent commit, as a hexadecimal string. Shorthands (7 first characters) are also supported.134        If specified and `create_pr` is `False`, the commit will fail if `revision` does not point to `parent_commit`.135        If specified and `create_pr` is `True`, the pull request will be created from `parent_commit`.136        Specifying `parent_commit` ensures the repo has not changed before committing the changes, and can be137        especially useful if the repo is updated / committed too concurrently.138Returns:139    `str`: URL of the commit which updated the card metadata.140)r`rR)rV)141�path_or_fileobj�path_in_reporwrar`rxryr{rzr|N)	r`rurrrre�142write_textr[r)r"rwrar`rxryrzr{r|�tmpdir�tmp_path�urls            r#�push_to_hub�RepoCard.push_to_hub�s���R�/����	�	
�
�
�	�
�*�
#�
%���F�|�i�&=�&=�=�H�����D�	�G��<�� #�H�
�&�4�4���#�-�#5�#�!�+��C�&��143�&�
%��144�s�AB�145B'�	card_data�
template_path�template_strc��[5(aSSKnO[S5eUR5R	5nURU5 Ub[
U5R5nUc#[
UR5R5nURU5nUR"SSUR50UD6nU"U5$)a�Initialize a RepoCard from a template. By default, it uses the default template.146 147Templates are Jinja2 templates that can be customized by passing keyword arguments.148 149Args:150    card_data (`huggingface_hub.CardData`):151        A huggingface_hub.CardData instance containing the metadata you want to include in the YAML152        header of the repo card on the Hugging Face Hub.153    template_path (`str`, *optional*):154        A path to a markdown file with optional Jinja template variables that can be filled155        in with `template_kwargs`. Defaults to the default template.156 157Returns:158    [`huggingface_hub.repocard.RepoCard`]: A RepoCard instance with the specified card data and content from the159    template.160rNzjUsing RepoCard.from_template requires Jinja2 to be installed. Please install it with `pip install Jinja2`.r�r6)r�jinja2�ImportError�to_dict�copy�updater�	read_text�default_template_path�Template�renderr/)	rgr�r�r��template_kwargsr��kwargs�templaters	         r#�
from_template�RepoCard.from_template!s���0�����9��
�161�"�"�$�)�)�+���
�
�o�&��$��
�.�8�8�:�L����� 9� 9�:�D�D�F�L��?�?�<�0���/�/�J�I�,=�,=�,?�J�6�J���7�|�r&)r-r0rr.r r1)F)NNFrI)NNNNNNN�NN)�__name__�162__module__�__qualname__�__firstlineno__rrB�TEMPLATE_MODELCARD_PATHr�r`r[�boolr$�propertyr�setterrJrr]�classmethodrirur�r��__static_attributes__r6r&r#rr%s����O�3���I�#��#�T�#�J�W��W�163
�^�^�6�s�6��6�4��T�C�Z��(�!%� �',�3P��t��3P���:�3P��T�z�	3P�164!%�3P��3P�j#�#��*�#�P!� $�%)�)-�#�!%�$(�=��=��T�z�=���:�	=�165�d�166�=� �$�J�
=���*�=��$�;�=��T�z�=�~�%)�#'�	(��(��T�z�(��D�j�	(��(r&rc	�b^�\rSrSr\r\rSr\	S	S\S\167S-S\168S-4U4Sjjj5rSrU=r
$)169�	ModelCardiMrNr�r�r�c�(>�[TU]"XU40UD6$)a5	Initialize a ModelCard from a template. By default, it uses the default template, which can be found here:170https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/templates/modelcard_template.md171 172Templates are Jinja2 templates that can be customized by passing keyword arguments.173 174Args:175    card_data (`huggingface_hub.ModelCardData`):176        A huggingface_hub.ModelCardData instance containing the metadata you want to include in the YAML177        header of the model card on the Hugging Face Hub.178    template_path (`str`, *optional*):179        A path to a markdown file with optional Jinja template variables that can be filled180        in with `template_kwargs`. Defaults to the default template.181 182Returns:183    [`huggingface_hub.ModelCard`]: A ModelCard instance with the specified card data and content from the184    template.185 186Example:187    ```python188    >>> from huggingface_hub import ModelCard, ModelCardData, EvalResult189 190    >>> # Using the Default Template191    >>> card_data = ModelCardData(192    ...     language='en',193    ...     license='mit',194    ...     library_name='timm',195    ...     tags=['image-classification', 'resnet'],196    ...     datasets=['beans'],197    ...     metrics=['accuracy'],198    ... )199    >>> card = ModelCard.from_template(200    ...     card_data,201    ...     model_description='This model does x + y...'202    ... )203 204    >>> # Including Evaluation Results205    >>> card_data = ModelCardData(206    ...     language='en',207    ...     tags=['image-classification', 'resnet'],208    ...     eval_results=[209    ...         EvalResult(210    ...             task_type='image-classification',211    ...             dataset_type='beans',212    ...             dataset_name='Beans',213    ...             metric_type='accuracy',214    ...             metric_value=0.9,215    ...         ),216    ...     ],217    ...     model_name='my-cool-model',218    ... )219    >>> card = ModelCard.from_template(card_data)220 221    >>> # Using a Custom Template222    >>> card_data = ModelCardData(223    ...     language='en',224    ...     tags=['image-classification', 'resnet']225    ... )226    >>> card = ModelCard.from_template(227    ...     card_data=card_data,228    ...     template_path='./src/huggingface_hub/templates/modelcard_template.md',229    ...     custom_template_var='custom value',  # will be replaced in template if it exists230    ... )231 232    ```233��superr��rgr�r�r�r��	__class__s     �r#r��ModelCard.from_templateRs���R�w�$�Y�|�_��_�_r&r6r�)r�r�r�r�rrBr�r�r`r�r[r�r��
__classcell__�r�s@r#r�r�Ms[���#�O�3���I��%)�#'�	H`� �H`��T�z�H`��D�j�	H`��H`r&r�c	�b^�\rSrSr\r\rSr\	S	S\S\234S-S\235S-4U4Sjjj5rSrU=r
$)236�DatasetCardi��datasetNr�r�r�c�(>�[TU]"XU40UD6$)adInitialize a DatasetCard from a template. By default, it uses the default template, which can be found here:237https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/templates/datasetcard_template.md238 239Templates are Jinja2 templates that can be customized by passing keyword arguments.240 241Args:242    card_data (`huggingface_hub.DatasetCardData`):243        A huggingface_hub.DatasetCardData instance containing the metadata you want to include in the YAML244        header of the dataset card on the Hugging Face Hub.245    template_path (`str`, *optional*):246        A path to a markdown file with optional Jinja template variables that can be filled247        in with `template_kwargs`. Defaults to the default template.248 249Returns:250    [`huggingface_hub.DatasetCard`]: A DatasetCard instance with the specified card data and content from the251    template.252 253Example:254    ```python255    >>> from huggingface_hub import DatasetCard, DatasetCardData256 257    >>> # Using the Default Template258    >>> card_data = DatasetCardData(259    ...     language='en',260    ...     license='mit',261    ...     annotations_creators='crowdsourced',262    ...     task_categories=['text-classification'],263    ...     task_ids=['sentiment-classification', 'text-scoring'],264    ...     multilinguality='monolingual',265    ...     pretty_name='My Text Classification Dataset',266    ... )267    >>> card = DatasetCard.from_template(268    ...     card_data,269    ...     pretty_name=card_data.pretty_name,270    ... )271 272    >>> # Using a Custom Template273    >>> card_data = DatasetCardData(274    ...     language='en',275    ...     license='mit',276    ... )277    >>> card = DatasetCard.from_template(278    ...     card_data=card_data,279    ...     template_path='./src/huggingface_hub/templates/datasetcard_template.md',280    ...     custom_template_var='custom value',  # will be replaced in template if it exists281    ... )282 283    ```284r�r�s     �r#r��DatasetCard.from_template�s���r�w�$�Y�|�_��_�_r&r6r�)r�r�r�r�r	rB�TEMPLATE_DATASETCARD_PATHr�r`r�r[r�r�r�r�s@r#r�r��sV���%�O�5���I��%)�#'�	8`�"�8`��T�z�8`��D�j�	8`��8`r&r�c� �\rSrSr\r\rSrSr	g)�	SpaceCardi��spacer6N)285r�r�r�r�rrBr�r�r`r�r6r&r#r�r��s��#�O�3���Ir&r�r�return)�
r(�
286Nc��URS5nURS5nURS5nX-S:XagX1:XaX2:XagX:�agg)z�Detect the line ending of a string. Used by RepoCard to avoid making huge diff on newlines.287 288Uses same implementation as in Hub server, keep it in sync.289 290Returns:291    str: The detected line ending of the string.292r�r(r�rN)�count)r�cr�lf�crlfs    r#r,r,�sQ��293���t�	�B�	���t�	�B��=�=�� �D�	�w�!�|���z�d�j��	�w��r&�294local_pathc��[U5R5n[RU5nU(aLUR	S5n[295R"U5nUb[U[5(aU$[S5eg)Nr4r5)296rr�r7r8r9r;r<r=r>r?)r�rrErFr.s     r#�
metadata_loadr��sh���:��(�(�*�G��#�#�G�,�E���[�[��^�297��~�~�j�)���<�:�d�D�1�1��K��D�E�E�r&r.c���SnSn[RRU5(a~[USSS9nUR	5n[UR[5(aURSnO+[UR[5(aURnSSS5 [USSSS9n[USUS	9n[RU5nU(a2USUR5S298UUS299U3-X6R5S-nOS300UUS301UU3nURU5 UR5 SSS5 g!,(df   N�=f!,(df   g=f)a302Save the metadata dict in the upper YAML part Trying to preserve newlines as303in the existing file. Docs about open() with newline="" parameter:304https://docs.python.org/3/library/functions.html?highlight=open#open Does305not work with "^M" linebreaks, which are replaced by 306 307r(rQ�utf8)rUrVrNrPF)�	sort_keysr*r))�os�path�existsrYrfr=�newlines�tupler[rr7r8�startr:rZ�close)r�r.r*r�readme�	data_yamlrE�outputs        r#�
metadata_saver�s2���J��G�	�w�w�~�~�j�!�!�
�*�b�6�
:�f��k�k�m�G��&�/�/�5�1�1�#�_�_�Q�/�308��F�O�O�S�1�1�#�_�_�309�;�310�j�#�r�F�	;�v��d�e�311�K�	� �'�'��0����_�u�{�{�}�-�#�j�\�)��C�PZ�|�0\�\�_f�gp�gp�gr�gt�_u�u�F��:�,�y�k��Z�L��	�J�F����V������312<�	;�;�
:��313<�	;�s�A+E�3BE�314E�315E"F)�metrics_config�metrics_verified�dataset_config�
dataset_split�dataset_revision�metrics_verification_token�model_pretty_name�task_pretty_name�task_id�metrics_pretty_name�316metrics_id�
metrics_value�dataset_pretty_name�317dataset_idr�r�r�r�r�r�c�B�S[U[UUUUUUUUU	U
U318UUS9
/S90$)u�319Creates a metadata dict with the result from a model evaluated on a dataset.320 321Args:322    model_pretty_name (`str`):323        The name of the model in natural language.324    task_pretty_name (`str`):325        The name of a task in natural language.326    task_id (`str`):327        Example: automatic-speech-recognition. A task id.328    metrics_pretty_name (`str`):329        A name for the metric in natural language. Example: Test WER.330    metrics_id (`str`):331        Example: wer. A metric id from https://hf.co/metrics.332    metrics_value (`Any`):333        The value from the metric. Example: 20.0 or "20.0 ± 1.2".334    dataset_pretty_name (`str`):335        The name of the dataset in natural language.336    dataset_id (`str`):337        Example: common_voice. A dataset id from https://hf.co/datasets.338    metrics_config (`str`, *optional*):339        The name of the metric configuration used in `load_metric()`.340        Example: bleurt-large-512 in `load_metric("bleurt", "bleurt-large-512")`.341    metrics_verified (`bool`, *optional*, defaults to `False`):342        Indicates whether the metrics originate from Hugging Face's [evaluation service](https://huggingface.co/spaces/autoevaluate/model-evaluator) or not. Automatically computed by Hugging Face, do not set.343    dataset_config (`str`, *optional*):344        Example: fr. The name of the dataset configuration used in `load_dataset()`.345    dataset_split (`str`, *optional*):346        Example: test. The name of the dataset split used in `load_dataset()`.347    dataset_revision (`str`, *optional*):348        Example: 5503434ddd753f426f4b38109466949a1217c2bb. The name of the dataset dataset revision349        used in `load_dataset()`.350    metrics_verification_token (`bool`, *optional*):351        A JSON Web Token that is used to verify whether the metrics originate from Hugging Face's [evaluation service](https://huggingface.co/spaces/autoevaluate/model-evaluator) or not.352 353Returns:354    `dict`: a metadata dict with the result from a model evaluated on a dataset.355 356Example:357    ```python358    >>> from huggingface_hub import metadata_eval_result359    >>> results = metadata_eval_result(360    ...         model_pretty_name="RoBERTa fine-tuned on ReactionGIF",361    ...         task_pretty_name="Text Classification",362    ...         task_id="text-classification",363    ...         metrics_pretty_name="Accuracy",364    ...         metrics_id="accuracy",365    ...         metrics_value=0.2662102282047272,366    ...         dataset_pretty_name="ReactionJPEG",367    ...         dataset_id="julien-c/reactionjpeg",368    ...         dataset_config="default",369    ...         dataset_split="test",370    ... )371    >>> results == {372    ...     'model-index': [373    ...         {374    ...             'name': 'RoBERTa fine-tuned on ReactionGIF',375    ...             'results': [376    ...                 {377    ...                     'task': {378    ...                         'type': 'text-classification',379    ...                         'name': 'Text Classification'380    ...                     },381    ...                     'dataset': {382    ...                         'name': 'ReactionJPEG',383    ...                         'type': 'julien-c/reactionjpeg',384    ...                         'config': 'default',385    ...                         'split': 'test'386    ...                     },387    ...                     'metrics': [388    ...                         {389    ...                             'type': 'accuracy',390    ...                             'value': 0.2662102282047272,391    ...                             'name': 'Accuracy',392    ...                             'verified': False393    ...                         }394    ...                     ]395    ...                 }396    ...             ]397    ...         }398    ...     ]399    ... }400    True401 402    ```403�model-index)
�	task_name�	task_type�metric_name�metric_type�metric_value�dataset_name�dataset_type�
metric_config�verified�verify_tokenr�r�r�)�404model_name�eval_results)r
r405)r�r�r�r�r�r�r�r�r�r�r�r�r�r�s              r#�metadata_eval_resultr�'sQ��R	�2�(��.�%� 3� *�!.�!4�!+�"0�-�!;�#1�"/�%5���406��r&)r`�	overwriterarxryrzr{r|rw�metadatar`r�rarxryrzr{r|c���UbUOSnUbUS:Xa[n407O(US:Xa[n408OUS:Xa[n409O[SU35eU410R	XUS9nUR5GH�up�US:XGa=S	U
S411;a[USU5U
S412S	'[U
5up�URRc"X�RlX�Rl
MoURRnUH�nSnUH�nURU5(dMUU:wa-U(d&[S
URSUR S35eSnUR"UlUR$SLdMrUR&UlM� U(aM�URRR)U5 M� GMJURR+U5b5U(d.URR+U5U
:wa[SUS35eX�RU'GM� UR-UUUUUUUU	S9$![413a. US:Xa[S5eU414R
[55nGNf=f)a415Updates the metadata in the README.md of a repository on the Hugging Face Hub.416If the README.md file doesn't exist yet, a new one is created with metadata and417the default ModelCard or DatasetCard template. For `space` repo, an error is thrown418as a Space cannot exist without a `README.md` file.419 420Args:421    repo_id (`str`):422        The name of the repository.423    metadata (`dict`):424        A dictionary containing the metadata to be updated.425    repo_type (`str`, *optional*):426        Set to `"dataset"` or `"space"` if updating to a dataset or space,427        `None` or `"model"` if updating to a model. Default is `None`.428    overwrite (`bool`, *optional*, defaults to `False`):429        If set to `True` an existing field can be overwritten, otherwise430        attempting to overwrite an existing field will cause an error.431    token (`str`, *optional*):432        The Hugging Face authentication token.433    commit_message (`str`, *optional*):434        The summary / title / first line of the generated commit. Defaults to435        `f"Update metadata with huggingface_hub"`436    commit_description (`str` *optional*)437        The description of the generated commit438    revision (`str`, *optional*):439        The git revision to commit from. Defaults to the head of the440        `"main"` branch.441    create_pr (`boolean`, *optional*):442        Whether or not to create a Pull Request from `revision` with that commit.443        Defaults to `False`.444    parent_commit (`str`, *optional*):445        The OID / SHA of the parent commit, as a hexadecimal string. Shorthands (7 first characters) are also supported.446        If specified and `create_pr` is `False`, the commit will fail if `revision` does not point to `parent_commit`.447        If specified and `create_pr` is `True`, the pull request will be created from `parent_commit`.448        Specifying `parent_commit` ensures the repo has not changed before committing the changes, and can be449        especially useful if the repo is updated / committed too concurrently.450Returns:451    `str`: URL of the commit which updated the card metadata.452 453Example:454    ```python455    >>> from huggingface_hub import metadata_update456    >>> metadata = {'model-index': [{'name': 'RoBERTa fine-tuned on ReactionGIF',457    ...             'results': [{'dataset': {'name': 'ReactionGIF',458    ...                                      'type': 'julien-c/reactiongif'},459    ...                           'metrics': [{'name': 'Recall',460    ...                                        'type': 'recall',461    ...                                        'value': 0.7762102282047272}],462    ...                          'task': {'name': 'Text Classification',463    ...                                   'type': 'text-classification'}}]}]}464    >>> url = metadata_update("hf-internal-testing/reactiongif-roberta-card", metadata)465 466    ```467z$Update metadata with huggingface_hubrr�r�zUnknown repo_type: )rar`zJCannot update metadata on a Space that doesn't contain a `README.md` file.r��namerr�Fz6You passed a new value for the existing metric 'name: z, type: z6'. Set `overwrite=True` to overwrite existing metrics.Tz9You passed a new value for the existing meta data field 'z7'. Set `overwrite=True` to overwrite existing metadata.)rar`rxryr{rzr|)r�r�rr?rirr�r�items�getattrrr.r�r��is_equal_except_valuer�r�r�r�r��append�getr�)rwr�r`r�rarxryrzr{r|�468card_class�card�key�valuer��new_results�existing_results�469new_result�result_found�existing_results                    r#�metadata_updater��ss��H(6�'A�^�Gm�N���I��0��470�	�i�	� �471�	�g�	��472��.�y�k�:�;�;�4����w�y��I���n�n�&�473���-���U�1�X�%�#*�4��w�#G��a��� �&A�%�&H�#�J��y�y�%�%�-�)4�	�	�&�'1�	�	�$�#'�9�9�#9�#9� �#.�J�#(�L�+;��%�;�;�O�L�L�)�_�<�Y�&0�%/�/9�/E�/E�.F�h�'1�'=�'=�&>�?F�%F�'"�!"�,0�L�;E�;R�;R�O�8�.�7�7�4�?�?I�?V�?V�� <�,<�(�<��	�	�.�.�5�5�j�A�!#.�&�y�y�}�}�S�!�-�i�D�I�I�M�M�RU�DV�Z_�D_� �O�PS�u�UL�L���474"'�	�	�#��W'�Z������%�-���#��	�	��k�4�����i�j�j��'�'��475�3��
4�s�H%�%4I�I)7r��re�pathlibr�typingrrr;�huggingface_hub.file_downloadr�huggingface_hub.hf_apir�huggingface_hub.repocard_datarr	r476rrr
r�huggingface_hub.utilsrrrrrrQr�errorsr�utilsrrr�477get_loggerr�r@�__file__rWr�r��compiler7rr�r�r�r[r,r>r�r�r�r�r�r6r&r#�<module>rs���	�	����9�.����r�q��&�H�H�478�	�	�H�	%���x�.�/�/�+�=�@W�W�� ��N�1�1�K�?�B[�[���:�:�R�S��e�e�P	N`��N`�b>`�(�>`�B�������1I�)J��*479�c�D�j�480�T�D�[�481��c�D�j������T"&�"�!%� $�#'�-1�}��}��}��	}�482�}��
}��}��}��}��$�J�}��}��$�J�}���:�}��D�j�}�!$�d�483�}� 484�!}�@�485!���!%�%)��� $�R�
�R��R��T�z�	R�486�R���:�
R��$�J�R��d�487�R��D�j�R��R���:�R�	�R��Rr&
codekingpro/portable-devtools · Team Ai