File size: 6,705 Bytes
5e6e724 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
{
"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\"\\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",
"<!-- This model card has been generated automatically according to the information the training script had access to. You\n",
"should probably proofread and complete it, then remove this comment. -->\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",
"\n",
"\n",
"\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": []
}
]
} |