File size: 6,156 Bytes
ac4f0d6 |
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 192 193 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "4mDGz9V6JC0a",
"outputId": "c5353c98-f1b4-4840-ea3e-0abd1aaefc6b"
},
"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"
]
}
],
"source": [
"!pip install git+https://github.com/cosmo3769/diffusers@standardize-model-card-t2i-lora -q"
]
},
{
"cell_type": "code",
"source": [
"import os\n",
"from diffusers.utils.hub_utils import load_or_create_model_card, populate_model_card"
],
"metadata": {
"id": "r0rK5JfUrAfc"
},
"execution_count": 2,
"outputs": []
},
{
"cell_type": "code",
"source": [
"def save_model_card(repo_id: str, images=None, base_model=str, dataset_name=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",
"# LoRA text2image fine-tuning - {repo_id}\n",
"These are LoRA adaption weights for {base_model}. The weights were fine-tuned on the {dataset_name} dataset. You can find some example images in the following. \\n\n",
"{img_str}\n",
"\"\"\"\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",
" \"lora\",\n",
" ]\n",
" model_card = populate_model_card(model_card, tags=tags)\n",
"\n",
" model_card.save(os.path.join(repo_folder, \"README.md\"))"
],
"metadata": {
"id": "6mgnDhfzrTp4"
},
"execution_count": 3,
"outputs": []
},
{
"cell_type": "code",
"source": [
"from diffusers.utils import load_image\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=\"cosmo3769/test\",\n",
" images=images,\n",
" base_model=\"runwayml/stable-diffusion-v1-5\",\n",
" dataset_name=\"text-to-image\",\n",
" repo_folder=\".\",\n",
")"
],
"metadata": {
"id": "JTEDsOd_rm7-"
},
"execution_count": 9,
"outputs": []
},
{
"cell_type": "code",
"source": [
"!cat README.md"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "NwCOmASdsUCT",
"outputId": "119e5ee4-e737-4c58-c7f1-6e1ccbe274a9"
},
"execution_count": 10,
"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",
"- lora\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",
"# LoRA text2image fine-tuning - cosmo3769/test\n",
"These are LoRA adaption weights for runwayml/stable-diffusion-v1-5. The weights were fine-tuned on the text-to-image dataset. 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": "w7IqDNR72RGf"
},
"execution_count": null,
"outputs": []
}
],
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 0
} |