Ë
    Q^(h­‡  ã                   ó  — d dl Z d dlZd dlmZ d dlmZmZmZmZm	Z	m
Z
 d dlZd dlZd dlmZ d dlmZ d dlmZmZmZmZmZmZmZ d dlmZmZmZ dd	lmZ dd
lm Z  ddl!m"Z"m#Z#m$Z$  e#jJ                  e&«      Z' ee(«      jR                  dz  dz  Z* ee(«      jR                  dz  dz  Z+ ejX                  d«      Z- G d„ d«      Z. G d„ de.«      Z/ G d„ de.«      Z0 G d„ de.«      Z1de2ded   fd„Z3de
e2ef   dee   fd„Z4de
e2ef   deddfd„Z5dd ddddd!œd"e2d#e2d$e2d%e2d&e2d'ed(e2d)e2d*ee2   d+e6d,ee2   d-ee2   d.ee2   d/ee2   defd0„Z7e$dd ddddd dd1œd2e2d3ed4ee2   d5e6d6ee2   d7ee2   d8ee2   d9ee2   d:e6d;ee2   de2fd<„«       Z8y)=é    N)ÚPath)ÚAnyÚDictÚLiteralÚOptionalÚTypeÚUnion)Úhf_hub_download)Úupload_file)ÚCardDataÚDatasetCardDataÚ
EvalResultÚModelCardDataÚSpaceCardDataÚeval_results_to_model_indexÚmodel_index_to_eval_results)Úget_sessionÚis_jinja_availableÚ	yaml_dumpé   )Ú	constants)ÚEntryNotFoundError)ÚSoftTemporaryDirectoryÚloggingÚvalidate_hf_hub_argsÚ	templateszmodelcard_template.mdzdatasetcard_template.mdz1^(\s*---[\r\n]+)([\S\s]*?)([\r\n]+---(\r\n|\n|$))c                   óf  — e Zd ZeZeZdZddede	fd„Z
ed„ «       Zej                  defd„«       Zd„ Zdeeef   fd	„Ze	 	 	 ddeeef   dee   dee   de	fd„«       Zddee   fd„Z	 	 	 	 	 	 	 ddedee   dee   dee   dee   dee   dee	   dee   fd„Ze	 	 ddedee   dee   fd„«       Zy
) ÚRepoCardÚmodelÚcontentÚignore_metadata_errorsc                 ó    — || _         || _        y)a¶  Initialize a RepoCard from string content. The content should be a
        Markdown file with a YAML block at the beginning and a Markdown body.

        Args:
            content (`str`): The content of the Markdown file.

        Example:
            ```python
            >>> from huggingface_hub.repocard import RepoCard
            >>> text = '''
            ... ---
            ... language: en
            ... license: mit
            ... ---
            ...
            ... # My repo
            ... '''
            >>> card = RepoCard(text)
            >>> card.data.to_dict()
            {'language': 'en', 'license': 'mit'}
            >>> card.text
            '\n# My repo\n'

            ```
        <Tip>
        Raises the following error:

            - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
              when the content of the repo card metadata is not a dictionary.

        </Tip>
        N)r!   r    )Úselfr    r!   s      úV/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/huggingface_hub/repocard.pyÚ__init__zRepoCard.__init__+   s   € ðH '=ˆÔ#Øˆ�ó    c                 ó®   — t        | j                  «      xs d}d|› | j                  j                  || j                  ¬«      › |› d|› | j
                  › �S )zLThe content of the RepoCard, including the YAML block and the Markdown body.ú
