Loads or creates a model card. Args: repo_id_or_path (`str`): The repo id (e.g., "runwayml/stable-diffusion-v1-5") or local path where to look for the model card. token (`str`, *optional*): Authentication token. Will default to the stored token. See
(
repo_id_or_path: str = None,
token: Optional[str] = None,
is_pipeline: bool = False,
from_training: bool = False,
model_description: Optional[str] = None,
base_model: str = None,
prompt: Optional[str] = None,
license: Optional[str] = None,
widget: Optional[List[dict]] = None,
inference: Optional[bool] = None,
)
| 97 | |
| 98 | |
| 99 | def load_or_create_model_card( |
| 100 | repo_id_or_path: str = None, |
| 101 | token: Optional[str] = None, |
| 102 | is_pipeline: bool = False, |
| 103 | from_training: bool = False, |
| 104 | model_description: Optional[str] = None, |
| 105 | base_model: str = None, |
| 106 | prompt: Optional[str] = None, |
| 107 | license: Optional[str] = None, |
| 108 | widget: Optional[List[dict]] = None, |
| 109 | inference: Optional[bool] = None, |
| 110 | ) -> ModelCard: |
| 111 | """ |
| 112 | Loads or creates a model card. |
| 113 | |
| 114 | Args: |
| 115 | repo_id_or_path (`str`): |
| 116 | The repo id (e.g., "runwayml/stable-diffusion-v1-5") or local path where to look for the model card. |
| 117 | token (`str`, *optional*): |
| 118 | Authentication token. Will default to the stored token. See https://huggingface.co/settings/token for more |
| 119 | details. |
| 120 | is_pipeline (`bool`): |
| 121 | Boolean to indicate if we're adding tag to a [`DiffusionPipeline`]. |
| 122 | from_training: (`bool`): Boolean flag to denote if the model card is being created from a training script. |
| 123 | model_description (`str`, *optional*): Model description to add to the model card. Helpful when using |
| 124 | `load_or_create_model_card` from a training script. |
| 125 | base_model (`str`): Base model identifier (e.g., "stabilityai/stable-diffusion-xl-base-1.0"). Useful |
| 126 | for DreamBooth-like training. |
| 127 | prompt (`str`, *optional*): Prompt used for training. Useful for DreamBooth-like training. |
| 128 | license: (`str`, *optional*): License of the output artifact. Helpful when using |
| 129 | `load_or_create_model_card` from a training script. |
| 130 | widget (`List[dict]`, *optional*): Widget to accompany a gallery template. |
| 131 | inference: (`bool`, optional): Whether to turn on inference widget. Helpful when using |
| 132 | `load_or_create_model_card` from a training script. |
| 133 | """ |
| 134 | if not is_jinja_available(): |
| 135 | raise ValueError( |
| 136 | "Modelcard rendering is based on Jinja templates." |
| 137 | " Please make sure to have `jinja` installed before using `load_or_create_model_card`." |
| 138 | " To install it, please run `pip install Jinja2`." |
| 139 | ) |
| 140 | |
| 141 | try: |
| 142 | # Check if the model card is present on the remote repo |
| 143 | model_card = ModelCard.load(repo_id_or_path, token=token) |
| 144 | except (EntryNotFoundError, RepositoryNotFoundError): |
| 145 | # Otherwise create a model card from template |
| 146 | if from_training: |
| 147 | model_card = ModelCard.from_template( |
| 148 | card_data=ModelCardData( # Card metadata object that will be converted to YAML block |
| 149 | license=license, |
| 150 | library_name="diffusers", |
| 151 | inference=inference, |
| 152 | base_model=base_model, |
| 153 | instance_prompt=prompt, |
| 154 | widget=widget, |
| 155 | ), |
| 156 | template_path=MODEL_CARD_TEMPLATE_PATH, |