Skip to content

Commit 54c39ba

Browse files
committed
Improve notebook and add requirements file
1 parent f628477 commit 54c39ba

File tree

2 files changed

+96
-45
lines changed

2 files changed

+96
-45
lines changed

Stable_Diffusion_AI_Notebook.ipynb

Lines changed: 70 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"nbformat_minor": 0,
44
"metadata": {
55
"colab": {
6-
"name": "Stable_Diffusion_AI_Notebook.ipynb",
76
"provenance": [],
87
"collapsed_sections": [],
98
"private_outputs": true
@@ -22,25 +21,34 @@
2221
{
2322
"cell_type": "markdown",
2423
"source": [
25-
"# Stable Diffusion AI Notebook\n",
24+
"# Stable Diffusion AI Notebook (Release 1.13)\n",
2625
"\n",
2726
"<img src=\"https://user-images.githubusercontent.com/60411196/186547976-d9de378a-9de8-4201-9c25-c057a9c59bad.jpeg\" alt=\"stable-diffusion-ai\" width=\"170px\"/> <br>\n",
2827
"#### Instructions:\n",
2928
"1. Execute each cell in order to mount a Dream bot and create images from text. <br>\n",
30-
"2. Once cells 1-8 were run correctly you'll be executing a terminal in cell #9, you'll to enter `pipenv run scripts/dream.py` command to run Dream bot.<br> \n",
29+
"2. Once cells 1-8 were run correctly you'll be executing a terminal in cell #9, you'll need to enter `python scripts/dream.py` command to run Dream bot.<br> \n",
3130
"3. After launching dream bot, you'll see: <br> `Dream > ` in terminal. <br> Insert a command, eg. `Dream > Astronaut floating in a distant galaxy`, or type `-h` for help.\n",
32-
"3. After completion you'll see your generated images in path `stable-diffusion/outputs/img-samples/`, you can also display images in cell #10.\n",
31+
"3. After completion you'll see your generated images in path `stable-diffusion/outputs/img-samples/`, you can also show last generated images in cell #10.\n",
3332
"4. To quit Dream bot use `q` command. <br> \n",
3433
"---\n",
3534
"<font color=\"red\">Note:</font> It takes some time to load, but after installing all dependencies you can use the bot all time you want while colab instance is up. <br>\n",
36-
"<font color=\"red\">Requirements:</font> For this notebook to work you need to have [Stable-Diffusion-v-1-4](https://huggingface.co/CompVis/stable-diffusion-v-1-4-original) stored in your Google Drive, it will be needed in cell #6\n",
35+
"<font color=\"red\">Requirements:</font> For this notebook to work you need to have [Stable-Diffusion-v-1-4](https://huggingface.co/CompVis/stable-diffusion-v-1-4-original) stored in your Google Drive, it will be needed in cell #7\n",
3736
"##### For more details visit Github repository: [lstein/stable-diffusion](https://github.com/lstein/stable-diffusion)\n",
3837
"---\n"
3938
],
4039
"metadata": {
4140
"id": "ycYWcsEKc6w7"
4241
}
4342
},
43+
{
44+
"cell_type": "markdown",
45+
"source": [
46+
"## ◢ Installation"
47+
],
48+
"metadata": {
49+
"id": "dr32VLxlnouf"
50+
}
51+
},
4452
{
4553
"cell_type": "code",
4654
"source": [
@@ -68,55 +76,77 @@
6876
"from os.path import exists\n",
6977
"\n",
7078
"if exists(\"/content/stable-diffusion/\")==True:\n",
79+
" %cd /content/stable-diffusion/\n",
7180
" print(\"Already downloaded repo\")\n",
7281
"else:\n",
7382
" !git clone --quiet https://github.com/lstein/stable-diffusion.git # Original repo\n",
74-
" %cd stable-diffusion/\n",
75-
" !git checkout --quiet tags/release-1.09\n",
76-
" "
83+
" %cd /content/stable-diffusion/\n",
84+
" !git checkout --quiet tags/release-1.13"
7785
]
7886
},
7987
{
8088
"cell_type": "code",
8189
"source": [
82-
"#@title 3. Install Python 3.8 \n",
83-
"%%capture --no-stderr\n",
90+
"#@title 3. Install dependencies\n",
8491
"import gc\n",
85-
"!apt-get -qq install python3.8\n",
92+
"\n",
93+
"if exists(\"/content/stable-diffusion/requirements-colab.txt\")==True:\n",
94+
" %cd /content/stable-diffusion/\n",
95+
" print(\"Already downloaded requirements file\")\n",
96+
"else:\n",
97+
" !wget https://raw.githubusercontent.com/lstein/stable-diffusion/development/requirements-colab.txt\n",
98+
"!pip install colab-xterm\n",
99+
"!pip install -r requirements-colab.txt\n",
86100
"gc.collect()"
87101
],
88102
"metadata": {
89-
"id": "daHlozvwKesj",
90-
"cellView": "form"
103+
"cellView": "form",
104+
"id": "QbXcGXYEFSNB"
91105
},
92106
"execution_count": null,
93107
"outputs": []
94108
},
95109
{
96110
"cell_type": "code",
97111
"source": [
98-
"#@title 4. Install dependencies from file in a VirtualEnv\n",
99-
"#@markdown Be patient, it takes ~ 5 - 7min <br>\n",
100-
"%%capture --no-stderr\n",
101-
"#Virtual environment\n",
102-
"!pip install pipenv -q\n",
103-
"!pip install colab-xterm\n",
104-
"%load_ext colabxterm\n",
105-
"!pipenv --python 3.8\n",
106-
"!pipenv install -r requirements.txt --skip-lock\n",
107-
"gc.collect()\n"
112+
"#@title 4. Load small ML models required\n",
113+
"%cd /content/stable-diffusion/\n",
114+
"!python scripts/preload_models.py\n",
115+
"gc.collect()"
108116
],
109117
"metadata": {
110118
"cellView": "form",
111-
"id": "QbXcGXYEFSNB"
119+
"id": "ChIDWxLVHGGJ"
112120
},
113121
"execution_count": null,
114122
"outputs": []
115123
},
116124
{
117125
"cell_type": "code",
118126
"source": [
119-
"#@title 5. Mount google Drive\n",
127+
"#@title 5. Restart Runtime\n",
128+
"exit()"
129+
],
130+
"metadata": {
131+
"cellView": "form",
132+
"id": "8rSMhgnAttQa"
133+
},
134+
"execution_count": null,
135+
"outputs": []
136+
},
137+
{
138+
"cell_type": "markdown",
139+
"source": [
140+
"## ◢ Configuration"
141+
],
142+
"metadata": {
143+
"id": "795x1tMoo8b1"
144+
}
145+
},
146+
{
147+
"cell_type": "code",
148+
"source": [
149+
"#@title 6. Mount google Drive\n",
120150
"from google.colab import drive\n",
121151
"drive.mount('/content/drive')"
122152
],
@@ -130,7 +160,7 @@
130160
{
131161
"cell_type": "code",
132162
"source": [
133-
"#@title 6. Drive Path to model\n",
163+
"#@title 7. Drive Path to model\n",
134164
"#@markdown Path should start with /content/drive/path-to-your-file <br>\n",
135165
"#@markdown <font color=\"red\">Note:</font> Model should be downloaded from https://huggingface.co <br>\n",
136166
"#@markdown Lastest release: [Stable-Diffusion-v-1-4](https://huggingface.co/CompVis/stable-diffusion-v-1-4-original)\n",
@@ -152,7 +182,7 @@
152182
{
153183
"cell_type": "code",
154184
"source": [
155-
"#@title 7. Symlink to model\n",
185+
"#@title 8. Symlink to model\n",
156186
"\n",
157187
"from os.path import exists\n",
158188
"import os \n",
@@ -181,32 +211,27 @@
181211
"outputs": []
182212
},
183213
{
184-
"cell_type": "code",
214+
"cell_type": "markdown",
185215
"source": [
186-
"#@title 8. Load small ML models required\n",
187-
"%%capture --no-stderr\n",
188-
"!pipenv run scripts/preload_models.py\n",
189-
"gc.collect()"
216+
"## ◢ Execution"
190217
],
191218
"metadata": {
192-
"cellView": "form",
193-
"id": "ChIDWxLVHGGJ"
194-
},
195-
"execution_count": null,
196-
"outputs": []
219+
"id": "Mc28N0_NrCQH"
220+
}
197221
},
198222
{
199223
"cell_type": "code",
200224
"source": [
201225
"#@title 9. Run Terminal and Execute Dream bot\n",
202226
"#@markdown <font color=\"blue\">Steps:</font> <br>\n",
203-
"#@markdown 1. Execute command `pipenv run scripts/dream.py` to run dream bot.<br>\n",
227+
"#@markdown 1. Execute command `python scripts/dream.py` to run dream bot.<br>\n",
204228
"#@markdown 2. After initialized you'll see `Dream>` line.<br>\n",
205229
"#@markdown 3. Example text: `Astronaut floating in a distant galaxy` <br>\n",
206230
"#@markdown 4. To quit Dream bot use: `q` command.<br>\n",
207231
"\n",
208-
"#Run from virtual env\n",
209-
"\n",
232+
"import gc\n",
233+
"%cd /content/stable-diffusion/\n",
234+
"%load_ext colabxterm\n",
210235
"%xterm\n",
211236
"gc.collect()"
212237
],
@@ -220,18 +245,18 @@
220245
{
221246
"cell_type": "code",
222247
"source": [
223-
"#@title 10. Show generated images\n",
224-
"\n",
248+
"#@title 10. Show the last 15 generated images\n",
249+
"import gc\n",
225250
"import glob\n",
226251
"import matplotlib.pyplot as plt\n",
227252
"import matplotlib.image as mpimg\n",
228253
"%matplotlib inline\n",
229254
"\n",
230255
"images = []\n",
231-
"for img_path in glob.glob('/content/stable-diffusion/outputs/img-samples/*.png'):\n",
256+
"for img_path in sorted(glob.glob('/content/stable-diffusion/outputs/img-samples/*.png'), reverse=True):\n",
232257
" images.append(mpimg.imread(img_path))\n",
233258
"\n",
234-
"# Remove ticks and labels on x-axis and y-axis both\n",
259+
"images = images[:15] \n",
235260
"\n",
236261
"plt.figure(figsize=(20,10))\n",
237262
"\n",
@@ -253,4 +278,4 @@
253278
"outputs": []
254279
}
255280
]
256-
}
281+
}

requirements-colab.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
albumentations==0.4.3
2+
clean-fid==0.1.29
3+
einops==0.3.0
4+
huggingface-hub==0.8.1
5+
imageio-ffmpeg==0.4.2
6+
imageio==2.9.0
7+
kornia==0.6.0
8+
numpy==1.21.6
9+
omegaconf==2.1.1
10+
opencv-python==4.6.0.66
11+
pillow==9.2.0
12+
pip>=22
13+
pudb==2019.2
14+
pytorch-lightning==1.4.2
15+
streamlit==1.12.0
16+
taming-transformers-rom1504==0.0.6
17+
test-tube>=0.7.5
18+
torch-fidelity==0.3.0
19+
torchmetrics==0.6.0
20+
torchtext==0.6.0
21+
transformers==4.19.2
22+
torch==1.12.1+cu113
23+
torchvision==0.13.1+cu113
24+
git+https://github.com/openai/CLIP.git@main#egg=clip
25+
git+https://github.com/lstein/k-diffusion.git@master#egg=k-diffusion
26+
-e .

0 commit comments

Comments
 (0)