ú---)Ú
line_breakÚoriginal_order)Ú_detect_line_endingÚ_contentÚdataÚto_yamlÚ_original_orderÚtext)r#   r*   s     r$   r    zRepoCard.contentR   s}   € ô )¨¯©Ó7Ò?¸4ˆ
Ø�Z�L §¡×!2Ñ!2¸jÐY]×YmÑYmÐ!2Ó!nÐ oÐpzÐo{Ð{~ð  @Jð  Kð  LP÷  LUñ  LUð  KVð  Wð  	Wr&   c                 ó¼  — || _         t        j                  |«      }|r]|j                  d«      }||j	                  «       d | _        t        j                  |«      }|€i }t        |t        «      s)t        d«      ‚t        j                  d«       i }|| _         | j                  di |¤d| j                  i¤Ž| _        t!        |j#                  «       «      | _        y)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Ú
isinstanceÚdictÚ
ValueErrorÚloggerÚwarningÚcard_data_classr!   r.   ÚlistÚkeysr0   )r#   r    ÚmatchÚ
yaml_blockÚ	data_dicts        r$   r    zRepoCard.contentX   sÁ   € ð  ˆŒä ×'Ñ'¨Ó0ˆÙàŸ™ Q›ˆJØ §	¡	£ Ð.ˆDŒIÜŸ™ zÓ2ˆIàÐ Ø�	ô ˜i¬Ô.Ü Ð!LÓMÐMô �N‰NÐ_Ô`ØˆIØˆDŒIà(�D×(Ñ(Ñi¨9ÑiÈT×MhÑMhÒiˆŒ	Ü# I§N¡NÓ$4Ó5ˆÕr&   c                 ó   — | j                   S ©N)r    )r#   s    r$   Ú__str__zRepoCard.__str__s   s   € Ø�|‰|Ðr&   Úfilepathc                 óÐ   — t        |«      }|j                  j                  dd¬«       t        |ddd¬«      5 }|j	                  t        | «      «       ddd«       y# 1 sw Y   yxY w)a{  Save a RepoCard to a file.

        Args:
            filepath (`Union[Path, str]`): Filepath to the markdown file to save.

        Example:
            ```python
            >>> from huggingface_hub.repocard import RepoCard
            >>> card = RepoCard("---\nlanguage: en\n---\n# This is a test repo card")
            >>> card.save("/tmp/test.md")

            ```
        T)ÚparentsÚexist_okÚwÚ úutf-8©ÚmodeÚnewlineÚencodingN)r   ÚparentÚmkdirÚopenÚwriteÚstr)r#   rJ   Úfs      r$   ÚsavezRepoCard.savev   sY   € ô ˜“>ˆØ�‰×Ñ d°TÐÔ:ä�( ¨b¸7ÔCð 	ÀqØ�G‰G”C˜“IÔ÷	÷ 	ñ 	ús   ¸AÁA%NÚrepo_id_or_pathÚ	repo_typeÚtokenc                 óx  — t        |«      j                  «       rt        |«      }nTt        |t        «      r5t        t	        |t
        j                  |xs | j                  |¬«      «      }nt        d|› d�«      ‚|j                  ddd¬«      5 } | |j                  «       |¬«      cd	d	d	«       S # 1 sw Y   y	xY w)
a˜  Initialize a RepoCard from a Hugging Face Hub repo's README.md or a local filepath.

        Args:
            repo_id_or_path (`Union[str, Path]`):
                The repo ID associated with a Hugging Face Hub repo or a local filepath.
            repo_type (`str`, *optional*):
                The type of Hugging Face repo to push to. Defaults to None, which will use use "model". Other options
                are "dataset" and "space". Not used when loading from a local filepath. If this is called from a child
                class, the default value will be the child class's `repo_type`.
            token (`str`, *optional*):
                Authentication token, obtained with `huggingface_hub.HfApi.login` method. Will default to the stored token.
            ignore_metadata_errors (`str`):
                If True, errors while parsing the metadata section will be ignored. Some information might be lost during
                the process. Use it at your own risk.

        Returns:
            [`huggingface_hub.repocard.RepoCard`]: The RepoCard (or subclass) initialized from the repo's
                README.md file or filepath.

        Example:
            ```python
            >>> from huggingface_hub.repocard import RepoCard
            >>> card = RepoCard.load("nateraw/food")
            >>> assert card.data.tags == ["generated_from_trainer", "image-classification", "pytorch"]

            ```
        )r]   r^   z.Cannot load RepoCard: path not found on disk (z).ÚrrO   rP   rQ   )r!   N)r   Úis_filer<   rY   r
   r   ÚREPOCARD_NAMEr]   r>   rW   Úread)Úclsr\   r]   r^   r!   Ú	card_pathrZ   s          r$   ÚloadzRepoCard.loadŠ   s°   € ôH �Ó ×(Ñ(Ô*Ü˜_Ó-‰IÜ˜¬Ô-ÜÜØ#Ü×+Ñ+Ø'Ò8¨3¯=©=Øô	ó‰Iô ÐMÈoÐM^Ð^`ÐaÓbÐbð �^‰^ ¨b¸7ˆ^ÓCð 	PÀqÙ�q—v‘v“xÐ8NÔO÷	P÷ 	Pò 	Pús   ÂB0Â0B9c                 ó8  — |xs | j                   }|t        | «      dœ}ddi}	 t        «       j                  d||¬«      }|j	                  «        y# t
        j                  j                  $ r+}j                  dk(  rt        |j                  «      ‚|‚d}~ww xY w)a†  Validates card against Hugging Face Hub's card validation logic.
        Using this function requires access to the internet, so it is only called
        internally by [`huggingface_hub.repocard.RepoCard.push_to_hub`].

        Args:
            repo_type (`str`, *optional*, defaults to "model"):
                The type of Hugging Face repo to push to. Options are "model", "dataset", and "space".
                If this function is called from a child class, the default will be the child class's `repo_type`.

        <Tip>
        Raises the following errors:

            - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
              if the card fails validation checks.
            - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)
              if the request to the Hub API fails for any other reason.

        </Tip>
        )ÚrepoTyper    ÚAcceptz
