+
    QV-jþŠ  ã                   ób  € ^ RI t ^ RIt^ RIHt ^ RIHtHt ^ RIt^ RIH	t	 ^ RI
Ht ^ RIHtHtHtHtHtHtHt ^ RIHtHtHtHtHt ^RIHt ^R	IHt ^R
IHtH t H!t! ] PD                  ! ]#4      t$]! ]%4      PL                  R,          R,          t']! ]%4      PL                  R,          R,          t(]PR                  ! R4      t* ! R R4      t+ ! R R]+4      t, ! R R]+4      t- ! R R]+4      t.R R lt/R R lt0R R lt1RRRRR RR!RR"RR#R/R$ R% llt2]!R&RR'RR(RR)RR*RR+RR,RR-R/R. R/ ll4       t3R# )0é    N)ÚPath)ÚAnyÚLiteral)Úhf_hub_download)Úupload_file)ÚCardDataÚDatasetCardDataÚ
EvalResultÚ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Ú	templateszmodelcard_template.mdzdatasetcard_template.mdz1^(\s*---[\r\n]+)([\S\s]*?)([\r\n]+---(\r\n|\n|$))c                   ó  a € ] tR t^%t o ]t]tRtRV 3R lR llt	]
R 4       t]P                  V 3R lR l4       tR tV 3R lR	 lt]RV 3R lR ll4       tRV 3R lR lltRV 3R lR llt]RV 3R lR ll4       tRtV tR
# )ÚRepoCardÚmodelc                ó&   <€ V ^8„  d   QhRS[ RS[/# )é   ÚcontentÚignore_metadata_errors©ÚstrÚbool)ÚformatÚ__classdict__s   "€Úi/Volumes/fast/ai/experiments/ui-tars-smoke/.venv/lib/python3.14/site-packages/huggingface_hub/repocard.pyÚ__annotate__ÚRepoCard.__annotate__*   s   ø€ ÷ #ñ #¡ð #¹Tñ #ó    c                ó   € W n         Wn        R# )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.
N)r    r   )Úselfr   r    s   &&&r&   Ú__init__ÚRepoCard.__init__*   s   € ðD '=Ô#ØŽr)   c                ó¸   € \        V P                  4      ;'       g    RpRV V P                  P                  WP                  R7       V RV V P
                   2# )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+   r1   s   & r&   r   ÚRepoCard.contentO   s}   € ô )¨¯©Ó7×?Ð?¸4ˆ
