# Repo Cards and Repo Card Data

## Repository Cards

The huggingface\_hub library provides a Python interface to create, share, and update Model/Dataset Cards. Visit the [dedicated documentation page](https://huggingface.co/docs/hub/models-cards) for a deeper view of what Model Cards on the Hub are, and how they work under the hood. You can also check out our [Model Cards guide](https://huggingface.co/docs/huggingface_hub/how-to-model-cards) to get a feel for how you would use these utilities in your own projects.

### Repo Card

The `RepoCard` object is the parent class of [ModelCard](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/cards#huggingface_hub.ModelCard), [DatasetCard](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/cards#huggingface_hub.DatasetCard) and `SpaceCard`.

#### class huggingface\_hub.RepoCard

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/repocard.py#L37)

( content: strignore\_metadata\_errors: bool = False )

**\_\_init\_\_**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/repocard.py#L42)

( content: strignore\_metadata\_errors: bool = False )

Parameters

* **content** (`str`) — The content of the Markdown file.

Initialize a RepoCard from string content. The content should be a Markdown file with a YAML block at the beginning and a Markdown body.



Example:

Copied

```
>>> 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'
```

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.

**from\_template**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/repocard.py#L292)

( card\_data: CardDatatemplate\_path: typing.Optional\[str] = None\*\*template\_kwargs ) → [huggingface\_hub.repocard.RepoCard](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/cards#huggingface_hub.RepoCard)

Parameters

* **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](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/cards#huggingface_hub.RepoCard)

A RepoCard instance with the specified card data and content from the template.

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.

**load**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/repocard.py#L136)

( repo\_id\_or\_path: typing.Union\[str, pathlib.Path]repo\_type: typing.Optional\[str] = Nonetoken: typing.Optional\[str] = Noneignore\_metadata\_errors: bool = False ) → [huggingface\_hub.repocard.RepoCard](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/cards#huggingface_hub.RepoCard)

Parameters

* **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](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/cards#huggingface_hub.RepoCard)

The RepoCard (or subclass) initialized from the repo’s README.md file or filepath.

Initialize a RepoCard from a Hugging Face Hub repo’s README.md or a local filepath.



Example:

Copied

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

**push\_to\_hub**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/repocard.py#L229)

( repo\_id: strtoken: typing.Optional\[str] = Nonerepo\_type: typing.Optional\[str] = Nonecommit\_message: typing.Optional\[str] = Nonecommit\_description: typing.Optional\[str] = Nonerevision: typing.Optional\[str] = Nonecreate\_pr: typing.Optional\[bool] = Noneparent\_commit: typing.Optional\[str] = None ) → `str`

Parameters

* **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.

Push a RepoCard to a Hugging Face Hub repo.

**save**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/repocard.py#L116)

( filepath: typing.Union\[pathlib.Path, str] )

Parameters

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

Save a RepoCard to a file.



Example:

Copied

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

**validate**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/repocard.py#L190)

( repo\_type: typing.Optional\[str] = None )

Parameters

* **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`.

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()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/cards#huggingface_hub.RepoCard.push_to_hub).

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.

### Card Data

The [CardData](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/cards#huggingface_hub.CardData) object is the parent class of [ModelCardData](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/cards#huggingface_hub.ModelCardData) and [DatasetCardData](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/cards#huggingface_hub.DatasetCardData).

#### class huggingface\_hub.CardData

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/repocard_data.py#L151)

( ignore\_metadata\_errors: bool = False\*\*kwargs )

Structure containing metadata from a RepoCard.

[CardData](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/cards#huggingface_hub.CardData) is the parent class of [ModelCardData](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/cards#huggingface_hub.ModelCardData) and [DatasetCardData](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/cards#huggingface_hub.DatasetCardData).

Metadata can be exported as a dictionary or YAML. Export can be customized to alter the representation of the data (example: flatten evaluation results). `CardData` behaves as a dictionary (can get, pop, set values) but do not inherit from `dict` to allow this export step.

**get**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/repocard_data.py#L199)

( key: strdefault: typing.Any = None )

Get value for a given metadata key.

**pop**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/repocard_data.py#L203)

( key: strdefault: typing.Any = None )

Pop value for a given metadata key.

**to\_dict**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/repocard_data.py#L164)

( ) → `dict`

Returns

`dict`

CardData represented as a dictionary ready to be dumped to a YAML block for inclusion in a README.md file.

Converts CardData to a dict.

**to\_yaml**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/repocard_data.py#L184)

( line\_break = None ) → `str`

Parameters

* **line\_break** (str, _optional_) — The line break to use when dumping to yaml.

Returns

`str`

CardData represented as a YAML block.

Dumps CardData to a YAML block for inclusion in a README.md file.

### Model Cards

#### ModelCard

#### class huggingface\_hub.ModelCard

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/repocard.py#L330)

( content: strignore\_metadata\_errors: bool = False )

**from\_template**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/repocard.py#L335)

( card\_data: ModelCardDatatemplate\_path: typing.Optional\[str] = None\*\*template\_kwargs ) → [huggingface\_hub.ModelCard](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/cards#huggingface_hub.ModelCard)

Parameters

* **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](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/cards#huggingface_hub.ModelCard)

A ModelCard instance with the specified card data and content from the template.

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](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.



Example:

Copied

```
>>> 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
... )
```

#### ModelCardData

#### class huggingface\_hub.ModelCardData

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/repocard_data.py#L220)

( language: typing.Union\[typing.List\[str], str, NoneType] = Nonelicense: typing.Optional\[str] = Nonelibrary\_name: typing.Optional\[str] = Nonetags: typing.Optional\[typing.List\[str]] = Nonedatasets: typing.Optional\[typing.List\[str]] = Nonemetrics: typing.Optional\[typing.List\[str]] = Noneeval\_results: typing.Optional\[typing.List\[huggingface\_hub.repocard\_data.EvalResult]] = Nonemodel\_name: typing.Optional\[str] = Noneignore\_metadata\_errors: bool = False\*\*kwargs )

Parameters

* **language** (`Union[str, List[str]]`, _optional_) — Language of model’s training data or metadata. It must be an ISO 639-1, 639-2 or 639-3 code (two/three letters), or a special value like “code”, “multilingual”. Defaults to `None`.
* **license** (`str`, _optional_) — License of this model. Example: apache-2.0 or any license from [https://huggingface.co/docs/hub/repositories-licenses](https://huggingface.co/docs/hub/repositories-licenses). Defaults to None.
* **library\_name** (`str`, _optional_) — Name of library used by this model. Example: keras or any library from [https://github.com/huggingface/hub-docs/blob/main/js/src/lib/interfaces/Libraries.ts](https://github.com/huggingface/hub-docs/blob/main/js/src/lib/interfaces/Libraries.ts). Defaults to None.
* **tags** (`List[str]`, _optional_) — List of tags to add to your model that can be used when filtering on the Hugging Face Hub. Defaults to None.
* **datasets** (`List[str]`, _optional_) — List of datasets that were used to train this model. Should be a dataset ID found on [https://hf.co/datasets](https://hf.co/datasets). Defaults to None.
* **metrics** (`List[str]`, _optional_) — List of metrics used to evaluate this model. Should be a metric name that can be found at [https://hf.co/metrics](https://hf.co/metrics). Example: ‘accuracy’. Defaults to None.
* **eval\_results** (`Union[List[EvalResult], EvalResult]`, _optional_) — List of `huggingface_hub.EvalResult` that define evaluation results of the model. If provided, `model_name` is used to as a name on PapersWithCode’s leaderboards. Defaults to `None`.
* **model\_name** (`str`, _optional_) — A name for this model. It is used along with `eval_results` to construct the `model-index` within the card’s metadata. The name you supply here is what will be used on PapersWithCode’s leaderboards. If None is provided then the repo name is used as a default. Defaults to None.
* **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.
* **kwargs** (`dict`, _optional_) — Additional metadata that will be added to the model card. Defaults to None.

Model Card Metadata that is used by Hugging Face Hub when included at the top of your README.md



Example:

Copied

```
>>> from huggingface_hub import ModelCardData
>>> card_data = ModelCardData(
...     language="en",
...     license="mit",
...     library_name="timm",
...     tags=['image-classification', 'resnet'],
... )
>>> card_data.to_dict()
{'language': 'en', 'license': 'mit', 'library_name': 'timm', 'tags': ['image-classification', 'resnet']}
```

### Dataset Cards

Dataset cards are also known as Data Cards in the ML Community.

#### DatasetCard

#### class huggingface\_hub.DatasetCard

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/repocard.py#L410)

( content: strignore\_metadata\_errors: bool = False )

**from\_template**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/repocard.py#L415)

( card\_data: DatasetCardDatatemplate\_path: typing.Optional\[str] = None\*\*template\_kwargs ) → [huggingface\_hub.DatasetCard](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/cards#huggingface_hub.DatasetCard)

Parameters

* **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](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/cards#huggingface_hub.DatasetCard)

A DatasetCard instance with the specified card data and content from the template.

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](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.



Example:

Copied

```
>>> 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
... )
```

#### DatasetCardData

#### class huggingface\_hub.DatasetCardData

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/repocard_data.py#L326)

( language: typing.Union\[typing.List\[str], str, NoneType] = Nonelicense: typing.Union\[typing.List\[str], str, NoneType] = Noneannotations\_creators: typing.Union\[typing.List\[str], str, NoneType] = Nonelanguage\_creators: typing.Union\[typing.List\[str], str, NoneType] = Nonemultilinguality: typing.Union\[typing.List\[str], str, NoneType] = Nonesize\_categories: typing.Union\[typing.List\[str], str, NoneType] = Nonesource\_datasets: typing.Optional\[typing.List\[str]] = Nonetask\_categories: typing.Union\[typing.List\[str], str, NoneType] = Nonetask\_ids: typing.Union\[typing.List\[str], str, NoneType] = Nonepaperswithcode\_id: typing.Optional\[str] = Nonepretty\_name: typing.Optional\[str] = Nonetrain\_eval\_index: typing.Optional\[typing.Dict] = Noneconfig\_names: typing.Union\[typing.List\[str], str, NoneType] = Noneignore\_metadata\_errors: bool = False\*\*kwargs )

Parameters

* **language** (`List[str]`, _optional_) — Language of dataset’s data or metadata. It must be an ISO 639-1, 639-2 or 639-3 code (two/three letters), or a special value like “code”, “multilingual”.
* **license** (`Union[str, List[str]]`, _optional_) — License(s) of this dataset. Example: apache-2.0 or any license from [https://huggingface.co/docs/hub/repositories-licenses](https://huggingface.co/docs/hub/repositories-licenses).
* **annotations\_creators** (`Union[str, List[str]]`, _optional_) — How the annotations for the dataset were created. Options are: ‘found’, ‘crowdsourced’, ‘expert-generated’, ‘machine-generated’, ‘no-annotation’, ‘other’.
* **language\_creators** (`Union[str, List[str]]`, _optional_) — How the text-based data in the dataset was created. Options are: ‘found’, ‘crowdsourced’, ‘expert-generated’, ‘machine-generated’, ‘other’
* **multilinguality** (`Union[str, List[str]]`, _optional_) — Whether the dataset is multilingual. Options are: ‘monolingual’, ‘multilingual’, ‘translation’, ‘other’.
* **size\_categories** (`Union[str, List[str]]`, _optional_) — The number of examples in the dataset. Options are: ‘n<1K’, ‘1K1T’, and ‘other’.
* **source\_datasets** (`List[str]]`, _optional_) — Indicates whether the dataset is an original dataset or extended from another existing dataset. Options are: ‘original’ and ‘extended’.
* **task\_categories** (`Union[str, List[str]]`, _optional_) — What categories of task does the dataset support?
* **task\_ids** (`Union[str, List[str]]`, _optional_) — What specific tasks does the dataset support?
* **paperswithcode\_id** (`str`, _optional_) — ID of the dataset on PapersWithCode.
* **pretty\_name** (`str`, _optional_) — A more human-readable name for the dataset. (ex. “Cats vs. Dogs”)
* **train\_eval\_index** (`Dict`, _optional_) — A dictionary that describes the necessary spec for doing evaluation on the Hub. If not provided, it will be gathered from the ‘train-eval-index’ key of the kwargs.
* **config\_names** (`Union[str, List[str]]`, _optional_) — A list of the available dataset configs for the dataset.

Dataset Card Metadata that is used by Hugging Face Hub when included at the top of your README.md

### Space Cards

#### SpaceCard

#### class huggingface\_hub.SpaceCard

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/repocard.py#L474)

( content: strignore\_metadata\_errors: bool = False )

#### SpaceCardData

#### class huggingface\_hub.SpaceCardData

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/repocard_data.py#L406)

( title: typing.Optional\[str] = Nonesdk: typing.Optional\[str] = Nonesdk\_version: typing.Optional\[str] = Nonepython\_version: typing.Optional\[str] = Noneapp\_file: typing.Optional\[str] = Noneapp\_port: typing.Optional\[int] = Nonelicense: typing.Optional\[str] = Noneduplicated\_from: typing.Optional\[str] = Nonemodels: typing.Optional\[typing.List\[str]] = Nonedatasets: typing.Optional\[typing.List\[str]] = Nonetags: typing.Optional\[typing.List\[str]] = Noneignore\_metadata\_errors: bool = False\*\*kwargs )

Parameters

* **title** (`str`, _optional_) — Title of the Space.
* **sdk** (`str`, _optional_) — SDK of the Space (one of `gradio`, `streamlit`, `docker`, or `static`).
* **sdk\_version** (`str`, _optional_) — Version of the used SDK (if Gradio/Streamlit sdk).
* **python\_version** (`str`, _optional_) — Python version used in the Space (if Gradio/Streamlit sdk).
* **app\_file** (`str`, _optional_) — Path to your main application file (which contains either gradio or streamlit Python code, or static html code). Path is relative to the root of the repository.
* **app\_port** (`str`, _optional_) — Port on which your application is running. Used only if sdk is `docker`.
* **license** (`str`, _optional_) — License of this model. Example: apache-2.0 or any license from [https://huggingface.co/docs/hub/repositories-licenses](https://huggingface.co/docs/hub/repositories-licenses).
* **duplicated\_from** (`str`, _optional_) — ID of the original Space if this is a duplicated Space.
* **models** (List`str`, _optional_) — List of models related to this Space. Should be a dataset ID found on [https://hf.co/models](https://hf.co/models).
* **datasets** (`List[str]`, _optional_) — List of datasets related to this Space. Should be a dataset ID found on [https://hf.co/datasets](https://hf.co/datasets).
* **tags** (`List[str]`, _optional_) — List of tags to add to your Space that can be used when filtering on the Hub.
* **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.
* **kwargs** (`dict`, _optional_) — Additional metadata that will be added to the space card.

Space Card Metadata that is used by Hugging Face Hub when included at the top of your README.md

To get an exhaustive reference of Spaces configuration, please visit [https://huggingface.co/docs/hub/spaces-config-reference#spaces-configuration-reference](https://huggingface.co/docs/hub/spaces-config-reference#spaces-configuration-reference).



Example:

Copied

```
>>> from huggingface_hub import SpaceCardData
>>> card_data = SpaceCardData(
...     title="Dreambooth Training",
...     license="mit",
...     sdk="gradio",
...     duplicated_from="multimodalart/dreambooth-training"
... )
>>> card_data.to_dict()
{'title': 'Dreambooth Training', 'sdk': 'gradio', 'license': 'mit', 'duplicated_from': 'multimodalart/dreambooth-training'}
```

### Utilities

#### EvalResult

#### class huggingface\_hub.EvalResult

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/repocard_data.py#L15)

( task\_type: strdataset\_type: strdataset\_name: strmetric\_type: strmetric\_value: typing.Anytask\_name: typing.Optional\[str] = Nonedataset\_config: typing.Optional\[str] = Nonedataset\_split: typing.Optional\[str] = Nonedataset\_revision: typing.Optional\[str] = Nonedataset\_args: typing.Union\[typing.Dict\[str, typing.Any], NoneType] = Nonemetric\_name: typing.Optional\[str] = Nonemetric\_config: typing.Optional\[str] = Nonemetric\_args: typing.Union\[typing.Dict\[str, typing.Any], NoneType] = Noneverified: typing.Optional\[bool] = Noneverify\_token: typing.Optional\[str] = None )

Parameters

* **task\_type** (`str`) — The task identifier. Example: “image-classification”.
* **dataset\_type** (`str`) — The dataset identifier. Example: “common\_voice”. Use dataset id from [https://hf.co/datasets](https://hf.co/datasets).
* **dataset\_name** (`str`) — A pretty name for the dataset. Example: “Common Voice (French)“.
* **metric\_type** (`str`) — The metric identifier. Example: “wer”. Use metric id from [https://hf.co/metrics](https://hf.co/metrics).
* **metric\_value** (`Any`) — The metric value. Example: 0.9 or “20.0 ± 1.2”.
* **task\_name** (`str`, _optional_) — A pretty name for the task. Example: “Speech Recognition”.
* **dataset\_config** (`str`, _optional_) — The name of the dataset configuration used in `load_dataset()`. Example: fr in `load_dataset("common_voice", "fr")`. See the `datasets` docs for more info: [https://hf.co/docs/datasets/package\_reference/loading\_methods#datasets.load\_dataset.name](https://hf.co/docs/datasets/package_reference/loading_methods#datasets.load_dataset.name)
* **dataset\_split** (`str`, _optional_) — The split used in `load_dataset()`. Example: “test”.
* **dataset\_revision** (`str`, _optional_) — The revision (AKA Git Sha) of the dataset used in `load_dataset()`. Example: 5503434ddd753f426f4b38109466949a1217c2bb
* **dataset\_args** (`Dict[str, Any]`, _optional_) — The arguments passed during `Metric.compute()`. Example for `bleu`: `{"max_order": 4}`
* **metric\_name** (`str`, _optional_) — A pretty name for the metric. Example: “Test WER”.
* **metric\_config** (`str`, _optional_) — The name of the metric configuration used in `load_metric()`. Example: bleurt-large-512 in `load_metric("bleurt", "bleurt-large-512")`. See the `datasets` docs for more info: [https://huggingface.co/docs/datasets/v2.1.0/en/loading#load-configurations](https://huggingface.co/docs/datasets/v2.1.0/en/loading#load-configurations)
* **metric\_args** (`Dict[str, Any]`, _optional_) — The arguments passed during `Metric.compute()`. Example for `bleu`: max\_order: 4
* **verified** (`bool`, _optional_) — 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.
* **verify\_token** (`str`, _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.

Flattened representation of individual evaluation results found in model-index of Model Cards.

For more information on the model-index spec, see [https://github.com/huggingface/hub-docs/blob/main/modelcard.md?plain=1](https://github.com/huggingface/hub-docs/blob/main/modelcard.md?plain=1).

**is\_equal\_except\_value**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/repocard_data.py#L135)

( other: EvalResult )

Return True if `self` and `other` describe exactly the same metric but with a different value.

#### model\_index\_to\_eval\_results

**huggingface\_hub.repocard\_data.model\_index\_to\_eval\_results**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/repocard_data.py#L487)

( model\_index: typing.List\[typing.Dict\[str, typing.Any]] ) → model\_name (`str`)

Parameters

* **model\_index** (`List[Dict[str, Any]]`) — A model index data structure, likely coming from a README.md file on the Hugging Face Hub.

Returns

model\_name (`str`)

The name of the model as found in the model index. This is used as the identifier for the model on leaderboards like PapersWithCode. eval\_results (`List[EvalResult]`): A list of `huggingface_hub.EvalResult` objects containing the metrics reported in the provided model\_index.

Takes in a model index and returns the model name and a list of `huggingface_hub.EvalResult` objects.

A detailed spec of the model index can be found here: [https://github.com/huggingface/hub-docs/blob/main/modelcard.md?plain=1](https://github.com/huggingface/hub-docs/blob/main/modelcard.md?plain=1)



Example:

Copied

```
>>> from huggingface_hub.repocard_data import model_index_to_eval_results
>>> # Define a minimal model index
>>> model_index = [
...     {
...         "name": "my-cool-model",
...         "results": [
...             {
...                 "task": {
...                     "type": "image-classification"
...                 },
...                 "dataset": {
...                     "type": "beans",
...                     "name": "Beans"
...                 },
...                 "metrics": [
...                     {
...                         "type": "accuracy",
...                         "value": 0.9
...                     }
...                 ]
...             }
...         ]
...     }
... ]
>>> model_name, eval_results = model_index_to_eval_results(model_index)
>>> model_name
'my-cool-model'
>>> eval_results[0].task_type
'image-classification'
>>> eval_results[0].metric_type
'accuracy'
```

#### eval\_results\_to\_model\_index

**huggingface\_hub.repocard\_data.eval\_results\_to\_model\_index**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/repocard_data.py#L599)

( model\_name: streval\_results: typing.List\[huggingface\_hub.repocard\_data.EvalResult] ) → model\_index (`List[Dict[str, Any]]`)

Parameters

* **model\_name** (`str`) — Name of the model (ex. “my-cool-model”). This is used as the identifier for the model on leaderboards like PapersWithCode.
* **eval\_results** (`List[EvalResult]`) — List of `huggingface_hub.EvalResult` objects containing the metrics to be reported in the model-index.

Returns

model\_index (`List[Dict[str, Any]]`)

The eval\_results converted to a model-index.

Takes in given model name and list of `huggingface_hub.EvalResult` and returns a valid model-index that will be compatible with the format expected by the Hugging Face Hub.



Example:

Copied

```
>>> from huggingface_hub.repocard_data import eval_results_to_model_index, EvalResult
>>> # Define minimal eval_results
>>> eval_results = [
...     EvalResult(
...         task_type="image-classification",  # Required
...         dataset_type="beans",  # Required
...         dataset_name="Beans",  # Required
...         metric_type="accuracy",  # Required
...         metric_value=0.9,  # Required
...     )
... ]
>>> eval_results_to_model_index("my-cool-model", eval_results)
[{'name': 'my-cool-model', 'results': [{'task': {'type': 'image-classification'}, 'dataset': {'name': 'Beans', 'type': 'beans'}, 'metrics': [{'type': 'accuracy', 'value': 0.9}]}]}]
```

#### metadata\_eval\_result

**huggingface\_hub.metadata\_eval\_result**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/repocard.py#L546)

( model\_pretty\_name: strtask\_pretty\_name: strtask\_id: strmetrics\_pretty\_name: strmetrics\_id: strmetrics\_value: typing.Anydataset\_pretty\_name: strdataset\_id: strmetrics\_config: typing.Optional\[str] = Nonemetrics\_verified: bool = Falsedataset\_config: typing.Optional\[str] = Nonedataset\_split: typing.Optional\[str] = Nonedataset\_revision: typing.Optional\[str] = Nonemetrics\_verification\_token: typing.Optional\[str] = None ) → `dict`

Parameters

* **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](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](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.

Creates a metadata dict with the result from a model evaluated on a dataset.



Example:

Copied

```
>>> 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
```

#### metadata\_update

**huggingface\_hub.metadata\_update**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/repocard.py#L674)

( repo\_id: strmetadata: typing.Dictrepo\_type: typing.Optional\[str] = Noneoverwrite: bool = Falsetoken: typing.Optional\[str] = Nonecommit\_message: typing.Optional\[str] = Nonecommit\_description: typing.Optional\[str] = Nonerevision: typing.Optional\[str] = Nonecreate\_pr: bool = Falseparent\_commit: typing.Optional\[str] = None ) → `str`

Parameters

* **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.

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.



Example:

Copied

```
>>> 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)
```