text/plainz(https://huggingface.co/api/validate-yaml)Úheadersi�  N)r]   rY   r   ÚpostÚraise_for_statusÚrequestsÚ
exceptionsÚ	HTTPErrorÚstatus_coder>   r1   )r#   r]   Úbodyrj   r`   Úexcs         r$   ÚvalidatezRepoCard.validateÀ   s™   € ð, Ò/ §¡ˆ	ð "Ü˜4“yñ
ˆð ˜\Ð*ˆð	Ü“×"Ñ"Ð#MÈtÐ]dÐ"ÓeˆAØ×ÑÕ øÜ×"Ñ"×,Ñ,ò 	Ø�}‰} Ò#Ü  §¡Ó(Ð(à�	ûð		ús   ¤,A ÁBÁ.&BÂBÚrepo_idÚcommit_messageÚcommit_descriptionÚrevisionÚ	create_prÚparent_commitc	                 óN  — |xs | j                   }| j                  |¬«       t        «       5 }	t        |	«      t        j
                  z  }
|
j                  t        | «      «       t        t        |
«      t        j
                  ||||||||¬«
      }ddd«       |S # 1 sw Y   S xY w)aA  Push a RepoCard to a Hugging Face Hub repo.

        Args:
            repo_id (`str`):
                The repo ID of the Hugging Face Hub repo to push to. Example: "nateraw/food".
            token (`str`, *optional*):
                Authentication token, obtained with `huggingface_hub.HfApi.login` method. Will default to
                the stored token.
            repo_type (`str`, *optional*, defaults to "model"):
                The type of Hugging Face repo to push to. Options are "model", "dataset", and "space". If this
                function is called by a child class, it will default to the child class's `repo_type`.
            commit_message (`str`, *optional*):
                The summary / title / first line of the generated commit.
            commit_description (`str`, *optional*)
                The description of the generated commit.
            revision (`str`, *optional*):
                The git revision to commit from. Defaults to the head of the `"main"` branch.
            create_pr (`bool`, *optional*):
                Whether or not to create a Pull Request with this commit. Defaults to `False`.
            parent_commit (`str`, *optional*):
                The OID / SHA of the parent commit, as a hexadecimal string. Shorthands (7 first characters) are also supported.
                If specified and `create_pr` is `False`, the commit will fail if `revision` does not point to `parent_commit`.
                If specified and `create_pr` is `True`, the pull request will be created from `parent_commit`.
                Specifying `parent_commit` ensures the repo has not changed before committing the changes, and can be
                especially useful if the repo is updated / committed to concurrently.
        Returns:
            `str`: URL of the commit which updated the card metadata.
        )r]   )
Úpath_or_fileobjÚpath_in_report   r^   r]   ru   rv   rx   rw   ry   N)	r]   rs   r   r   r   rb   Ú
write_textrY   r   )r#   rt   r^   r]   ru   rv   rw   rx   ry   ÚtmpdirÚtmp_pathÚurls               r$   Úpush_to_hubzRepoCard.push_to_hubç   s¡   € ðR Ò/ §¡ˆ	ð 	�‰ 	ˆÔ*ä#Ó%ð 	¨Ü˜F“|¤i×&=Ñ&=Ñ=ˆHØ×Ñ¤ D£	Ô*ÜÜ # H£Ü&×4Ñ4ØØØ#Ø-Ø#5Ø#Ø!Ø+ôˆC÷	ð ˆ
÷	ð ˆ
ús   ­A#BÂB$Ú	card_dataÚtemplate_pathÚtemplate_strc                 óŠ  — t        «       rddl}nt        d«      ‚|j                  «       j	                  «       }|j                  |«       |�t        |«      j                  «       }|€#t        | j                  «      j                  «       }|j                  |«      } |j                  dd|j                  «       i|¤Ž} | |«      S )a'  Initialize a RepoCard from a template. By default, it uses the default template.

        Templates are Jinja2 templates that can be customized by passing keyword arguments.

        Args:
            card_data (`huggingface_hub.CardData`):
                A huggingface_hub.CardData instance containing the metadata you want to include in the YAML
                header of the repo card on the Hugging Face Hub.
            template_path (`str`, *optional*):
                A path to a markdown file with optional Jinja template variables that can be filled
                in with `template_kwargs`. Defaults to the default template.

        Returns:
            [`huggingface_hub.repocard.RepoCard`]: A RepoCard instance with the specified card data and content from the
            template.
        r   NzjUsing RepoCard.from_template requires Jinja2 to be installed. Please install it with `pip install Jinja2`.r‚   r5   )r   Újinja2ÚImportErrorÚto_dictÚcopyÚupdater   Ú	read_textÚdefault_template_pathÚTemplateÚrenderr/   )	rd   r‚   rƒ   r„   Útemplate_kwargsr†   ÚkwargsÚtemplater    s	            r$   Úfrom_templatezRepoCard.from_template&  sµ   € ô0 ÔÜäð9óð ð
 ×"Ñ"Ó$×)Ñ)Ó+ˆØ�‰�oÔ&àÐ$Ü Ó.×8Ñ8Ó:ˆLØÐÜ × 9Ñ 9Ó:×DÑDÓFˆLØ—?‘? <Ó0ˆØ!�(—/‘/ÑJ¨I×,=Ñ,=Ó,?ÐJÀ6ÑJˆÙ�7‹|Ðr&   )F)NNFrH   )NNNNNNN©NN)Ú__name__Ú