Ø�Z�L §¡×!2Ñ!2¸j×YmÑYmÐ!2Ó!nÐ oÐpzÐo{Ð{~ð  @Jð  Kð  LP÷  LUñ  LUð  KVð  Wð  	Wr)   c                ó    <€ V ^8„  d   QhRS[ /# )r   r   ©r"   )r$   r%   s   "€r&   r'   r(   V   s   ø€ ÷ 6ñ 6™sñ 6r)   c                óØ  € Wn         \        P                  V4      pV'       dg   VP                  ^4      pWP	                  4       R V n        \        P                  ! V4      pVf   / p\        V\        4      '       g   \        R4      hM\        P                  R4       / pWn        V P                  ! R/ VBRV P                  /B V n        \!        VP#                  4       4      V n        R# )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    © )r4   ÚREGEX_YAML_BLOCKÚsearchÚgroupÚendr8   ÚyamlÚ	safe_loadÚ
isinstanceÚdictÚ
ValueErrorÚloggerÚwarningÚcard_data_classr    r5   ÚlistÚkeysr7   )r+   r   ÚmatchÚ
yaml_blockÚ	data_dicts   &&   r&   r   r9   U   sÁ   € ð  Œä ×'Ñ'¨Ó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                ó   € V P                   # ©N)r   )r+   s   &r&   Ú__str__ÚRepoCard.__str__p   s   € Ø�|‰|Ðr)   c                ó0   <€ V ^8„  d   QhRS[ S[,          /# )r   Úfilepath)r   r"   )r$   r%   s   "€r&   r'   r(   s   s   ø€ ÷ ñ ™T¡C�Zñ r)   c                óò   € \        V4      pVP                  P                  RRR7       \        VRRRR7      ;_uu_ 4       pVP	                  \        V 4      4       RRR4       R#   + '       g   i     R# ; i)a3  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Úwriter"   )r+   rU   Úfs   && r&   ÚsaveÚRepoCard.saves   sW   € ô ˜“>ˆØ�‰×Ñ d°TÐÔ:ä�( ¨b¸7×CÕCÀqØ�G‰G”C˜“IÔ÷ D×C×CÒCús   Á A%Á%A6	Nc                ó^   <€ V ^8„  d   QhRS[ S[,          RS[ R,          RS[ R,          RS[/# )r   Úrepo_id_or_pathÚ	repo_typeNÚtokenr    )r"   r   r#   )r$   r%   s   "€r&   r'   r(   ˆ   sE   ø€ ÷ 3Pñ 3Pá™t�ð3Pñ ˜•:ð3Pñ �T�zð	3Pñ
 !%ñ3Pr)   c           	     ó¾  € \        V4      P                  4       '       d   \        V4      pM`\        V\        4      '       d<   \        \	        T\
        P                  T;'       g    V P                  VR7      4      pM\        RV R24      hVP                  RRRR7      ;_uu_ 4       pV ! VP                  4       VR7      uuR	R	R	4       #   + '       g   i     R	# ; i)
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 "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"]

    ```
)ri   rj   z.Cannot load RepoCard: path not found on disk (z).ÚrrZ   r[   r\   )r    N)r   Úis_filerE   r"   r   r   ÚREPOCARD_NAMEri   rG   rb   Úread)Úclsrh   ri   rj   r    Ú	card_pathrd   s   &&&&&  r&   ÚloadÚRepoCard.load‡   s³   € ôH �Ó ×(Ñ(×*Ò*Ü˜_Ó-‰IÜ˜¬×-Ò-ÜÜØ#Ü×+Ñ+Ø'×8Ð8¨3¯=©=Øô	ó‰Iô ÐMÈoÐM^Ð^`ÐaÓbÐbð �^‰^ ¨b¸7ˆ^×CÔCÀqÙ�q—v‘v“xÐ8NÔO÷ D×C×CÓCús   Â(CÃC	c                ó.   <€ V ^8„  d   QhRS[ R,          /# )r   ri   Nr;   )r$   r%   s   "€r&   r'   r(   ½   s   ø€ ÷ #ñ #¡#¨¥*ñ #r)   c                ó  € T;'       g    V P                   pRVR\        V 4      /pRR/p \        4       P                  RW#R7      p\	        V4       R#   \
         d.   pXP                  R8X  d   \        TP                  4      hThRp?ii ; i)	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.
ÚrepoTyper   ÚAcceptz
text/plainz(https://huggingface.co/api/validate-yaml)ÚjsonÚheadersi�  N)	ri   r"   r   Úpostr   r   Ústatus_coderG   r8   )r+   ri   Úbodyry   ÚresponseÚexcs   &&    r&   ÚvalidateÚRepoCard.validate½   s�   € ð( ×/Ð/ §¡ˆ	ð ˜	Ø”s˜4“yð
ˆð ˜\Ð*ˆð	Ü"“}×)Ñ)Ð*TÐ[_Ð)ÓqˆHÜ Ö)øÜô 	Ø×#Ñ# sÔ*Ü  §¡Ó/Ð/à�	ûð		ús   «&A ÁBÁ(BÂBc                ó¬   <€ V ^8„  d   QhRS[ RS[ R,          RS[ R,          RS[ R,          RS[ R,          RS[ R,          RS[R,          R	S[ R,          /# )
r   Úrepo_idrj   Nri   Úcommit_messageÚcommit_descriptionÚrevisionÚ	create_prÚparent_commitr!   )r$   r%   s   "€r&   r'   r(   â   sw   ø€ ÷ =ñ =áð=ñ �T�zð=ñ ˜•:ð	=ñ
 ˜d�
ð=ñ   $�Jð=ñ ˜•*ð=ñ ˜$•;ð=ñ ˜T•zñ=r)   c	                ó„  € T;'       g    V P                   pV P                  VR7       \        4       ;_uu_ 4       p	\        V	4      \        P
                  ,          p
