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
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"metadata": {
|
7 |
+
"colab": {
|
8 |
+
"base_uri": "https://localhost:8080/"
|
9 |
+
},
|
10 |
+
"id": "4mDGz9V6JC0a",
|
11 |
+
"outputId": "a52fc5ef-3095-4433-ab8f-3c9c80f96b51"
|
12 |
+
},
|
13 |
+
"outputs": [
|
14 |
+
{
|
15 |
+
"output_type": "stream",
|
16 |
+
"name": "stdout",
|
17 |
+
"text": [
|
18 |
+
" Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n",
|
19 |
+
" Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n",
|
20 |
+
" Preparing metadata (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n",
|
21 |
+
" Building wheel for diffusers (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n"
|
22 |
+
]
|
23 |
+
}
|
24 |
+
],
|
25 |
+
"source": [
|
26 |
+
"!pip install git+https://github.com/cosmo3769/diffusers@standardize-model-card-template-t2i-adapter-sdxl -q"
|
27 |
+
]
|
28 |
+
},
|
29 |
+
{
|
30 |
+
"cell_type": "code",
|
31 |
+
"source": [
|
32 |
+
"import os\n",
|
33 |
+
"from PIL import Image\n",
|
34 |
+
"from diffusers.utils.hub_utils import load_or_create_model_card, populate_model_card"
|
35 |
+
],
|
36 |
+
"metadata": {
|
37 |
+
"id": "r0rK5JfUrAfc"
|
38 |
+
},
|
39 |
+
"execution_count": 4,
|
40 |
+
"outputs": []
|
41 |
+
},
|
42 |
+
{
|
43 |
+
"cell_type": "code",
|
44 |
+
"source": [
|
45 |
+
"def image_grid(imgs, rows, cols):\n",
|
46 |
+
" assert len(imgs) == rows * cols\n",
|
47 |
+
"\n",
|
48 |
+
" w, h = imgs[0].size\n",
|
49 |
+
" grid = Image.new(\"RGB\", size=(cols * w, rows * h))\n",
|
50 |
+
"\n",
|
51 |
+
" for i, img in enumerate(imgs):\n",
|
52 |
+
" grid.paste(img, box=(i % cols * w, i // cols * h))\n",
|
53 |
+
" return grid"
|
54 |
+
],
|
55 |
+
"metadata": {
|
56 |
+
"id": "m68SWTnH4qGY"
|
57 |
+
},
|
58 |
+
"execution_count": 5,
|
59 |
+
"outputs": []
|
60 |
+
},
|
61 |
+
{
|
62 |
+
"cell_type": "code",
|
63 |
+
"source": [
|
64 |
+
"def save_model_card(repo_id: str, image_logs: dict = None, base_model: str = None, repo_folder: str = None):\n",
|
65 |
+
" img_str = \"\"\n",
|
66 |
+
" if image_logs is not None:\n",
|
67 |
+
" img_str = \"You can find some example images below.\\n\"\n",
|
68 |
+
" for i, log in enumerate(image_logs):\n",
|
69 |
+
" images = log[\"images\"]\n",
|
70 |
+
" validation_prompt = log[\"validation_prompt\"]\n",
|
71 |
+
" validation_image = log[\"validation_image\"]\n",
|
72 |
+
" validation_image.save(os.path.join(repo_folder, \"image_control.png\"))\n",
|
73 |
+
" img_str += f\"prompt: {validation_prompt}\\n\"\n",
|
74 |
+
" images = [validation_image] + images\n",
|
75 |
+
" image_grid(images, 1, len(images)).save(os.path.join(repo_folder, f\"images_{i}.png\"))\n",
|
76 |
+
" img_str += f\"\\n\"\n",
|
77 |
+
"\n",
|
78 |
+
" model_description = f\"\"\"\n",
|
79 |
+
"# t2iadapter-{repo_id}\n",
|
80 |
+
"\n",
|
81 |
+
"These are t2iadapter weights trained on {base_model} with new type of conditioning.\n",
|
82 |
+
"{img_str}\n",
|
83 |
+
"\"\"\"\n",
|
84 |
+
" model_card = load_or_create_model_card(\n",
|
85 |
+
" repo_id_or_path=repo_id,\n",
|
86 |
+
" from_training=True,\n",
|
87 |
+
" license=\"creativeml-openrail-m\",\n",
|
88 |
+
" base_model=base_model,\n",
|
89 |
+
" model_description=model_description,\n",
|
90 |
+
" inference=True,\n",
|
91 |
+
" )\n",
|
92 |
+
"\n",
|
93 |
+
" tags = [\"stable-diffusion-xl\", \"stable-diffusion-xl-diffusers\", \"text-to-image\", \"diffusers\", \"t2iadapter\"]\n",
|
94 |
+
" model_card = populate_model_card(model_card, tags=tags)\n",
|
95 |
+
"\n",
|
96 |
+
" model_card.save(os.path.join(repo_folder, \"README.md\"))"
|
97 |
+
],
|
98 |
+
"metadata": {
|
99 |
+
"id": "6mgnDhfzrTp4"
|
100 |
+
},
|
101 |
+
"execution_count": 6,
|
102 |
+
"outputs": []
|
103 |
+
},
|
104 |
+
{
|
105 |
+
"cell_type": "code",
|
106 |
+
"source": [
|
107 |
+
"from diffusers.utils import load_image\n",
|
108 |
+
"\n",
|
109 |
+
"images = [\n",
|
110 |
+
" load_image(\"https://huggingface.co/datasets/diffusers/docs-images/resolve/main/amused/A%20mushroom%20in%20%5BV%5D%20style.png\")\n",
|
111 |
+
" for _ in range(3)\n",
|
112 |
+
"]\n",
|
113 |
+
"\n",
|
114 |
+
"image_logs = [\n",
|
115 |
+
" dict(\n",
|
116 |
+
" images=[image],\n",
|
117 |
+
" validation_prompt=\"validation_prompt\",\n",
|
118 |
+
" validation_image=image,\n",
|
119 |
+
" )\n",
|
120 |
+
" for image in images\n",
|
121 |
+
"]\n",
|
122 |
+
"\n",
|
123 |
+
"save_model_card(\n",
|
124 |
+
" repo_id=\"cosmo3769/t2i-adapter-sdxl\",\n",
|
125 |
+
" image_logs=image_logs,\n",
|
126 |
+
" base_model=\"runwayml/stable-diffusion-v1-5\",\n",
|
127 |
+
" repo_folder=\".\",\n",
|
128 |
+
")"
|
129 |
+
],
|
130 |
+
"metadata": {
|
131 |
+
"id": "JTEDsOd_rm7-"
|
132 |
+
},
|
133 |
+
"execution_count": 7,
|
134 |
+
"outputs": []
|
135 |
+
},
|
136 |
+
{
|
137 |
+
"cell_type": "code",
|
138 |
+
"source": [
|
139 |
+
"!cat README.md"
|
140 |
+
],
|
141 |
+
"metadata": {
|
142 |
+
"colab": {
|
143 |
+
"base_uri": "https://localhost:8080/"
|
144 |
+
},
|
145 |
+
"id": "NwCOmASdsUCT",
|
146 |
+
"outputId": "c1422ff2-17ec-4917-f23f-1ebdcd9eab9c"
|
147 |
+
},
|
148 |
+
"execution_count": 8,
|
149 |
+
"outputs": [
|
150 |
+
{
|
151 |
+
"output_type": "stream",
|
152 |
+
"name": "stdout",
|
153 |
+
"text": [
|
154 |
+
"---\n",
|
155 |
+
"license: creativeml-openrail-m\n",
|
156 |
+
"library_name: diffusers\n",
|
157 |
+
"tags:\n",
|
158 |
+
"- stable-diffusion-xl\n",
|
159 |
+
"- stable-diffusion-xl-diffusers\n",
|
160 |
+
"- text-to-image\n",
|
161 |
+
"- diffusers\n",
|
162 |
+
"- t2iadapter\n",
|
163 |
+
"inference: true\n",
|
164 |
+
"base_model: runwayml/stable-diffusion-v1-5\n",
|
165 |
+
"---\n",
|
166 |
+
"\n",
|
167 |
+
"<!-- This model card has been generated automatically according to the information the training script had access to. You\n",
|
168 |
+
"should probably proofread and complete it, then remove this comment. -->\n",
|
169 |
+
"\n",
|
170 |
+
"\n",
|
171 |
+
"# t2iadapter-cosmo3769/t2i-adapter-sdxl\n",
|
172 |
+
"\n",
|
173 |
+
"These are t2iadapter weights trained on runwayml/stable-diffusion-v1-5 with new type of conditioning.\n",
|
174 |
+
"You can find some example images below.\n",
|
175 |
+
"prompt: validation_prompt\n",
|
176 |
+
"\n",
|
177 |
+
"prompt: validation_prompt\n",
|
178 |
+
"\n",
|
179 |
+
"prompt: validation_prompt\n",
|
180 |
+
"\n",
|
181 |
+
"\n",
|
182 |
+
"\n",
|
183 |
+
"\n",
|
184 |
+
"## Intended uses & limitations\n",
|
185 |
+
"\n",
|
186 |
+
"#### How to use\n",
|
187 |
+
"\n",
|
188 |
+
"```python\n",
|
189 |
+
"# TODO: add an example code snippet for running this diffusion pipeline\n",
|
190 |
+
"```\n",
|
191 |
+
"\n",
|
192 |
+
"#### Limitations and bias\n",
|
193 |
+
"\n",
|
194 |
+
"[TODO: provide examples of latent issues and potential remediations]\n",
|
195 |
+
"\n",
|
196 |
+
"## Training details\n",
|
197 |
+
"\n",
|
198 |
+
"[TODO: describe the data used to train the model]"
|
199 |
+
]
|
200 |
+
}
|
201 |
+
]
|
202 |
+
},
|
203 |
+
{
|
204 |
+
"cell_type": "code",
|
205 |
+
"source": [],
|
206 |
+
"metadata": {
|
207 |
+
"id": "w7IqDNR72RGf"
|
208 |
+
},
|
209 |
+
"execution_count": null,
|
210 |
+
"outputs": []
|
211 |
+
}
|
212 |
+
],
|
213 |
+
"metadata": {
|
214 |
+
"colab": {
|
215 |
+
"provenance": []
|
216 |
+
},
|
217 |
+
"kernelspec": {
|
218 |
+
"display_name": "Python 3",
|
219 |
+
"name": "python3"
|
220 |
+
},
|
221 |
+
"language_info": {
|
222 |
+
"name": "python"
|
223 |
+
}
|
224 |
+
},
|
225 |
+
"nbformat": 4,
|
226 |
+
"nbformat_minor": 0
|
227 |
+
}
|