__module__Ú__qualname__r   rA   ÚTEMPLATE_MODELCARD_PATHrŒ   r]   rY   Úboolr%   Úpropertyr    ÚsetterrI   r	   r   r[   Úclassmethodr   rf   rs   r�   r’   r5   r&   r$   r   r   &   sª  „ Ø€OØ3ÐØ€Iñ% ð %¸Tó %ðN ñWó ðWð
 ‡^�^ð6˜sò 6ó ð6ò4ð˜U 4¨ 9Ñ-ó ð( ð $(Ø#Ø',ñ3Pà˜s D˜yÑ)ð3Pð ˜C‘=ð3Pð ˜‰}ð	3Pð
 !%ò3Pó ð3Pñj% (¨3¡-ó %ðT  $Ø#'Ø(,Ø,0Ø"&Ø$(Ø'+ñ=àð=ð ˜‰}ð=ð ˜C‘=ð	=ð
 ! ™ð=ð % S™Mð=ð ˜3‘-ð=ð ˜D‘>ð=ð   ‘}ó=ð~ ð (,Ø&*ñ	(àð(ð   ‘}ð(ð ˜s‘mò	(ó ñ(r&   r   c            	       óT   ‡ — e Zd ZeZeZdZe	 	 ddede	e
   de	e
   fˆ fd„«       Zˆ xZS )Ú	ModelCardr   r‚   rƒ   r„   c                 ó(   •— t        ‰| �  |||fi |¤ŽS )aõ
  Initialize a ModelCard from a template. By default, it uses the default template, which can be found here:
        https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/templates/modelcard_template.md

        Templates are Jinja2 templates that can be customized by passing keyword arguments.

        Args:
            card_data (`huggingface_hub.ModelCardData`):
                A huggingface_hub.ModelCardData instance containing the metadata you want to include in the YAML
                header of the model card on the Hugging Face Hub.
            template_path (`str`, *optional*):
                A path to a markdown file with optional Jinja template variables that can be filled
                in with `template_kwargs`. Defaults to the default template.

        Returns:
            [`huggingface_hub.ModelCard`]: A ModelCard instance with the specified card data and content from the
            template.

        Example:
            ```python
            >>> from huggingface_hub import ModelCard, ModelCardData, EvalResult

            >>> # Using the Default Template
            >>> card_data = ModelCardData(
            ...     language='en',
            ...     license='mit',
            ...     library_name='timm',
            ...     tags=['image-classification', 'resnet'],
            ...     datasets=['beans'],
            ...     metrics=['accuracy'],
            ... )
            >>> card = ModelCard.from_template(
            ...     card_data,
            ...     model_description='This model does x + y...'
            ... )

            >>> # Including Evaluation Results
            >>> card_data = ModelCardData(
            ...     language='en',
            ...     tags=['image-classification', 'resnet'],
            ...     eval_results=[
            ...         EvalResult(
            ...             task_type='image-classification',
            ...             dataset_type='beans',
            ...             dataset_name='Beans',
            ...             metric_type='accuracy',
            ...             metric_value=0.9,
            ...         ),
            ...     ],
            ...     model_name='my-cool-model',
            ... )
            >>> card = ModelCard.from_template(card_data)

            >>> # Using a Custom Template
            >>> card_data = ModelCardData(
            ...     language='en',
            ...     tags=['image-classification', 'resnet']
            ... )
            >>> card = ModelCard.from_template(
            ...     card_data=card_data,
            ...     template_path='./src/huggingface_hub/templates/modelcard_template.md',
            ...     custom_template_var='custom value',  # will be replaced in template if it exists
            ... )

            ```
        ©Úsuperr’   ©rd   r‚   rƒ   r„   r�   Ú	__class__s        €r$   r’   zModelCard.from_templateW  s   ø€ ôR ‰wÑ$ Y°¸|Ñ_ÈÑ_Ð_r&   r“   )r”   r•   r–   r   rA   r—   rŒ   r]   r›   r   rY   r’   Ú__classcell__©r¢   s   @r$   r�   r�   R  s[   ø„ Ø#€OØ3ÐØ€Iàð (,Ø&*ñ	H`à ðH`ð   ‘}ðH`ð ˜s‘mô	H`ó ôH`r&   r�   c            	       óT   ‡ — e Zd ZeZeZdZe	 	 ddede	e
   de	e
   fˆ fd„«       Zˆ xZS )ÚDatasetCardÚdatasetr‚   rƒ   r„   c                 ó(   •— t        ‰| �  |||fi |¤ŽS )a¬  Initialize a DatasetCard from a template. By default, it uses the default template, which can be found here:
        https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/templates/datasetcard_template.md

        Templates are Jinja2 templates that can be customized by passing keyword arguments.

        Args:
            card_data (`huggingface_hub.DatasetCardData`):
                A huggingface_hub.DatasetCardData instance containing the metadata you want to include in the YAML
                header of the dataset card on the Hugging Face Hub.
            template_path (`str`, *optional*):
                A path to a markdown file with optional Jinja template variables that can be filled
                in with `template_kwargs`. Defaults to the default template.

        Returns:
            [`huggingface_hub.DatasetCard`]: A DatasetCard instance with the specified card data and content from the
            template.

        Example:
            ```python
            >>> from huggingface_hub import DatasetCard, DatasetCardData

            >>> # Using the Default Template
            >>> card_data = DatasetCardData(
            ...     language='en',
            ...     license='mit',
            ...     annotations_creators='crowdsourced',
            ...     task_categories=['text-classification'],
            ...     task_ids=['sentiment-classification', 'text-scoring'],
            ...     multilinguality='monolingual',
            ...     pretty_name='My Text Classification Dataset',
            ... )
            >>> card = DatasetCard.from_template(
            ...     card_data,
            ...     pretty_name=card_data.pretty_name,
            ... )

            >>> # Using a Custom Template
            >>> card_data = DatasetCardData(
            ...     language='en',
            ...     license='mit',
            ... )
            >>> card = DatasetCard.from_template(
            ...     card_data=card_data,
            ...     template_path='./src/huggingface_hub/templates/datasetcard_template.md',
            ...     custom_template_var='custom value',  # will be replaced in template if it exists
            ... )

            ```
        rŸ   r¡   s        €r$   r’   zDatasetCard.from_template¨  s   ø€ ôr ‰wÑ$ Y°¸|Ñ_ÈÑ_Ð_r&   r“   )r”   r•   r–   r   rA   ÚTEMPLATE_DATASETCARD_PATHrŒ   r]   r›   r   rY   r’   r£   r¤   s   @r$   r¦   r¦   £  sV   ø„ Ø%€OØ5ÐØ€Iàð (,Ø&*ñ	8`à"ð8`ð   ‘}ð8`ð ˜s‘mô	8`ó ô8`r&   r¦   c                   ó   — e Zd ZeZeZdZy)Ú	SpaceCardÚspaceN)r”   r•   r–   r   rA   r—   rŒ   r]   r5   r&   r$   r«   r«   ä  s   „ Ø#€OØ3ÐØ�Ir&   r«   r    Úreturn)úr(   ú
Nc                 óž   — | j                  d«      }| j                  d«      }| j                  d«      }||z   dk(  ry||k(  r||k(  ry||kD  ryy)zäDetect the line ending of a string. Used by RepoCard to avoid making huge diff on newlines.

    Uses same implementation as in Hub server, keep it in sync.

    Returns:
        str: The detected line ending of the string.
    r®   r(   r¯   r   N)Úcount)r    ÚcrÚlfÚcrlfs       r$   r,   r,   ê  sY   € ð 
�‰�tÓ	€BØ	�‰�tÓ	€BØ�=‰=˜Ó €DØ	ˆB�w�!‚|ØØˆr‚z�d˜b’jØØ	ˆB‚wØàr&   Ú
local_pathc                 óî   — t        | «      j                  «       }t        j                  |«      }|rE|j	                  d«      }t        j                  |«      }|�t        |t        «      r|S t        d«      ‚y )Nr3   r4   )
r   r‹   r6   r7   r8   r:   r;   r<   r=   r>   )rµ   r    rD   rE   r.   s        r$   Úmetadata_loadr·   ÿ  se   € Ü�:Ó×(Ñ(Ó*€GÜ×#Ñ# GÓ,€EÙØ—[‘[ “^ˆ
Ü�~‰~˜jÓ)ˆØˆ<œ: d¬DÔ1ØˆKÜÐDÓEÐEàr&   r.   c                 ó¤  — d}d}t         j                  j                  | «      rxt        | ddd¬«      5 }|j	                  «       }t        |j                  t        «      r|j                  d   }n&t        |j                  t        «      r|j                  }ddd«       t        | ddd¬«      5 }t        |d	|¬
«      }t        j                  |«      }|r3|d|j                  «        d|› |› d|› �z   ||j                  «       d z   }nd|› |› d|› |› �}|j                  |«       |j                  «        ddd«       y# 1 sw Y   Œ§xY w# 1 sw Y   yxY w)a&  
    Save the metadata dict in the upper YAML part Trying to preserve newlines as
    in the existing file. Docs about open() with newline="" parameter:
    https://docs.python.org/3/library/functions.html?highlight=open#open Does
    not work with "^M" linebreaks, which are replaced by 

    r(   rO   r`   Úutf8)rS   rT   r   NrN   F)Ú	sort_keysr*   r)   )ÚosÚpathÚexistsrW   rc   r<   ÚnewlinesÚtuplerY   r   r6   r7   Ústartr9   rX   Úclose)rµ   r.   r*   r    ÚreadmeÚ	data_yamlrD   Úoutputs           r$   Úmetadata_saverÅ     s>  € ð €JØ€Gä	‡w�w‡~�~�jÔ!Ü�*˜c¨2¸Ô?ð 	-À6Ø—k‘k“mˆGÜ˜&Ÿ/™/¬5Ô1Ø#Ÿ_™_¨QÑ/‘