V
P                  \        V 4      RR7       \        \        V
4      \        P
                  VVVVVVVVR7
      pRRR4       V#   + '       g   i     X# ; i)ar  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 too concurrently.
Returns:
    `str`: URL of the commit which updated the card metadata.
)ri   r[   )r_   )
Úpath_or_fileobjÚpath_in_repor‚   rj   ri   rƒ   r„   r†   r…   r‡   N)	ri   r   r   r   r   rn   Ú
write_textr"   r   )r+   r‚   rj   ri   rƒ   r„   r…   r†   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÷ &ð ˆ
÷ &Ö%ð ˆ
ús   »A)B.Â.B?	c                óH   <€ V ^8„  d   QhRS[ RS[R,          RS[R,          /# ©r   Ú	card_dataÚtemplate_pathNÚtemplate_str)r   r"   )r$   r%   s   "€r&   r'   r(   "  s1   ø€ ÷ +ñ +áð+ñ ˜T•zð+ñ ˜D•jñ	+r)   c                óž  € \        4       '       d   ^ RIpM\        R4      hVP                  4       P	                  4       pVP                  V4       Ve   \        V4      P                  4       pVf$   \        V P                  4      P                  4       pVP                  V4      pVP                  ! RRVP                  4       /VB pV ! V4      # )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.
    template_str (`str`, *optional*):
        A raw Jinja template string with optional variables. Used when neither `template_path`
        nor the default template is appropriate. Ignored if `template_path` is also provided.

Returns:
    [`huggingface_hub.repocard.RepoCard`]: A RepoCard instance with the specified card data and content from the
    template.
NzjUsing RepoCard.from_template requires Jinja2 to be installed. Please install it with `pip install Jinja2`.r“   r>   )r   Újinja2ÚImportErrorÚto_dictÚcopyÚupdater   Ú	read_textÚdefault_template_pathÚTemplateÚrenderr6   )	rp   r“   r”   r•   Útemplate_kwargsr—   ÚkwargsÚtemplater   s	   &&&&,    r&   Úfrom_templateÚRepoCard.from_template!  s¶   € ô6 ×ÒÜäð9óð ð
 ×"Ñ"Ó$×)Ñ)Ó+ˆØ�‰�oÔ&àÒ$Ü Ó.×8Ñ8Ó:ˆLØÒÜ × 9Ñ 9Ó:×DÑDÓFˆLØ—?‘? <Ó0ˆØ—/’/ÑJ¨I×,=Ñ,=Ó,?ÐJÀ6ÑJˆÙ�7‹|Ðr)   )r4   r7   r   r5   r    r8   )F)NNFrQ   )NNNNNNN©NN)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__r   rJ   ÚTEMPLATE_MODELCARD_PATHr�   ri   r,   Úpropertyr   ÚsetterrR   re   Úclassmethodrr   r   r�   r£   Ú__static_attributes__Ú__classdictcell__)r%   s   @r&   r   r   %   s©   ø‡ € Ø€OØ3ÐØ€I÷#ò #ðJ ñWó ðWð
 ‡^�^÷6ó ð6ò4÷ð ð( ÷3Pñ 3Pó ð3P÷j#ò #÷J=ò =ð~ ÷+ñ +ó ö+r)   r   c                   óX   a a€ ] tR tRt o]t]tRt]	RV3R lV 3R lll4       t
RtVtV ;t# )Ú	ModelCardiP  r   c                óH   <€ V ^8„  d   QhRS[ RS[R,          RS[R,          /# r’   )r   r"   )r$   r%   s   "€r&   r'   ÚModelCard.__annotate__V  s;   ø€ ÷ K`ñ K`á ðK`ñ ˜T•zðK`ñ ˜D•jñ	K`r)   c                ó(   <€ \         SV `  ! WV3/ VB # )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.
    template_str (`str`, *optional*):
        A raw Jinja template string with optional variables. Used when neither `template_path`
        nor the default template is appropriate. Ignored if `template_path` is also provided.

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£   ©rp   r“   r”   r•   r    Ú	__class__s   &&&&,€r&   r£   ÚModelCard.from_templateU  s   ø€ ôX ‰wÒ$ Y¸|Ñ_ÈÑ_Ð_r)   r>   r¥   )r¦   r§   r¨   r©   r   rJ   rª   r�   ri   r­   r£   r®   r¯   Ú__classcell__©r¸   r%   s   @@r&   r±   r±   P  s9   ù‡ € Ø#€OØ3ÐØ€Ià÷K`ô K`ó ÷K`ð K`r)   r±   c                   óX   a a€ ] tR tRt o]t]tRt]	RV3R lV 3R lll4       t
RtVtV ;t# )ÚDatasetCardi¤  Údatasetc                óH   <€ V ^8„  d   QhRS[ RS[R,          RS[R,          /# r’   )r	   r"   )r$   r%   s   "€r&   r'   ÚDatasetCard.__annotate__ª  s6   ø€ ÷ ;`ñ ;`á"ð;`ñ ˜T•zð;`ñ ˜D•jñ	;`r)   c                ó(   <€ \         SV `  ! WV3/ VB # )aG  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.
    template_str (`str`, *optional*):
        A raw Jinja template string with optional variables. Used when neither `template_path`
        nor the default template is appropriate. Ignored if `template_path` is also provided.

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£   ÚDatasetCard.from_template©  s   ø€ ôx ‰wÒ$ Y¸|Ñ_ÈÑ_Ð_r)   r>   r¥   )r¦   r§   r¨   r©   r	   rJ   ÚTEMPLATE_DATASETCARD_PATHr�   ri   r­   r£   r®   r¯   rº   r»   s   @@r&   r½   r½   ¤  s5   ù‡ € Ø%€OØ5ÐØ€Ià÷;`ô ;`ó ÷;`ð ;`r)   r½   c                   ó"   € ] tR tRt]t]tRtRt	R# )Ú	SpaceCardiè  Úspacer>   N)
r¦   r§   r¨   r©   r   rJ   rª   r�   ri   r®   r>   r)   r&   rÅ   rÅ   è  s   † Ø#€OØ3ÐØ„Ir)   rÅ   c                ó>   € V ^8„  d   QhR\         R\        R,          /# )r   r   Úreturn)Úr/   ú
N)r"   r   )r$   s   "r&   r'   r'   î  s    € ÷ ñ ¤ð ¬Ð1IÕ)Jñ r)   c                ó¶   € V P                  R4      pV P                  R4      pV P                  R4      pW,           ^ 8X  d   R# W18X  d	   W28X  d   R# W8”  d   R# R# )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Ê   N)Úcount)r   ÚcrÚlfÚcrlfs   &   r&   r3   r3   î  sQ   € ð 
�‰�tÓ	€BØ	�‰�tÓ	€BØ�=‰=˜Ó €DØ	…w�!„|ÙØ„z�d”jÙØ	„wÙár)   c                óT   € V ^8„  d   QhR\         \        ,          R\        R,          /# )r   Ú
local_pathrÈ   N©r"   r   rF   )r$   s   "r&   r'   r'     s"   € ÷ 
ñ 
œc¤D�jð 
¬T°D­[ñ 
r)   c                 ó  € \        V 4      P                  4       p\        P                  V4      pV'       dO   VP	                  ^4      p\
        P                  ! V4      pVe   \        V\        4      '       d   V# \        R4      hR# )r   Nr=   )
