Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[RepoCard] Keep scalar tags intact without expanding API
  • Loading branch information
Wauplin committed Sep 28, 2026
commit 399a1c6ad26579ef42b464c84bfc58fa974fb567
14 changes: 7 additions & 7 deletions src/huggingface_hub/repocard_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ class ModelCardData(CardData):
then the repo name is used as a default. Defaults to None.
pipeline_tag (`str`, *optional*):
The pipeline tag associated with the model. Example: "text-classification".
tags (`str` or `list[str]`, *optional*):
List of tags (or single tag) to add to your model that can be used when filtering on the Hugging
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.
ignore_metadata_errors (`str`):
If True, errors while parsing the metadata section will be ignored. Some information might be lost during
Expand Down Expand Up @@ -346,7 +346,7 @@ def __init__(
metrics: list[str] | None = None,
model_name: str | None = None,
pipeline_tag: str | None = None,
tags: str | list[str] | None = None,
tags: list[str] | None = None,
ignore_metadata_errors: bool = False,
**kwargs,
):
Expand Down Expand Up @@ -505,8 +505,8 @@ class SpaceCardData(CardData):
List of models related to this Space. Should be a dataset ID found on 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.
tags (`str` or `list[str]`, *optional*):
List of tags (or single tag) to add to your Space that can be used when filtering on the Hub.
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.
Expand Down Expand Up @@ -540,7 +540,7 @@ def __init__(
duplicated_from: str | None = None,
models: list[str] | None = None,
datasets: list[str] | None = None,
tags: str | list[str] | None = None,
tags: list[str] | None = None,
ignore_metadata_errors: bool = False,
**kwargs,
):
Expand Down Expand Up @@ -767,7 +767,7 @@ def eval_results_to_model_index(model_name: str, eval_results: list[EvalResult])
return _remove_none(model_index)


def _to_unique_list(tags: str | list[str] | None) -> list[str] | None:
def _to_unique_list(tags: list[str] | None) -> list[str] | None:
if tags is None:
return tags
if isinstance(tags, str):
Expand Down
13 changes: 0 additions & 13 deletions tests/test_repocard.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,12 +883,6 @@ def test_preserve_order_load_save(self):
model_card.data.license = "test"
assert model_card.content == "---\nlicense: test\ndatasets:\n- foo\n- bar\n---\n\nHello\n"

def test_model_card_scalar_tags_in_frontmatter(self):
content = "---\ntags: text-classification\nlanguage: en\n---\nbody"
model_card = ModelCard(content)
assert model_card.data.tags == ["text-classification"]
assert model_card.content == "---\ntags:\n- text-classification\nlanguage: en\n---\nbody"


class TestDatasetCard:
def test_load_datasetcard_from_file(self):
Expand Down Expand Up @@ -985,10 +979,3 @@ def test_load_spacecard_from_hub(self) -> None:
assert isinstance(card.data, SpaceCardData)
assert card.data.title == "Dreambooth Training"
assert card.data.app_port is None

def test_space_card_scalar_tags_in_frontmatter(self):
content = "---\ntags: gradio\ntitle: My App\n---\nbody"
space_card = SpaceCard(content)
assert space_card.data.tags == ["gradio"]
assert space_card.content == "---\ntags:\n- gradio\ntitle: My App\n---\nbody"

8 changes: 0 additions & 8 deletions tests/test_repocard_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,6 @@ def test_model_card_unique_tags(self):
data = ModelCardData(tags=["tag2", "tag1", "tag2", "tag3"])
assert data.tags == ["tag2", "tag1", "tag3"]

def test_model_card_scalar_tag(self):
data = ModelCardData(tags="text-classification")
assert data.tags == ["text-classification"]

def test_remove_top_level_none_values(self):
as_obj = ModelCardData(tags=["tag1", None], foo={"bar": 3, "baz": None}, pipeline_tag=None)
as_dict = as_obj.to_dict()
Expand Down Expand Up @@ -388,7 +384,3 @@ def test_space_card_data(self) -> None:
"duplicated_from": "multimodalart/dreambooth-training",
}
assert card_data.tags is None # SpaceCardData has some default attributes

def test_space_card_data_scalar_tag(self) -> None:
card_data = SpaceCardData(tags="gradio")
assert card_data.tags == ["gradio"]
Loading