Ü˜FŸO™O¬SÔ1Ø#Ÿ_™_�
÷	-ô 
ˆj˜# r°FÔ	;ð 
¸vÜ˜d¨eÀ
ÔKˆ	ä ×'Ñ'¨Ó0ˆÙØ˜_˜uŸ{™{›}Ð-°#°j°\À)ÀÈCÐPZÈ|Ð0\Ñ\Ð_fÐgl×gpÑgpÓgrÐgtÐ_uÑu‰Fà˜:˜, y k°°Z°LÀÀ	ÐJˆFà�‰�VÔØ�‰Œ÷
ð 
÷	-ð 	-ú÷
ð 
ús   ³A!D:Â+BEÄ:EÅE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Ú
metrics_idÚmetrics_valueÚdataset_pretty_nameÚ
dataset_idrÆ   rÇ   rÈ   rÉ   rÊ   rË   c                 óN   — dt        | t        |||||||||	||
||¬«      g¬«      iS )u  
    Creates a metadata dict with the result from a model evaluated on a dataset.

    Args:
        model_pretty_name (`str`):
            The name of the model in natural language.
        task_pretty_name (`str`):
            The name of a task in natural language.
        task_id (`str`):
            Example: automatic-speech-recognition. A task id.
        metrics_pretty_name (`str`):
            A name for the metric in natural language. Example: Test WER.
        metrics_id (`str`):
            Example: wer. A metric id from https://hf.co/metrics.
        metrics_value (`Any`):
            The value from the metric. Example: 20.0 or "20.0 Â± 1.2".
        dataset_pretty_name (`str`):
            The name of the dataset in natural language.
        dataset_id (`str`):
            Example: common_voice. A dataset id from https://hf.co/datasets.
        metrics_config (`str`, *optional*):
            The name of the metric configuration used in `load_metric()`.
            Example: bleurt-large-512 in `load_metric("bleurt", "bleurt-large-512")`.
        metrics_verified (`bool`, *optional*, defaults to `False`):
            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.
        dataset_config (`str`, *optional*):
            Example: fr. The name of the dataset configuration used in `load_dataset()`.
        dataset_split (`str`, *optional*):
            Example: test. The name of the dataset split used in `load_dataset()`.
        dataset_revision (`str`, *optional*):
            Example: 5503434ddd753f426f4b38109466949a1217c2bb. The name of the dataset dataset revision
            used in `load_dataset()`.
        metrics_verification_token (`bool`, *optional*):
            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.

    Returns:
        `dict`: a metadata dict with the result from a model evaluated on a dataset.

    Example:
        ```python
        >>> from huggingface_hub import metadata_eval_result
        >>> results = metadata_eval_result(
        ...         model_pretty_name="RoBERTa fine-tuned on ReactionGIF",
        ...         task_pretty_name="Text Classification",
        ...         task_id="text-classification",
        ...         metrics_pretty_name="Accuracy",
        ...         metrics_id="accuracy",
        ...         metrics_value=0.2662102282047272,
        ...         dataset_pretty_name="ReactionJPEG",
        ...         dataset_id="julien-c/reactionjpeg",
        ...         dataset_config="default",
        ...         dataset_split="test",
        ... )
        >>> results == {
        ...     'model-index': [
        ...         {
        ...             'name': 'RoBERTa fine-tuned on ReactionGIF',
        ...             'results': [
        ...                 {
        ...                     'task': {
        ...                         'type': 'text-classification',
        ...                         'name': 'Text Classification'
        ...                     },
        ...                     'dataset': {
        ...                         'name': 'ReactionJPEG',
        ...                         'type': 'julien-c/reactionjpeg',
        ...                         'config': 'default',
        ...                         'split': 'test'
        ...                     },
        ...                     'metrics': [
        ...                         {
        ...                             'type': 'accuracy',
        ...                             'value': 0.2662102282047272,
        ...                             'name': 'Accuracy',
        ...                             'verified': False
        ...                         }
        ...                     ]
        ...                 }
        ...             ]
        ...         }
        ...     ]
        ... }
        True

        ```
    úmodel-index)Ú	task_nameÚ	task_typeÚmetric_nameÚmetric_typeÚmetric_valueÚdataset_nameÚdataset_typeÚmetric_configÚverifiedÚverify_tokenrÈ   rÉ   rÊ   )Ú