r   rœ   r?   r@   rA   rC   rD   rE   rF   rG   )rÑ   r   rM   rN   r5   s   &    r&   Úmetadata_loadrÔ     sh   € Ü�:Ó×(Ñ(Ó*€GÜ×#Ñ# GÓ,€EßØ—[‘[ “^ˆ
Ü�~Š~˜jÓ)ˆØŠ<œ: d¬D×1Ò1ØˆKÜÐDÓEÐEár)   c                óJ   € V ^8„  d   QhR\         \        ,          R\        RR/# )r   rÑ   r5   rÈ   NrÒ   )r$   s   "r&   r'   r'     s%   € ÷ ñ œc¤D�jð ´ð ¸ñ r)   c                ó(  € RpRp\         P                  P                  V 4      '       d�   \        V RRR7      ;_uu_ 4       pVP	                  4       p\        VP                  \        4      '       d   VP                  ^ ,          pM,\        VP                  \        4      '       d   VP                  pRRR4       \        V RRRR7      ;_uu_ 4       p\        VRVR7      p\        P                  V4      pV'       d;   VRVP                  4        R	V V R	V 2,           W6P                  4       R ,           pMR	V V R	V V 2pVP                  V4       VP                  4        RRR4       R#   + '       g   i     LÄ; i  + '       g   i     R# ; i)
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/   rZ   Úutf8)r^   r_   NrY   F)Ú	sort_keysr1   r0   )ÚosÚpathÚexistsrb   ro   rE   ÚnewlinesÚtupler"   r   r?   r@   ÚstartrB   rc   Úclose)rÑ   r5   r1   r   ÚreadmeÚ	data_yamlrM   Úoutputs   &&      r&   Úmetadata_saverã     s;  € ð €JØ€Gä	‡w�w‡~�~�j×!Ò!Ü�* b°6×:Õ:¸fØ—k‘k“mˆGÜ˜&Ÿ/™/¬5×1Ò1Ø#Ÿ_™_¨QÕ/‘
Ü˜FŸO™O¬S×1Ò1Ø#Ÿ_™_�
÷ ;ô 
ˆj˜# r°F×	;Õ	;¸vÜ˜d¨eÀ
ÔKˆ	ä ×'Ñ'¨Ó0ˆßØ˜_˜uŸ{™{›}Ð-°#°j°\À)ÀÈCÐPZÈ|Ð0\Õ\Ð_f×gpÑgpÓgrÐgtÐ_uÕu‰Fà˜:˜, y k°°Z°LÀÀ	ÐJˆFà�‰�VÔØ�‰Œ÷ 
<Ñ	;÷ ;×:ú÷ 
<×	;Ð	;ús   Á A1E-ÃBF Å-E=	Æ F	Úmetrics_configÚmetrics_verifiedFÚdataset_configÚdataset_splitÚdataset_revisionÚmetrics_verification_tokenc                ó  € V ^8„  d   QhR\         R\         R\         R\         R\         R\        R\         R\         R	\         R
,          R\        R\         R
,          R\         R
,          R\         R
,          R\         R
,          R\        /# )r   Úmodel_pretty_nameÚtask_pretty_nameÚtask_idÚmetrics_pretty_nameÚ
metrics_idÚmetrics_valueÚdataset_pretty_nameÚ
dataset_idrä   Nrå   ræ   rç   rè   ré   rÈ   )r"   r   r#   rF   )r$   s   "r&   r'   r'   0  sÅ   € ÷ }ñ }äð}ô ð}ô ð	}ô
 ð}ô ð}ô ð}ô ð}ô ð}ô ˜$•Jð}ô ð}ô ˜$•Jð}ô ˜•:ð}ô ˜D•jð}ô !$ d¥
