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,
)
# 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
# If the model path exists locally and includes the
# 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.
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)
if card is not None:
if card.data is None:
card.data = ModelCardData()
if card.data.tags is None:
+5 -1
View File
@@ -271,7 +271,11 @@ def get_readme_intro(
base_refusals: int,
bad_prompts: list[Prompt],
) -> str:
model_link = f"[{settings.model}](https://huggingface.co/{settings.model})"
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})"
return f"""# This is a decensored version of {
model_link