fix: produce card for local models with existing readme (#157)

This commit is contained in:
Spiky Moth
2026-02-15 14:40:10 +01:00
committed by GitHub
parent 27097bfe8e
commit 3a115e280c
2 changed files with 20 additions and 4 deletions
+15 -3
View File
@@ -823,11 +823,23 @@ def run():
token=token, token=token,
) )
# If the model path doesn't exist locally, it can be assumed # If the model path exists locally and includes the
# to be a model hosted on the Hugging Face Hub, in which case # card, use it directly. If the model path doesn't
# exist locally, it can be assumed to be a model
# hosted on the Hugging Face Hub, in which case
# we can retrieve the model card. # we can retrieve the model card.
if not Path(settings.model).exists(): model_path = Path(settings.model)
if model_path.exists():
card_path = (
model_path / huggingface_hub.constants.REPOCARD_NAME
)
if card_path.exists():
card = ModelCard.load(card_path)
else:
card = None
else:
card = ModelCard.load(settings.model) card = ModelCard.load(settings.model)
if card is not None:
if card.data is None: if card.data is None:
card.data = ModelCardData() card.data = ModelCardData()
if card.data.tags is None: if card.data.tags is None:
+4
View File
@@ -271,6 +271,10 @@ def get_readme_intro(
base_refusals: int, base_refusals: int,
bad_prompts: list[Prompt], bad_prompts: list[Prompt],
) -> str: ) -> str:
if Path(settings.model).exists():
# Hide the path, which may contain private information.
model_link = "a model"
else:
model_link = f"[{settings.model}](https://huggingface.co/{settings.model})" model_link = f"[{settings.model}](https://huggingface.co/{settings.model})"
return f"""# This is a decensored version of { return f"""# This is a decensored version of {