fix: produce card for local models with existing readme (#157)
This commit is contained in:
+15
-3
@@ -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:
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user