Stepheni12 commited on
Commit
5e6e724
1 Parent(s): f75e2f7

Upload test_model_card_template_textual_inversion_sdxl.ipynb

Browse files
test_model_card_template_textual_inversion_sdxl.ipynb ADDED
@@ -0,0 +1,191 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "nbformat": 4,
3
+ "nbformat_minor": 0,
4
+ "metadata": {
5
+ "colab": {
6
+ "provenance": []
7
+ },
8
+ "kernelspec": {
9
+ "name": "python3",
10
+ "display_name": "Python 3"
11
+ },
12
+ "language_info": {
13
+ "name": "python"
14
+ }
15
+ },
16
+ "cells": [
17
+ {
18
+ "cell_type": "code",
19
+ "source": [
20
+ "!pip install git+https://github.com/Stepheni12/diffusers@standardize-model-card-textual-inversion-sdxl -q"
21
+ ],
22
+ "metadata": {
23
+ "colab": {
24
+ "base_uri": "https://localhost:8080/"
25
+ },
26
+ "id": "pEdpa_COHbFk",
27
+ "outputId": "727fa789-f32f-4884-fa55-5e00e1fc9e0f"
28
+ },
29
+ "execution_count": 1,
30
+ "outputs": [
31
+ {
32
+ "output_type": "stream",
33
+ "name": "stdout",
34
+ "text": [
35
+ " Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n",
36
+ " Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n",
37
+ " Preparing metadata (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n",
38
+ " Building wheel for diffusers (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n"
39
+ ]
40
+ }
41
+ ]
42
+ },
43
+ {
44
+ "cell_type": "code",
45
+ "execution_count": 5,
46
+ "metadata": {
47
+ "colab": {
48
+ "base_uri": "https://localhost:8080/"
49
+ },
50
+ "id": "uSJtonDqFav3",
51
+ "outputId": "ab9fb3d1-0ade-4846-ad18-e9260cab2f43"
52
+ },
53
+ "outputs": [
54
+ {
55
+ "output_type": "stream",
56
+ "name": "stderr",
57
+ "text": [
58
+ "/usr/local/lib/python3.10/dist-packages/huggingface_hub/utils/_token.py:88: UserWarning: \n",
59
+ "The secret `HF_TOKEN` does not exist in your Colab secrets.\n",
60
+ "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",
61
+ "You will be able to reuse this secret in all of your notebooks.\n",
62
+ "Please note that authentication is recommended but still optional to access public models or datasets.\n",
63
+ " warnings.warn(\n"
64
+ ]
65
+ }
66
+ ],
67
+ "source": [
68
+ "from diffusers.utils.hub_utils import load_or_create_model_card, populate_model_card\n",
69
+ "from diffusers.utils import load_image\n",
70
+ "import os\n",
71
+ "\n",
72
+ "def save_model_card(repo_id: str, images=None, base_model=str, repo_folder=None):\n",
73
+ " img_str = \"\"\n",
74
+ " for i, image in enumerate(images):\n",
75
+ " image.save(os.path.join(repo_folder, f\"image_{i}.png\"))\n",
76
+ " img_str += f\"![img_{i}](./image_{i}.png)\\n\"\n",
77
+ "\n",
78
+ " model_description = f\"\"\"\n",
79
+ "# Textual inversion text2image fine-tuning - {repo_id}\n",
80
+ "These are textual inversion adaption weights for {base_model}. You can find some example images in the following. \\n\n",
81
+ "{img_str}\n",
82
+ "\"\"\"\n",
83
+ " model_card = load_or_create_model_card(\n",
84
+ " repo_id_or_path=repo_id,\n",
85
+ " from_training=True,\n",
86
+ " license=\"creativeml-openrail-m\",\n",
87
+ " base_model=base_model,\n",
88
+ " model_description=model_description,\n",
89
+ " inference=True,\n",
90
+ " )\n",
91
+ "\n",
92
+ " tags = [\n",
93
+ " \"stable-diffusion\",\n",
94
+ " \"stable-diffusion-diffusers\",\n",
95
+ " \"text-to-image\",\n",
96
+ " \"diffusers\",\n",
97
+ " \"controlnet\",\n",
98
+ " ]\n",
99
+ "\n",
100
+ " model_card = populate_model_card(model_card, tags=tags)\n",
101
+ "\n",
102
+ " model_card.save(os.path.join(repo_folder, \"README.md\"))\n",
103
+ "\n",
104
+ "\n",
105
+ "images = [\n",
106
+ " load_image(\"https://huggingface.co/datasets/diffusers/docs-images/resolve/main/amused/A%20mushroom%20in%20%5BV%5D%20style.png\")\n",
107
+ " for _ in range(3)\n",
108
+ "]\n",
109
+ "\n",
110
+ "save_model_card(\n",
111
+ " repo_id=\"Stepheni12/test-model-card-template-textual-inversion-sdxl\",\n",
112
+ " images=images,\n",
113
+ " base_model=\"runwayml/stable-diffusion-v1-5\",\n",
114
+ " repo_folder=\".\"\n",
115
+ ")"
116
+ ]
117
+ },
118
+ {
119
+ "cell_type": "code",
120
+ "source": [
121
+ "!cat README.md"
122
+ ],
123
+ "metadata": {
124
+ "colab": {
125
+ "base_uri": "https://localhost:8080/"
126
+ },
127
+ "id": "5TbvfJWZHycP",
128
+ "outputId": "bf0c9a13-aa2f-4992-944c-8e8ab6af3fca"
129
+ },
130
+ "execution_count": 6,
131
+ "outputs": [
132
+ {
133
+ "output_type": "stream",
134
+ "name": "stdout",
135
+ "text": [
136
+ "---\n",
137
+ "license: creativeml-openrail-m\n",
138
+ "library_name: diffusers\n",
139
+ "tags:\n",
140
+ "- stable-diffusion\n",
141
+ "- stable-diffusion-diffusers\n",
142
+ "- text-to-image\n",
143
+ "- diffusers\n",
144
+ "- controlnet\n",
145
+ "inference: true\n",
146
+ "base_model: runwayml/stable-diffusion-v1-5\n",
147
+ "---\n",
148
+ "\n",
149
+ "<!-- This model card has been generated automatically according to the information the training script had access to. You\n",
150
+ "should probably proofread and complete it, then remove this comment. -->\n",
151
+ "\n",
152
+ "\n",
153
+ "# Textual inversion text2image fine-tuning - Stepheni12/test-model-card-template-textual-inversion-sdxl\n",
154
+ "These are textual inversion adaption weights for runwayml/stable-diffusion-v1-5. You can find some example images in the following. \n",
155
+ "\n",
156
+ "![img_0](./image_0.png)\n",
157
+ "![img_1](./image_1.png)\n",
158
+ "![img_2](./image_2.png)\n",
159
+ "\n",
160
+ "\n",
161
+ "\n",
162
+ "## Intended uses & limitations\n",
163
+ "\n",
164
+ "#### How to use\n",
165
+ "\n",
166
+ "```python\n",
167
+ "# TODO: add an example code snippet for running this diffusion pipeline\n",
168
+ "```\n",
169
+ "\n",
170
+ "#### Limitations and bias\n",
171
+ "\n",
172
+ "[TODO: provide examples of latent issues and potential remediations]\n",
173
+ "\n",
174
+ "## Training details\n",
175
+ "\n",
176
+ "[TODO: describe the data used to train the model]"
177
+ ]
178
+ }
179
+ ]
180
+ },
181
+ {
182
+ "cell_type": "code",
183
+ "source": [],
184
+ "metadata": {
185
+ "id": "Zd8vT0ISIwEn"
186
+ },
187
+ "execution_count": null,
188
+ "outputs": []
189
+ }
190
+ ]
191
+ }