model_nameÚeval_results)r   r   )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ôðô
ðð r&   )r]   Ú	overwriter^   ru   rv   rw   rx   ry   rt   Úmetadatar]   rã   r^   ru   rv   rw   rx   ry   c          
      ó|  — |�|nd}|�|dk(  rt         }
n&|dk(  rt        }
n|dk(  rt        }
nt        d|› �«      ‚	 |
j	                  | ||¬«      }|j                  «       D �]ˆ  \  }}|dk(  �r#d	|d
   vrt        |d| «      |d
   d	<   t        |«      \  }}|j                  j                  €#||j                  _        ||j                  _        Œn|j                  j                  }|D ]¥  }d}|D ]t  }|j                  |«      sŒ||k7  r(|s&t        d|j                  › d|j                   › d�«      ‚d}|j"                  |_        |j$                  du sŒd|j&                  |_        Œv |rŒ�|j                  j                  j)                  |«       Œ§ �Œ0|j                  j+                  |«      �/|s-|j                  j+                  |«      |k7  rt        d|› d�«      ‚||j                  |<   �Œ‹ |j-                  | |||||||	¬«      S # t
        $ r- |dk(  rt        d«      ‚|
j                  t        «       «      }Y �Œêw xY w)aã  
    Updates the metadata in the README.md of a repository on the Hugging Face Hub.
    If the README.md file doesn't exist yet, a new one is created with metadata and an
    the default ModelCard or DatasetCard template. For `space` repo, an error is thrown
    as a Space cannot exist without a `README.md` file.

    Args:
        repo_id (`str`):
            The name of the repository.
        metadata (`dict`):
            A dictionary containing the metadata to be updated.
        repo_type (`str`, *optional*):
            Set to `"dataset"` or `"space"` if updating to a dataset or space,
            `None` or `"model"` if updating to a model. Default is `None`.
        overwrite (`bool`, *optional*, defaults to `False`):
            If set to `True` an existing field can be overwritten, otherwise
            attempting to overwrite an existing field will cause an error.
        token (`str`, *optional*):
            The Hugging Face authentication token.
        commit_message (`str`, *optional*):
            The summary / title / first line of the generated commit. Defaults to
            `f"Update metadata with huggingface_hub"`
        commit_description (`str` *optional*)
            The description of the generated commit
        revision (`str`, *optional*):
            The git revision to commit from. Defaults to the head of the
            `"main"` branch.
        create_pr (`boolean`, *optional*):
            Whether or not to create a Pull Request from `revision` with that commit.
            Defaults to `False`.
        parent_commit (`str`, *optional*):
            The OID / SHA of the parent commit, as a hexadecimal string. Shorthands (7 first characters) are also supported.
            If specified and `create_pr` is `False`, the commit will fail if `revision` does not point to `parent_commit`.
            If specified and `create_pr` is `True`, the pull request will be created from `parent_commit`.
            Specifying `parent_commit` ensures the repo has not changed before committing the changes, and can be
            especially useful if the repo is updated / committed to concurrently.
    Returns:
        `str`: URL of the commit which updated the card metadata.

    Example:
        ```python
        >>> from huggingface_hub import metadata_update
        >>> metadata = {'model-index': [{'name': 'RoBERTa fine-tuned on ReactionGIF',
        ...             'results': [{'dataset': {'name': 'ReactionGIF',
        ...                                      'type': 'julien-c/reactiongif'},
        ...                           'metrics': [{'name': 'Recall',
        ...                                        'type': 'recall',
        ...                                        'value': 0.7762102282047272}],
        ...                          'task': {'name': 'Text Classification',
        ...                                   'type': 'text-classification'}}]}]}
        >>> url = metadata_update("hf-internal-testing/reactiongif-roberta-card", metadata)

        ```
    z$Update metadata with huggingface_hubr   r§   r¬   zUnknown repo_type: )r^   r]   zJCannot update metadata on a Space that doesn't contain a `README.md` file.rÕ   Únamer   rà   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.)r^   r]   ru   rv   rx   rw   ry   )r�   r¦   r   r>   rf   r   r’   r   ÚitemsÚgetattrr   r.   rá   rà   Úis_equal_except_valuerØ   rÙ   rÚ   rÞ   rß   ÚappendÚgetr�   )rt   rä   r]   rã   r^   ru   rv   rw   rx   ry   Ú
