{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "code", "source": [ "!pip install git+https://github.com/Stepheni12/diffusers@standardize-model-card-textual-inversion-sdxl -q" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "pEdpa_COHbFk", "outputId": "727fa789-f32f-4884-fa55-5e00e1fc9e0f" }, "execution_count": 1, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ " Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n", " Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n", " Preparing metadata (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n", " Building wheel for diffusers (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n" ] } ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "uSJtonDqFav3", "outputId": "ab9fb3d1-0ade-4846-ad18-e9260cab2f43" }, "outputs": [ { "output_type": "stream", "name": "stderr", "text": [ "/usr/local/lib/python3.10/dist-packages/huggingface_hub/utils/_token.py:88: UserWarning: \n", "The secret `HF_TOKEN` does not exist in your Colab secrets.\n", "To authenticate with the Hugging Face Hub, create a token in your settings tab (https://huggingface.co/settings/tokens), set it as secret in your Google Colab and restart your session.\n", "You will be able to reuse this secret in all of your notebooks.\n", "Please note that authentication is recommended but still optional to access public models or datasets.\n", " warnings.warn(\n" ] } ], "source": [ "from diffusers.utils.hub_utils import load_or_create_model_card, populate_model_card\n", "from diffusers.utils import load_image\n", "import os\n", "\n", "def save_model_card(repo_id: str, images=None, base_model=str, repo_folder=None):\n", " img_str = \"\"\n", " for i, image in enumerate(images):\n", " image.save(os.path.join(repo_folder, f\"image_{i}.png\"))\n", " img_str += f\"![img_{i}](./image_{i}.png)\\n\"\n", "\n", " model_description = f\"\"\"\n", "# Textual inversion text2image fine-tuning - {repo_id}\n", "These are textual inversion adaption weights for {base_model}. You can find some example images in the following. \\n\n", "{img_str}\n", "\"\"\"\n", " model_card = load_or_create_model_card(\n", " repo_id_or_path=repo_id,\n", " from_training=True,\n", " license=\"creativeml-openrail-m\",\n", " base_model=base_model,\n", " model_description=model_description,\n", " inference=True,\n", " )\n", "\n", " tags = [\n", " \"stable-diffusion\",\n", " \"stable-diffusion-diffusers\",\n", " \"text-to-image\",\n", " \"diffusers\",\n", " \"controlnet\",\n", " ]\n", "\n", " model_card = populate_model_card(model_card, tags=tags)\n", "\n", " model_card.save(os.path.join(repo_folder, \"README.md\"))\n", "\n", "\n", "images = [\n", " load_image(\"https://huggingface.co/datasets/diffusers/docs-images/resolve/main/amused/A%20mushroom%20in%20%5BV%5D%20style.png\")\n", " for _ in range(3)\n", "]\n", "\n", "save_model_card(\n", " repo_id=\"Stepheni12/test-model-card-template-textual-inversion-sdxl\",\n", " images=images,\n", " base_model=\"runwayml/stable-diffusion-v1-5\",\n", " repo_folder=\".\"\n", ")" ] }, { "cell_type": "code", "source": [ "!cat README.md" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "5TbvfJWZHycP", "outputId": "bf0c9a13-aa2f-4992-944c-8e8ab6af3fca" }, "execution_count": 6, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "---\n", "license: creativeml-openrail-m\n", "library_name: diffusers\n", "tags:\n", "- stable-diffusion\n", "- stable-diffusion-diffusers\n", "- text-to-image\n", "- diffusers\n", "- controlnet\n", "inference: true\n", "base_model: runwayml/stable-diffusion-v1-5\n", "---\n", "\n", "\n", "\n", "\n", "# Textual inversion text2image fine-tuning - Stepheni12/test-model-card-template-textual-inversion-sdxl\n", "These are textual inversion adaption weights for runwayml/stable-diffusion-v1-5. You can find some example images in the following. \n", "\n", "![img_0](./image_0.png)\n", "![img_1](./image_1.png)\n", "![img_2](./image_2.png)\n", "\n", "\n", "\n", "## Intended uses & limitations\n", "\n", "#### How to use\n", "\n", "```python\n", "# TODO: add an example code snippet for running this diffusion pipeline\n", "```\n", "\n", "#### Limitations and bias\n", "\n", "[TODO: provide examples of latent issues and potential remediations]\n", "\n", "## Training details\n", "\n", "[TODO: describe the data used to train the model]" ] } ] }, { "cell_type": "code", "source": [], "metadata": { "id": "Zd8vT0ISIwEn" }, "execution_count": null, "outputs": [] } ] }