MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / save_model_card

Function save_model_card

diffusers/examples/controlnet/train_controlnet.py:210–249  ·  view source on GitHub ↗
(repo_id: str, image_logs=None, base_model=str, repo_folder=None)

Source from the content-addressed store, hash-verified

208
209
210def save_model_card(repo_id: str, image_logs=None, base_model=str, repo_folder=None):
211 img_str = ""
212 if image_logs is not None:
213 img_str = "You can find some example images below.\n\n"
214 for i, log in enumerate(image_logs):
215 images = log["images"]
216 validation_prompt = log["validation_prompt"]
217 validation_image = log["validation_image"]
218 validation_image.save(os.path.join(repo_folder, "image_control.png"))
219 img_str += f"prompt: {validation_prompt}\n"
220 images = [validation_image] + images
221 image_grid(images, 1, len(images)).save(os.path.join(repo_folder, f"images_{i}.png"))
222 img_str += f"![images_{i})](./images_{i}.png)\n"
223
224 model_description = f"""
225# controlnet-{repo_id}
226
227These are controlnet weights trained on {base_model} with new type of conditioning.
228{img_str}
229"""
230 model_card = load_or_create_model_card(
231 repo_id_or_path=repo_id,
232 from_training=True,
233 license="creativeml-openrail-m",
234 base_model=base_model,
235 model_description=model_description,
236 inference=True,
237 )
238
239 tags = [
240 "stable-diffusion",
241 "stable-diffusion-diffusers",
242 "text-to-image",
243 "diffusers",
244 "controlnet",
245 "diffusers-training",
246 ]
247 model_card = populate_model_card(model_card, tags=tags)
248
249 model_card.save(os.path.join(repo_folder, "README.md"))
250
251
252def parse_args(input_args=None):

Callers 1

mainFunction · 0.70

Calls 3

populate_model_cardFunction · 0.90
image_gridFunction · 0.70

Tested by

no test coverage detected