card_classÚcardÚkeyÚvaluerà   Únew_resultsÚexisting_resultsÚ
new_resultÚresult_foundÚexisting_results                       r$   Úmetadata_updaterõ   ¬  s�  € ðH (6Ð'A‘^ÐGm€Nð Ð˜I¨Ò0Ü‰
Ø	�iÒ	Ü ‰
Ø	�gÒ	Ü‰
äÐ.¨y¨kÐ:Ó;Ð;ð4Ø�‰˜w¨e¸yˆÓIˆð —n‘nÓ&ó +'‰
ˆˆUØ�-Óà˜U 1™XÑ%Ü#*¨4°¸wÓ#G��a‘˜Ñ Ü&AÀ%Ó&HÑ#ˆJ˜Ø�y‰y×%Ñ%Ð-Ø)4�—	‘	Ô&Ø'1�—	‘	Õ$à#'§9¡9×#9Ñ#9Ð ð #.ò B�JØ#(�LØ+;ò W˜Ø%×;Ñ;¸OÕLØ)¨_Ò<ÁYÜ&0ð%/Ø/9×/EÑ/EÐ.FÀhØ'1×'=Ñ'=Ð&>ð ?Fð%Fó'"ð !"ð ,0˜LØ;E×;RÑ;R˜OÔ8Ø.×7Ñ7¸4Ò?Ø?I×?VÑ?V Õ <ðWò (ØŸ	™	×.Ñ.×5Ñ5°jÕAò!Bð& �y‰y�}‰}˜SÓ!Ð-±iÀDÇIÁIÇMÁMÐRUÓDVÐZ_ÒD_Ü ØOÐPSÈuð ULð Lóð ð
 "'�—	‘	˜#“ðW+'ðZ ×ÑØØØØ%Ø-ØØØ#ð ó 	ð 	øôi ò 4Ø˜ÒÜÐiÓjÐjð ×'Ñ'¬«
Ó3‹ð4ús   ¼H È2H;È:H;)9r»   ÚreÚpathlibr   Útypingr   r   r   r   r   r	   rm   r:   Úhuggingface_hub.file_downloadr
   Úhuggingface_hub.hf_apir   Úhuggingface_hub.repocard_datar   r   r   r   r   r   r   Úhuggingface_hub.utilsr   r   r   rO   r   Úerrorsr   Úutilsr   r   r   Ú