ð}ô  
ñ!}r)   c                óN   € R\        V \        VVVVVVVVV	VV
VVR7      .R7      /# )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  0  sQ   € ðR 	Ô2Ø(äØ.Ø%Ø 3Ø *Ø!.Ø!4Ø!+Ø"0Ø-Ø!;Ø#1Ø"/Ø%5ôðô
ðð r)   ri   Ú	overwriterj   rƒ   r„   r…   r†   r‡   c                óð   € V ^8„  d   QhR\         R\        R\         R,          R\        R\         R,          R\         R,          R\         R,          R	\         R,          R
\        R\         R,          R\         /# )r   r‚   Úmetadatari   Nr  rj   rƒ   r„   r…   r†   r‡   rÈ   )r"   rF   r#   )r$   s   "r&   r'   r'   ±  s›   € ÷ Rñ RÜðRäðRô �T�zð	Rô
 ðRô ��:ðRô ˜$•JðRô ˜d�
ðRô �D�jðRô ðRô ˜•:ðRô 	ñRr)   c               ó   € Ve   TMRpVe   VR8X  d   \         p
M*VR8X  d   \        p
MVR8X  d   \        p
M\        RV 24      h V
P	                  WVR7      pVP                  4        EF¼  w  rÍVR8X  EdM   R	V^ ,          9  d   \        VR
V 4      V^ ,          R	&   \        V4      w  rïVP                  P                  f#   WûP                  n        WëP                  n        Kz  VP                  P                  pV FÁ  pRpV F‡  pVP                  V4      '       g   K  VV8w  d/   V'       g'   \        RVP                   RVP                    R24      hRpVP"                  Vn        VP$                  RJ g   Kv  VP&                  Vn        K‰  	  V'       d   Kœ  VP                  P                  P)                  V4       KÃ  	  EKZ  VP                  P+                  V4      e8   V'       g0   VP                  P+                  V4      V8w  d   \        RV R24      hWÛP                  V&   EK¿  	  VP-                  V VVVVVVV	R7      #   \
         d0    TR8X  d   \        R4      hT
