nekohacker591 commited on
Commit
94445d6
·
1 Parent(s): b616614

Upload Base_SD_SageMaker notebook03 (1).ipynb

Browse files
Base_SD_SageMaker notebook03 (1).ipynb ADDED
@@ -0,0 +1,278 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {
6
+ "id": "grG2f8fRZI6V",
7
+ "tags": []
8
+ },
9
+ "source": [
10
+ "# **StableDiffusion SageMaker version by @marat_ai**\n",
11
+ "\n",
12
+ "\n",
13
+ "![youtube.png](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAJ1BMVEVHcEz/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/////mJj/wcH/jY3aUCqcAAAACHRSTlMA8czbELSvDrGIfzkAAABCSURBVBiVY2AgA7CwMTMycgABIyMzGztQgIkDCTABBThQAEyAixtNgIeTkwu/AIYWZEMxrGVhZWaE8BiZWVnI8RoAJWEEDt2WmW4AAAAASUVORK5CYII=) **[YouTube](https://www.youtube.com/watch?v=dQw4w9WgXcQ)** | ![youtube.png](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAA0lBMVEVHcEwASXEAVIIASXEAW40AW40AW40AW40AW40AW40ASXEARmwASXEAPV4ATnkAQGQAUoAAUn8AWowAQmYANFEANVIAQWUASXEAUHwAQmcAWowASXEAUX0AW40ASXGPscSPr8B/pLh/rcYMUXdJfZkDS3KlwtIqdqBWhqB9q8WZtsY/dpQzbY1Xh6GUs8MAWowAUHwAVoUqdp8AVIJ9pLkqZ4h9orelvsyJq70AWosAWYoATniNrb+kwM8ATHZ+oreBpbnF1t8DS3PI1+BbiaNbiqT25ex8AAAAHXRSTlMAmzOe3PvEmp3+3Ar+CjM0M/v7CgoKCsUzNNz7+yV3I4EAAACzSURBVBjTTY/XEoJADEUjbUEBezdrASxg7737/79kdmEcz9PeM5NsLgCRY5qua0yBmKJpocQyMyJXDPxhCGPiHyZAzcJBvy3pL9FSgCGOhlwyXC+QgYbYO/si+/suXzVAJ+Hdyfg3r8t5Kxbj12TyGAvRlCPR9Pl5B9OIRFouDQOxIwi3nKfApW8vHcluw+26POx45QkqXerQ6YdTnKtlUcahcrM5RVstJX1dphXy6VRWvL8EBRlO0i9n9wAAAABJRU5ErkJggg==) **[[email protected]]** |\n",
14
+ "\n",
15
+ "\n",
16
+ "_That notebook creates a local instance that constantly saves to your Amazon storage, so you don't need to download all models and install all requirements every time. Only once._"
17
+ ]
18
+ },
19
+ {
20
+ "cell_type": "markdown",
21
+ "metadata": {
22
+ "id": "RE1n8kLOZI6Y",
23
+ "jp-MarkdownHeadingCollapsed": true,
24
+ "tags": []
25
+ },
26
+ "source": [
27
+ "# **STEP 1** (Runs only once!)\n",
28
+ "## Requirements 👇\n",
29
+ "* _Don't forget to specify your ngroc token_"
30
+ ]
31
+ },
32
+ {
33
+ "cell_type": "code",
34
+ "execution_count": 1,
35
+ "metadata": {
36
+ "id": "A1p2bOziZI6Y",
37
+ "tags": []
38
+ },
39
+ "outputs": [
40
+ {
41
+ "name": "stdout",
42
+ "output_type": "stream",
43
+ "text": [
44
+ "\u001b[1;32mDone!\n"
45
+ ]
46
+ }
47
+ ],
48
+ "source": [
49
+ "print('\u001b[1;32mInstalling requirements...')\n",
50
+ "\n",
51
+ "from IPython.display import clear_output\n",
52
+ "!conda install -c conda-forge libglib -y & conda update -n base conda -y\n",
53
+ "\n",
54
+ "!pip install tqdm\n",
55
+ "\n",
56
+ "clear_output()\n",
57
+ "print('\u001b[1;32mDone! Conda installed!')\n",
58
+ "\n",
59
+ "!git clone https://github.com/rocketpal/stable-diffusion-webui\n",
60
+ "%cd stable-diffusion-webui\n",
61
+ "\n",
62
+ "'''\n",
63
+ "%pip install -r requirements.txt --quiet\n",
64
+ "'''\n",
65
+ "\n",
66
+ "#ControlNet ext\n",
67
+ "\n",
68
+ "%cd /home/studio-lab-user/stable-diffusion-webui/extensions/\n",
69
+ "!git clone https://github.com/rocketpal/sd-webui-controlnet\n",
70
+ "%cd /home/studio-lab-user/stable-diffusion-webui\n",
71
+ "\n",
72
+ "clear_output()\n",
73
+ "print('\u001b[1;32mDone!')"
74
+ ]
75
+ },
76
+ {
77
+ "cell_type": "markdown",
78
+ "metadata": {
79
+ "id": "7tJLpUoHZI6Z",
80
+ "jp-MarkdownHeadingCollapsed": true,
81
+ "tags": []
82
+ },
83
+ "source": [
84
+ "# **STEP 2.1** (Runs only once!)\n",
85
+ "## Download Base models 👇\n",
86
+ "\n",
87
+ "* Don't forget to run the cell bellow!"
88
+ ]
89
+ },
90
+ {
91
+ "cell_type": "code",
92
+ "execution_count": null,
93
+ "metadata": {
94
+ "id": "FQyXmO0fZI6a",
95
+ "tags": []
96
+ },
97
+ "outputs": [],
98
+ "source": [
99
+ "#Base models:\n",
100
+ "\n",
101
+ "model_link1 = 'https://huggingface.co/SG161222/Realistic_Vision_V5.1_noVAE/resolve/main/Realistic_Vision_V5.1.safetensors'\n",
102
+ "model_link2 = ''\n",
103
+ "model_link3 = ''\n",
104
+ "model_link4 = ''\n",
105
+ "model_link5 = ''\n",
106
+ "\n",
107
+ "\n",
108
+ "\n",
109
+ "\n",
110
+ "\n",
111
+ "\n",
112
+ "\n",
113
+ "\n",
114
+ "\n",
115
+ "\n",
116
+ "\n",
117
+ "\n",
118
+ "\n",
119
+ "\n",
120
+ "#Run this to download base models:\n",
121
+ "\n",
122
+ "import os\n",
123
+ "import requests\n",
124
+ "from tqdm import tqdm\n",
125
+ "\n",
126
+ "# Function to download a file with progress\n",
127
+ "def download_file(url, target_dir):\n",
128
+ " filename = url.split(\"/\")[-1] # Extract the filename from the URL\n",
129
+ " download_path = os.path.join(target_dir, filename)\n",
130
+ " response = requests.get(url, stream=True)\n",
131
+ " total_size = int(response.headers.get(\"content-length\", 0))\n",
132
+ " block_size = 1024 # 1 Kibibyte\n",
133
+ "\n",
134
+ " with open(download_path, \"wb\") as file, tqdm(\n",
135
+ " desc=filename,\n",
136
+ " total=total_size,\n",
137
+ " unit=\"B\",\n",
138
+ " unit_scale=True,\n",
139
+ " unit_divisor=1024,\n",
140
+ " ) as bar:\n",
141
+ " for data in response.iter_content(block_size):\n",
142
+ " file.write(data)\n",
143
+ " bar.update(len(data))\n",
144
+ "\n",
145
+ "\n",
146
+ "\n",
147
+ "#Base models\n",
148
+ "download_links = [model_link1,\n",
149
+ " model_link2,\n",
150
+ " model_link3,\n",
151
+ " model_link4,\n",
152
+ " model_link5\n",
153
+ " ]\n",
154
+ "\n",
155
+ "\n",
156
+ "target_dir = \"/home/studio-lab-user/stable-diffusion-webui/models/Stable-diffusion/\"\n",
157
+ "\n",
158
+ "# Loop through the download links and download files to the target directory\n",
159
+ "for link in download_links:\n",
160
+ " if link == '':\n",
161
+ " pass\n",
162
+ " else:\n",
163
+ " download_file(link, target_dir)"
164
+ ]
165
+ },
166
+ {
167
+ "cell_type": "markdown",
168
+ "metadata": {
169
+ "id": "3wZXNNiHZI6c",
170
+ "jp-MarkdownHeadingCollapsed": true,
171
+ "tags": []
172
+ },
173
+ "source": [
174
+ "# **STEP 3**\n",
175
+ "## Run StableDiffusion 👇\n",
176
+ "Don't forget to specify your ngroc token!"
177
+ ]
178
+ },
179
+ {
180
+ "cell_type": "code",
181
+ "execution_count": null,
182
+ "metadata": {
183
+ "_kg_hide-input": false,
184
+ "_kg_hide-output": false,
185
+ "id": "8af-hu-3ZI6c",
186
+ "tags": []
187
+ },
188
+ "outputs": [],
189
+ "source": [
190
+ "%cd ~/stable-diffusion-webui\n",
191
+ "!python launch.py --listen --xformers --enable-insecure-extension-access --gradio-queue --ngrok 2W3231xwzhftRMwLpIS0jiDd2lTNqs_6JmzFy51yhDQ85Q7NxeCT"
192
+ ]
193
+ },
194
+ {
195
+ "cell_type": "markdown",
196
+ "metadata": {
197
+ "id": "xMNePTxDZI6c",
198
+ "jp-MarkdownHeadingCollapsed": true,
199
+ "tags": []
200
+ },
201
+ "source": [
202
+ "# **Maintenance**"
203
+ ]
204
+ },
205
+ {
206
+ "cell_type": "code",
207
+ "execution_count": null,
208
+ "metadata": {
209
+ "id": "U3fphZyuZI6c",
210
+ "tags": []
211
+ },
212
+ "outputs": [],
213
+ "source": [
214
+ "#clean remove all env, cache and file\n",
215
+ "\n",
216
+ "!rm -r /home/studio-lab-user/.cache\n",
217
+ "!rm -r /home/studio-lab-user/.conda\n",
218
+ "!conda remove -n \"env_name\" --all\n",
219
+ "!rm -rf /home/studio-lab-user/*"
220
+ ]
221
+ },
222
+ {
223
+ "cell_type": "code",
224
+ "execution_count": null,
225
+ "metadata": {
226
+ "id": "YApy5h6TZI6d"
227
+ },
228
+ "outputs": [],
229
+ "source": [
230
+ "#Check the storage available\n",
231
+ "!df -h | grep -E 'Avail|home'"
232
+ ]
233
+ },
234
+ {
235
+ "cell_type": "code",
236
+ "execution_count": null,
237
+ "metadata": {
238
+ "id": "vwRdajvuZI6d",
239
+ "tags": []
240
+ },
241
+ "outputs": [],
242
+ "source": [
243
+ "#List all folders and sizes\n",
244
+ "!du -h --max-depth=1 /home/studio-lab-user"
245
+ ]
246
+ }
247
+ ],
248
+ "metadata": {
249
+ "colab": {
250
+ "collapsed_sections": [
251
+ "RE1n8kLOZI6Y",
252
+ "7tJLpUoHZI6Z",
253
+ "3wZXNNiHZI6c",
254
+ "xMNePTxDZI6c"
255
+ ],
256
+ "provenance": []
257
+ },
258
+ "kernelspec": {
259
+ "display_name": "default:Python",
260
+ "language": "python",
261
+ "name": "conda-env-default-py"
262
+ },
263
+ "language_info": {
264
+ "codemirror_mode": {
265
+ "name": "ipython",
266
+ "version": 3
267
+ },
268
+ "file_extension": ".py",
269
+ "mimetype": "text/x-python",
270
+ "name": "python",
271
+ "nbconvert_exporter": "python",
272
+ "pygments_lexer": "ipython3",
273
+ "version": "3.9.16"
274
+ }
275
+ },
276
+ "nbformat": 4,
277
+ "nbformat_minor": 4
278
+ }