get_loggerr”   r?   Ú__file__rU   r—   r©   Úcompiler6   r   r�   r¦   r«   rY   r,   r·   rÅ   r˜   râ   rõ   r5   r&   r$   ú<module>r     sÉ  ðÛ 	Û 	Ý ß <× <ã Û å 9Ý .÷÷ ñ ÷ MÑ Lå Ý &ß HÑ Hð 
ˆ×	Ñ	˜HÓ	%€ñ ˜x›.×/Ñ/°+Ñ=Ð@WÑWÐ Ù  ›N×1Ñ1°KÑ?ÐB[Ñ[Ð ð �2—:‘:ÐRÓSÐ ÷iñ iôX	N`�ô N`ôb>`�(ô >`ôB�ô ð ð ¨Ð1IÑ)Jó ð*
˜e C¨ IÑ.ð 
°8¸D±>ó 
ð˜e C¨ IÑ.ð °dð ¸tó ðT %)Ø"Ø$(Ø#'Ø&*Ø04ò}àð}ð ð}ð ð	}ð
 ð}ð ð}ð ð}ð ð}ð ð}ð ˜S‘Mð}ð ð}ð ˜S‘Mð}ð ˜C‘=ð}ð ˜s‘mð}ð !)¨¡ð}ð  
ó!}ð@ ð
  $ØØØ$(Ø(,Ø"ØØ#'òQØðQàðQð ˜‰}ð	Qð
 ðQð �C‰=ðQð ˜S‘MðQð ! ™ðQð �s‰mðQð ðQð ˜C‘=ðQð 	òQó ñQr&   