P                  \        4       4      p EL#i ; i)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
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 too 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: )rj   ri   zJCannot update metadata on a Space that doesn't contain a `README.md` file.rô   Únamerÿ   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.)rj   ri   rƒ   r„   r†   r…   r‡   )r±   r½   r   rG   rr   r   r£   r   ÚitemsÚgetattrr   r5   r   rÿ   Úis_equal_except_valuer÷   rø   rù   rý   rþ   ÚappendÚgetr�   )r‚   r  ri   r  rj   rƒ   r„   r…   r†   r‡   Ú
card_classÚcardÚkeyÚvaluerÿ   Únew_resultsÚexisting_resultsÚ
new_resultÚresult_foundÚexisting_results   &&$$$$$$$$          r&   Úmetadata_updater  °  ss  € ðH (6Ò'A‘^ÐGm€Nð Ò˜I¨Ô0Ü‰
Ø	�iÔ	Ü ‰
Ø	�gÔ	Ü‰
äÐ.¨y¨kÐ:Ó;Ð;ð4Ø�‰˜w¸yˆÓIˆð —n‘n×&‰
ˆØ�-Õà˜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ð ULð Lóð ð
 "'—	‘	˜#”ñW 'ðZ ×ÑØØØØ%Ø-ØØØ#ð ó 	ð 	øôk ô 4Ø˜ÔÜÐiÓjÐjð ×'Ñ'¬«
Ó3‹ð4ús   ÁI É6I=É<I=)4rÙ   ÚreÚpathlibr   Útypingr   r   rC   Úhuggingface_hub.file_downloadr   Úhuggingface_hub.hf_apir   Úhuggingface_hub.repocard_datar   r	   r
   r   r   r   r   Úhuggingface_hub.utilsr   r   r   r   r   rZ   r   Úerrorsr   Úutilsr   r   r   Ú
get_loggerr¦   rH   Ú__file__r`   rª   rÃ   Úcompiler?   r   r±   r½   rÅ   r3   rÔ   rã   r  r  r>   r)   r&   Ú<module>r"     sœ  ðÛ 	Û 	Ý ß ã å 9Ý .÷÷ ñ ÷ rÕ qå Ý &ß HÑ Hð 
×	Ò	˜HÓ	%€ñ ˜x›.×/Ñ/°+Õ=Ð@WÕWÐ Ù  ›N×1Ñ1°KÕ?ÐB[Õ[Ð ð —:’:ÐRÓSÐ ÷hñ hôV	Q`�ô Q`ôhA`�(ô A`ôH�ô õõ*
õð@}ð "&ð}ð #ð}ð "&ð}ð !%ð}ð $(ð}ð .2÷}ð@ ðRð !ð	Rð
 ðRð ðRð "&ðRð &*ðRð  ðRð ðRð !%öRó òRr)   