NagisaNao commited on
Commit
ceeafb1
·
verified ·
1 Parent(s): b1c69a6

test colab free plan

Browse files
files_cells/notebooks/en/auto-cleaner_en.ipynb ADDED
@@ -0,0 +1,378 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "##~ AutoCleaner V3.6 CODE | BY: ANXETY ~##\n",
21
+ "\n",
22
+ "# --change log--\n",
23
+ "\"\"\"\n",
24
+ "V3.6 | 13.03.24\n",
25
+ "Fixed selection window\n",
26
+ "Dynamic update of memory display\n",
27
+ "\"\"\"\n",
28
+ "\n",
29
+ "\n",
30
+ "import os\n",
31
+ "import time\n",
32
+ "import ipywidgets as widgets\n",
33
+ "from ipywidgets import Label, Button, VBox, HBox\n",
34
+ "from IPython.display import display, HTML, Javascript\n",
35
+ "\n",
36
+ "\n",
37
+ "# ================= DETECT ENV =================\n",
38
+ "def detect_environment():\n",
39
+ " environments = {\n",
40
+ " 'COLAB_GPU': ('Google Colab', \"/content\"),\n",
41
+ " 'KAGGLE_URL_BASE': ('Kaggle', \"/kaggle/working/content\"),\n",
42
+ " 'SAGEMAKER_INTERNAL_IMAGE_URI': ('SageMaker Studio Lab', \"/home/studio-lab-user/content\")\n",
43
+ " }\n",
44
+ "\n",
45
+ " for env_var, (environment, path) in environments.items():\n",
46
+ " if env_var in os.environ:\n",
47
+ " return environment, path\n",
48
+ "\n",
49
+ "env, root_path = detect_environment()\n",
50
+ "webui_path = f\"{root_path}/sdw\"\n",
51
+ "# ----------------------------------------------\n",
52
+ "\n",
53
+ "\n",
54
+ "directories = {\n",
55
+ " \"Images\": f\"{webui_path}/outputs\",\n",
56
+ " \"Models\": f\"{webui_path}/models/Stable-diffusion/\",\n",
57
+ " \"Vae\": f\"{webui_path}/models/VAE/\",\n",
58
+ " \"LoRa\": f\"{webui_path}/models/Lora/\",\n",
59
+ " \"ControlNet Models\": f\"{webui_path}/models/ControlNet/\"\n",
60
+ "}\n",
61
+ "\n",
62
+ "\n",
63
+ "# ==================== CSS ====================\n",
64
+ "CSS = \"\"\"\n",
65
+ "<style>\n",
66
+ "/* General Styles */\n",
67
+ "\n",
68
+ "hr {\n",
69
+ " border-color: grey;\n",
70
+ " background-color: grey;\n",
71
+ " opacity: 0.25;\n",
72
+ "}\n",
73
+ "\n",
74
+ ".instruction_AC {\n",
75
+ " font-family: cursive;\n",
76
+ " font-size: 18px;\n",
77
+ " color: grey;\n",
78
+ " user-select: none;\n",
79
+ " cursor: default;\n",
80
+ "}\n",
81
+ "\n",
82
+ "\n",
83
+ "/* Container style */\n",
84
+ "\n",
85
+ ".container_AC {\n",
86
+ " position: relative;\n",
87
+ " background-color: #232323;\n",
88
+ " width: 800px;\n",
89
+ " height: auto;\n",
90
+ " padding: 15px;\n",
91
+ " border-radius: 15px;\n",
92
+ " box-shadow: 0 0 50px rgba(0, 0, 0, 0.3);\n",
93
+ " margin-bottom: 5px;\n",
94
+ " overflow: visible;\n",
95
+ "}\n",
96
+ "\n",
97
+ ".container_AC::before {\n",
98
+ " position: absolute;\n",
99
+ " top: 5px;\n",
100
+ " right: 10px;\n",
101
+ " content: \"AutoCleanerV3.6\";\n",
102
+ " font-weight: bold;\n",
103
+ " font-size: 24px;\n",
104
+ " color: rgba(0, 0, 0, 0.2);\n",
105
+ "}\n",
106
+ "\n",
107
+ ".container_AC::after {\n",
108
+ " position: absolute;\n",
109
+ " top: 30px;\n",
110
+ " right: 10px;\n",
111
+ " content: \"ANXETY\";\n",
112
+ " font-weight: bold;\n",
113
+ " font-size: 18px;\n",
114
+ " color: rgba(0, 0, 0, 0.2);\n",
115
+ "}\n",
116
+ "\n",
117
+ ".custom-select-multiple_AC select {\n",
118
+ " padding: 10px;\n",
119
+ " font-family: cursive;\n",
120
+ " border: 1px solid #262626 !important;\n",
121
+ " border-radius: 10px;\n",
122
+ " color: white;\n",
123
+ " background-color: #1c1c1c;\n",
124
+ " box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);\n",
125
+ "}\n",
126
+ "\n",
127
+ ".output_AC {\n",
128
+ " padding: 10px;\n",
129
+ " height: auto;\n",
130
+ " border: 1px solid #262626;\n",
131
+ " border-radius: 10px;\n",
132
+ " background-color: #1c1c1c;\n",
133
+ " box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);\n",
134
+ " width: auto;\n",
135
+ " box-sizing: border-box;\n",
136
+ "}\n",
137
+ "\n",
138
+ ".output_message_AC {\n",
139
+ " font-family: cursive;\n",
140
+ " color: white !important;\n",
141
+ " font-size: 14px;\n",
142
+ " user-select: none;\n",
143
+ " cursor: default\n",
144
+ "}\n",
145
+ "\n",
146
+ "\n",
147
+ ".storage_info_AC {\n",
148
+ " padding: 5px 20px;\n",
149
+ " height: auto;\n",
150
+ " border: 1px solid #262626;\n",
151
+ " border-radius: 10px;\n",
152
+ " background-color: #1c1c1c;\n",
153
+ " box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);\n",
154
+ " width: auto;\n",
155
+ " font-family: cursive;\n",
156
+ " color: #B2B2B2 !important;\n",
157
+ " font-size: 14px;\n",
158
+ " user-select: none;\n",
159
+ " cursor: default\n",
160
+ "}\n",
161
+ "\n",
162
+ "\n",
163
+ "/* Button and storage info layout */\n",
164
+ ".lower_information_panel_AC {\n",
165
+ " display: flex;\n",
166
+ " align-items: center;\n",
167
+ " justify-content: space-between;\n",
168
+ "}\n",
169
+ "\n",
170
+ "\n",
171
+ "/* Button style */\n",
172
+ "\n",
173
+ ".button_AC {\n",
174
+ " width: auto;\n",
175
+ " font-family: cursive;\n",
176
+ " color: white !important;\n",
177
+ " font-size: 14px;\n",
178
+ " font-weight: bold;\n",
179
+ " height: 35px;\n",
180
+ " border-radius: 15px;\n",
181
+ " background-image: radial-gradient(circle at top left, purple 10%, violet 90%);\n",
182
+ " background-size: 200% 200%;\n",
183
+ " background-position: left bottom;\n",
184
+ " transition: background 0.5s ease-in-out, transform 0.3s ease;\n",
185
+ "}\n",
186
+ "\n",
187
+ ".button_AC:hover {\n",
188
+ " cursor: pointer;\n",
189
+ " background-size: 200% 200%;\n",
190
+ " background-position: right bottom;\n",
191
+ " transform: translateY(1px);\n",
192
+ "}\n",
193
+ "\n",
194
+ ".button_execute_AC:hover {\n",
195
+ " background-image: radial-gradient(circle at top left, purple 10%, #93ac47 90%);\n",
196
+ "}\n",
197
+ "\n",
198
+ ".button_clear_AC:hover {\n",
199
+ " background-image: radial-gradient(circle at top left, purple 10%, #fc3468 90%);\n",
200
+ "}\n",
201
+ "\n",
202
+ ".button_execute_AC:active,\n",
203
+ ".button_clear_AC:active {\n",
204
+ " filter: brightness(0.75);\n",
205
+ "}\n",
206
+ "\n",
207
+ ".jupyter-widgets.lm-Widget:focus {\n",
208
+ " outline: none;\n",
209
+ "}\n",
210
+ "\n",
211
+ "\n",
212
+ "/* Animation of elements */\n",
213
+ "\n",
214
+ "/* Emergence */\n",
215
+ ".container_AC {\n",
216
+ " animation-name: slideInTopBlur;\n",
217
+ " animation-duration: 0.7s;\n",
218
+ " animation-fill-mode: forwards;\n",
219
+ "}\n",
220
+ "\n",
221
+ "@keyframes slideInTopBlur {\n",
222
+ " 0% {\n",
223
+ " transform: translate3d(0, 50%, 0) scale(0.85) rotate3d(1, 0, 0, -85deg);\n",
224
+ " filter: blur(5px) grayscale(1) brightness(0.5);\n",
225
+ " opacity: 0;\n",
226
+ " }\n",
227
+ " 100% {\n",
228
+ " transform: translate3d(0, 0, 0) scale(1) rotate3d(1, 0, 0, 0deg);\n",
229
+ " filter: blur(0) grayscale(0) brightness(1);\n",
230
+ " opacity: 1;\n",
231
+ " }\n",
232
+ "}\n",
233
+ "\n",
234
+ "/* Leaving */\n",
235
+ ".container_AC.hide {\n",
236
+ " animation-name: slideOutTopBlur;\n",
237
+ " animation-duration: 0.5s;\n",
238
+ " animation-fill-mode: forwards;\n",
239
+ "}\n",
240
+ "\n",
241
+ "@keyframes slideOutTopBlur {\n",
242
+ " 0% {\n",
243
+ " transform: translate3d(0, 0, 0) scale(1);\n",
244
+ " filter: blur(0) grayscale(0) brightness(1);\n",
245
+ " opacity: 1;\n",
246
+ " }\n",
247
+ " 100% {\n",
248
+ " transform: translate3d(0, -100%, 0);\n",
249
+ " filter: blur(5px) grayscale(1) brightness(0);\n",
250
+ " opacity: 0;\n",
251
+ " }\n",
252
+ "}\n",
253
+ "</style>\n",
254
+ "\"\"\"\n",
255
+ "\n",
256
+ "display(HTML(CSS))\n",
257
+ "# ==================== CSS ====================\n",
258
+ "\n",
259
+ "\n",
260
+ "# ================ AutoCleaner function ================\n",
261
+ "def clean_directory(directory):\n",
262
+ " deleted_files = 0\n",
263
+ " for root, dirs, files in os.walk(directory):\n",
264
+ " for file in files:\n",
265
+ " if file.endswith((\".txt\", \".yaml\")):\n",
266
+ " continue\n",
267
+ " os.remove(os.path.join(root, file))\n",
268
+ " deleted_files += 1\n",
269
+ " return deleted_files\n",
270
+ "\n",
271
+ "\n",
272
+ "def get_word_variant(n, variants):\n",
273
+ " unit = abs(n) % 10\n",
274
+ " tens = abs(n) % 100\n",
275
+ " if tens in range(11, 15):\n",
276
+ " return variants[2]\n",
277
+ " elif unit == 1:\n",
278
+ " return variants[0]\n",
279
+ " elif unit in range(2, 5):\n",
280
+ " return variants[1]\n",
281
+ " else:\n",
282
+ " return variants[2]\n",
283
+ "\n",
284
+ "\n",
285
+ "def update_memory_info():\n",
286
+ " disk_space = psutil.disk_usage(os.getcwd())\n",
287
+ " total = disk_space.total / (1024 ** 3)\n",
288
+ " used = disk_space.used / (1024 ** 3)\n",
289
+ " free = disk_space.free / (1024 ** 3)\n",
290
+ "\n",
291
+ " storage_info.value = f'''\n",
292
+ " <div class=\"storage_info_AC\">Total storage: {total:.2f} GB <span style=\"color: #555\">|</span> Used: {used:.2f} GB <span style=\"color: #555\">|</span> Free: {free:.2f} GB</div>\n",
293
+ " '''\n",
294
+ "\n",
295
+ "\n",
296
+ "def on_execute_button_press(button):\n",
297
+ " selected_cleaners = auto_cleaner_widget.value\n",
298
+ " deleted_files_dict = {}\n",
299
+ "\n",
300
+ " for option in selected_cleaners:\n",
301
+ " if option in directories:\n",
302
+ " deleted_files_dict[option] = clean_directory(directories[option])\n",
303
+ "\n",
304
+ " output.clear_output()\n",
305
+ "\n",
306
+ " with output:\n",
307
+ " for message in generate_messages(deleted_files_dict):\n",
308
+ " message_widget = HTML(f'<p class=\"output_message_AC\">{message}</p>')\n",
309
+ " display(message_widget)\n",
310
+ "\n",
311
+ " update_memory_info()\n",
312
+ "\n",
313
+ "\n",
314
+ "def on_clear_button_press(button):\n",
315
+ " container.add_class(\"hide\")\n",
316
+ " time.sleep(0.5)\n",
317
+ " widgets.Widget.close_all()\n",
318
+ "\n",
319
+ "\n",
320
+ "def generate_messages(deleted_files_dict):\n",
321
+ " messages = []\n",
322
+ " word_variants = {\n",
323
+ " \"Images\": [\"Image\", \"Images\", \"Images\"],\n",
324
+ " \"Models\": [\"Model\", \"Models\", \"Models\"],\n",
325
+ " \"Vae\": [\"VAE\", \"VAE\", \"VAE\"],\n",
326
+ " \"LoRa\": [\"LoRa\", \"LoRa\", \"LoRa\"],\n",
327
+ " \"ControlNet Models\": [\"ControlNet Model\", \"ControlNet Models\", \"ControlNet Models\"]\n",
328
+ " }\n",
329
+ " deleted_word_variants = [\"Deleted\", \"Deleted\", \"Deleted\"]\n",
330
+ " for key, value in deleted_files_dict.items():\n",
331
+ " word_variant = word_variants.get(key, [\"\", \"\", \"\"])\n",
332
+ " deleted_word = get_word_variant(value, deleted_word_variants)\n",
333
+ " object_word = get_word_variant(value, word_variant)\n",
334
+ " messages.append(f\"{deleted_word} {value} {object_word}\")\n",
335
+ " return messages\n",
336
+ "# ================ AutoCleaner function ================\n",
337
+ "\n",
338
+ "\n",
339
+ "# --- storage memory ---\n",
340
+ "import psutil\n",
341
+ "disk_space = psutil.disk_usage(os.getcwd())\n",
342
+ "total = disk_space.total / (1024 ** 3)\n",
343
+ "used = disk_space.used / (1024 ** 3)\n",
344
+ "free = disk_space.free / (1024 ** 3)\n",
345
+ "\n",
346
+ "\n",
347
+ "# UI Code\n",
348
+ "AutoCleaner_options = AutoCleaner_options = list(directories.keys())\n",
349
+ "instruction_label = widgets.HTML('''\n",
350
+ "<span class=\"instruction_AC\">Use <span style=\"color: #B2B2B2;\">ctrl</span> or <span style=\"color: #B2B2B2;\">shift</span> for multiple selections.</span>\n",
351
+ "''')\n",
352
+ "auto_cleaner_widget = widgets.SelectMultiple(options=AutoCleaner_options, layout=widgets.Layout(width='auto')).add_class(\"custom-select-multiple_AC\")\n",
353
+ "output = widgets.Output().add_class(\"output_AC\")\n",
354
+ "# ---\n",
355
+ "execute_button = Button(description='Execute Cleaning').add_class(\"button_execute_AC\").add_class(\"button_AC\")\n",
356
+ "execute_button.on_click(on_execute_button_press)\n",
357
+ "clear_button = Button(description='Hide Widget').add_class(\"button_clear_AC\").add_class(\"button_AC\")\n",
358
+ "clear_button.on_click(on_clear_button_press)\n",
359
+ "# ---\n",
360
+ "storage_info = widgets.HTML(f'''\n",
361
+ "<div class=\"storage_info_AC\">Total storage: {total:.2f} GB <span style=\"color: #555\">|</span> Used: {used:.2f} GB <span style=\"color: #555\">|</span> Free: {free:.2f} GB</div>\n",
362
+ "''')\n",
363
+ "# ---\n",
364
+ "buttons = widgets.HBox([execute_button, clear_button])\n",
365
+ "lower_information_panel = widgets.HBox([buttons, storage_info]).add_class(\"lower_information_panel_AC\")\n",
366
+ "\n",
367
+ "container = VBox([instruction_label, widgets.HTML('<hr>'), auto_cleaner_widget, output, widgets.HTML('<hr>'), lower_information_panel]).add_class(\"container_AC\")\n",
368
+ "\n",
369
+ "display(container)"
370
+ ],
371
+ "metadata": {
372
+ "id": "I22dFg7F2j3G"
373
+ },
374
+ "execution_count": null,
375
+ "outputs": []
376
+ }
377
+ ]
378
+ }
files_cells/notebooks/en/downloading_en.ipynb ADDED
@@ -0,0 +1,579 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "##~ DOWNLOADING CODE | BY: ANXETY ~##\n",
21
+ "\n",
22
+ "import os\n",
23
+ "import re\n",
24
+ "import time\n",
25
+ "import json\n",
26
+ "import requests\n",
27
+ "import subprocess\n",
28
+ "from datetime import timedelta\n",
29
+ "from subprocess import getoutput\n",
30
+ "from urllib.parse import unquote\n",
31
+ "from IPython.utils import capture\n",
32
+ "from IPython.display import clear_output\n",
33
+ "\n",
34
+ "\n",
35
+ "# ================= DETECT ENV =================\n",
36
+ "def detect_environment():\n",
37
+ " environments = {\n",
38
+ " 'COLAB_GPU': ('Google Colab', \"/content\"),\n",
39
+ " 'KAGGLE_URL_BASE': ('Kaggle', \"/kaggle/working/content\"),\n",
40
+ " 'SAGEMAKER_INTERNAL_IMAGE_URI': ('SageMaker Studio Lab', \"/home/studio-lab-user/content\")\n",
41
+ " }\n",
42
+ "\n",
43
+ " for env_var, (environment, path) in environments.items():\n",
44
+ " if env_var in os.environ:\n",
45
+ " return environment, path\n",
46
+ "\n",
47
+ "env, root_path = detect_environment()\n",
48
+ "webui_path = f\"{root_path}/sdw\"\n",
49
+ "# ----------------------------------------------\n",
50
+ "\n",
51
+ "\n",
52
+ "# === ONLY SAGEMAKER ===\n",
53
+ "if env == \"SageMaker Studio Lab\":\n",
54
+ " print(\"Updating dependencies, may take some time...\")\n",
55
+ " !pip install -q --upgrade torchsde\n",
56
+ " !pip install -q --upgrade pip\n",
57
+ " !pip install -q --upgrade psutil\n",
58
+ "\n",
59
+ " clear_output()\n",
60
+ "\n",
61
+ "\n",
62
+ "# ================ LIBRARIES ================\n",
63
+ "flag_file = f\"{root_path}/libraries_installed.txt\"\n",
64
+ "\n",
65
+ "if not os.path.exists(flag_file):\n",
66
+ " # A1111 update webui to 1.8.0\n",
67
+ " xformers = \"xformers==0.0.23.post1 triton==2.1.0\"\n",
68
+ " torch = \"torch==2.1.2+cu121 torchvision==0.16.2+cu121 --extra-index-url https://download.pytorch.org/whl/cu121\"\n",
69
+ "\n",
70
+ " print(\"Installing the libraries, it's going to take a while....\", end='')\n",
71
+ " with capture.capture_output() as cap:\n",
72
+ " !apt-get update && apt -y install aria2\n",
73
+ " !npm install -g localtunnel &> /dev/null\n",
74
+ " !curl -s -OL https://github.com/DEX-1101/sd-webui-notebook/raw/main/res/new_tunnel --output-dir {root_path}\n",
75
+ " !curl -s -Lo /usr/bin/cl https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 && chmod +x /usr/bin/cl\n",
76
+ " !pip install insightface\n",
77
+ "\n",
78
+ " if env == \"SageMaker Studio Lab\":\n",
79
+ " %pip install -q opencv-python-headless huggingface-hub\n",
80
+ " %conda update -q -n base conda\n",
81
+ " %conda install -q -y aria2\n",
82
+ " %conda install -q -y glib\n",
83
+ " !pip install tensorflow\n",
84
+ "\n",
85
+ " !wget -P /home/studio-lab-user https://huggingface.co/NagisaNao/fast_repo/resolve/main/sagemaker/FULL_DELETED_NOTEBOOK.ipynb\n",
86
+ "\n",
87
+ " if env == \"Google Colab\":\n",
88
+ " !pip install -q {xformers} -U\n",
89
+ " else:\n",
90
+ " !pip install -q {torch} -U\n",
91
+ " !pip install -q {xformers} -U\n",
92
+ "\n",
93
+ " with open(flag_file, \"w\") as f:\n",
94
+ " f.write(\"hey ;3\")\n",
95
+ " del cap\n",
96
+ " print(\"\\rLibraries are installed!\" + \" \"*35)\n",
97
+ " time.sleep(2)\n",
98
+ " clear_output()\n",
99
+ "\n",
100
+ "\n",
101
+ "# ================= loading settings V4 =================\n",
102
+ "def load_settings(path):\n",
103
+ " if os.path.exists(path):\n",
104
+ " with open(path, 'r') as file:\n",
105
+ " return json.load(file)\n",
106
+ " return {}\n",
107
+ "\n",
108
+ "settings = load_settings(f'{root_path}/settings.json')\n",
109
+ "\n",
110
+ "variables = [\n",
111
+ " 'Model', 'Model_Num', 'Inpainting_Model',\n",
112
+ " 'Vae', 'Vae_Num',\n",
113
+ " 'latest_webui', 'latest_exstensions', 'detailed_download',\n",
114
+ " 'controlnet', 'controlnet_Num', 'commit_hash', 'optional_huggingface_token',\n",
115
+ " 'ngrok_token' 'commandline_arguments',\n",
116
+ " 'Model_url', 'Vae_url', 'LoRA_url', 'Embedding_url', 'Extensions_url', 'custom_file_urls'\n",
117
+ "]\n",
118
+ "\n",
119
+ "locals().update({key: settings.get(key) for key in variables})\n",
120
+ "\n",
121
+ "\n",
122
+ "# ================= OTHER =================\n",
123
+ "try:\n",
124
+ " start_colab\n",
125
+ "except:\n",
126
+ " start_colab = int(time.time())-5\n",
127
+ "\n",
128
+ "# CONFIG DIR\n",
129
+ "models_dir = f\"{webui_path}/models/Stable-diffusion\"\n",
130
+ "vaes_dir = f\"{webui_path}/models/VAE\"\n",
131
+ "embeddings_dir = f\"{webui_path}/embeddings\"\n",
132
+ "loras_dir = f\"{webui_path}/models/Lora\"\n",
133
+ "extensions_dir = f\"{webui_path}/extensions\"\n",
134
+ "control_dir = f\"{webui_path}/models/ControlNet\"\n",
135
+ "\n",
136
+ "\n",
137
+ "# ================= MAIN CODE =================\n",
138
+ "# --- Obsolescence warning ---\n",
139
+ "if env == \"SageMaker Studio Lab\":\n",
140
+ " print(\"You are using the 'SageMaker' environment - this environment is outdated so many bugs will not be fixed and it will be cut in functionality. To save memory and/or to avoid bugs.\\n\\n\")\n",
141
+ "\n",
142
+ "\n",
143
+ "if not os.path.exists(webui_path):\n",
144
+ " start_install = int(time.time())\n",
145
+ " print(\"⌚ Unpacking Stable Diffusion...\", end='')\n",
146
+ " with capture.capture_output() as cap:\n",
147
+ " !aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/NagisaNao/fast_repo/resolve/main/FULL_REPO.zip -o repo.zip\n",
148
+ " !unzip -q -o repo.zip -d {webui_path}\n",
149
+ " !rm -rf repo.zip\n",
150
+ "\n",
151
+ " %cd {root_path}\n",
152
+ " os.environ[\"SAFETENSORS_FAST_GPU\"]='1'\n",
153
+ " os.environ[\"CUDA_MODULE_LOADING\"]=\"LAZY\"\n",
154
+ " os.environ[\"TF_CPP_MIN_LOG_LEVEL\"] = \"3\"\n",
155
+ " os.environ[\"PYTHONWARNINGS\"] = \"ignore\"\n",
156
+ "\n",
157
+ " !echo -n {start_colab} > {webui_path}/static/colabTimer.txt\n",
158
+ " del cap\n",
159
+ " install_time = timedelta(seconds=time.time()-start_install)\n",
160
+ " print(\"\\r🚀 Unpacking is complete! For\",\"%02d:%02d:%02d ⚡\\n\" % (install_time.seconds / 3600, (install_time.seconds / 60) % 60, install_time.seconds % 60), end='', flush=True)\n",
161
+ "else:\n",
162
+ " !echo -n {start_colab} > {webui_path}/static/colabTimer.txt\n",
163
+ " print(\"🚀 All unpacked... Skip. ⚡\")\n",
164
+ " start_colab = float(open(f'{webui_path}/static/colabTimer.txt', 'r').read())\n",
165
+ " time_since_start = str(timedelta(seconds=time.time()-start_colab)).split('.')[0]\n",
166
+ " print(f\"⌚️ You have been conducting this session for - \\033[33m{time_since_start}\\033[0m\")\n",
167
+ "\n",
168
+ "\n",
169
+ "## Changes extensions and WebUi\n",
170
+ "if latest_webui or latest_exstensions:\n",
171
+ " action = \"Updating WebUI and Extensions\" if latest_webui and latest_exstensions else (\"WebUI Update\" if latest_webui else \"Update Extensions\")\n",
172
+ " print(f\"⌚️ {action}...\", end='', flush=True)\n",
173
+ " with capture.capture_output() as cap:\n",
174
+ " !git config --global user.email \"[email protected]\"\n",
175
+ " !git config --global user.name \"Your Name\"\n",
176
+ "\n",
177
+ " ## Update Webui\n",
178
+ " if latest_webui:\n",
179
+ " %cd {webui_path}\n",
180
+ " !git restore .\n",
181
+ " !git pull -X theirs --rebase --autostash\n",
182
+ "\n",
183
+ " ## Update extensions\n",
184
+ " if latest_exstensions:\n",
185
+ " if env != \"SageMaker Studio Lab\":\n",
186
+ " !{'for dir in ' + webui_path + '/extensions/*/; do cd \\\"$dir\\\" && git reset --hard && git pull; done'}\n",
187
+ " else:\n",
188
+ " !{'for dir in /home/studio-lab-user/content/sdw/extensions/*/; do cd \\\"$dir\\\" && git fetch origin && git pull; done'}\n",
189
+ "\n",
190
+ " !cd {webui_path}/repositories/stable-diffusion-stability-ai && git restore .\n",
191
+ " del cap\n",
192
+ " print(f\"\\r✨ {action} Completed!\")\n",
193
+ "\n",
194
+ "\n",
195
+ "# === FIXING ERRORS ===\n",
196
+ "# --- All ---\n",
197
+ "# --- Encrypt-Image ---\n",
198
+ "!sed -i '9,37d' {webui_path}/extensions/Encrypt-Image/javascript/encrypt_images_info.js\n",
199
+ "\n",
200
+ "# --- SageMaker ---\n",
201
+ "if env == \"SageMaker Studio Lab\":\n",
202
+ " with capture.capture_output() as cap:\n",
203
+ " # --- SuperMerger Remove ---\n",
204
+ " if os.path.exists(f\"{webui_path}/extensions/supermerger\"):\n",
205
+ " !rm -rf {webui_path}/extensions/supermerger\n",
206
+ " # --- Launch (Style) ---\n",
207
+ " !wget -O {webui_path}/modules/styles.py https://huggingface.co/NagisaNao/fast_repo/resolve/main/sagemaker/fixing/webui/styles.py\n",
208
+ " del cap\n",
209
+ "\n",
210
+ "\n",
211
+ "## Version switching\n",
212
+ "if commit_hash:\n",
213
+ " print('⏳ Time machine activation...', end=\"\", flush=True)\n",
214
+ " with capture.capture_output() as cap:\n",
215
+ " %cd {webui_path}\n",
216
+ " !git config --global user.email \"[email protected]\"\n",
217
+ " !git config --global user.name \"Your Name\"\n",
218
+ " !git reset --hard {commit_hash}\n",
219
+ " del cap\n",
220
+ " print(f\"\\r⌛️ The time machine has been activated! Current commit: \\033[34m{commit_hash}\\033[0m\")\n",
221
+ "\n",
222
+ "\n",
223
+ "## Downloading model and stuff | oh yeah~ I'm starting to misunderstand my own code ( almost my own ;3 )\n",
224
+ "print(\"📦 Downloading models and stuff...\", end='')\n",
225
+ "model_list = {\n",
226
+ " \"1.Anime (by Xpuct) + INP\": [\n",
227
+ " {\"url\": \"https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2.safetensors\", \"name\": \"Anime_v2.safetensors\"},\n",
228
+ " {\"url\": \"https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2-inpainting.safetensors\", \"name\": \"Anime_v2-inpainting.safetensors\"}\n",
229
+ " ],\n",
230
+ " \"2.Cetus-Mix [Anime] [V4] + INP\": [\n",
231
+ " {\"url\": \"https://civitai.com/api/download/models/130298\", \"name\": \"CetusMix_V4.safetensors\"},\n",
232
+ " {\"url\": \"https://civitai.com/api/download/models/139882\", \"name\": \"CetusMix_V4-inpainting.safetensors\"}\n",
233
+ " ],\n",
234
+ " \"3.Counterfeit [Anime] [V3] + INP\": [\n",
235
+ " {\"url\": \"https://civitai.com/api/download/models/125050\", \"name\": \"Counterfeit_V3.safetensors\"},\n",
236
+ " {\"url\": \"https://civitai.com/api/download/models/137911\", \"name\": \"Counterfeit_V3-inpainting.safetensors\"}\n",
237
+ " ],\n",
238
+ " \"4.CuteColor [Anime] [V3]\": [\n",
239
+ " {\"url\": \"https://civitai.com/api/download/models/138754\", \"name\": \"CuteColor_V3.safetensors\"}\n",
240
+ " ],\n",
241
+ " \"5.Dark-Sushi-Mix [Anime]\": [\n",
242
+ " {\"url\": \"https://civitai.com/api/download/models/101640\", \"name\": \"DarkSushiMix_2_5D.safetensors\"},\n",
243
+ " {\"url\": \"https://civitai.com/api/download/models/56071\", \"name\": \"DarkSushiMix_colorful.safetensors\"}\n",
244
+ " ],\n",
245
+ " \"6.Meina-Mix [Anime] [V11] + INP\": [\n",
246
+ " {\"url\": \"https://civitai.com/api/download/models/119057\", \"name\": \"MeinaMix_V11.safetensors\"},\n",
247
+ " {\"url\": \"https://civitai.com/api/download/models/120702\", \"name\": \"MeinaMix_V11-inpainting.safetensors\"}\n",
248
+ " ],\n",
249
+ " \"7.Mix-Pro [Anime] [V4] + INP\": [\n",
250
+ " {\"url\": \"https://civitai.com/api/download/models/125668\", \"name\": \"MixPro_V4.safetensors\"},\n",
251
+ " {\"url\": \"https://civitai.com/api/download/models/139878\", \"name\": \"MixPro_V4-inpainting.safetensors\"}\n",
252
+ " ],\n",
253
+ " \"8.BluMix [Anime] [V7]\": [\n",
254
+ " {\"url\": \"https://civitai.com/api/download/models/361779\", \"name\": \"BluMix_v7.safetensors\"}\n",
255
+ " ]\n",
256
+ "}\n",
257
+ "\n",
258
+ "# 1-4 (fp16/cleaned)\n",
259
+ "vae_list = {\n",
260
+ " \"1.Anime.vae\": [\n",
261
+ " {\"url\": \"https://civitai.com/api/download/models/131654\", \"name\": \"Anime.vae.safetensors\"},\n",
262
+ " {\"url\": \"https://civitai.com/api/download/models/131658\", \"name\": \"vae-ft-mse.vae.safetensors\"}\n",
263
+ " ],\n",
264
+ " \"2.Anything.vae\": [{\"url\": \"https://civitai.com/api/download/models/131656\", \"name\": \"Anything.vae.safetensors\"}],\n",
265
+ " \"3.Blessed2.vae\": [{\"url\": \"https://civitai.com/api/download/models/142467\", \"name\": \"Blessed2.vae.safetensors\"}],\n",
266
+ " \"4.ClearVae.vae\": [{\"url\": \"https://civitai.com/api/download/models/133362\", \"name\": \"ClearVae_23.vae.safetensors\"}],\n",
267
+ " \"5.WD.vae\": [{\"url\": \"https://huggingface.co/NoCrypt/resources/resolve/main/VAE/wd.vae.safetensors\", \"name\": \"WD.vae.safetensors\"}]\n",
268
+ "}\n",
269
+ "\n",
270
+ "controlnet_list = {\n",
271
+ " \"1.canny\": [\n",
272
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny_fp16.safetensors\", \"name\": \"control_v11p_sd15_canny_fp16.safetensors\"},\n",
273
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_canny_fp16.yaml\", \"name\": \"control_v11p_sd15_canny_fp16.yaml\"}\n",
274
+ " ],\n",
275
+ " \"2.openpose\": [\n",
276
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose_fp16.safetensors\", \"name\": \"control_v11p_sd15_openpose_fp16.safetensors\"},\n",
277
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_openpose_fp16.yaml\", \"name\": \"control_v11p_sd15_openpose_fp16.yaml\"}\n",
278
+ " ],\n",
279
+ " \"3.depth\": [\n",
280
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth_fp16.safetensors\", \"name\": \"control_v11f1p_sd15_depth_fp16.safetensors\"},\n",
281
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1p_sd15_depth_fp16.yaml\", \"name\": \"control_v11f1p_sd15_depth_fp16.yaml\"},\n",
282
+ " {\"url\": \"https://huggingface.co/NagisaNao/models/resolve/main/ControlNet_v11/control_v11p_sd15_depth_anything_fp16.safetensors\", \"name\": \"control_v11p_sd15_depth_anything_fp16.safetensors\"}\n",
283
+ " ],\n",
284
+ " \"4.normal_map\": [\n",
285
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_normalbae_fp16.safetensors\", \"name\": \"control_v11p_sd15_normalbae_fp16.safetensors\"},\n",
286
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_normalbae_fp16.yaml\", \"name\": \"control_v11p_sd15_normalbae_fp16.yaml\"}\n",
287
+ " ],\n",
288
+ " \"5.mlsd\": [\n",
289
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_mlsd_fp16.safetensors\", \"name\": \"control_v11p_sd15_mlsd_fp16.safetensors\"},\n",
290
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_mlsd_fp16.yaml\", \"name\": \"control_v11p_sd15_mlsd_fp16.yaml\"}\n",
291
+ " ],\n",
292
+ " \"6.lineart\": [\n",
293
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart_fp16.safetensors\", \"name\": \"control_v11p_sd15_lineart_fp16.safetensors\"},\n",
294
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15s2_lineart_anime_fp16.safetensors\", \"name\": \"control_v11p_sd15s2_lineart_anime_fp16.safetensors\"},\n",
295
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_lineart_fp16.yaml\", \"name\": \"control_v11p_sd15_lineart_fp16.yaml\"},\n",
296
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15s2_lineart_anime_fp16.yaml\", \"name\": \"control_v11p_sd15s2_lineart_anime_fp16.yaml\"}\n",
297
+ " ],\n",
298
+ " \"7.soft_edge\": [\n",
299
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge_fp16.safetensors\", \"name\": \"control_v11p_sd15_softedge_fp16.safetensors\"},\n",
300
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_softedge_fp16.yaml\", \"name\": \"control_v11p_sd15_softedge_fp16.yaml\"}\n",
301
+ " ],\n",
302
+ " \"8.scribble\": [\n",
303
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble_fp16.safetensors\", \"name\": \"control_v11p_sd15_scribble_fp16.safetensors\"},\n",
304
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_scribble_fp16.yaml\", \"name\": \"control_v11p_sd15_scribble_fp16.yaml\"}\n",
305
+ " ],\n",
306
+ " \"9.segmentation\": [\n",
307
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg_fp16.safetensors\", \"name\": \"control_v11p_sd15_seg_fp16.safetensors\"},\n",
308
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_seg_fp16.yaml\", \"name\": \"control_v11p_sd15_seg_fp16.yaml\"}\n",
309
+ " ],\n",
310
+ " \"10.shuffle\": [\n",
311
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle_fp16.safetensors\", \"name\": \"control_v11e_sd15_shuffle_fp16.safetensors\"},\n",
312
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_shuffle_fp16.yaml\", \"name\": \"control_v11e_sd15_shuffle_fp16.yaml\"}\n",
313
+ " ],\n",
314
+ " \"11.tile\": [\n",
315
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile_fp16.safetensors\", \"name\": \"control_v11f1e_sd15_tile_fp16.safetensors\"},\n",
316
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1e_sd15_tile_fp16.yaml\", \"name\": \"control_v11f1e_sd15_tile_fp16.yaml\"}\n",
317
+ " ],\n",
318
+ " \"12.inpaint\": [\n",
319
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_inpaint_fp16.safetensors\", \"name\": \"control_v11p_sd15_inpaint_fp16.safetensors\"},\n",
320
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_inpaint_fp16.yaml\", \"name\": \"control_v11p_sd15_inpaint_fp16.yaml\"}\n",
321
+ " ],\n",
322
+ " \"13.instruct_p2p\": [\n",
323
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p_fp16.safetensors\", \"name\": \"control_v11e_sd15_ip2p_fp16.safetensors\"},\n",
324
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_ip2p_fp16.yaml\", \"name\": \"control_v11e_sd15_ip2p_fp16.yaml\"}\n",
325
+ " ]\n",
326
+ "}\n",
327
+ "\n",
328
+ "extension_repo = []\n",
329
+ "prefixes = [\n",
330
+ " \"model:\",\n",
331
+ " \"vae:\",\n",
332
+ " \"lora:\",\n",
333
+ " \"embeddings:\",\n",
334
+ " \"extensions:\"\n",
335
+ "]\n",
336
+ "\n",
337
+ "!mkdir -p {models_dir} {vaes_dir} {embeddings_dir} {loras_dir} {control_dir}\n",
338
+ "\n",
339
+ "url = \"\"\n",
340
+ "hf_token = optional_huggingface_token if optional_huggingface_token else \"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\"\n",
341
+ "user_header = f\"\\\"Authorization: Bearer {hf_token}\\\"\"\n",
342
+ "\n",
343
+ "def handle_manual(url):\n",
344
+ " original_url = url\n",
345
+ " url = url.split(':', 1)[1]\n",
346
+ " file_name = re.search(r'\\[(.*?)\\]', url)\n",
347
+ " file_name = file_name.group(1) if file_name else None\n",
348
+ " if file_name:\n",
349
+ " url = re.sub(r'\\[.*?\\]', '', url)\n",
350
+ "\n",
351
+ " dir_mapping = {\"model\": models_dir, \"vae\": vaes_dir, \"lora\": loras_dir, \"embeddings\": embeddings_dir, \"extensions\": None}\n",
352
+ "\n",
353
+ " for prefix, dir in dir_mapping.items():\n",
354
+ " if original_url.startswith(f\"{prefix}:\"):\n",
355
+ " if prefix != \"extensions\":\n",
356
+ " manual_download(url, dir, file_name=file_name)\n",
357
+ " else:\n",
358
+ " extension_repo.append((url, file_name))\n",
359
+ "\n",
360
+ "def manual_download(url, dst_dir, file_name):\n",
361
+ " basename = url.split(\"/\")[-1] if file_name is None else file_name\n",
362
+ "\n",
363
+ " # I do it at my own risk..... Fucking CivitAi >:(\n",
364
+ " civitai_token = \"62c0c5956b2f9defbd844d754000180b\"\n",
365
+ " if 'civitai' in url and civitai_token:\n",
366
+ " url = f\"{url}?token={civitai_token}\"\n",
367
+ "\n",
368
+ " # -- GDrive --\n",
369
+ " if 'drive.google' in url:\n",
370
+ " if 'folders' in url:\n",
371
+ " !gdown --folder \"{url}\" -O {dst_dir} --fuzzy -c\n",
372
+ " else:\n",
373
+ " !gdown \"{url}\" -O {dst_dir} --fuzzy -c\n",
374
+ " # -- Huggin Face --\n",
375
+ " elif 'huggingface' in url:\n",
376
+ " if '/blob/' in url:\n",
377
+ " url = url.replace('/blob/', '/resolve/')\n",
378
+ " if file_name:\n",
379
+ " !aria2c --optimize-concurrent-downloads --console-log-level=error --summary-interval=10 --header={user_header} -c -j5 -x16 -s16 -k1M -d {dst_dir} -o {basename} {url}\n",
380
+ " else:\n",
381
+ " parsed_link = '\\n{}\\n\\tout={}'.format(url, unquote(url.split('/')[-1]))\n",
382
+ " !echo -e \"{parsed_link}\" | aria2c --header={user_header} --console-log-level=error --summary-interval=10 -i- -j5 -x16 -s16 -k1M -c -d \"{dst_dir}\" -o {basename}\n",
383
+ " # -- Other --\n",
384
+ " elif 'http' in url or 'magnet' in url:\n",
385
+ " if file_name:\n",
386
+ " !aria2c --optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c -d {dst_dir} -o {file_name} {url}\n",
387
+ " else:\n",
388
+ " parsed_link = '\"{}\"'.format(url)\n",
389
+ " !aria2c --optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c -d {dst_dir} -Z {parsed_link}\n",
390
+ "\n",
391
+ "def download(url):\n",
392
+ " links_and_paths = url.split(',')\n",
393
+ "\n",
394
+ " for link_or_path in links_and_paths:\n",
395
+ " link_or_path = link_or_path.strip()\n",
396
+ " if not link_or_path:\n",
397
+ " continue\n",
398
+ "\n",
399
+ " if any(link_or_path.startswith(prefix.lower()) for prefix in prefixes):\n",
400
+ " handle_manual(link_or_path)\n",
401
+ " continue\n",
402
+ "\n",
403
+ " url, dst_dir, file_name = link_or_path.split()\n",
404
+ " manual_download(url, dst_dir, file_name)\n",
405
+ "\n",
406
+ "submodels = []\n",
407
+ "\n",
408
+ "def add_submodels(selection, num_selection, model_dict, dst_dir):\n",
409
+ " if selection == \"none\":\n",
410
+ " return []\n",
411
+ " if selection == \"ALL\":\n",
412
+ " all_models = []\n",
413
+ " for models in model_dict.values():\n",
414
+ " all_models.extend(models)\n",
415
+ " selected_models = all_models\n",
416
+ " else:\n",
417
+ " selected_models = model_dict[selection]\n",
418
+ " selected_nums = map(int, num_selection.replace(',', '').split())\n",
419
+ "\n",
420
+ " for num in selected_nums:\n",
421
+ " if 1 <= num <= len(model_dict):\n",
422
+ " name = list(model_dict)[num - 1]\n",
423
+ " selected_models.extend(model_dict[name])\n",
424
+ "\n",
425
+ " unique_models = list({model['name']: model for model in selected_models}.values())\n",
426
+ "\n",
427
+ " for model in unique_models:\n",
428
+ " model['dst_dir'] = dst_dir\n",
429
+ "\n",
430
+ " return unique_models\n",
431
+ "\n",
432
+ "submodels += add_submodels(Model, Model_Num, model_list, models_dir) # model\n",
433
+ "submodels += add_submodels(Vae, Vae_Num, vae_list, vaes_dir) # vae\n",
434
+ "submodels += add_submodels(controlnet, \"\" if controlnet == \"ALL\" else controlnet_Num, controlnet_list, control_dir) # controlnet\n",
435
+ "\n",
436
+ "for submodel in submodels:\n",
437
+ " if not Inpainting_Model and \"inpainting\" in submodel['name']:\n",
438
+ " continue\n",
439
+ "\n",
440
+ " url += f\"{submodel['url']} {submodel['dst_dir']} {submodel['name']}, \"\n",
441
+ "\n",
442
+ "def process_file_download(file_url):\n",
443
+ " global Model_url, Vae_url, LoRA_url, Embedding_url, Extensions_url\n",
444
+ " urls_dict = {\n",
445
+ " 'model': 'Model_url',\n",
446
+ " 'vae': 'Vae_url',\n",
447
+ " 'embed': 'Embedding_url',\n",
448
+ " 'lora': 'LoRA_url',\n",
449
+ " 'extension': 'Extensions_url'\n",
450
+ " }\n",
451
+ "\n",
452
+ " if file_url.startswith(\"http\"):\n",
453
+ " if \"blob\" in file_url:\n",
454
+ " file_url = file_url.replace(\"blob\", \"raw\")\n",
455
+ " response = requests.get(file_url)\n",
456
+ " lines = response.text.split('\\n')\n",
457
+ " else:\n",
458
+ " with open(file_url, 'r') as file:\n",
459
+ " lines = file.readlines()\n",
460
+ "\n",
461
+ " current_tag = None\n",
462
+ " for line in lines:\n",
463
+ " if line.strip().startswith('#'):\n",
464
+ " current_tag = next((tag for tag in urls_dict if tag in line.lower()), None)\n",
465
+ " elif current_tag and line.strip():\n",
466
+ " urls = [url.strip() for url in line.split()]\n",
467
+ " for url in urls:\n",
468
+ " if url.startswith(\"http\"):\n",
469
+ " globals()[urls_dict[current_tag]] += \", \" + url\n",
470
+ "\n",
471
+ "# fix all possible errors/options and function call\n",
472
+ "if custom_file_urls:\n",
473
+ " if not custom_file_urls.endswith('.txt'):\n",
474
+ " custom_file_urls += '.txt'\n",
475
+ " if not custom_file_urls.startswith('http'):\n",
476
+ " if not custom_file_urls.startswith(root_path):\n",
477
+ " custom_file_urls = f'{root_path}/{custom_file_urls}'\n",
478
+ " if custom_file_urls.count('/content') >= 2:\n",
479
+ " custom_file_urls = re.sub(r'(/content){2,}', '/content', custom_file_urls)\n",
480
+ "\n",
481
+ " try:\n",
482
+ " process_file_download(custom_file_urls)\n",
483
+ " except FileNotFoundError:\n",
484
+ " pass\n",
485
+ "\n",
486
+ "urls = [Model_url, Vae_url, LoRA_url, Embedding_url, Extensions_url]\n",
487
+ "\n",
488
+ "for i, prefix in enumerate(prefixes):\n",
489
+ " if urls[i]:\n",
490
+ " prefixed_urls = [f\"{prefix}{u}\" for u in urls[i].replace(',', '').split()]\n",
491
+ " if prefixed_urls:\n",
492
+ " url += \", \".join(prefixed_urls) + \", \"\n",
493
+ "\n",
494
+ "if detailed_download == \"on\":\n",
495
+ " print(\"\\n\\n\\033[33m# ====== Detailed Download ====== #\\n\\033[0m\")\n",
496
+ " download(url)\n",
497
+ " print(\"\\n\\033[33m# =============================== #\\n\\033[0m\")\n",
498
+ "else:\n",
499
+ " with capture.capture_output() as cap:\n",
500
+ " download(url)\n",
501
+ " del cap\n",
502
+ "\n",
503
+ "print(\"\\r🏁 Download Complete!\" + \" \"*15)\n",
504
+ "\n",
505
+ "\n",
506
+ "# Cleaning shit after downloading...\n",
507
+ "!find \\( -name \".ipynb_checkpoints\" -o -name \".aria2\" \\) -type d -exec rm -r {} \\; >/dev/null 2>&1\n",
508
+ "\n",
509
+ "\n",
510
+ "## Install of Custom extensions\n",
511
+ "if len(extension_repo) > 0:\n",
512
+ " print(\"✨ Installing custom extensions...\", end='', flush=True)\n",
513
+ " with capture.capture_output() as cap:\n",
514
+ " for repo, repo_name in extension_repo:\n",
515
+ " if not repo_name:\n",
516
+ " repo_name = repo.split('/')[-1]\n",
517
+ " !cd {extensions_dir} \\\n",
518
+ " && git clone {repo} {repo_name} \\\n",
519
+ " && cd {repo_name} \\\n",
520
+ " && git fetch\n",
521
+ " del cap\n",
522
+ " print(f\"\\r📦 Installed '{len(extension_repo)}', Custom extensions!\")\n",
523
+ "\n",
524
+ "\n",
525
+ "## List Models and stuff\n",
526
+ "if detailed_download == \"off\":\n",
527
+ " print(\"\\n\\n\\033[33mIf you don't see any downloaded files, enable the 'Detailed Downloads' feature in the widget.\")\n",
528
+ "\n",
529
+ "if any(not file.endswith('.txt') for file in os.listdir(models_dir)):\n",
530
+ " print(\"\\n\\033[33m➤ Models\\033[0m\")\n",
531
+ " !find {models_dir}/ -mindepth 1 ! -name '*.txt' -printf '%f\\n'\n",
532
+ "if any(not file.endswith('.txt') for file in os.listdir(vaes_dir)):\n",
533
+ " print(\"\\n\\033[33m➤ VAEs\\033[0m\")\n",
534
+ " !find {vaes_dir}/ -mindepth 1 ! -name '*.txt' -printf '%f\\n'\n",
535
+ "if any(not file.endswith('.txt') and not os.path.isdir(os.path.join(embeddings_dir, file)) for file in os.listdir(embeddings_dir)):\n",
536
+ " print(\"\\n\\033[33m➤ Embeddings\\033[0m\")\n",
537
+ " !find {embeddings_dir}/ -mindepth 1 -maxdepth 1 \\( -name '*.pt' -or -name '*.safetensors' \\) -printf '%f\\n'\n",
538
+ "if any(not file.endswith('.txt') for file in os.listdir(loras_dir)):\n",
539
+ " print(\"\\n\\033[33m➤ LoRAs\\033[0m\")\n",
540
+ " !find {loras_dir}/ -mindepth 1 ! -name '*.keep' -printf '%f\\n'\n",
541
+ "print(f\"\\n\\033[33m➤ Extensions\\033[0m\")\n",
542
+ "!find {extensions_dir}/ -mindepth 1 -maxdepth 1 ! -name '*.txt' -printf '%f\\n'\n",
543
+ "if any(not file.endswith(('.txt', '.yaml')) for file in os.listdir(control_dir)):\n",
544
+ " print(\"\\n\\033[33m➤ ControlNet\\033[0m\")\n",
545
+ " !find {control_dir}/ -mindepth 1 ! -name '*.yaml' -printf '%f\\n' | sed 's/^[^_]*_[^_]*_[^_]*_\\(.*\\)_fp16\\.safetensors$/\\1/'\n",
546
+ "\n",
547
+ "\n",
548
+ "# === OTHER ===\n",
549
+ "# Downlaod discord tags UmiWildcards\n",
550
+ "files_umi = [\n",
551
+ " \"https://huggingface.co/NagisaNao/fast_repo/resolve/main/extensions/UmiWildacrd/discord/200_pan_gen.txt\",\n",
552
+ " \"https://huggingface.co/NagisaNao/fast_repo/resolve/main/extensions/UmiWildacrd/discord/150_bra_gen.txt\"\n",
553
+ "]\n",
554
+ "save_dir_path = f\"{webui_path}/extensions/Umi-AI-Wildcards/wildcards/discord\"\n",
555
+ "\n",
556
+ "with capture.capture_output() as cap:\n",
557
+ " for file in files_umi:\n",
558
+ " !aria2c --optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c -d {save_dir_path} {file}\n",
559
+ "del cap\n",
560
+ "\n",
561
+ "\n",
562
+ "# === ONLY SAGEMAKER ===\n",
563
+ "if env == \"SageMaker Studio Lab\":\n",
564
+ " with capture.capture_output() as cap:\n",
565
+ " !rm -rf /home/studio-lab-user/.conda/envs/studiolab-safemode\n",
566
+ " !rm -rf /home/studio-lab-user/.conda/envs/sagemaker-distribution\n",
567
+ " !rm -rf /home/studio-lab-user/.conda/pkgs/cache\n",
568
+ " !pip cache purge\n",
569
+ " !rm -rf ~/.cache\n",
570
+ " del cap"
571
+ ],
572
+ "metadata": {
573
+ "id": "2lJmbqrs3Mu8"
574
+ },
575
+ "execution_count": null,
576
+ "outputs": []
577
+ }
578
+ ]
579
+ }
files_cells/notebooks/en/launch_en.ipynb ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "execution_count": null,
20
+ "metadata": {
21
+ "id": "JKTCrY9LU7Oq"
22
+ },
23
+ "outputs": [],
24
+ "source": [
25
+ "##~ LAUNCH CODE | BY: ANXETY ~##\n",
26
+ "\n",
27
+ "import os\n",
28
+ "import re\n",
29
+ "import time\n",
30
+ "import json\n",
31
+ "import requests\n",
32
+ "from datetime import timedelta\n",
33
+ "\n",
34
+ "\n",
35
+ "# ================= DETECT ENV =================\n",
36
+ "def detect_environment():\n",
37
+ " environments = {\n",
38
+ " 'COLAB_GPU': ('Google Colab', \"/content\"),\n",
39
+ " 'KAGGLE_URL_BASE': ('Kaggle', \"/kaggle/working/content\"),\n",
40
+ " 'SAGEMAKER_INTERNAL_IMAGE_URI': ('SageMaker Studio Lab', \"/home/studio-lab-user/content\")\n",
41
+ " }\n",
42
+ "\n",
43
+ " for env_var, (environment, path) in environments.items():\n",
44
+ " if env_var in os.environ:\n",
45
+ " return environment, path\n",
46
+ "\n",
47
+ "env, root_path = detect_environment()\n",
48
+ "webui_path = f\"{root_path}/sdw\"\n",
49
+ "# ----------------------------------------------\n",
50
+ "\n",
51
+ "def load_settings():\n",
52
+ " SETTINGS_FILE = f'{root_path}/settings.json'\n",
53
+ " if os.path.exists(SETTINGS_FILE):\n",
54
+ " with open(SETTINGS_FILE, 'r') as f:\n",
55
+ " settings = json.load(f)\n",
56
+ " return settings\n",
57
+ "\n",
58
+ "settings = load_settings()\n",
59
+ "ngrok_token = settings['ngrok_token']\n",
60
+ "commandline_arguments = settings['commandline_arguments']\n",
61
+ "\n",
62
+ "\n",
63
+ "# ======================== TUNNEL ========================\n",
64
+ "if env != \"SageMaker Studio Lab\":\n",
65
+ " import cloudpickle as pickle\n",
66
+ "\n",
67
+ " password = \"x1101\"\n",
68
+ " def get_public_ip(version='ipv4'):\n",
69
+ " try:\n",
70
+ " url = f'https://api64.ipify.org?format=json&{version}=true'\n",
71
+ " response = requests.get(url)\n",
72
+ " data = response.json()\n",
73
+ " public_ip = data['ip']\n",
74
+ " return public_ip\n",
75
+ " except Exception as e:\n",
76
+ " print(f\"Error getting public {version} address:\", e)\n",
77
+ "\n",
78
+ " public_ipv4 = get_public_ip(version='ipv4')\n",
79
+ "\n",
80
+ " tunnel_class = pickle.load(open(f\"{root_path}/new_tunnel\", \"rb\"), encoding=\"utf-8\")\n",
81
+ " tunnel_port= 1101\n",
82
+ " tunnel = tunnel_class(tunnel_port)\n",
83
+ " tunnel.add_tunnel(command=\"cl tunnel --url localhost:{port}\", name=\"cl\", pattern=re.compile(r\"[\\w-]+\\.trycloudflare\\.com\"))\n",
84
+ " tunnel.add_tunnel(command=\"lt --port {port}\", name=\"lt\", pattern=re.compile(r\"[\\w-]+\\.loca\\.lt\"), note=\"Password : \" + \"\\033[32m\" + public_ipv4 + \"\\033[0m\" + \" rerun cell if 404 error.\")\n",
85
+ "# ======================== TUNNEL ========================\n",
86
+ "\n",
87
+ "\n",
88
+ "# automatic fixing path V2\n",
89
+ "!sed -i 's#\"tagger_hf_cache_dir\": \".*models/interrogators\"#\"tagger_hf_cache_dir\": \"{root_path}/sdw/models/interrogators\"#' {webui_path}/config.json\n",
90
+ "!sed -i 's#\"additional_networks_extra_lora_path\": \".*models/Lora/\"#\"additional_networks_extra_lora_path\": \"{root_path}/sdw/models/Lora/\"#' {webui_path}/config.json\n",
91
+ "# ---\n",
92
+ "!sed -i 's/\"sd_checkpoint_hash\": \".*\"/\"sd_checkpoint_hash\": \"\"/g; s/\"sd_model_checkpoint\": \".*\"/\"sd_model_checkpoint\": \"\"/g; s/\"sd_vae\": \".*\"/\"sd_vae\": \"None\"/g' {webui_path}/config.json\n",
93
+ "\n",
94
+ "\n",
95
+ "if env != \"SageMaker Studio Lab\":\n",
96
+ " with tunnel:\n",
97
+ " !#python -m http.server 1101\n",
98
+ " %cd {webui_path}\n",
99
+ "\n",
100
+ " if ngrok_token:\n",
101
+ " commandline_arguments += ' --ngrok ' + ngrok_token\n",
102
+ " commandline_arguments += f\" --port=1101 --encrypt-pass=1769\" # --encrypt-pass={password}\n",
103
+ "\n",
104
+ " !COMMANDLINE_ARGS=\"{commandline_arguments}\" python launch.py\n",
105
+ "\n",
106
+ " start_colab = float(open(f'{webui_path}/static/colabTimer.txt', 'r').read())\n",
107
+ " time_since_start = str(timedelta(seconds=time.time()-start_colab)).split('.')[0]\n",
108
+ " print(f\"\\n⌚️ \\033[0mYou have been conducting this session for - \\033[33m{time_since_start}\\033[0m\\n\\n\")\n",
109
+ "\n",
110
+ "else:\n",
111
+ " if ngrok_token:\n",
112
+ " %cd {webui_path}\n",
113
+ "\n",
114
+ " commandline_arguments += ' --ngrok ' + ngrok_token\n",
115
+ "\n",
116
+ " !COMMANDLINE_ARGS=\"{commandline_arguments}\" python launch.py\n",
117
+ "\n",
118
+ " start_colab = float(open(f'{webui_path}/static/colabTimer.txt', 'r').read())\n",
119
+ " time_since_start = str(timedelta(seconds=time.time()-start_colab)).split('.')[0]\n",
120
+ " print(f\"\\n⌚️ \\033[0mYou have been conducting this session for - \\033[33m{time_since_start}\\033[0m\\n\\n\")\n",
121
+ "\n",
122
+ " else:\n",
123
+ " print(\"Oops... I think you forgot to insert the token `ngrok`..... go back to widgets and insert it to start webui... no way without it :/\\nYou can get the token here:\\n\\nhttps://dashboard.ngrok.com/get-started/your-authtoken\")"
124
+ ]
125
+ }
126
+ ]
127
+ }
files_cells/notebooks/en/widgets_en.ipynb ADDED
@@ -0,0 +1,447 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "##~ WIDGET CODE | BY: ANXETY ~##\n",
21
+ "\n",
22
+ "import os\n",
23
+ "import json\n",
24
+ "import ipywidgets as widgets\n",
25
+ "from ipywidgets import widgets, Layout, Label, Button, VBox, HBox\n",
26
+ "from IPython.display import display, HTML, Javascript, clear_output\n",
27
+ "\n",
28
+ "\n",
29
+ "# ================= DETECT ENV =================\n",
30
+ "def detect_environment():\n",
31
+ " environments = {\n",
32
+ " 'COLAB_GPU': ('Google Colab', \"/content\"),\n",
33
+ " 'KAGGLE_URL_BASE': ('Kaggle', \"/kaggle/working/content\"),\n",
34
+ " 'SAGEMAKER_INTERNAL_IMAGE_URI': ('SageMaker Studio Lab', \"/home/studio-lab-user/content\")\n",
35
+ " }\n",
36
+ "\n",
37
+ " for env_var, (environment, path) in environments.items():\n",
38
+ " if env_var in os.environ:\n",
39
+ " return environment, path\n",
40
+ "\n",
41
+ "env, root_path = detect_environment()\n",
42
+ "webui_path = f\"{root_path}/sdw\"\n",
43
+ "\n",
44
+ "!mkdir -p {root_path}\n",
45
+ "# ----------------------------------------------\n",
46
+ "\n",
47
+ "\n",
48
+ "# ==================== CSS JS ====================\n",
49
+ "CSS = '''\n",
50
+ "<style>\n",
51
+ "/* General Styles */\n",
52
+ ".header {\n",
53
+ " font-family: cursive;\n",
54
+ " font-size: 20px;\n",
55
+ " font-weight: bold;\n",
56
+ " color: #ff8cee;\n",
57
+ " margin-bottom: 15px;\n",
58
+ " user-select: none;\n",
59
+ " cursor: default;\n",
60
+ " display: inline-block;\n",
61
+ "}\n",
62
+ "\n",
63
+ "hr {\n",
64
+ " border-color: grey;\n",
65
+ " background-color: grey;\n",
66
+ " opacity: 0.25;\n",
67
+ "}\n",
68
+ "\n",
69
+ "\n",
70
+ "/* Container style */\n",
71
+ "\n",
72
+ ".container {\n",
73
+ " position: relative;\n",
74
+ " background-color: #232323;\n",
75
+ " width: 1080px;\n",
76
+ " padding: 10px 15px;\n",
77
+ " border-radius: 15px;\n",
78
+ " box-shadow: 0 0 50px rgba(0, 0, 0, 0.3);\n",
79
+ " margin-bottom: 5px;\n",
80
+ " overflow: visible;\n",
81
+ "}\n",
82
+ "\n",
83
+ ".container::after {\n",
84
+ " position: absolute;\n",
85
+ " top: 5px;\n",
86
+ " right: 10px;\n",
87
+ " content: \"ANXETY\";\n",
88
+ " font-weight: bold;\n",
89
+ " font-size: 24px;\n",
90
+ " color: rgba(0, 0, 0, 0.15);\n",
91
+ "}\n",
92
+ "\n",
93
+ ".container_custom_downlad {\n",
94
+ " height: 55px;\n",
95
+ " overflow: hidden;\n",
96
+ " transition: all 0.5s;\n",
97
+ "}\n",
98
+ "\n",
99
+ ".container_custom_downlad.expanded {\n",
100
+ " height: 270px;\n",
101
+ "}\n",
102
+ "\n",
103
+ "\n",
104
+ "/* Element text style */\n",
105
+ "\n",
106
+ ".widget-html,\n",
107
+ ".widget-button,\n",
108
+ ".widget-text label,\n",
109
+ ".widget-checkbox label,\n",
110
+ ".widget-dropdown label,\n",
111
+ ".widget-dropdown select,\n",
112
+ ".widget-text input[type=\"text\"] {\n",
113
+ " font-family: cursive;\n",
114
+ " font-size: 14px;\n",
115
+ " color: white !important;\n",
116
+ " user-select: none;\n",
117
+ "}\n",
118
+ "\n",
119
+ ".widget-text input[type=\"text\"]::placeholder {\n",
120
+ " color: grey;\n",
121
+ "}\n",
122
+ "\n",
123
+ "\n",
124
+ "/* Input field styles */\n",
125
+ "\n",
126
+ ".widget-dropdown select,\n",
127
+ ".widget-text input[type=\"text\"] {\n",
128
+ " height: 30px;\n",
129
+ " background-color: #1c1c1c;\n",
130
+ " border: 1px solid #262626;\n",
131
+ " border-radius: 10px;\n",
132
+ " box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);\n",
133
+ " transition: all 0.3s ease-in-out;\n",
134
+ "}\n",
135
+ "\n",
136
+ ".widget-dropdown select:focus,\n",
137
+ ".widget-text input[type=\"text\"]:focus {\n",
138
+ " border-color: #006ee5;\n",
139
+ "}\n",
140
+ "\n",
141
+ ".widget-dropdown select:hover,\n",
142
+ ".widget-text input[type=\"text\"]:hover {\n",
143
+ " transform: scale(1.003);\n",
144
+ " background-color: #262626;\n",
145
+ " box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);\n",
146
+ "}\n",
147
+ "\n",
148
+ "\n",
149
+ "/* Button styles */\n",
150
+ "\n",
151
+ ".button_save {\n",
152
+ " font-size: 15px;\n",
153
+ " font-weight: bold;\n",
154
+ " width: 120px;\n",
155
+ " height: 35px;\n",
156
+ " border-radius: 15px;\n",
157
+ " background-image: radial-gradient(circle at top left, purple 10%, violet 90%);\n",
158
+ " background-size: 200% 200%;\n",
159
+ " background-position: left bottom;\n",
160
+ " transition: background 0.5s ease-in-out, transform 0.3s ease;\n",
161
+ "}\n",
162
+ "\n",
163
+ ".button_save:hover {\n",
164
+ " cursor: pointer;\n",
165
+ " background-image: radial-gradient(circle at top left, purple 10%, #93ac47 90%);\n",
166
+ " background-size: 200% 200%;\n",
167
+ " background-position: right bottom;\n",
168
+ " transform: translateY(1px);\n",
169
+ "}\n",
170
+ "\n",
171
+ ".button_ngrok {\n",
172
+ " font-size: 12px;\n",
173
+ " height: 30px;\n",
174
+ " border-radius: 10px;\n",
175
+ " padding: 1px 12px;\n",
176
+ " background-image: radial-gradient(circle at top left, purple 10%, violet 90%);\n",
177
+ " background-size: 200% 200%;\n",
178
+ " background-position: left bottom;\n",
179
+ " transition: background 0.5s ease-in-out, transform 0.3s ease;\n",
180
+ " white-space: nowrap;\n",
181
+ "}\n",
182
+ "\n",
183
+ ".button_ngrok:hover {\n",
184
+ " cursor: pointer;\n",
185
+ " background-image: radial-gradient(circle at top left, purple 10%, #e2a9a8 90%);\n",
186
+ " background-size: 200% 200%;\n",
187
+ " background-position: right bottom;\n",
188
+ " transform: translateY(1px);\n",
189
+ "}\n",
190
+ "\n",
191
+ ".button_save:active,\n",
192
+ ".button_ngrok:active {\n",
193
+ " filter: brightness(0.75);\n",
194
+ "}\n",
195
+ "\n",
196
+ "\n",
197
+ "/* Popup style of `FAQ` window */\n",
198
+ "\n",
199
+ ".info {\n",
200
+ " position: absolute;\n",
201
+ " top: -5px;\n",
202
+ " right: 95px;\n",
203
+ " color: grey;\n",
204
+ " font-family: cursive;\n",
205
+ " font-size: 14px;\n",
206
+ " font-weight: normal;\n",
207
+ " user-select: none;\n",
208
+ " pointer-events: none;\n",
209
+ " opacity: 0;\n",
210
+ " transition: opacity 0.3s ease-in-out;\n",
211
+ " display: inline-block;\n",
212
+ "}\n",
213
+ "\n",
214
+ ".popup {\n",
215
+ " position: absolute;\n",
216
+ " top: 120px;\n",
217
+ " z-index: 999;\n",
218
+ " width: auto;\n",
219
+ " padding: 10px;\n",
220
+ " text-align: center;\n",
221
+ " background-color: rgba(255, 255, 255, 0.05);\n",
222
+ " backdrop-filter: blur(20px);\n",
223
+ " border: 1px solid rgba(255, 255, 255, 0.45);\n",
224
+ " border-radius: 8px;\n",
225
+ " box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);\n",
226
+ " opacity: 0;\n",
227
+ " color: #fff;\n",
228
+ " font-size: 16px;\n",
229
+ " font-family: cursive;\n",
230
+ " user-select: none;\n",
231
+ " cursor: default;\n",
232
+ " pointer-events: none;\n",
233
+ " transform: rotate(-5deg);\n",
234
+ " transition: top 0.3s ease-in-out, opacity 0.3s ease-in-out, transform 0.3s ease-in-out;\n",
235
+ "}\n",
236
+ "\n",
237
+ ".sample {\n",
238
+ " display: inline-block;\n",
239
+ " margin-top: 25px;\n",
240
+ " padding: 10px 100px;\n",
241
+ " background-color: rgba(255, 255, 255, 0.2);\n",
242
+ " color: #c6e2ff;\n",
243
+ " border: 2px solid rgba(255, 255, 255, 0.2);\n",
244
+ " border-radius: 8px;\n",
245
+ " box-shadow: 0 0 10px rgba(255, 255, 255, 0.2), inset 0 0 25px rgba(255, 255, 255, 0.2);\n",
246
+ "}\n",
247
+ "\n",
248
+ ".info.showed {\n",
249
+ " opacity: 1;\n",
250
+ " pointer-events: auto;\n",
251
+ "}\n",
252
+ "\n",
253
+ ".info:hover + .popup {\n",
254
+ " top: 35px;\n",
255
+ " opacity: 1;\n",
256
+ " pointer-events: initial;\n",
257
+ " transform: rotate(0deg);\n",
258
+ "}\n",
259
+ "\n",
260
+ "\n",
261
+ "/* Animation of elements */\n",
262
+ "\n",
263
+ ".container,\n",
264
+ ".button_save {\n",
265
+ " animation-name: showedWidgets;\n",
266
+ " animation-duration: 1s;\n",
267
+ "}\n",
268
+ "\n",
269
+ "@keyframes showedWidgets {\n",
270
+ " 0% {\n",
271
+ " transform: translate3d(-65%, 15%, 0) scale(0) rotate(15deg);\n",
272
+ " filter: blur(25px) grayscale(1) brightness(0.3);\n",
273
+ " opacity: 0;\n",
274
+ " }\n",
275
+ " 100% {\n",
276
+ " transform: translate3d(0, 0, 0) scale(1) rotate(0deg);\n",
277
+ " filter: blur(0) grayscale(0) brightness(1);\n",
278
+ " opacity: 1;\n",
279
+ " }\n",
280
+ "}\n",
281
+ "</style>\n",
282
+ "\n",
283
+ "<!-- TOGGLE 'CustomDL' SCRIPT -->\n",
284
+ "<script>\n",
285
+ "function toggleContainer() {\n",
286
+ " let downloadContainer = document.querySelector('.container_custom_downlad');\n",
287
+ " let info = document.querySelector('.info');\n",
288
+ "\n",
289
+ " downloadContainer.classList.toggle('expanded');\n",
290
+ " info.classList.toggle('showed');\n",
291
+ "}\n",
292
+ "</script>\n",
293
+ "'''\n",
294
+ "\n",
295
+ "display(HTML(CSS))\n",
296
+ "# ==================== CSS JS ====================\n",
297
+ "\n",
298
+ "\n",
299
+ "# ==================== WIDGETS ====================\n",
300
+ "# --- global widgets ---\n",
301
+ "style = {'description_width': 'initial'}\n",
302
+ "layout = widgets.Layout(min_width='1047px')\n",
303
+ "\n",
304
+ "HR = widgets.HTML('<hr>')\n",
305
+ "\n",
306
+ "# --- MODEL ---\n",
307
+ "model_header = widgets.HTML('<div class=\"header\">Model Selection<div>')\n",
308
+ "model_options = ['none',\n",
309
+ " '1.Anime (by Xpuct) + INP',\n",
310
+ " '2.Cetus-Mix [Anime] [V4] + INP',\n",
311
+ " '3.Counterfeit [Anime] [V3] + INP',\n",
312
+ " '4.CuteColor [Anime] [V3]',\n",
313
+ " '5.Dark-Sushi-Mix [Anime]',\n",
314
+ " '6.Meina-Mix [Anime] [V11] + INP',\n",
315
+ " '7.Mix-Pro [Anime] [V4] + INP',\n",
316
+ " '8.BluMix [Anime] [V7]']\n",
317
+ "# ---\n",
318
+ "Model_widget = widgets.Dropdown(options=model_options, value='3.Counterfeit [Anime] [V3] + INP', description='Model:', style=style, layout=layout)\n",
319
+ "Model_Num_widget = widgets.Text(description='Model Number:', placeholder='Enter the model numbers to be downloaded using comma/space.', style=style, layout=layout)\n",
320
+ "Inpainting_Model_widget = widgets.Checkbox(value=False, description='Inpainting Models', style=style)\n",
321
+ "\n",
322
+ "display(widgets.VBox([model_header, Model_widget, Model_Num_widget, Inpainting_Model_widget]).add_class(\"container\"))\n",
323
+ "\n",
324
+ "# --- VAE ---\n",
325
+ "vae_header = widgets.HTML('<div class=\"header\" >VAE Selection</div>')\n",
326
+ "vae_options = ['none',\n",
327
+ " '1.Anime.vae',\n",
328
+ " '2.Anything.vae',\n",
329
+ " '3.Blessed2.vae',\n",
330
+ " '4.ClearVae.vae',\n",
331
+ " '5.WD.vae']\n",
332
+ "Vae_widget = widgets.Dropdown(options=vae_options, value='3.Blessed2.vae', description='Vae:', style=style, layout=layout)\n",
333
+ "Vae_Num_widget = widgets.Text(description='Vae number:', placeholder='Enter the vae numbers to be downloaded using comma/space.', style=style, layout=layout)\n",
334
+ "\n",
335
+ "display(widgets.VBox([vae_header, Vae_widget, Vae_Num_widget]).add_class(\"container\"))\n",
336
+ "\n",
337
+ "# --- ADDITIONAL ---\n",
338
+ "additional_header = widgets.HTML('<div class=\"header\">Additional</div>')\n",
339
+ "latest_webui_widget = widgets.Checkbox(value=True, description='Update WebUI', style=style)\n",
340
+ "latest_exstensions_widget = widgets.Checkbox(value=True, description='Update Extensions', style=style)\n",
341
+ "detailed_download_widget = widgets.Dropdown(options=['off', 'on'], value='off', description='Detailed Download:', style=style)\n",
342
+ "latest_changes_widget = HBox([latest_webui_widget, latest_exstensions_widget, detailed_download_widget], layout=widgets.Layout(justify_content='space-between'))\n",
343
+ "controlnet_options = ['none', 'ALL', '1.canny',\n",
344
+ " '2.openpose', '3.depth',\n",
345
+ " '4.normal_map', '5.mlsd',\n",
346
+ " '6.lineart', '7.soft_edge',\n",
347
+ " '8.scribble', '9.segmentation',\n",
348
+ " '10.shuffle', '11.tile',\n",
349
+ " '12.inpaint', '13.instruct_p2p']\n",
350
+ "# ---\n",
351
+ "controlnet_widget = widgets.Dropdown(options=controlnet_options, value='none', description='ControlNet:', style=style, layout=layout)\n",
352
+ "controlnet_Num_widget = widgets.Text(description='ControlNet Number:', placeholder='Enter the ControlNet model numbers to be downloaded using comma/space.', style=style, layout=layout)\n",
353
+ "commit_hash_widget = widgets.Text(description='Commit Hash:', style=style, layout=layout)\n",
354
+ "optional_huggingface_token_widget = widgets.Text(description='Huggingface token:', style=style, layout=layout)\n",
355
+ "ngrok_token_widget = widgets.Text(description='Ngrok token:', style=style, layout=widgets.Layout(width='1047px'))\n",
356
+ "ngrock_button = widgets.HTML('<a href=\"https://dashboard.ngrok.com/get-started/your-authtoken\" target=\"_blank\">Get Ngrok Token</a>').add_class(\"button_ngrok\")\n",
357
+ "ngrok_widget = widgets.HBox([ngrok_token_widget, ngrock_button], style=style, layout=layout)\n",
358
+ "# ---\n",
359
+ "commandline_arguments_options = \"--listen --enable-insecure-extension-access --theme dark --no-half-vae --disable-console-progressbars --xformers\"\n",
360
+ "commandline_arguments_widget = widgets.Text(description='Arguments:', value=commandline_arguments_options, style=style, layout=layout)\n",
361
+ "\n",
362
+ "display(widgets.VBox([\n",
363
+ " additional_header, latest_changes_widget, HR, controlnet_widget, controlnet_Num_widget, commit_hash_widget, optional_huggingface_token_widget, ngrok_widget, HR, commandline_arguments_widget\n",
364
+ " ]).add_class(\"container\"))\n",
365
+ "\n",
366
+ "# --- CUSTOM DOWNLOAD ---\n",
367
+ "custom_download_header_popup = widgets.HTML('''\n",
368
+ "<style>\n",
369
+ "/* Term Colors */\n",
370
+ ".sample_label {color: #dbafff;}\n",
371
+ ".braces {color: #ffff00;}\n",
372
+ ".extension {color: #eb934b;}\n",
373
+ ".file_name {color: #ffffd8;}\n",
374
+ "</style>\n",
375
+ "\n",
376
+ "<div class=\"header\" style=\"cursor: pointer;\" onclick=\"toggleContainer()\">Custom Download</div>\n",
377
+ "<!-- PopUp Window -->\n",
378
+ "<div class=\"info\">FAQ?</div>\n",
379
+ "<div class=\"popup\">\n",
380
+ " Separate multiple URLs with a comma/space. For a <span class=\"file_name\">custom name</span> file/extension, specify it with <span class=\"braces\">[]</span>\n",
381
+ " after the URL without spaces.\n",
382
+ " <span style=\"color: #ff9999\">For files, be sure to specify</span> - <span class=\"extension\">Filename Extension.</span>\n",
383
+ " <div class=\"sample\">\n",
384
+ " <span class=\"sample_label\">Example for File:</span>\n",
385
+ " https://civitai.com/api/download/models/229782<span class=\"braces\">[</span><span class=\"file_name\">Detailer</span><span class=\"extension\">.safetensors</span><span class=\"braces\">]</span>\n",
386
+ " <br>\n",
387
+ " <span class=\"sample_label\">Example for Extension:</span>\n",
388
+ " https://github.com/hako-mikan/sd-webui-regional-prompter<span class=\"braces\">[</span><span class=\"file_name\">Regional-Prompter</span><span class=\"braces\">]</span>\n",
389
+ " </div>\n",
390
+ "</div>\n",
391
+ "''')\n",
392
+ "# ---\n",
393
+ "Model_url_widget = widgets.Text(description='Model:', style=style, layout=layout)\n",
394
+ "Vae_url_widget = widgets.Text(description='Vae:', style=style, layout=layout)\n",
395
+ "LoRA_url_widget = widgets.Text(description='LoRa:', style=style, layout=layout)\n",
396
+ "Embedding_url_widget = widgets.Text(description='Embedding:', style=style, layout=layout)\n",
397
+ "Extensions_url_widget = widgets.Text(description='Extensions:', style=style, layout=layout)\n",
398
+ "custom_file_urls_widget = widgets.Text(description='File (txt):', style=style, layout=layout)\n",
399
+ "\n",
400
+ "display(widgets.VBox([\n",
401
+ " custom_download_header_popup, Model_url_widget, Vae_url_widget, LoRA_url_widget, Embedding_url_widget, Extensions_url_widget, custom_file_urls_widget\n",
402
+ " ]).add_class(\"container\").add_class(\"container_custom_downlad\"))\n",
403
+ "\n",
404
+ "# --- Save Button ---\n",
405
+ "save_button = widgets.Button(description='Save').add_class(\"button_save\")\n",
406
+ "display(save_button)\n",
407
+ "\n",
408
+ "\n",
409
+ "# ============ Load / Save - Settings V2 ============\n",
410
+ "SETTINGS_FILE = f'{root_path}/settings.json'\n",
411
+ "\n",
412
+ "settings_keys = [\n",
413
+ " 'Model', 'Model_Num', 'Inpainting_Model',\n",
414
+ " 'Vae', 'Vae_Num',\n",
415
+ " 'latest_webui', 'latest_exstensions', 'detailed_download',\n",
416
+ " 'controlnet', 'controlnet_Num', 'commit_hash', 'optional_huggingface_token',\n",
417
+ " 'ngrok_token', 'commandline_arguments',\n",
418
+ " 'Model_url', 'Vae_url', 'LoRA_url', 'Embedding_url', 'Extensions_url', 'custom_file_urls'\n",
419
+ "]\n",
420
+ "\n",
421
+ "def save_settings():\n",
422
+ " settings = {key: globals()[f\"{key}_widget\"].value for key in settings_keys}\n",
423
+ " with open(SETTINGS_FILE, 'w') as f:\n",
424
+ " json.dump(settings, f)\n",
425
+ "\n",
426
+ "def load_settings():\n",
427
+ " if os.path.exists(SETTINGS_FILE):\n",
428
+ " with open(SETTINGS_FILE, 'r') as f:\n",
429
+ " settings = json.load(f)\n",
430
+ " for key in settings_keys:\n",
431
+ " globals()[f\"{key}_widget\"].value = settings.get(key)\n",
432
+ "\n",
433
+ "def save_data(button):\n",
434
+ " save_settings()\n",
435
+ " widgets.Widget.close_all()\n",
436
+ "\n",
437
+ "settings = load_settings()\n",
438
+ "save_button.on_click(save_data)"
439
+ ],
440
+ "metadata": {
441
+ "id": "2lJmbqrs3Mu8"
442
+ },
443
+ "execution_count": null,
444
+ "outputs": []
445
+ }
446
+ ]
447
+ }
files_cells/notebooks/ru/auto-cleaner_ru.ipynb ADDED
@@ -0,0 +1,378 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "##~ AutoCleaner V3.6 CODE | BY: ANXETY ~##\n",
21
+ "\n",
22
+ "# --change log--\n",
23
+ "\"\"\"\n",
24
+ "V3.6 | 13.03.24\n",
25
+ "Fixed selection window\n",
26
+ "Dynamic update of memory display\n",
27
+ "\"\"\"\n",
28
+ "\n",
29
+ "\n",
30
+ "import os\n",
31
+ "import time\n",
32
+ "import ipywidgets as widgets\n",
33
+ "from ipywidgets import Label, Button, VBox, HBox\n",
34
+ "from IPython.display import display, HTML\n",
35
+ "\n",
36
+ "\n",
37
+ "# ================= DETECT ENV =================\n",
38
+ "def detect_environment():\n",
39
+ " environments = {\n",
40
+ " 'COLAB_GPU': ('Google Colab', \"/content\"),\n",
41
+ " 'KAGGLE_URL_BASE': ('Kaggle', \"/kaggle/working/content\"),\n",
42
+ " 'SAGEMAKER_INTERNAL_IMAGE_URI': ('SageMaker Studio Lab', \"/home/studio-lab-user/content\")\n",
43
+ " }\n",
44
+ "\n",
45
+ " for env_var, (environment, path) in environments.items():\n",
46
+ " if env_var in os.environ:\n",
47
+ " return environment, path\n",
48
+ "\n",
49
+ "env, root_path = detect_environment()\n",
50
+ "webui_path = f\"{root_path}/sdw\"\n",
51
+ "# ----------------------------------------------\n",
52
+ "\n",
53
+ "\n",
54
+ "directories = {\n",
55
+ " \"Изображения\": f\"{webui_path}/outputs\",\n",
56
+ " \"Модели\": f\"{webui_path}/models/Stable-diffusion/\",\n",
57
+ " \"Vae\": f\"{webui_path}/models/VAE/\",\n",
58
+ " \"LoRa\": f\"{webui_path}/models/Lora/\",\n",
59
+ " \"ControlNet Модели\": f\"{webui_path}/models/ControlNet/\"\n",
60
+ "}\n",
61
+ "\n",
62
+ "\n",
63
+ "# ==================== CSS ====================\n",
64
+ "CSS_AC = \"\"\"\n",
65
+ "<style>\n",
66
+ "/* General Styles */\n",
67
+ "\n",
68
+ "hr {\n",
69
+ " border-color: grey;\n",
70
+ " background-color: grey;\n",
71
+ " opacity: 0.25;\n",
72
+ "}\n",
73
+ "\n",
74
+ ".instruction_AC {\n",
75
+ " font-family: cursive;\n",
76
+ " font-size: 18px;\n",
77
+ " color: grey;\n",
78
+ " user-select: none;\n",
79
+ " cursor: default;\n",
80
+ "}\n",
81
+ "\n",
82
+ "\n",
83
+ "/* Container style */\n",
84
+ "\n",
85
+ ".container_AC {\n",
86
+ " position: relative;\n",
87
+ " background-color: #232323;\n",
88
+ " width: 800px;\n",
89
+ " height: auto;\n",
90
+ " padding: 15px;\n",
91
+ " border-radius: 15px;\n",
92
+ " box-shadow: 0 0 50px rgba(0, 0, 0, 0.3);\n",
93
+ " margin-bottom: 5px;\n",
94
+ " overflow: visible;\n",
95
+ "}\n",
96
+ "\n",
97
+ ".container_AC::before {\n",
98
+ " position: absolute;\n",
99
+ " top: 5px;\n",
100
+ " right: 10px;\n",
101
+ " content: \"AutoCleanerV3.6\";\n",
102
+ " font-weight: bold;\n",
103
+ " font-size: 24px;\n",
104
+ " color: rgba(0, 0, 0, 0.2);\n",
105
+ "}\n",
106
+ "\n",
107
+ ".container_AC::after {\n",
108
+ " position: absolute;\n",
109
+ " top: 30px;\n",
110
+ " right: 10px;\n",
111
+ " content: \"ANXETY\";\n",
112
+ " font-weight: bold;\n",
113
+ " font-size: 18px;\n",
114
+ " color: rgba(0, 0, 0, 0.2);\n",
115
+ "}\n",
116
+ "\n",
117
+ ".custom-select-multiple_AC select {\n",
118
+ " padding: 10px;\n",
119
+ " font-family: cursive;\n",
120
+ " border: 1px solid #262626 !important;\n",
121
+ " border-radius: 10px;\n",
122
+ " color: white;\n",
123
+ " background-color: #1c1c1c;\n",
124
+ " box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);\n",
125
+ "}\n",
126
+ "\n",
127
+ ".output_AC {\n",
128
+ " padding: 10px;\n",
129
+ " height: auto;\n",
130
+ " border: 1px solid #262626;\n",
131
+ " border-radius: 10px;\n",
132
+ " background-color: #1c1c1c;\n",
133
+ " box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);\n",
134
+ " width: auto;\n",
135
+ " box-sizing: border-box;\n",
136
+ "}\n",
137
+ "\n",
138
+ ".output_message_AC {\n",
139
+ " font-family: cursive;\n",
140
+ " color: white !important;\n",
141
+ " font-size: 14px;\n",
142
+ " user-select: none;\n",
143
+ " cursor: default\n",
144
+ "}\n",
145
+ "\n",
146
+ "\n",
147
+ ".storage_info_AC {\n",
148
+ " padding: 5px 20px;\n",
149
+ " height: auto;\n",
150
+ " border: 1px solid #262626;\n",
151
+ " border-radius: 10px;\n",
152
+ " background-color: #1c1c1c;\n",
153
+ " box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);\n",
154
+ " width: auto;\n",
155
+ " font-family: cursive;\n",
156
+ " color: #B2B2B2 !important;\n",
157
+ " font-size: 14px;\n",
158
+ " user-select: none;\n",
159
+ " cursor: default\n",
160
+ "}\n",
161
+ "\n",
162
+ "\n",
163
+ "/* Button and storage info layout */\n",
164
+ ".lower_information_panel_AC {\n",
165
+ " display: flex;\n",
166
+ " align-items: center;\n",
167
+ " justify-content: space-between;\n",
168
+ "}\n",
169
+ "\n",
170
+ "\n",
171
+ "/* Button style */\n",
172
+ "\n",
173
+ ".button_AC {\n",
174
+ " width: auto;\n",
175
+ " font-family: cursive;\n",
176
+ " color: white !important;\n",
177
+ " font-size: 14px;\n",
178
+ " font-weight: bold;\n",
179
+ " height: 35px;\n",
180
+ " border-radius: 15px;\n",
181
+ " background-image: radial-gradient(circle at top left, purple 10%, violet 90%);\n",
182
+ " background-size: 200% 200%;\n",
183
+ " background-position: left bottom;\n",
184
+ " transition: background 0.5s ease-in-out, transform 0.3s ease;\n",
185
+ "}\n",
186
+ "\n",
187
+ ".button_AC:hover {\n",
188
+ " cursor: pointer;\n",
189
+ " background-size: 200% 200%;\n",
190
+ " background-position: right bottom;\n",
191
+ " transform: translateY(1px);\n",
192
+ "}\n",
193
+ "\n",
194
+ ".button_execute_AC:hover {\n",
195
+ " background-image: radial-gradient(circle at top left, purple 10%, #93ac47 90%);\n",
196
+ "}\n",
197
+ "\n",
198
+ ".button_clear_AC:hover {\n",
199
+ " background-image: radial-gradient(circle at top left, purple 10%, #fc3468 90%);\n",
200
+ "}\n",
201
+ "\n",
202
+ ".button_execute_AC:active,\n",
203
+ ".button_clear_AC:active {\n",
204
+ " filter: brightness(0.75);\n",
205
+ "}\n",
206
+ "\n",
207
+ ".jupyter-widgets.lm-Widget:focus {\n",
208
+ " outline: none;\n",
209
+ "}\n",
210
+ "\n",
211
+ "\n",
212
+ "/* Animation of elements */\n",
213
+ "\n",
214
+ "/* Emergence */\n",
215
+ ".container_AC {\n",
216
+ " animation-name: slideInTopBlur;\n",
217
+ " animation-duration: 0.7s;\n",
218
+ " animation-fill-mode: forwards;\n",
219
+ "}\n",
220
+ "\n",
221
+ "@keyframes slideInTopBlur {\n",
222
+ " 0% {\n",
223
+ " transform: translate3d(0, 50%, 0) scale(0.85) rotate3d(1, 0, 0, -85deg);\n",
224
+ " filter: blur(5px) grayscale(1) brightness(0.5);\n",
225
+ " opacity: 0;\n",
226
+ " }\n",
227
+ " 100% {\n",
228
+ " transform: translate3d(0, 0, 0) scale(1) rotate3d(1, 0, 0, 0deg);\n",
229
+ " filter: blur(0) grayscale(0) brightness(1);\n",
230
+ " opacity: 1;\n",
231
+ " }\n",
232
+ "}\n",
233
+ "\n",
234
+ "/* Leaving */\n",
235
+ ".container_AC.hide {\n",
236
+ " animation-name: slideOutTopBlur;\n",
237
+ " animation-duration: 0.3s;\n",
238
+ " animation-fill-mode: forwards;\n",
239
+ "}\n",
240
+ "\n",
241
+ "@keyframes slideOutTopBlur {\n",
242
+ " 0% {\n",
243
+ " transform: translate3d(0, 0, 0) scale(1);\n",
244
+ " filter: blur(0) grayscale(0) brightness(1);\n",
245
+ " opacity: 1;\n",
246
+ " }\n",
247
+ " 100% {\n",
248
+ " transform: translate3d(0, -100%, 0);\n",
249
+ " filter: blur(5px) grayscale(1) brightness(0);\n",
250
+ " opacity: 0;\n",
251
+ " }\n",
252
+ "}\n",
253
+ "</style>\n",
254
+ "\"\"\"\n",
255
+ "\n",
256
+ "display(HTML(CSS_AC))\n",
257
+ "# ==================== CSS ====================\n",
258
+ "\n",
259
+ "\n",
260
+ "# ================ AutoCleaner function ================\n",
261
+ "def clean_directory(directory):\n",
262
+ " deleted_files = 0\n",
263
+ " for root, dirs, files in os.walk(directory):\n",
264
+ " for file in files:\n",
265
+ " if file.endswith((\".txt\", \".yaml\")):\n",
266
+ " continue\n",
267
+ " os.remove(os.path.join(root, file))\n",
268
+ " deleted_files += 1\n",
269
+ " return deleted_files\n",
270
+ "\n",
271
+ "\n",
272
+ "def get_word_variant(n, variants):\n",
273
+ " unit = abs(n) % 10\n",
274
+ " tens = abs(n) % 100\n",
275
+ " if tens in range(11, 15):\n",
276
+ " return variants[2]\n",
277
+ " elif unit == 1:\n",
278
+ " return variants[0]\n",
279
+ " elif unit in range(2, 5):\n",
280
+ " return variants[1]\n",
281
+ " else:\n",
282
+ " return variants[2]\n",
283
+ "\n",
284
+ "\n",
285
+ "def update_memory_info():\n",
286
+ " disk_space = psutil.disk_usage(os.getcwd())\n",
287
+ " total = disk_space.total / (1024 ** 3)\n",
288
+ " used = disk_space.used / (1024 ** 3)\n",
289
+ " free = disk_space.free / (1024 ** 3)\n",
290
+ "\n",
291
+ " storage_info.value = f'''\n",
292
+ " <div class=\"storage_info_AC\">Всего: {total:.2f} GB <span style=\"color: #555\">|</span> Используется: {used:.2f} GB <span style=\"color: #555\">|</span> Свободно: {free:.2f} GB</div>\n",
293
+ " '''\n",
294
+ "\n",
295
+ "\n",
296
+ "def on_execute_button_press(button):\n",
297
+ " selected_cleaners = auto_cleaner_widget.value\n",
298
+ " deleted_files_dict = {}\n",
299
+ "\n",
300
+ " for option in selected_cleaners:\n",
301
+ " if option in directories:\n",
302
+ " deleted_files_dict[option] = clean_directory(directories[option])\n",
303
+ "\n",
304
+ " output.clear_output()\n",
305
+ "\n",
306
+ " with output:\n",
307
+ " for message in generate_messages(deleted_files_dict):\n",
308
+ " message_widget = HTML(f'<p class=\"output_message_AC\">{message}</p>')\n",
309
+ " display(message_widget)\n",
310
+ "\n",
311
+ " update_memory_info()\n",
312
+ "\n",
313
+ "\n",
314
+ "def on_clear_button_press(button):\n",
315
+ " container.add_class(\"hide\")\n",
316
+ " time.sleep(0.5)\n",
317
+ " widgets.Widget.close_all()\n",
318
+ "\n",
319
+ "\n",
320
+ "def generate_messages(deleted_files_dict):\n",
321
+ " messages = []\n",
322
+ " word_variants = {\n",
323
+ " \"Изображения\": [\"Изображение\", \"Изображения\", \"Изображений\"],\n",
324
+ " \"Модели\": [\"Модель\", \"Модели\", \"Моделей\"],\n",
325
+ " \"Vae\": [\"VAE\", \"VAE\", \"VAE\"],\n",
326
+ " \"LoRa\": [\"LoRa\", \"LoRa\", \"LoRa\"],\n",
327
+ " \"ControlNet Модели\": [\"ControlNet Модель\", \"ControlNet Модели\", \"ControlNet Моделей\"]\n",
328
+ " }\n",
329
+ " deleted_word_variants = [\"Удалена\", \"Удалены\", \"Удалено\"]\n",
330
+ " for key, value in deleted_files_dict.items():\n",
331
+ " word_variant = word_variants.get(key, [\"\", \"\", \"\"])\n",
332
+ " deleted_word = get_word_variant(value, deleted_word_variants)\n",
333
+ " object_word = get_word_variant(value, word_variant)\n",
334
+ " messages.append(f\"{deleted_word} {value} {object_word}\")\n",
335
+ " return messages\n",
336
+ "# ================ AutoCleaner function ================\n",
337
+ "\n",
338
+ "\n",
339
+ "# --- storage memory ---\n",
340
+ "import psutil\n",
341
+ "disk_space = psutil.disk_usage(os.getcwd())\n",
342
+ "total = disk_space.total / (1024 ** 3)\n",
343
+ "used = disk_space.used / (1024 ** 3)\n",
344
+ "free = disk_space.free / (1024 ** 3)\n",
345
+ "\n",
346
+ "\n",
347
+ "# UI Code\n",
348
+ "AutoCleaner_options = AutoCleaner_options = list(directories.keys())\n",
349
+ "instruction_label = widgets.HTML('''\n",
350
+ "<span class=\"instruction_AC\">Используйте <span style=\"color: #B2B2B2;\">ctrl</span> или <span style=\"color: #B2B2B2;\">shift</span> для множественного выбора.</span>\n",
351
+ "''')\n",
352
+ "auto_cleaner_widget = widgets.SelectMultiple(options=AutoCleaner_options, layout=widgets.Layout(width=\"auto\")).add_class(\"custom-select-multiple_AC\")\n",
353
+ "output = widgets.Output().add_class(\"output_AC\")\n",
354
+ "# ---\n",
355
+ "execute_button = Button(description='Выполнить Очистку').add_class(\"button_execute_AC\").add_class(\"button_AC\")\n",
356
+ "execute_button.on_click(on_execute_button_press)\n",
357
+ "clear_button = Button(description='Скрыть Виджет').add_class(\"button_clear_AC\").add_class(\"button_AC\")\n",
358
+ "clear_button.on_click(on_clear_button_press)\n",
359
+ "# ---\n",
360
+ "storage_info = widgets.HTML(f'''\n",
361
+ "<div class=\"storage_info_AC\">Всего: {total:.2f} GB <span style=\"color: #555\">|</span> Используется: {used:.2f} GB <span style=\"color: #555\">|</span> Свободно: {free:.2f} GB</div>\n",
362
+ "''')\n",
363
+ "# ---\n",
364
+ "buttons = widgets.HBox([execute_button, clear_button])\n",
365
+ "lower_information_panel = widgets.HBox([buttons, storage_info]).add_class(\"lower_information_panel_AC\")\n",
366
+ "\n",
367
+ "container = VBox([instruction_label, widgets.HTML('<hr>'), auto_cleaner_widget, output, widgets.HTML('<hr>'), lower_information_panel]).add_class(\"container_AC\")\n",
368
+ "\n",
369
+ "display(container)"
370
+ ],
371
+ "metadata": {
372
+ "id": "I22dFg7F2j3G"
373
+ },
374
+ "execution_count": null,
375
+ "outputs": []
376
+ }
377
+ ]
378
+ }
files_cells/notebooks/ru/downloading_ru.ipynb ADDED
@@ -0,0 +1,586 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "##~ DOWNLOADING CODE | BY: ANXETY ~##\n",
21
+ "\n",
22
+ "import os\n",
23
+ "import re\n",
24
+ "import time\n",
25
+ "import json\n",
26
+ "import requests\n",
27
+ "import subprocess\n",
28
+ "from datetime import timedelta\n",
29
+ "from subprocess import getoutput\n",
30
+ "from urllib.parse import unquote\n",
31
+ "from IPython.utils import capture\n",
32
+ "from IPython.display import clear_output\n",
33
+ "\n",
34
+ "\n",
35
+ "# ================= DETECT ENV =================\n",
36
+ "def check_colab_subscription():\n",
37
+ " return (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024. ** 3) <= 20)\n",
38
+ "free_plan = check_colab_subscription()\n",
39
+ "\n",
40
+ "def detect_environment():\n",
41
+ " environments = {\n",
42
+ " 'COLAB_GPU': ('Google Colab', \"/root\" if free_plan else \"/content\"),\n",
43
+ " 'KAGGLE_URL_BASE': ('Kaggle', \"/kaggle/working/content\"),\n",
44
+ " 'SAGEMAKER_INTERNAL_IMAGE_URI': ('SageMaker Studio Lab', \"/home/studio-lab-user/content\")\n",
45
+ " }\n",
46
+ "\n",
47
+ " for env_var, (environment, path) in environments.items():\n",
48
+ " if env_var in os.environ:\n",
49
+ " return environment, path\n",
50
+ "\n",
51
+ "env, root_path = detect_environment()\n",
52
+ "webui_path = f\"{root_path}/sdw\"\n",
53
+ "# ----------------------------------------------\n",
54
+ "\n",
55
+ "\n",
56
+ "# === ONLY SAGEMAKER ===\n",
57
+ "if env == \"SageMaker Studio Lab\":\n",
58
+ " print(\"Обновление зависимостей, может занять некоторое время...\")\n",
59
+ " !pip install -q --upgrade torchsde\n",
60
+ " !pip install -q --upgrade pip\n",
61
+ " !pip install -q --upgrade psutil\n",
62
+ "\n",
63
+ " clear_output()\n",
64
+ "\n",
65
+ "\n",
66
+ "# ================ LIBRARIES ================\n",
67
+ "flag_file = f\"{root_path}/libraries_installed.txt\"\n",
68
+ "\n",
69
+ "if not os.path.exists(flag_file):\n",
70
+ " # automatic1111 update webui to 1.8.0\n",
71
+ " xformers = \"xformers==0.0.23.post1 triton==2.1.0\"\n",
72
+ " torch = \"torch==2.1.2+cu121 torchvision==0.16.2+cu121 --extra-index-url https://download.pytorch.org/whl/cu121\"\n",
73
+ "\n",
74
+ " print(\"Установка библиотек, это займет какое-то время...\", end='')\n",
75
+ " with capture.capture_output() as cap:\n",
76
+ " !apt-get update && apt -y install aria2\n",
77
+ " !npm install -g localtunnel &> /dev/null\n",
78
+ " !curl -s -OL https://github.com/DEX-1101/sd-webui-notebook/raw/main/res/new_tunnel --output-dir {root_path}\n",
79
+ " !curl -s -Lo /usr/bin/cl https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 && chmod +x /usr/bin/cl\n",
80
+ " !pip install insightface\n",
81
+ "\n",
82
+ " if env == \"SageMaker Studio Lab\":\n",
83
+ " %pip install -q opencv-python-headless huggingface-hub\n",
84
+ " %conda update -q -n base conda\n",
85
+ " %conda install -q -y aria2\n",
86
+ " %conda install -q -y glib\n",
87
+ " !pip install tensorflow\n",
88
+ "\n",
89
+ " !wget -P /home/studio-lab-user https://huggingface.co/NagisaNao/fast_repo/resolve/main/sagemaker/FULL_DELETED_NOTEBOOK.ipynb\n",
90
+ "\n",
91
+ " if env == \"Google Colab\":\n",
92
+ " !pip install -q {xformers} -U\n",
93
+ " else:\n",
94
+ " !pip install -q {torch} -U\n",
95
+ " !pip install -q {xformers} -U\n",
96
+ "\n",
97
+ " with open(flag_file, \"w\") as f:\n",
98
+ " f.write(\"hey ;3\")\n",
99
+ " del cap\n",
100
+ " print(\"\\rБиблиотеки установлены!\" + \" \"*35)\n",
101
+ " time.sleep(2)\n",
102
+ " clear_output()\n",
103
+ "\n",
104
+ "\n",
105
+ "# ================= loading settings V4 =================\n",
106
+ "def load_settings(path):\n",
107
+ " if os.path.exists(path):\n",
108
+ " with open(path, 'r') as file:\n",
109
+ " return json.load(file)\n",
110
+ " return {}\n",
111
+ "\n",
112
+ "settings = load_settings(f'{root_path}/settings.json')\n",
113
+ "\n",
114
+ "variables = [\n",
115
+ " 'Model', 'Model_Num', 'Inpainting_Model',\n",
116
+ " 'Vae', 'Vae_Num',\n",
117
+ " 'latest_webui', 'latest_exstensions', 'detailed_download',\n",
118
+ " 'controlnet', 'controlnet_Num', 'commit_hash', 'optional_huggingface_token',\n",
119
+ " 'ngrok_token' 'commandline_arguments',\n",
120
+ " 'Model_url', 'Vae_url', 'LoRA_url', 'Embedding_url', 'Extensions_url', 'custom_file_urls'\n",
121
+ "]\n",
122
+ "\n",
123
+ "locals().update({key: settings.get(key) for key in variables})\n",
124
+ "\n",
125
+ "\n",
126
+ "# ================= OTHER =================\n",
127
+ "try:\n",
128
+ " start_colab\n",
129
+ "except:\n",
130
+ " start_colab = int(time.time())-5\n",
131
+ "\n",
132
+ "# CONFIG DIR\n",
133
+ "models_dir = f\"{webui_path}/models/Stable-diffusion\"\n",
134
+ "vaes_dir = f\"{webui_path}/models/VAE\"\n",
135
+ "embeddings_dir = f\"{webui_path}/embeddings\"\n",
136
+ "loras_dir = f\"{webui_path}/models/Lora\"\n",
137
+ "extensions_dir = f\"{webui_path}/extensions\"\n",
138
+ "control_dir = f\"{webui_path}/models/ControlNet\"\n",
139
+ "\n",
140
+ "\n",
141
+ "# ================= MAIN CODE =================\n",
142
+ "# --- Obsolescence warning ---\n",
143
+ "if env == \"SageMaker Studio Lab\":\n",
144
+ " print(\"Вы используете среду 'SageMaker' - эта среда устарела, поэтому многие ошибки не будут исправлены, а ее функциональность будет урезана. Для экономии памяти и/или во избежание ошибок.\\n\\n\")\n",
145
+ "\n",
146
+ "\n",
147
+ "if not os.path.exists(webui_path):\n",
148
+ " start_install = int(time.time())\n",
149
+ " print(\"⌚ Распоковка Stable Diffusion...\", end='')\n",
150
+ " with capture.capture_output() as cap:\n",
151
+ " !aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/NagisaNao/fast_repo/resolve/main/FULL_REPO.zip -o repo.zip\n",
152
+ " !unzip -q -o repo.zip -d {webui_path}\n",
153
+ " !rm -rf repo.zip\n",
154
+ "\n",
155
+ " %cd {root_path}\n",
156
+ " os.environ[\"SAFETENSORS_FAST_GPU\"]='1'\n",
157
+ " os.environ[\"CUDA_MODULE_LOADING\"]=\"LAZY\"\n",
158
+ " os.environ[\"TF_CPP_MIN_LOG_LEVEL\"] = \"3\"\n",
159
+ " os.environ[\"PYTHONWARNINGS\"] = \"ignore\"\n",
160
+ "\n",
161
+ " !echo -n {start_colab} > {webui_path}/static/colabTimer.txt\n",
162
+ " del cap\n",
163
+ " install_time = timedelta(seconds=time.time()-start_install)\n",
164
+ " print(\"\\r🚀 Распаковка Завершена! За\",\"%02d:%02d:%02d ⚡\\n\" % (install_time.seconds / 3600, (install_time.seconds / 60) % 60, install_time.seconds % 60), end='', flush=True)\n",
165
+ "else:\n",
166
+ " !echo -n {start_colab} > {webui_path}/static/colabTimer.txt\n",
167
+ " print(\"🚀 Все распакованно... Пропуск. ⚡\")\n",
168
+ " start_colab = float(open(f'{webui_path}/static/colabTimer.txt', 'r').read())\n",
169
+ " time_since_start = str(timedelta(seconds=time.time()-start_colab)).split('.')[0]\n",
170
+ " print(f\"⌚️ Вы проводите эту сессию в течение - \\033[33m{time_since_start}\\033[0m\")\n",
171
+ "\n",
172
+ "\n",
173
+ "## Changes extensions and WebUi\n",
174
+ "if latest_webui or latest_exstensions:\n",
175
+ " action = \"Обновление WebUI и Расширений\" if latest_webui and latest_exstensions else (\"Обновление WebUI\" if latest_webui else \"Обновление Расширений\")\n",
176
+ " print(f\"⌚️ {action}...\", end='', flush=True)\n",
177
+ " with capture.capture_output() as cap:\n",
178
+ " !git config --global user.email \"[email protected]\"\n",
179
+ " !git config --global user.name \"Your Name\"\n",
180
+ "\n",
181
+ " ## Update Webui\n",
182
+ " if latest_webui:\n",
183
+ " %cd {webui_path}\n",
184
+ " !git restore .\n",
185
+ " !git pull -X theirs --rebase --autostash\n",
186
+ "\n",
187
+ " ## Update extensions\n",
188
+ " if latest_exstensions:\n",
189
+ " if env != \"SageMaker Studio Lab\":\n",
190
+ " !{'for dir in ' + webui_path + '/extensions/*/; do cd \\\"$dir\\\" && git reset --hard && git pull; done'}\n",
191
+ " else:\n",
192
+ " !{'for dir in /home/studio-lab-user/content/sdw/extensions/*/; do cd \\\"$dir\\\" && git fetch origin && git pull; done'}\n",
193
+ "\n",
194
+ " !cd {webui_path}/repositories/stable-diffusion-stability-ai && git restore .\n",
195
+ " del cap\n",
196
+ " print(f\"\\r✨ {action} Завершено!\")\n",
197
+ "\n",
198
+ "\n",
199
+ "# === FIXING ERRORS ===\n",
200
+ "# --- All ---\n",
201
+ "# --- Encrypt-Image ---\n",
202
+ "!sed -i '9,37d' {webui_path}/extensions/Encrypt-Image/javascript/encrypt_images_info.js\n",
203
+ "if env = \"Google Colab\":\n",
204
+ " if os.path.exists(f\"{webui_path}/extensions/Encrypt-Image\"):\n",
205
+ " !rm -rf {webui_path}/extensions/Encrypt-Image\n",
206
+ "\n",
207
+ "# --- SageMaker ---\n",
208
+ "if env == \"SageMaker Studio Lab\":\n",
209
+ " with capture.capture_output() as cap:\n",
210
+ " # --- SuperMerger Remove ---\n",
211
+ " if os.path.exists(f\"{webui_path}/extensions/supermerger\"):\n",
212
+ " !rm -rf {webui_path}/extensions/supermerger\n",
213
+ " # --- Launch (Style) ---\n",
214
+ " !wget -O {webui_path}/modules/styles.py https://huggingface.co/NagisaNao/fast_repo/resolve/main/sagemaker/fixing/webui/styles.py\n",
215
+ " del cap\n",
216
+ "\n",
217
+ "\n",
218
+ "## Version switching\n",
219
+ "if commit_hash:\n",
220
+ " print('⏳ Активация машины времени...', end=\"\", flush=True)\n",
221
+ " with capture.capture_output() as cap:\n",
222
+ " %cd {webui_path}\n",
223
+ " !git config --global user.email \"[email protected]\"\n",
224
+ " !git config --global user.name \"Your Name\"\n",
225
+ " !git reset --hard {commit_hash}\n",
226
+ " del cap\n",
227
+ " print(f\"\\r⌛️ Машина времени активированна! Текущий коммит: \\033[34m{commit_hash}\\033[0m\")\n",
228
+ "\n",
229
+ "\n",
230
+ "## Downloading model and stuff | oh yeah~ I'm starting to misunderstand my own code ( almost my own ;3 )\n",
231
+ "print(\"📦 Скачивание моделей и прочего...\", end='')\n",
232
+ "model_list = {\n",
233
+ " \"1.Anime (by Xpuct) + INP\": [\n",
234
+ " {\"url\": \"https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2.safetensors\", \"name\": \"Anime_v2.safetensors\"},\n",
235
+ " {\"url\": \"https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2-inpainting.safetensors\", \"name\": \"Anime_v2-inpainting.safetensors\"}\n",
236
+ " ],\n",
237
+ " \"2.Cetus-Mix [Anime] [V4] + INP\": [\n",
238
+ " {\"url\": \"https://civitai.com/api/download/models/130298\", \"name\": \"CetusMix_V4.safetensors\"},\n",
239
+ " {\"url\": \"https://civitai.com/api/download/models/139882\", \"name\": \"CetusMix_V4-inpainting.safetensors\"}\n",
240
+ " ],\n",
241
+ " \"3.Counterfeit [Anime] [V3] + INP\": [\n",
242
+ " {\"url\": \"https://civitai.com/api/download/models/125050\", \"name\": \"Counterfeit_V3.safetensors\"},\n",
243
+ " {\"url\": \"https://civitai.com/api/download/models/137911\", \"name\": \"Counterfeit_V3-inpainting.safetensors\"}\n",
244
+ " ],\n",
245
+ " \"4.CuteColor [Anime] [V3]\": [\n",
246
+ " {\"url\": \"https://civitai.com/api/download/models/138754\", \"name\": \"CuteColor_V3.safetensors\"}\n",
247
+ " ],\n",
248
+ " \"5.Dark-Sushi-Mix [Anime]\": [\n",
249
+ " {\"url\": \"https://civitai.com/api/download/models/101640\", \"name\": \"DarkSushiMix_2_5D.safetensors\"},\n",
250
+ " {\"url\": \"https://civitai.com/api/download/models/56071\", \"name\": \"DarkSushiMix_colorful.safetensors\"}\n",
251
+ " ],\n",
252
+ " \"6.Meina-Mix [Anime] [V11] + INP\": [\n",
253
+ " {\"url\": \"https://civitai.com/api/download/models/119057\", \"name\": \"MeinaMix_V11.safetensors\"},\n",
254
+ " {\"url\": \"https://civitai.com/api/download/models/120702\", \"name\": \"MeinaMix_V11-inpainting.safetensors\"}\n",
255
+ " ],\n",
256
+ " \"7.Mix-Pro [Anime] [V4] + INP\": [\n",
257
+ " {\"url\": \"https://civitai.com/api/download/models/125668\", \"name\": \"MixPro_V4.safetensors\"},\n",
258
+ " {\"url\": \"https://civitai.com/api/download/models/139878\", \"name\": \"MixPro_V4-inpainting.safetensors\"}\n",
259
+ " ],\n",
260
+ " \"8.BluMix [Anime] [V7]\": [\n",
261
+ " {\"url\": \"https://civitai.com/api/download/models/361779\", \"name\": \"BluMix_v7.safetensors\"}\n",
262
+ " ]\n",
263
+ "}\n",
264
+ "\n",
265
+ "# 1-4 (fp16/cleaned)\n",
266
+ "vae_list = {\n",
267
+ " \"1.Anime.vae\": [\n",
268
+ " {\"url\": \"https://civitai.com/api/download/models/131654\", \"name\": \"Anime.vae.safetensors\"},\n",
269
+ " {\"url\": \"https://civitai.com/api/download/models/131658\", \"name\": \"vae-ft-mse.vae.safetensors\"}\n",
270
+ " ],\n",
271
+ " \"2.Anything.vae\": [{\"url\": \"https://civitai.com/api/download/models/131656\", \"name\": \"Anything.vae.safetensors\"}],\n",
272
+ " \"3.Blessed2.vae\": [{\"url\": \"https://civitai.com/api/download/models/142467\", \"name\": \"Blessed2.vae.safetensors\"}],\n",
273
+ " \"4.ClearVae.vae\": [{\"url\": \"https://civitai.com/api/download/models/133362\", \"name\": \"ClearVae_23.vae.safetensors\"}],\n",
274
+ " \"5.WD.vae\": [{\"url\": \"https://huggingface.co/NoCrypt/resources/resolve/main/VAE/wd.vae.safetensors\", \"name\": \"WD.vae.safetensors\"}]\n",
275
+ "}\n",
276
+ "\n",
277
+ "controlnet_list = {\n",
278
+ " \"1.canny\": [\n",
279
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny_fp16.safetensors\", \"name\": \"control_v11p_sd15_canny_fp16.safetensors\"},\n",
280
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_canny_fp16.yaml\", \"name\": \"control_v11p_sd15_canny_fp16.yaml\"}\n",
281
+ " ],\n",
282
+ " \"2.openpose\": [\n",
283
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose_fp16.safetensors\", \"name\": \"control_v11p_sd15_openpose_fp16.safetensors\"},\n",
284
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_openpose_fp16.yaml\", \"name\": \"control_v11p_sd15_openpose_fp16.yaml\"}\n",
285
+ " ],\n",
286
+ " \"3.depth\": [\n",
287
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth_fp16.safetensors\", \"name\": \"control_v11f1p_sd15_depth_fp16.safetensors\"},\n",
288
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1p_sd15_depth_fp16.yaml\", \"name\": \"control_v11f1p_sd15_depth_fp16.yaml\"},\n",
289
+ " {\"url\": \"https://huggingface.co/NagisaNao/models/resolve/main/ControlNet_v11/control_v11p_sd15_depth_anything_fp16.safetensors\", \"name\": \"control_v11p_sd15_depth_anything_fp16.safetensors\"}\n",
290
+ " ],\n",
291
+ " \"4.normal_map\": [\n",
292
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_normalbae_fp16.safetensors\", \"name\": \"control_v11p_sd15_normalbae_fp16.safetensors\"},\n",
293
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_normalbae_fp16.yaml\", \"name\": \"control_v11p_sd15_normalbae_fp16.yaml\"}\n",
294
+ " ],\n",
295
+ " \"5.mlsd\": [\n",
296
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_mlsd_fp16.safetensors\", \"name\": \"control_v11p_sd15_mlsd_fp16.safetensors\"},\n",
297
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_mlsd_fp16.yaml\", \"name\": \"control_v11p_sd15_mlsd_fp16.yaml\"}\n",
298
+ " ],\n",
299
+ " \"6.lineart\": [\n",
300
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart_fp16.safetensors\", \"name\": \"control_v11p_sd15_lineart_fp16.safetensors\"},\n",
301
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15s2_lineart_anime_fp16.safetensors\", \"name\": \"control_v11p_sd15s2_lineart_anime_fp16.safetensors\"},\n",
302
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_lineart_fp16.yaml\", \"name\": \"control_v11p_sd15_lineart_fp16.yaml\"},\n",
303
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15s2_lineart_anime_fp16.yaml\", \"name\": \"control_v11p_sd15s2_lineart_anime_fp16.yaml\"}\n",
304
+ " ],\n",
305
+ " \"7.soft_edge\": [\n",
306
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge_fp16.safetensors\", \"name\": \"control_v11p_sd15_softedge_fp16.safetensors\"},\n",
307
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_softedge_fp16.yaml\", \"name\": \"control_v11p_sd15_softedge_fp16.yaml\"}\n",
308
+ " ],\n",
309
+ " \"8.scribble\": [\n",
310
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble_fp16.safetensors\", \"name\": \"control_v11p_sd15_scribble_fp16.safetensors\"},\n",
311
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_scribble_fp16.yaml\", \"name\": \"control_v11p_sd15_scribble_fp16.yaml\"}\n",
312
+ " ],\n",
313
+ " \"9.segmentation\": [\n",
314
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg_fp16.safetensors\", \"name\": \"control_v11p_sd15_seg_fp16.safetensors\"},\n",
315
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_seg_fp16.yaml\", \"name\": \"control_v11p_sd15_seg_fp16.yaml\"}\n",
316
+ " ],\n",
317
+ " \"10.shuffle\": [\n",
318
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle_fp16.safetensors\", \"name\": \"control_v11e_sd15_shuffle_fp16.safetensors\"},\n",
319
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_shuffle_fp16.yaml\", \"name\": \"control_v11e_sd15_shuffle_fp16.yaml\"}\n",
320
+ " ],\n",
321
+ " \"11.tile\": [\n",
322
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile_fp16.safetensors\", \"name\": \"control_v11f1e_sd15_tile_fp16.safetensors\"},\n",
323
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1e_sd15_tile_fp16.yaml\", \"name\": \"control_v11f1e_sd15_tile_fp16.yaml\"}\n",
324
+ " ],\n",
325
+ " \"12.inpaint\": [\n",
326
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_inpaint_fp16.safetensors\", \"name\": \"control_v11p_sd15_inpaint_fp16.safetensors\"},\n",
327
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_inpaint_fp16.yaml\", \"name\": \"control_v11p_sd15_inpaint_fp16.yaml\"}\n",
328
+ " ],\n",
329
+ " \"13.instruct_p2p\": [\n",
330
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p_fp16.safetensors\", \"name\": \"control_v11e_sd15_ip2p_fp16.safetensors\"},\n",
331
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_ip2p_fp16.yaml\", \"name\": \"control_v11e_sd15_ip2p_fp16.yaml\"}\n",
332
+ " ]\n",
333
+ "}\n",
334
+ "\n",
335
+ "extension_repo = []\n",
336
+ "prefixes = [\n",
337
+ " \"model:\",\n",
338
+ " \"vae:\",\n",
339
+ " \"lora:\",\n",
340
+ " \"embeddings:\",\n",
341
+ " \"extensions:\"\n",
342
+ "]\n",
343
+ "\n",
344
+ "!mkdir -p {models_dir} {vaes_dir} {embeddings_dir} {loras_dir} {control_dir}\n",
345
+ "\n",
346
+ "url = \"\"\n",
347
+ "hf_token = optional_huggingface_token if optional_huggingface_token else \"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\"\n",
348
+ "user_header = f\"\\\"Authorization: Bearer {hf_token}\\\"\"\n",
349
+ "\n",
350
+ "def handle_manual(url):\n",
351
+ " original_url = url\n",
352
+ " url = url.split(':', 1)[1]\n",
353
+ " file_name = re.search(r'\\[(.*?)\\]', url)\n",
354
+ " file_name = file_name.group(1) if file_name else None\n",
355
+ " if file_name:\n",
356
+ " url = re.sub(r'\\[.*?\\]', '', url)\n",
357
+ "\n",
358
+ " dir_mapping = {\"model\": models_dir, \"vae\": vaes_dir, \"lora\": loras_dir, \"embeddings\": embeddings_dir, \"extensions\": None}\n",
359
+ "\n",
360
+ " for prefix, dir in dir_mapping.items():\n",
361
+ " if original_url.startswith(f\"{prefix}:\"):\n",
362
+ " if prefix != \"extensions\":\n",
363
+ " manual_download(url, dir, file_name=file_name)\n",
364
+ " else:\n",
365
+ " extension_repo.append((url, file_name))\n",
366
+ "\n",
367
+ "def manual_download(url, dst_dir, file_name):\n",
368
+ " basename = url.split(\"/\")[-1] if file_name is None else file_name\n",
369
+ "\n",
370
+ " # I do it at my own risk..... Fucking CivitAi >:(\n",
371
+ " civitai_token = \"62c0c5956b2f9defbd844d754000180b\"\n",
372
+ " if 'civitai' in url and civitai_token:\n",
373
+ " url = f\"{url}?token={civitai_token}\"\n",
374
+ "\n",
375
+ " # -- GDrive --\n",
376
+ " if 'drive.google' in url:\n",
377
+ " if 'folders' in url:\n",
378
+ " !gdown --folder \"{url}\" -O {dst_dir} --fuzzy -c\n",
379
+ " else:\n",
380
+ " !gdown \"{url}\" -O {dst_dir} --fuzzy -c\n",
381
+ " # -- Huggin Face --\n",
382
+ " elif 'huggingface' in url:\n",
383
+ " if '/blob/' in url:\n",
384
+ " url = url.replace('/blob/', '/resolve/')\n",
385
+ " if file_name:\n",
386
+ " !aria2c --optimize-concurrent-downloads --console-log-level=error --summary-interval=10 --header={user_header} -c -j5 -x16 -s16 -k1M -d {dst_dir} -o {basename} {url}\n",
387
+ " else:\n",
388
+ " parsed_link = '\\n{}\\n\\tout={}'.format(url, unquote(url.split('/')[-1]))\n",
389
+ " !echo -e \"{parsed_link}\" | aria2c --header={user_header} --console-log-level=error --summary-interval=10 -i- -j5 -x16 -s16 -k1M -c -d \"{dst_dir}\" -o {basename}\n",
390
+ " # -- Other --\n",
391
+ " elif 'http' in url or 'magnet' in url:\n",
392
+ " if file_name:\n",
393
+ " !aria2c --optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c -d {dst_dir} -o {file_name} {url}\n",
394
+ " else:\n",
395
+ " parsed_link = '\"{}\"'.format(url)\n",
396
+ " !aria2c --optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c -d {dst_dir} -Z {parsed_link}\n",
397
+ "\n",
398
+ "def download(url):\n",
399
+ " links_and_paths = url.split(',')\n",
400
+ "\n",
401
+ " for link_or_path in links_and_paths:\n",
402
+ " link_or_path = link_or_path.strip()\n",
403
+ " if not link_or_path:\n",
404
+ " continue\n",
405
+ "\n",
406
+ " if any(link_or_path.startswith(prefix.lower()) for prefix in prefixes):\n",
407
+ " handle_manual(link_or_path)\n",
408
+ " continue\n",
409
+ "\n",
410
+ " url, dst_dir, file_name = link_or_path.split()\n",
411
+ " manual_download(url, dst_dir, file_name)\n",
412
+ "\n",
413
+ "submodels = []\n",
414
+ "\n",
415
+ "def add_submodels(selection, num_selection, model_dict, dst_dir):\n",
416
+ " if selection == \"none\":\n",
417
+ " return []\n",
418
+ " if selection == \"ALL\":\n",
419
+ " all_models = []\n",
420
+ " for models in model_dict.values():\n",
421
+ " all_models.extend(models)\n",
422
+ " selected_models = all_models\n",
423
+ " else:\n",
424
+ " selected_models = model_dict[selection]\n",
425
+ " selected_nums = map(int, num_selection.replace(',', '').split())\n",
426
+ "\n",
427
+ " for num in selected_nums:\n",
428
+ " if 1 <= num <= len(model_dict):\n",
429
+ " name = list(model_dict)[num - 1]\n",
430
+ " selected_models.extend(model_dict[name])\n",
431
+ "\n",
432
+ " unique_models = list({model['name']: model for model in selected_models}.values())\n",
433
+ "\n",
434
+ " for model in unique_models:\n",
435
+ " model['dst_dir'] = dst_dir\n",
436
+ "\n",
437
+ " return unique_models\n",
438
+ "\n",
439
+ "submodels += add_submodels(Model, Model_Num, model_list, models_dir) # model\n",
440
+ "submodels += add_submodels(Vae, Vae_Num, vae_list, vaes_dir) # vae\n",
441
+ "submodels += add_submodels(controlnet, \"\" if controlnet == \"ALL\" else controlnet_Num, controlnet_list, control_dir) # controlnet\n",
442
+ "\n",
443
+ "for submodel in submodels:\n",
444
+ " if not Inpainting_Model and \"inpainting\" in submodel['name']:\n",
445
+ " continue\n",
446
+ "\n",
447
+ " url += f\"{submodel['url']} {submodel['dst_dir']} {submodel['name']}, \"\n",
448
+ "\n",
449
+ "def process_file_download(file_url):\n",
450
+ " global Model_url, Vae_url, LoRA_url, Embedding_url, Extensions_url\n",
451
+ " urls_dict = {\n",
452
+ " 'model': 'Model_url',\n",
453
+ " 'vae': 'Vae_url',\n",
454
+ " 'embed': 'Embedding_url',\n",
455
+ " 'lora': 'LoRA_url',\n",
456
+ " 'extension': 'Extensions_url'\n",
457
+ " }\n",
458
+ "\n",
459
+ " if file_url.startswith(\"http\"):\n",
460
+ " if \"blob\" in file_url:\n",
461
+ " file_url = file_url.replace(\"blob\", \"raw\")\n",
462
+ " response = requests.get(file_url)\n",
463
+ " lines = response.text.split('\\n')\n",
464
+ " else:\n",
465
+ " with open(file_url, 'r') as file:\n",
466
+ " lines = file.readlines()\n",
467
+ "\n",
468
+ " current_tag = None\n",
469
+ " for line in lines:\n",
470
+ " if line.strip().startswith('#'):\n",
471
+ " current_tag = next((tag for tag in urls_dict if tag in line.lower()), None)\n",
472
+ " elif current_tag and line.strip():\n",
473
+ " urls = [url.strip() for url in line.split()]\n",
474
+ " for url in urls:\n",
475
+ " if url.startswith(\"http\"):\n",
476
+ " globals()[urls_dict[current_tag]] += \", \" + url\n",
477
+ "\n",
478
+ "# fix all possible errors/options and function call\n",
479
+ "if custom_file_urls:\n",
480
+ " if not custom_file_urls.endswith('.txt'):\n",
481
+ " custom_file_urls += '.txt'\n",
482
+ " if not custom_file_urls.startswith('http'):\n",
483
+ " if not custom_file_urls.startswith(root_path):\n",
484
+ " custom_file_urls = f'{root_path}/{custom_file_urls}'\n",
485
+ " if custom_file_urls.count('/content') >= 2:\n",
486
+ " custom_file_urls = re.sub(r'(/content){2,}', '/content', custom_file_urls)\n",
487
+ "\n",
488
+ " try:\n",
489
+ " process_file_download(custom_file_urls)\n",
490
+ " except FileNotFoundError:\n",
491
+ " pass\n",
492
+ "\n",
493
+ "urls = [Model_url, Vae_url, LoRA_url, Embedding_url, Extensions_url]\n",
494
+ "\n",
495
+ "for i, prefix in enumerate(prefixes):\n",
496
+ " if urls[i]:\n",
497
+ " prefixed_urls = [f\"{prefix}{u}\" for u in urls[i].replace(',', '').split()]\n",
498
+ " if prefixed_urls:\n",
499
+ " url += \", \".join(prefixed_urls) + \", \"\n",
500
+ "\n",
501
+ "if detailed_download == \"on\":\n",
502
+ " print(\"\\n\\n\\033[33m# ====== Подробная Загрузка ====== #\\n\\033[0m\")\n",
503
+ " download(url)\n",
504
+ " print(\"\\n\\033[33m# =============================== #\\n\\033[0m\")\n",
505
+ "else:\n",
506
+ " with capture.capture_output() as cap:\n",
507
+ " download(url)\n",
508
+ " del cap\n",
509
+ "\n",
510
+ "print(\"\\r🏁 Скачивание Завершено!\" + \" \"*15)\n",
511
+ "\n",
512
+ "\n",
513
+ "# Cleaning shit after downloading...\n",
514
+ "!find \\( -name \".ipynb_checkpoints\" -o -name \".aria2\" \\) -type d -exec rm -r {} \\; >/dev/null 2>&1\n",
515
+ "\n",
516
+ "\n",
517
+ "## Install of Custom extensions\n",
518
+ "if len(extension_repo) > 0:\n",
519
+ " print(\"✨ Устанвока кастомных расширений...\", end='', flush=True)\n",
520
+ " with capture.capture_output() as cap:\n",
521
+ " for repo, repo_name in extension_repo:\n",
522
+ " if not repo_name:\n",
523
+ " repo_name = repo.split('/')[-1]\n",
524
+ " !cd {extensions_dir} \\\n",
525
+ " && git clone {repo} {repo_name} \\\n",
526
+ " && cd {repo_name} \\\n",
527
+ " && git fetch\n",
528
+ " del cap\n",
529
+ " print(f\"\\r📦 Установлено '{len(extension_repo)}', Кастомных расширений!\")\n",
530
+ "\n",
531
+ "\n",
532
+ "## List Models and stuff\n",
533
+ "if detailed_download == \"off\":\n",
534
+ " print(\"\\n\\n\\033[33mЕсли вы не видете каких-то скаченных файлов, включите в виджетах функцию 'Подробная Загрузка'.\")\n",
535
+ "\n",
536
+ "if any(not file.endswith('.txt') for file in os.listdir(models_dir)):\n",
537
+ " print(\"\\n\\033[33m➤ Models\\033[0m\")\n",
538
+ " !find {models_dir}/ -mindepth 1 ! -name '*.txt' -printf '%f\\n'\n",
539
+ "if any(not file.endswith('.txt') for file in os.listdir(vaes_dir)):\n",
540
+ " print(\"\\n\\033[33m➤ VAEs\\033[0m\")\n",
541
+ " !find {vaes_dir}/ -mindepth 1 ! -name '*.txt' -printf '%f\\n'\n",
542
+ "if any(not file.endswith('.txt') and not os.path.isdir(os.path.join(embeddings_dir, file)) for file in os.listdir(embeddings_dir)):\n",
543
+ " print(\"\\n\\033[33m➤ Embeddings\\033[0m\")\n",
544
+ " !find {embeddings_dir}/ -mindepth 1 -maxdepth 1 \\( -name '*.pt' -or -name '*.safetensors' \\) -printf '%f\\n'\n",
545
+ "if any(not file.endswith('.txt') for file in os.listdir(loras_dir)):\n",
546
+ " print(\"\\n\\033[33m➤ LoRAs\\033[0m\")\n",
547
+ " !find {loras_dir}/ -mindepth 1 ! -name '*.keep' -printf '%f\\n'\n",
548
+ "print(f\"\\n\\033[33m➤ Extensions\\033[0m\")\n",
549
+ "!find {extensions_dir}/ -mindepth 1 -maxdepth 1 ! -name '*.txt' -printf '%f\\n'\n",
550
+ "if any(not file.endswith(('.txt', '.yaml')) for file in os.listdir(control_dir)):\n",
551
+ " print(\"\\n\\033[33m➤ ControlNet\\033[0m\")\n",
552
+ " !find {control_dir}/ -mindepth 1 ! -name '*.yaml' -printf '%f\\n' | sed 's/^[^_]*_[^_]*_[^_]*_\\(.*\\)_fp16\\.safetensors$/\\1/'\n",
553
+ "\n",
554
+ "\n",
555
+ "# === OTHER ===\n",
556
+ "# Downlaod discord tags UmiWildcards\n",
557
+ "files_umi = [\n",
558
+ " \"https://huggingface.co/NagisaNao/fast_repo/resolve/main/extensions/UmiWildacrd/discord/200_pan_gen.txt\",\n",
559
+ " \"https://huggingface.co/NagisaNao/fast_repo/resolve/main/extensions/UmiWildacrd/discord/150_bra_gen.txt\"\n",
560
+ "]\n",
561
+ "save_dir_path = f\"{webui_path}/extensions/Umi-AI-Wildcards/wildcards/discord\"\n",
562
+ "\n",
563
+ "with capture.capture_output() as cap:\n",
564
+ " for file in files_umi:\n",
565
+ " !aria2c --optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c -d {save_dir_path} {file}\n",
566
+ "del cap\n",
567
+ "\n",
568
+ "\n",
569
+ "# === ONLY SAGEMAKER ===\n",
570
+ "if env == \"SageMaker Studio Lab\":\n",
571
+ " with capture.capture_output() as cap:\n",
572
+ " !rm -rf /home/studio-lab-user/.conda/envs/studiolab-safemode\n",
573
+ " !rm -rf /home/studio-lab-user/.conda/envs/sagemaker-distribution\n",
574
+ " !rm -rf /home/studio-lab-user/.conda/pkgs/cache\n",
575
+ " !pip cache purge\n",
576
+ " !rm -rf ~/.cache\n",
577
+ " del cap"
578
+ ],
579
+ "metadata": {
580
+ "id": "2lJmbqrs3Mu8"
581
+ },
582
+ "execution_count": null,
583
+ "outputs": []
584
+ }
585
+ ]
586
+ }
files_cells/notebooks/ru/launch_ru.ipynb ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "execution_count": null,
20
+ "metadata": {
21
+ "id": "JKTCrY9LU7Oq"
22
+ },
23
+ "outputs": [],
24
+ "source": [
25
+ "##~ LAUNCH CODE | BY: ANXETY ~##\n",
26
+ "\n",
27
+ "import os\n",
28
+ "import re\n",
29
+ "import time\n",
30
+ "import json\n",
31
+ "import requests\n",
32
+ "from datetime import timedelta\n",
33
+ "\n",
34
+ "\n",
35
+ "# ================= DETECT ENV =================\n",
36
+ "def check_colab_subscription():\n",
37
+ " return (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024. ** 3) <= 20)\n",
38
+ "free_plan = check_colab_subscription()\n",
39
+ "\n",
40
+ "def detect_environment():\n",
41
+ " environments = {\n",
42
+ " 'COLAB_GPU': ('Google Colab', \"/root\" if free_plan else \"/content\"),\n",
43
+ " 'KAGGLE_URL_BASE': ('Kaggle', \"/kaggle/working/content\"),\n",
44
+ " 'SAGEMAKER_INTERNAL_IMAGE_URI': ('SageMaker Studio Lab', \"/home/studio-lab-user/content\")\n",
45
+ " }\n",
46
+ "\n",
47
+ " for env_var, (environment, path) in environments.items():\n",
48
+ " if env_var in os.environ:\n",
49
+ " return environment, path\n",
50
+ "\n",
51
+ "env, root_path = detect_environment()\n",
52
+ "webui_path = f\"{root_path}/sdw\"\n",
53
+ "# ----------------------------------------------\n",
54
+ "\n",
55
+ "def load_settings():\n",
56
+ " SETTINGS_FILE = f'{root_path}/settings.json'\n",
57
+ " if os.path.exists(SETTINGS_FILE):\n",
58
+ " with open(SETTINGS_FILE, 'r') as f:\n",
59
+ " settings = json.load(f)\n",
60
+ " return settings\n",
61
+ "\n",
62
+ "settings = load_settings()\n",
63
+ "ngrok_token = settings['ngrok_token']\n",
64
+ "commandline_arguments = settings['commandline_arguments']\n",
65
+ "\n",
66
+ "\n",
67
+ "# ======================== TUNNEL ========================\n",
68
+ "if env != \"SageMaker Studio Lab\":\n",
69
+ " import cloudpickle as pickle\n",
70
+ "\n",
71
+ " password = \"x1101\"\n",
72
+ " def get_public_ip(version='ipv4'):\n",
73
+ " try:\n",
74
+ " url = f'https://api64.ipify.org?format=json&{version}=true'\n",
75
+ " response = requests.get(url)\n",
76
+ " data = response.json()\n",
77
+ " public_ip = data['ip']\n",
78
+ " return public_ip\n",
79
+ " except Exception as e:\n",
80
+ " print(f\"Error getting public {version} address:\", e)\n",
81
+ "\n",
82
+ " public_ipv4 = get_public_ip(version='ipv4')\n",
83
+ "\n",
84
+ " tunnel_class = pickle.load(open(f\"{root_path}/new_tunnel\", \"rb\"), encoding=\"utf-8\")\n",
85
+ " tunnel_port= 1101\n",
86
+ " tunnel = tunnel_class(tunnel_port)\n",
87
+ " tunnel.add_tunnel(command=\"cl tunnel --url localhost:{port}\", name=\"cl\", pattern=re.compile(r\"[\\w-]+\\.trycloudflare\\.com\"))\n",
88
+ " tunnel.add_tunnel(command=\"lt --port {port}\", name=\"lt\", pattern=re.compile(r\"[\\w-]+\\.loca\\.lt\"), note=\"Password : \" + \"\\033[32m\" + public_ipv4 + \"\\033[0m\" + \" rerun cell if 404 error.\")\n",
89
+ "# ======================== TUNNEL ========================\n",
90
+ "\n",
91
+ "\n",
92
+ "# automatic fixing path V2\n",
93
+ "!sed -i 's#\"tagger_hf_cache_dir\": \".*models/interrogators\"#\"tagger_hf_cache_dir\": \"{root_path}/sdw/models/interrogators\"#' {webui_path}/config.json\n",
94
+ "!sed -i 's#\"additional_networks_extra_lora_path\": \".*models/Lora/\"#\"additional_networks_extra_lora_path\": \"{root_path}/sdw/models/Lora/\"#' {webui_path}/config.json\n",
95
+ "# ---\n",
96
+ "!sed -i 's/\"sd_checkpoint_hash\": \".*\"/\"sd_checkpoint_hash\": \"\"/g; s/\"sd_model_checkpoint\": \".*\"/\"sd_model_checkpoint\": \"\"/g; s/\"sd_vae\": \".*\"/\"sd_vae\": \"None\"/g' {webui_path}/config.json\n",
97
+ "\n",
98
+ "\n",
99
+ "if env != \"SageMaker Studio Lab\":\n",
100
+ " with tunnel:\n",
101
+ " !#python -m http.server 1101\n",
102
+ " %cd {webui_path}\n",
103
+ " commandline_arguments += f\" --port=1101\"\n",
104
+ "\n",
105
+ " if ngrok_token:\n",
106
+ " commandline_arguments += ' --ngrok ' + ngrok_token\n",
107
+ " if env != \"Google Colab\":\n",
108
+ " commandline_arguments += f\" --encrypt-pass=1769\"\n",
109
+ "\n",
110
+ " !COMMANDLINE_ARGS=\"{commandline_arguments}\" python launch.py\n",
111
+ "\n",
112
+ " start_colab = float(open(f'{webui_path}/static/colabTimer.txt', 'r').read())\n",
113
+ " time_since_start = str(timedelta(seconds=time.time()-start_colab)).split('.')[0]\n",
114
+ " print(f\"\\n⌚️ \\033[0mВы проводите эту сессию в течение - \\033[33m{time_since_start}\\033[0m\\n\\n\")\n",
115
+ "\n",
116
+ "else:\n",
117
+ " if ngrok_token:\n",
118
+ " %cd {webui_path}\n",
119
+ "\n",
120
+ " commandline_arguments += ' --ngrok ' + ngrok_token\n",
121
+ "\n",
122
+ " !COMMANDLINE_ARGS=\"{commandline_arguments}\" python launch.py\n",
123
+ "\n",
124
+ " start_colab = float(open(f'{webui_path}/static/colabTimer.txt', 'r').read())\n",
125
+ " time_since_start = str(timedelta(seconds=time.time()-start_colab)).split('.')[0]\n",
126
+ " print(f\"\\n⌚️ \\033[0mВы проводите эту сессию в течение - \\033[33m{time_since_start}\\033[0m\\n\\n\")\n",
127
+ "\n",
128
+ " else:\n",
129
+ " print(\"Упс... Я думаю, вы забыли вставить токен `ngrok`..... вернитесь к виджетам и вставьте его, чтобы запустить webui... без него никак :/\\nВы можете получить токен здесь:\\n\\nhttps://dashboard.ngrok.com/get-started/your-authtoken\")"
130
+ ]
131
+ }
132
+ ]
133
+ }
files_cells/notebooks/ru/widgets_ru.ipynb ADDED
@@ -0,0 +1,451 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "##~ WIDGET CODE | BY: ANXETY ~##\n",
21
+ "\n",
22
+ "import os\n",
23
+ "import json\n",
24
+ "import ipywidgets as widgets\n",
25
+ "from ipywidgets import widgets, Layout, Label, Button, VBox, HBox\n",
26
+ "from IPython.display import display, HTML, Javascript, clear_output\n",
27
+ "\n",
28
+ "\n",
29
+ "# ================= DETECT ENV =================\n",
30
+ "def check_colab_subscription():\n",
31
+ " return (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024. ** 3) <= 20)\n",
32
+ "free_plan = check_colab_subscription()\n",
33
+ "\n",
34
+ "def detect_environment():\n",
35
+ " environments = {\n",
36
+ " 'COLAB_GPU': ('Google Colab', \"/root\" if free_plan else \"/content\"),\n",
37
+ " 'KAGGLE_URL_BASE': ('Kaggle', \"/kaggle/working/content\"),\n",
38
+ " 'SAGEMAKER_INTERNAL_IMAGE_URI': ('SageMaker Studio Lab', \"/home/studio-lab-user/content\")\n",
39
+ " }\n",
40
+ "\n",
41
+ " for env_var, (environment, path) in environments.items():\n",
42
+ " if env_var in os.environ:\n",
43
+ " return environment, path\n",
44
+ "\n",
45
+ "env, root_path = detect_environment()\n",
46
+ "webui_path = f\"{root_path}/sdw\"\n",
47
+ "\n",
48
+ "!mkdir -p {root_path}\n",
49
+ "# ----------------------------------------------\n",
50
+ "\n",
51
+ "\n",
52
+ "# ==================== CSS JS ====================\n",
53
+ "CSS = '''\n",
54
+ "<style>\n",
55
+ "/* General Styles */\n",
56
+ ".header {\n",
57
+ " font-family: cursive;\n",
58
+ " font-size: 20px;\n",
59
+ " font-weight: bold;\n",
60
+ " color: #ff8cee;\n",
61
+ " margin-bottom: 15px;\n",
62
+ " user-select: none;\n",
63
+ " cursor: default;\n",
64
+ " display: inline-block;\n",
65
+ "}\n",
66
+ "\n",
67
+ "hr {\n",
68
+ " border-color: grey;\n",
69
+ " background-color: grey;\n",
70
+ " opacity: 0.25;\n",
71
+ "}\n",
72
+ "\n",
73
+ "\n",
74
+ "/* Container style */\n",
75
+ "\n",
76
+ ".container {\n",
77
+ " position: relative;\n",
78
+ " background-color: #232323;\n",
79
+ " width: 1080px;\n",
80
+ " padding: 10px 15px;\n",
81
+ " border-radius: 15px;\n",
82
+ " box-shadow: 0 0 50px rgba(0, 0, 0, 0.3);\n",
83
+ " margin-bottom: 5px;\n",
84
+ " overflow: visible;\n",
85
+ "}\n",
86
+ "\n",
87
+ ".container::after {\n",
88
+ " position: absolute;\n",
89
+ " top: 5px;\n",
90
+ " right: 10px;\n",
91
+ " content: \"ANXETY\";\n",
92
+ " font-weight: bold;\n",
93
+ " font-size: 24px;\n",
94
+ " color: rgba(0, 0, 0, 0.15);\n",
95
+ "}\n",
96
+ "\n",
97
+ ".container_custom_downlad {\n",
98
+ " height: 55px;\n",
99
+ " overflow: hidden;\n",
100
+ " transition: all 0.5s;\n",
101
+ "}\n",
102
+ "\n",
103
+ ".container_custom_downlad.expanded {\n",
104
+ " height: 270px;\n",
105
+ "}\n",
106
+ "\n",
107
+ "\n",
108
+ "/* Element text style */\n",
109
+ "\n",
110
+ ".widget-html,\n",
111
+ ".widget-button,\n",
112
+ ".widget-text label,\n",
113
+ ".widget-checkbox label,\n",
114
+ ".widget-dropdown label,\n",
115
+ ".widget-dropdown select,\n",
116
+ ".widget-text input[type=\"text\"] {\n",
117
+ " font-family: cursive;\n",
118
+ " font-size: 14px;\n",
119
+ " color: white !important;\n",
120
+ " user-select: none;\n",
121
+ "}\n",
122
+ "\n",
123
+ ".widget-text input[type=\"text\"]::placeholder {\n",
124
+ " color: grey;\n",
125
+ "}\n",
126
+ "\n",
127
+ "\n",
128
+ "/* Input field styles */\n",
129
+ "\n",
130
+ ".widget-dropdown select,\n",
131
+ ".widget-text input[type=\"text\"] {\n",
132
+ " height: 30px;\n",
133
+ " background-color: #1c1c1c;\n",
134
+ " border: 1px solid #262626;\n",
135
+ " border-radius: 10px;\n",
136
+ " box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);\n",
137
+ " transition: all 0.3s ease-in-out;\n",
138
+ "}\n",
139
+ "\n",
140
+ ".widget-dropdown select:focus,\n",
141
+ ".widget-text input[type=\"text\"]:focus {\n",
142
+ " border-color: #006ee5;\n",
143
+ "}\n",
144
+ "\n",
145
+ ".widget-dropdown select:hover,\n",
146
+ ".widget-text input[type=\"text\"]:hover {\n",
147
+ " transform: scale(1.003);\n",
148
+ " background-color: #262626;\n",
149
+ " box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);\n",
150
+ "}\n",
151
+ "\n",
152
+ "\n",
153
+ "/* Button styles */\n",
154
+ "\n",
155
+ ".button_save {\n",
156
+ " font-size: 15px;\n",
157
+ " font-weight: bold;\n",
158
+ " width: 120px;\n",
159
+ " height: 35px;\n",
160
+ " border-radius: 15px;\n",
161
+ " background-image: radial-gradient(circle at top left, purple 10%, violet 90%);\n",
162
+ " background-size: 200% 200%;\n",
163
+ " background-position: left bottom;\n",
164
+ " transition: background 0.5s ease-in-out, transform 0.3s ease;\n",
165
+ "}\n",
166
+ "\n",
167
+ ".button_save:hover {\n",
168
+ " cursor: pointer;\n",
169
+ " background-image: radial-gradient(circle at top left, purple 10%, #93ac47 90%);\n",
170
+ " background-size: 200% 200%;\n",
171
+ " background-position: right bottom;\n",
172
+ " transform: translateY(1px);\n",
173
+ "}\n",
174
+ "\n",
175
+ ".button_ngrok {\n",
176
+ " font-size: 12px;\n",
177
+ " height: 30px;\n",
178
+ " border-radius: 10px;\n",
179
+ " padding: 1px 12px;\n",
180
+ " background-image: radial-gradient(circle at top left, purple 10%, violet 90%);\n",
181
+ " background-size: 200% 200%;\n",
182
+ " background-position: left bottom;\n",
183
+ " transition: background 0.5s ease-in-out, transform 0.3s ease;\n",
184
+ " white-space: nowrap;\n",
185
+ "}\n",
186
+ "\n",
187
+ ".button_ngrok:hover {\n",
188
+ " cursor: pointer;\n",
189
+ " background-image: radial-gradient(circle at top left, purple 10%, #e2a9a8 90%);\n",
190
+ " background-size: 200% 200%;\n",
191
+ " background-position: right bottom;\n",
192
+ " transform: translateY(1px);\n",
193
+ "}\n",
194
+ "\n",
195
+ ".button_save:active,\n",
196
+ ".button_ngrok:active {\n",
197
+ " filter: brightness(0.75);\n",
198
+ "}\n",
199
+ "\n",
200
+ "\n",
201
+ "/* Popup style of `FAQ` window */\n",
202
+ "\n",
203
+ ".info {\n",
204
+ " position: absolute;\n",
205
+ " top: -5px;\n",
206
+ " right: 95px;\n",
207
+ " color: grey;\n",
208
+ " font-family: cursive;\n",
209
+ " font-size: 14px;\n",
210
+ " font-weight: normal;\n",
211
+ " user-select: none;\n",
212
+ " pointer-events: none;\n",
213
+ " opacity: 0;\n",
214
+ " transition: opacity 0.3s ease-in-out;\n",
215
+ " display: inline-block;\n",
216
+ "}\n",
217
+ "\n",
218
+ ".popup {\n",
219
+ " position: absolute;\n",
220
+ " top: 120px;\n",
221
+ " z-index: 999;\n",
222
+ " width: auto;\n",
223
+ " padding: 10px;\n",
224
+ " text-align: center;\n",
225
+ " background-color: rgba(255, 255, 255, 0.05);\n",
226
+ " backdrop-filter: blur(20px);\n",
227
+ " border: 1px solid rgba(255, 255, 255, 0.45);\n",
228
+ " border-radius: 8px;\n",
229
+ " box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);\n",
230
+ " opacity: 0;\n",
231
+ " color: #fff;\n",
232
+ " font-size: 16px;\n",
233
+ " font-family: cursive;\n",
234
+ " user-select: none;\n",
235
+ " cursor: default;\n",
236
+ " pointer-events: none;\n",
237
+ " transform: rotate(-5deg);\n",
238
+ " transition: top 0.3s ease-in-out, opacity 0.3s ease-in-out, transform 0.3s ease-in-out;\n",
239
+ "}\n",
240
+ "\n",
241
+ ".sample {\n",
242
+ " display: inline-block;\n",
243
+ " margin-top: 25px;\n",
244
+ " padding: 10px 100px;\n",
245
+ " background-color: rgba(255, 255, 255, 0.2);\n",
246
+ " color: #c6e2ff;\n",
247
+ " border: 2px solid rgba(255, 255, 255, 0.2);\n",
248
+ " border-radius: 8px;\n",
249
+ " box-shadow: 0 0 10px rgba(255, 255, 255, 0.2), inset 0 0 25px rgba(255, 255, 255, 0.2);\n",
250
+ "}\n",
251
+ "\n",
252
+ ".info.showed {\n",
253
+ " opacity: 1;\n",
254
+ " pointer-events: auto;\n",
255
+ "}\n",
256
+ "\n",
257
+ ".info:hover + .popup {\n",
258
+ " top: 35px;\n",
259
+ " opacity: 1;\n",
260
+ " pointer-events: initial;\n",
261
+ " transform: rotate(0deg);\n",
262
+ "}\n",
263
+ "\n",
264
+ "\n",
265
+ "/* Animation of elements */\n",
266
+ "\n",
267
+ ".container,\n",
268
+ ".button_save {\n",
269
+ " animation-name: showedWidgets;\n",
270
+ " animation-duration: 1s;\n",
271
+ "}\n",
272
+ "\n",
273
+ "@keyframes showedWidgets {\n",
274
+ " 0% {\n",
275
+ " transform: translate3d(-65%, 15%, 0) scale(0) rotate(15deg);\n",
276
+ " filter: blur(25px) grayscale(1) brightness(0.3);\n",
277
+ " opacity: 0;\n",
278
+ " }\n",
279
+ " 100% {\n",
280
+ " transform: translate3d(0, 0, 0) scale(1) rotate(0deg);\n",
281
+ " filter: blur(0) grayscale(0) brightness(1);\n",
282
+ " opacity: 1;\n",
283
+ " }\n",
284
+ "}\n",
285
+ "</style>\n",
286
+ "\n",
287
+ "<!-- TOGGLE 'CustomDL' SCRIPT -->\n",
288
+ "<script>\n",
289
+ "function toggleContainer() {\n",
290
+ " let downloadContainer = document.querySelector('.container_custom_downlad');\n",
291
+ " let info = document.querySelector('.info');\n",
292
+ "\n",
293
+ " downloadContainer.classList.toggle('expanded');\n",
294
+ " info.classList.toggle('showed');\n",
295
+ "}\n",
296
+ "</script>\n",
297
+ "'''\n",
298
+ "\n",
299
+ "display(HTML(CSS))\n",
300
+ "# ==================== CSS JS ====================\n",
301
+ "\n",
302
+ "\n",
303
+ "# ==================== WIDGETS ====================\n",
304
+ "# --- global widgets ---\n",
305
+ "style = {'description_width': 'initial'}\n",
306
+ "layout = widgets.Layout(min_width='1047px')\n",
307
+ "\n",
308
+ "HR = widgets.HTML('<hr>')\n",
309
+ "\n",
310
+ "# --- MODEL ---\n",
311
+ "model_header = widgets.HTML('<div class=\"header\">Выбор Модели<div>')\n",
312
+ "model_options = ['none',\n",
313
+ " '1.Anime (by Xpuct) + INP',\n",
314
+ " '2.Cetus-Mix [Anime] [V4] + INP',\n",
315
+ " '3.Counterfeit [Anime] [V3] + INP',\n",
316
+ " '4.CuteColor [Anime] [V3]',\n",
317
+ " '5.Dark-Sushi-Mix [Anime]',\n",
318
+ " '6.Meina-Mix [Anime] [V11] + INP',\n",
319
+ " '7.Mix-Pro [Anime] [V4] + INP',\n",
320
+ " '8.BluMix [Anime] [V7]']\n",
321
+ "# ---\n",
322
+ "Model_widget = widgets.Dropdown(options=model_options, value='3.Counterfeit [Anime] [V3] + INP', description='Модель:', style=style, layout=layout)\n",
323
+ "Model_Num_widget = widgets.Text(description='Номер Модели:', placeholder='Введите номера моделей для скачивания через запятую/пробел.', style=style, layout=layout)\n",
324
+ "Inpainting_Model_widget = widgets.Checkbox(value=False, description='Inpainting Модели', style=style)\n",
325
+ "\n",
326
+ "display(widgets.VBox([model_header, Model_widget, Model_Num_widget, Inpainting_Model_widget]).add_class(\"container\"))\n",
327
+ "\n",
328
+ "# --- VAE ---\n",
329
+ "vae_header = widgets.HTML('<div class=\"header\" >Выбор VAE</div>')\n",
330
+ "vae_options = ['none',\n",
331
+ " '1.Anime.vae',\n",
332
+ " '2.Anything.vae',\n",
333
+ " '3.Blessed2.vae',\n",
334
+ " '4.ClearVae.vae',\n",
335
+ " '5.WD.vae']\n",
336
+ "Vae_widget = widgets.Dropdown(options=vae_options, value='3.Blessed2.vae', description='Vae:', style=style, layout=layout)\n",
337
+ "Vae_Num_widget = widgets.Text(description='Номер Vae:', placeholder='Введите номера vae для скачивания через запятую/пробел.', style=style, layout=layout)\n",
338
+ "\n",
339
+ "display(widgets.VBox([vae_header, Vae_widget, Vae_Num_widget]).add_class(\"container\"))\n",
340
+ "\n",
341
+ "# --- ADDITIONAL ---\n",
342
+ "additional_header = widgets.HTML('<div class=\"header\">Дополнительно</div>')\n",
343
+ "latest_webui_widget = widgets.Checkbox(value=True, description='Обновить WebUI', style=style)\n",
344
+ "latest_exstensions_widget = widgets.Checkbox(value=True, description='Обновить Расширения', style=style)\n",
345
+ "detailed_download_widget = widgets.Dropdown(options=['off', 'on'], value='off', description='Подробная Загрузка:', style=style)\n",
346
+ "latest_changes_widget = HBox([latest_webui_widget, latest_exstensions_widget, detailed_download_widget], layout=widgets.Layout(justify_content='space-between'))\n",
347
+ "controlnet_options = ['none', 'ALL', '1.canny',\n",
348
+ " '2.openpose', '3.depth',\n",
349
+ " '4.normal_map', '5.mlsd',\n",
350
+ " '6.lineart', '7.soft_edge',\n",
351
+ " '8.scribble', '9.segmentation',\n",
352
+ " '10.shuffle', '11.tile',\n",
353
+ " '12.inpaint', '13.instruct_p2p']\n",
354
+ "# ---\n",
355
+ "controlnet_widget = widgets.Dropdown(options=controlnet_options, value='none', description='ControlNet:', style=style, layout=layout)\n",
356
+ "controlnet_Num_widget = widgets.Text(description='Номер ControlNet:', placeholder='Введите номера моделей ControlNet для скачивания через запятую/пробел.', style=style, layout=layout)\n",
357
+ "commit_hash_widget = widgets.Text(description='Commit Hash:', style=style, layout=layout)\n",
358
+ "optional_huggingface_token_widget = widgets.Text(description='Токен HuggingFace:', style=style, layout=layout)\n",
359
+ "ngrok_token_widget = widgets.Text(description='Токен Ngrok:', style=style, layout=widgets.Layout(width='1047px'))\n",
360
+ "ngrock_button = widgets.HTML('<a href=\"https://dashboard.ngrok.com/get-started/your-authtoken\" target=\"_blank\">Получить Ngrok Токен</a>').add_class(\"button_ngrok\")\n",
361
+ "ngrok_widget = widgets.HBox([ngrok_token_widget, ngrock_button], style=style, layout=layout)\n",
362
+ "# ---\n",
363
+ "commandline_arguments_options = \"--listen --enable-insecure-extension-access --theme dark --no-half-vae --disable-console-progressbars --xformers\"\n",
364
+ "commandline_arguments_widget = widgets.Text(description='Аргументы:', value=commandline_arguments_options, style=style, layout=layout)\n",
365
+ "\n",
366
+ "display(widgets.VBox([\n",
367
+ " additional_header, latest_changes_widget, HR, controlnet_widget, controlnet_Num_widget, commit_hash_widget, optional_huggingface_token_widget, ngrok_widget, HR, commandline_arguments_widget\n",
368
+ " ]).add_class(\"container\"))\n",
369
+ "\n",
370
+ "# --- CUSTOM DOWNLOAD ---\n",
371
+ "custom_download_header_popup = widgets.HTML('''\n",
372
+ "<style>\n",
373
+ "/* Color */\n",
374
+ ".sample_label {color: #dbafff;}\n",
375
+ ".braces {color: #ffff00;}\n",
376
+ ".extension {color: #eb934b;}\n",
377
+ ".file_name {color: #ffffd8;}\n",
378
+ "</style>\n",
379
+ "\n",
380
+ "<div class=\"header\" style=\"cursor: pointer;\" onclick=\"toggleContainer()\">Кастомная Загрузка</div>\n",
381
+ "<!-- PopUp window -->\n",
382
+ "<div class=\"info\" id=\"info_dl\">FAQ?</div>\n",
383
+ "<div class=\"popup\">\n",
384
+ " Разделите несколько URL-адресов запятой/пробелом. Для <span class=\"file_name\">пользовательского имени</span> файла/расширения укажите его через <span class=\"braces\">[]</span>\n",
385
+ " после URL без пробелов.\n",
386
+ " <span style=\"color: #ff9999\">Для файлов обязательно укажите</span> - <span class=\"extension\">Расширение Файла.</span>\n",
387
+ " <div class=\"sample\">\n",
388
+ " <span class=\"sample_label\">Пример для Файла:</span>\n",
389
+ " https://civitai.com/api/download/models/229782<span class=\"braces\">[</span><span class=\"file_name\">Detailer</span><span class=\"extension\">.safetensors</span><span class=\"braces\">]</span>\n",
390
+ " <br>\n",
391
+ " <span class=\"sample_label\">Пример для Расширения:</span>\n",
392
+ " https://github.com/hako-mikan/sd-webui-regional-prompter<span class=\"braces\">[</span><span class=\"file_name\">Regional-Prompter</span><span class=\"braces\">]</span>\n",
393
+ " </div>\n",
394
+ "</div>\n",
395
+ "''')\n",
396
+ "# ---\n",
397
+ "Model_url_widget = widgets.Text(description='Model:', style=style, layout=layout)\n",
398
+ "Vae_url_widget = widgets.Text(description='Vae:', style=style, layout=layout)\n",
399
+ "LoRA_url_widget = widgets.Text(description='LoRa:', style=style, layout=layout)\n",
400
+ "Embedding_url_widget = widgets.Text(description='Embedding:', style=style, layout=layout)\n",
401
+ "Extensions_url_widget = widgets.Text(description='Extensions:', style=style, layout=layout)\n",
402
+ "custom_file_urls_widget = widgets.Text(description='Файл (txt):', style=style, layout=layout)\n",
403
+ "\n",
404
+ "display(widgets.VBox([\n",
405
+ " custom_download_header_popup, Model_url_widget, Vae_url_widget, LoRA_url_widget, Embedding_url_widget, Extensions_url_widget, custom_file_urls_widget\n",
406
+ " ]).add_class(\"container\").add_class(\"container_custom_downlad\"))\n",
407
+ "\n",
408
+ "# --- Save Button ---\n",
409
+ "save_button = widgets.Button(description='Сохранить').add_class(\"button_save\")\n",
410
+ "display(save_button)\n",
411
+ "\n",
412
+ "\n",
413
+ "# ============ Load / Save - Settings V2 ============\n",
414
+ "SETTINGS_FILE = f'{root_path}/settings.json'\n",
415
+ "\n",
416
+ "settings_keys = [\n",
417
+ " 'Model', 'Model_Num', 'Inpainting_Model',\n",
418
+ " 'Vae', 'Vae_Num',\n",
419
+ " 'latest_webui', 'latest_exstensions', 'detailed_download',\n",
420
+ " 'controlnet', 'controlnet_Num', 'commit_hash', 'optional_huggingface_token',\n",
421
+ " 'ngrok_token', 'commandline_arguments',\n",
422
+ " 'Model_url', 'Vae_url', 'LoRA_url', 'Embedding_url', 'Extensions_url', 'custom_file_urls'\n",
423
+ "]\n",
424
+ "\n",
425
+ "def save_settings():\n",
426
+ " settings = {key: globals()[f\"{key}_widget\"].value for key in settings_keys}\n",
427
+ " with open(SETTINGS_FILE, 'w') as f:\n",
428
+ " json.dump(settings, f)\n",
429
+ "\n",
430
+ "def load_settings():\n",
431
+ " if os.path.exists(SETTINGS_FILE):\n",
432
+ " with open(SETTINGS_FILE, 'r') as f:\n",
433
+ " settings = json.load(f)\n",
434
+ " for key in settings_keys:\n",
435
+ " globals()[f\"{key}_widget\"].value = settings.get(key)\n",
436
+ "\n",
437
+ "def save_data(button):\n",
438
+ " save_settings()\n",
439
+ " widgets.Widget.close_all()\n",
440
+ "\n",
441
+ "settings = load_settings()\n",
442
+ "save_button.on_click(save_data)"
443
+ ],
444
+ "metadata": {
445
+ "id": "2lJmbqrs3Mu8"
446
+ },
447
+ "execution_count": null,
448
+ "outputs": []
449
+ }
450
+ ]
451
+ }
files_cells/python/en/auto-cleaner_en.py ADDED
@@ -0,0 +1,351 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ##~ AutoCleaner V3.6 CODE | BY: ANXETY ~##
2
+
3
+ # --change log--
4
+ """
5
+ V3.6 | 13.03.24
6
+ Fixed selection window
7
+ Dynamic update of memory display
8
+ """
9
+
10
+
11
+ import os
12
+ import time
13
+ import ipywidgets as widgets
14
+ from ipywidgets import Label, Button, VBox, HBox
15
+ from IPython.display import display, HTML, Javascript
16
+
17
+
18
+ # ================= DETECT ENV =================
19
+ def detect_environment():
20
+ environments = {
21
+ 'COLAB_GPU': ('Google Colab', "/content"),
22
+ 'KAGGLE_URL_BASE': ('Kaggle', "/kaggle/working/content"),
23
+ 'SAGEMAKER_INTERNAL_IMAGE_URI': ('SageMaker Studio Lab', "/home/studio-lab-user/content")
24
+ }
25
+
26
+ for env_var, (environment, path) in environments.items():
27
+ if env_var in os.environ:
28
+ return environment, path
29
+
30
+ env, root_path = detect_environment()
31
+ webui_path = f"{root_path}/sdw"
32
+ # ----------------------------------------------
33
+
34
+
35
+ directories = {
36
+ "Images": f"{webui_path}/outputs",
37
+ "Models": f"{webui_path}/models/Stable-diffusion/",
38
+ "Vae": f"{webui_path}/models/VAE/",
39
+ "LoRa": f"{webui_path}/models/Lora/",
40
+ "ControlNet Models": f"{webui_path}/models/ControlNet/"
41
+ }
42
+
43
+
44
+ # ==================== CSS ====================
45
+ CSS = """
46
+ <style>
47
+ /* General Styles */
48
+
49
+ hr {
50
+ border-color: grey;
51
+ background-color: grey;
52
+ opacity: 0.25;
53
+ }
54
+
55
+ .instruction_AC {
56
+ font-family: cursive;
57
+ font-size: 18px;
58
+ color: grey;
59
+ user-select: none;
60
+ cursor: default;
61
+ }
62
+
63
+
64
+ /* Container style */
65
+
66
+ .container_AC {
67
+ position: relative;
68
+ background-color: #232323;
69
+ width: 800px;
70
+ height: auto;
71
+ padding: 15px;
72
+ border-radius: 15px;
73
+ box-shadow: 0 0 50px rgba(0, 0, 0, 0.3);
74
+ margin-bottom: 5px;
75
+ overflow: visible;
76
+ }
77
+
78
+ .container_AC::before {
79
+ position: absolute;
80
+ top: 5px;
81
+ right: 10px;
82
+ content: "AutoCleanerV3.6";
83
+ font-weight: bold;
84
+ font-size: 24px;
85
+ color: rgba(0, 0, 0, 0.2);
86
+ }
87
+
88
+ .container_AC::after {
89
+ position: absolute;
90
+ top: 30px;
91
+ right: 10px;
92
+ content: "ANXETY";
93
+ font-weight: bold;
94
+ font-size: 18px;
95
+ color: rgba(0, 0, 0, 0.2);
96
+ }
97
+
98
+ .custom-select-multiple_AC select {
99
+ padding: 10px;
100
+ font-family: cursive;
101
+ border: 1px solid #262626 !important;
102
+ border-radius: 10px;
103
+ color: white;
104
+ background-color: #1c1c1c;
105
+ box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);
106
+ }
107
+
108
+ .output_AC {
109
+ padding: 10px;
110
+ height: auto;
111
+ border: 1px solid #262626;
112
+ border-radius: 10px;
113
+ background-color: #1c1c1c;
114
+ box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);
115
+ width: auto;
116
+ box-sizing: border-box;
117
+ }
118
+
119
+ .output_message_AC {
120
+ font-family: cursive;
121
+ color: white !important;
122
+ font-size: 14px;
123
+ user-select: none;
124
+ cursor: default
125
+ }
126
+
127
+
128
+ .storage_info_AC {
129
+ padding: 5px 20px;
130
+ height: auto;
131
+ border: 1px solid #262626;
132
+ border-radius: 10px;
133
+ background-color: #1c1c1c;
134
+ box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);
135
+ width: auto;
136
+ font-family: cursive;
137
+ color: #B2B2B2 !important;
138
+ font-size: 14px;
139
+ user-select: none;
140
+ cursor: default
141
+ }
142
+
143
+
144
+ /* Button and storage info layout */
145
+ .lower_information_panel_AC {
146
+ display: flex;
147
+ align-items: center;
148
+ justify-content: space-between;
149
+ }
150
+
151
+
152
+ /* Button style */
153
+
154
+ .button_AC {
155
+ width: auto;
156
+ font-family: cursive;
157
+ color: white !important;
158
+ font-size: 14px;
159
+ font-weight: bold;
160
+ height: 35px;
161
+ border-radius: 15px;
162
+ background-image: radial-gradient(circle at top left, purple 10%, violet 90%);
163
+ background-size: 200% 200%;
164
+ background-position: left bottom;
165
+ transition: background 0.5s ease-in-out, transform 0.3s ease;
166
+ }
167
+
168
+ .button_AC:hover {
169
+ cursor: pointer;
170
+ background-size: 200% 200%;
171
+ background-position: right bottom;
172
+ transform: translateY(1px);
173
+ }
174
+
175
+ .button_execute_AC:hover {
176
+ background-image: radial-gradient(circle at top left, purple 10%, #93ac47 90%);
177
+ }
178
+
179
+ .button_clear_AC:hover {
180
+ background-image: radial-gradient(circle at top left, purple 10%, #fc3468 90%);
181
+ }
182
+
183
+ .button_execute_AC:active,
184
+ .button_clear_AC:active {
185
+ filter: brightness(0.75);
186
+ }
187
+
188
+ .jupyter-widgets.lm-Widget:focus {
189
+ outline: none;
190
+ }
191
+
192
+
193
+ /* Animation of elements */
194
+
195
+ /* Emergence */
196
+ .container_AC {
197
+ animation-name: slideInTopBlur;
198
+ animation-duration: 0.7s;
199
+ animation-fill-mode: forwards;
200
+ }
201
+
202
+ @keyframes slideInTopBlur {
203
+ 0% {
204
+ transform: translate3d(0, 50%, 0) scale(0.85) rotate3d(1, 0, 0, -85deg);
205
+ filter: blur(5px) grayscale(1) brightness(0.5);
206
+ opacity: 0;
207
+ }
208
+ 100% {
209
+ transform: translate3d(0, 0, 0) scale(1) rotate3d(1, 0, 0, 0deg);
210
+ filter: blur(0) grayscale(0) brightness(1);
211
+ opacity: 1;
212
+ }
213
+ }
214
+
215
+ /* Leaving */
216
+ .container_AC.hide {
217
+ animation-name: slideOutTopBlur;
218
+ animation-duration: 0.5s;
219
+ animation-fill-mode: forwards;
220
+ }
221
+
222
+ @keyframes slideOutTopBlur {
223
+ 0% {
224
+ transform: translate3d(0, 0, 0) scale(1);
225
+ filter: blur(0) grayscale(0) brightness(1);
226
+ opacity: 1;
227
+ }
228
+ 100% {
229
+ transform: translate3d(0, -100%, 0);
230
+ filter: blur(5px) grayscale(1) brightness(0);
231
+ opacity: 0;
232
+ }
233
+ }
234
+ </style>
235
+ """
236
+
237
+ display(HTML(CSS))
238
+ # ==================== CSS ====================
239
+
240
+
241
+ # ================ AutoCleaner function ================
242
+ def clean_directory(directory):
243
+ deleted_files = 0
244
+ for root, dirs, files in os.walk(directory):
245
+ for file in files:
246
+ if file.endswith((".txt", ".yaml")):
247
+ continue
248
+ os.remove(os.path.join(root, file))
249
+ deleted_files += 1
250
+ return deleted_files
251
+
252
+
253
+ def get_word_variant(n, variants):
254
+ unit = abs(n) % 10
255
+ tens = abs(n) % 100
256
+ if tens in range(11, 15):
257
+ return variants[2]
258
+ elif unit == 1:
259
+ return variants[0]
260
+ elif unit in range(2, 5):
261
+ return variants[1]
262
+ else:
263
+ return variants[2]
264
+
265
+
266
+ def update_memory_info():
267
+ disk_space = psutil.disk_usage(os.getcwd())
268
+ total = disk_space.total / (1024 ** 3)
269
+ used = disk_space.used / (1024 ** 3)
270
+ free = disk_space.free / (1024 ** 3)
271
+
272
+ storage_info.value = f'''
273
+ <div class="storage_info_AC">Total storage: {total:.2f} GB <span style="color: #555">|</span> Used: {used:.2f} GB <span style="color: #555">|</span> Free: {free:.2f} GB</div>
274
+ '''
275
+
276
+
277
+ def on_execute_button_press(button):
278
+ selected_cleaners = auto_cleaner_widget.value
279
+ deleted_files_dict = {}
280
+
281
+ for option in selected_cleaners:
282
+ if option in directories:
283
+ deleted_files_dict[option] = clean_directory(directories[option])
284
+
285
+ output.clear_output()
286
+
287
+ with output:
288
+ for message in generate_messages(deleted_files_dict):
289
+ message_widget = HTML(f'<p class="output_message_AC">{message}</p>')
290
+ display(message_widget)
291
+
292
+ update_memory_info()
293
+
294
+
295
+ def on_clear_button_press(button):
296
+ container.add_class("hide")
297
+ time.sleep(0.5)
298
+ widgets.Widget.close_all()
299
+
300
+
301
+ def generate_messages(deleted_files_dict):
302
+ messages = []
303
+ word_variants = {
304
+ "Images": ["Image", "Images", "Images"],
305
+ "Models": ["Model", "Models", "Models"],
306
+ "Vae": ["VAE", "VAE", "VAE"],
307
+ "LoRa": ["LoRa", "LoRa", "LoRa"],
308
+ "ControlNet Models": ["ControlNet Model", "ControlNet Models", "ControlNet Models"]
309
+ }
310
+ deleted_word_variants = ["Deleted", "Deleted", "Deleted"]
311
+ for key, value in deleted_files_dict.items():
312
+ word_variant = word_variants.get(key, ["", "", ""])
313
+ deleted_word = get_word_variant(value, deleted_word_variants)
314
+ object_word = get_word_variant(value, word_variant)
315
+ messages.append(f"{deleted_word} {value} {object_word}")
316
+ return messages
317
+ # ================ AutoCleaner function ================
318
+
319
+
320
+ # --- storage memory ---
321
+ import psutil
322
+ disk_space = psutil.disk_usage(os.getcwd())
323
+ total = disk_space.total / (1024 ** 3)
324
+ used = disk_space.used / (1024 ** 3)
325
+ free = disk_space.free / (1024 ** 3)
326
+
327
+
328
+ # UI Code
329
+ AutoCleaner_options = AutoCleaner_options = list(directories.keys())
330
+ instruction_label = widgets.HTML('''
331
+ <span class="instruction_AC">Use <span style="color: #B2B2B2;">ctrl</span> or <span style="color: #B2B2B2;">shift</span> for multiple selections.</span>
332
+ ''')
333
+ auto_cleaner_widget = widgets.SelectMultiple(options=AutoCleaner_options, layout=widgets.Layout(width='auto')).add_class("custom-select-multiple_AC")
334
+ output = widgets.Output().add_class("output_AC")
335
+ # ---
336
+ execute_button = Button(description='Execute Cleaning').add_class("button_execute_AC").add_class("button_AC")
337
+ execute_button.on_click(on_execute_button_press)
338
+ clear_button = Button(description='Hide Widget').add_class("button_clear_AC").add_class("button_AC")
339
+ clear_button.on_click(on_clear_button_press)
340
+ # ---
341
+ storage_info = widgets.HTML(f'''
342
+ <div class="storage_info_AC">Total storage: {total:.2f} GB <span style="color: #555">|</span> Used: {used:.2f} GB <span style="color: #555">|</span> Free: {free:.2f} GB</div>
343
+ ''')
344
+ # ---
345
+ buttons = widgets.HBox([execute_button, clear_button])
346
+ lower_information_panel = widgets.HBox([buttons, storage_info]).add_class("lower_information_panel_AC")
347
+
348
+ container = VBox([instruction_label, widgets.HTML('<hr>'), auto_cleaner_widget, output, widgets.HTML('<hr>'), lower_information_panel]).add_class("container_AC")
349
+
350
+ display(container)
351
+
files_cells/python/en/downloading_en.py ADDED
@@ -0,0 +1,549 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ##~ DOWNLOADING CODE | BY: ANXETY ~##
2
+
3
+ import os
4
+ import re
5
+ import time
6
+ import json
7
+ import requests
8
+ import subprocess
9
+ from datetime import timedelta
10
+ from subprocess import getoutput
11
+ from urllib.parse import unquote
12
+ from IPython.utils import capture
13
+ from IPython.display import clear_output
14
+
15
+
16
+ # ================= DETECT ENV =================
17
+ def detect_environment():
18
+ environments = {
19
+ 'COLAB_GPU': ('Google Colab', "/content"),
20
+ 'KAGGLE_URL_BASE': ('Kaggle', "/kaggle/working/content"),
21
+ 'SAGEMAKER_INTERNAL_IMAGE_URI': ('SageMaker Studio Lab', "/home/studio-lab-user/content")
22
+ }
23
+
24
+ for env_var, (environment, path) in environments.items():
25
+ if env_var in os.environ:
26
+ return environment, path
27
+
28
+ env, root_path = detect_environment()
29
+ webui_path = f"{root_path}/sdw"
30
+ # ----------------------------------------------
31
+
32
+
33
+ # === ONLY SAGEMAKER ===
34
+ if env == "SageMaker Studio Lab":
35
+ print("Updating dependencies, may take some time...")
36
+ get_ipython().system('pip install -q --upgrade torchsde')
37
+ get_ipython().system('pip install -q --upgrade pip')
38
+ get_ipython().system('pip install -q --upgrade psutil')
39
+
40
+ clear_output()
41
+
42
+
43
+ # ================ LIBRARIES ================
44
+ flag_file = f"{root_path}/libraries_installed.txt"
45
+
46
+ if not os.path.exists(flag_file):
47
+ # A1111 update webui to 1.8.0
48
+ xformers = "xformers==0.0.23.post1 triton==2.1.0"
49
+ torch = "torch==2.1.2+cu121 torchvision==0.16.2+cu121 --extra-index-url https://download.pytorch.org/whl/cu121"
50
+
51
+ print("Installing the libraries, it's going to take a while....", end='')
52
+ with capture.capture_output() as cap:
53
+ get_ipython().system('apt-get update && apt -y install aria2')
54
+ get_ipython().system('npm install -g localtunnel &> /dev/null')
55
+ get_ipython().system('curl -s -OL https://github.com/DEX-1101/sd-webui-notebook/raw/main/res/new_tunnel --output-dir {root_path}')
56
+ get_ipython().system('curl -s -Lo /usr/bin/cl https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 && chmod +x /usr/bin/cl')
57
+ get_ipython().system('pip install insightface')
58
+
59
+ if env == "SageMaker Studio Lab":
60
+ get_ipython().run_line_magic('pip', 'install -q opencv-python-headless huggingface-hub')
61
+ get_ipython().run_line_magic('conda', 'update -q -n base conda')
62
+ get_ipython().run_line_magic('conda', 'install -q -y aria2')
63
+ get_ipython().run_line_magic('conda', 'install -q -y glib')
64
+ get_ipython().system('pip install tensorflow')
65
+
66
+ get_ipython().system('wget -P /home/studio-lab-user https://huggingface.co/NagisaNao/fast_repo/resolve/main/sagemaker/FULL_DELETED_NOTEBOOK.ipynb')
67
+
68
+ if env == "Google Colab":
69
+ get_ipython().system('pip install -q {xformers} -U')
70
+ else:
71
+ get_ipython().system('pip install -q {torch} -U')
72
+ get_ipython().system('pip install -q {xformers} -U')
73
+
74
+ with open(flag_file, "w") as f:
75
+ f.write("hey ;3")
76
+ del cap
77
+ print("\rLibraries are installed!" + " "*35)
78
+ time.sleep(2)
79
+ clear_output()
80
+
81
+
82
+ # ================= loading settings V4 =================
83
+ def load_settings(path):
84
+ if os.path.exists(path):
85
+ with open(path, 'r') as file:
86
+ return json.load(file)
87
+ return {}
88
+
89
+ settings = load_settings(f'{root_path}/settings.json')
90
+
91
+ variables = [
92
+ 'Model', 'Model_Num', 'Inpainting_Model',
93
+ 'Vae', 'Vae_Num',
94
+ 'latest_webui', 'latest_exstensions', 'detailed_download',
95
+ 'controlnet', 'controlnet_Num', 'commit_hash', 'optional_huggingface_token',
96
+ 'ngrok_token' 'commandline_arguments',
97
+ 'Model_url', 'Vae_url', 'LoRA_url', 'Embedding_url', 'Extensions_url', 'custom_file_urls'
98
+ ]
99
+
100
+ locals().update({key: settings.get(key) for key in variables})
101
+
102
+
103
+ # ================= OTHER =================
104
+ try:
105
+ start_colab
106
+ except:
107
+ start_colab = int(time.time())-5
108
+
109
+ # CONFIG DIR
110
+ models_dir = f"{webui_path}/models/Stable-diffusion"
111
+ vaes_dir = f"{webui_path}/models/VAE"
112
+ embeddings_dir = f"{webui_path}/embeddings"
113
+ loras_dir = f"{webui_path}/models/Lora"
114
+ extensions_dir = f"{webui_path}/extensions"
115
+ control_dir = f"{webui_path}/models/ControlNet"
116
+
117
+
118
+ # ================= MAIN CODE =================
119
+ # --- Obsolescence warning ---
120
+ if env == "SageMaker Studio Lab":
121
+ print("You are using the 'SageMaker' environment - this environment is outdated so many bugs will not be fixed and it will be cut in functionality. To save memory and/or to avoid bugs.\n\n")
122
+
123
+
124
+ if not os.path.exists(webui_path):
125
+ start_install = int(time.time())
126
+ print("⌚ Unpacking Stable Diffusion...", end='')
127
+ with capture.capture_output() as cap:
128
+ get_ipython().system('aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/NagisaNao/fast_repo/resolve/main/FULL_REPO.zip -o repo.zip')
129
+ get_ipython().system('unzip -q -o repo.zip -d {webui_path}')
130
+ get_ipython().system('rm -rf repo.zip')
131
+
132
+ get_ipython().run_line_magic('cd', '{root_path}')
133
+ os.environ["SAFETENSORS_FAST_GPU"]='1'
134
+ os.environ["CUDA_MODULE_LOADING"]="LAZY"
135
+ os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
136
+ os.environ["PYTHONWARNINGS"] = "ignore"
137
+
138
+ get_ipython().system('echo -n {start_colab} > {webui_path}/static/colabTimer.txt')
139
+ del cap
140
+ install_time = timedelta(seconds=time.time()-start_install)
141
+ print("\r🚀 Unpacking is complete! For","%02d:%02d:%02d ⚡\n" % (install_time.seconds / 3600, (install_time.seconds / 60) % 60, install_time.seconds % 60), end='', flush=True)
142
+ else:
143
+ get_ipython().system('echo -n {start_colab} > {webui_path}/static/colabTimer.txt')
144
+ print("🚀 All unpacked... Skip. ⚡")
145
+ start_colab = float(open(f'{webui_path}/static/colabTimer.txt', 'r').read())
146
+ time_since_start = str(timedelta(seconds=time.time()-start_colab)).split('.')[0]
147
+ print(f"⌚️ You have been conducting this session for - \033[33m{time_since_start}\033[0m")
148
+
149
+
150
+ ## Changes extensions and WebUi
151
+ if latest_webui or latest_exstensions:
152
+ action = "Updating WebUI and Extensions" if latest_webui and latest_exstensions else ("WebUI Update" if latest_webui else "Update Extensions")
153
+ print(f"⌚️ {action}...", end='', flush=True)
154
+ with capture.capture_output() as cap:
155
+ get_ipython().system('git config --global user.email "[email protected]"')
156
+ get_ipython().system('git config --global user.name "Your Name"')
157
+
158
+ ## Update Webui
159
+ if latest_webui:
160
+ get_ipython().run_line_magic('cd', '{webui_path}')
161
+ get_ipython().system('git restore .')
162
+ get_ipython().system('git pull -X theirs --rebase --autostash')
163
+
164
+ ## Update extensions
165
+ if latest_exstensions:
166
+ if env != "SageMaker Studio Lab":
167
+ get_ipython().system('{\'for dir in \' + webui_path + \'/extensions/*/; do cd \\"$dir\\" && git reset --hard && git pull; done\'}')
168
+ else:
169
+ get_ipython().system('{\'for dir in /home/studio-lab-user/content/sdw/extensions/*/; do cd \\"$dir\\" && git fetch origin && git pull; done\'}')
170
+
171
+ get_ipython().system('cd {webui_path}/repositories/stable-diffusion-stability-ai && git restore .')
172
+ del cap
173
+ print(f"\r✨ {action} Completed!")
174
+
175
+
176
+ # === FIXING ERRORS ===
177
+ # --- All ---
178
+ # --- Encrypt-Image ---
179
+ get_ipython().system("sed -i '9,37d' {webui_path}/extensions/Encrypt-Image/javascript/encrypt_images_info.js")
180
+
181
+ # --- SageMaker ---
182
+ if env == "SageMaker Studio Lab":
183
+ with capture.capture_output() as cap:
184
+ # --- SuperMerger Remove ---
185
+ if os.path.exists(f"{webui_path}/extensions/supermerger"):
186
+ get_ipython().system('rm -rf {webui_path}/extensions/supermerger')
187
+ # --- Launch (Style) ---
188
+ get_ipython().system('wget -O {webui_path}/modules/styles.py https://huggingface.co/NagisaNao/fast_repo/resolve/main/sagemaker/fixing/webui/styles.py')
189
+ del cap
190
+
191
+
192
+ ## Version switching
193
+ if commit_hash:
194
+ print('⏳ Time machine activation...', end="", flush=True)
195
+ with capture.capture_output() as cap:
196
+ get_ipython().run_line_magic('cd', '{webui_path}')
197
+ get_ipython().system('git config --global user.email "[email protected]"')
198
+ get_ipython().system('git config --global user.name "Your Name"')
199
+ get_ipython().system('git reset --hard {commit_hash}')
200
+ del cap
201
+ print(f"\r⌛️ The time machine has been activated! Current commit: \033[34m{commit_hash}\033[0m")
202
+
203
+
204
+ ## Downloading model and stuff | oh yeah~ I'm starting to misunderstand my own code ( almost my own ;3 )
205
+ print("📦 Downloading models and stuff...", end='')
206
+ model_list = {
207
+ "1.Anime (by Xpuct) + INP": [
208
+ {"url": "https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2.safetensors", "name": "Anime_v2.safetensors"},
209
+ {"url": "https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2-inpainting.safetensors", "name": "Anime_v2-inpainting.safetensors"}
210
+ ],
211
+ "2.Cetus-Mix [Anime] [V4] + INP": [
212
+ {"url": "https://civitai.com/api/download/models/130298", "name": "CetusMix_V4.safetensors"},
213
+ {"url": "https://civitai.com/api/download/models/139882", "name": "CetusMix_V4-inpainting.safetensors"}
214
+ ],
215
+ "3.Counterfeit [Anime] [V3] + INP": [
216
+ {"url": "https://civitai.com/api/download/models/125050", "name": "Counterfeit_V3.safetensors"},
217
+ {"url": "https://civitai.com/api/download/models/137911", "name": "Counterfeit_V3-inpainting.safetensors"}
218
+ ],
219
+ "4.CuteColor [Anime] [V3]": [
220
+ {"url": "https://civitai.com/api/download/models/138754", "name": "CuteColor_V3.safetensors"}
221
+ ],
222
+ "5.Dark-Sushi-Mix [Anime]": [
223
+ {"url": "https://civitai.com/api/download/models/101640", "name": "DarkSushiMix_2_5D.safetensors"},
224
+ {"url": "https://civitai.com/api/download/models/56071", "name": "DarkSushiMix_colorful.safetensors"}
225
+ ],
226
+ "6.Meina-Mix [Anime] [V11] + INP": [
227
+ {"url": "https://civitai.com/api/download/models/119057", "name": "MeinaMix_V11.safetensors"},
228
+ {"url": "https://civitai.com/api/download/models/120702", "name": "MeinaMix_V11-inpainting.safetensors"}
229
+ ],
230
+ "7.Mix-Pro [Anime] [V4] + INP": [
231
+ {"url": "https://civitai.com/api/download/models/125668", "name": "MixPro_V4.safetensors"},
232
+ {"url": "https://civitai.com/api/download/models/139878", "name": "MixPro_V4-inpainting.safetensors"}
233
+ ],
234
+ "8.BluMix [Anime] [V7]": [
235
+ {"url": "https://civitai.com/api/download/models/361779", "name": "BluMix_v7.safetensors"}
236
+ ]
237
+ }
238
+
239
+ # 1-4 (fp16/cleaned)
240
+ vae_list = {
241
+ "1.Anime.vae": [
242
+ {"url": "https://civitai.com/api/download/models/131654", "name": "Anime.vae.safetensors"},
243
+ {"url": "https://civitai.com/api/download/models/131658", "name": "vae-ft-mse.vae.safetensors"}
244
+ ],
245
+ "2.Anything.vae": [{"url": "https://civitai.com/api/download/models/131656", "name": "Anything.vae.safetensors"}],
246
+ "3.Blessed2.vae": [{"url": "https://civitai.com/api/download/models/142467", "name": "Blessed2.vae.safetensors"}],
247
+ "4.ClearVae.vae": [{"url": "https://civitai.com/api/download/models/133362", "name": "ClearVae_23.vae.safetensors"}],
248
+ "5.WD.vae": [{"url": "https://huggingface.co/NoCrypt/resources/resolve/main/VAE/wd.vae.safetensors", "name": "WD.vae.safetensors"}]
249
+ }
250
+
251
+ controlnet_list = {
252
+ "1.canny": [
253
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny_fp16.safetensors", "name": "control_v11p_sd15_canny_fp16.safetensors"},
254
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_canny_fp16.yaml", "name": "control_v11p_sd15_canny_fp16.yaml"}
255
+ ],
256
+ "2.openpose": [
257
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose_fp16.safetensors", "name": "control_v11p_sd15_openpose_fp16.safetensors"},
258
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_openpose_fp16.yaml", "name": "control_v11p_sd15_openpose_fp16.yaml"}
259
+ ],
260
+ "3.depth": [
261
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth_fp16.safetensors", "name": "control_v11f1p_sd15_depth_fp16.safetensors"},
262
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1p_sd15_depth_fp16.yaml", "name": "control_v11f1p_sd15_depth_fp16.yaml"},
263
+ {"url": "https://huggingface.co/NagisaNao/models/resolve/main/ControlNet_v11/control_v11p_sd15_depth_anything_fp16.safetensors", "name": "control_v11p_sd15_depth_anything_fp16.safetensors"}
264
+ ],
265
+ "4.normal_map": [
266
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_normalbae_fp16.safetensors", "name": "control_v11p_sd15_normalbae_fp16.safetensors"},
267
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_normalbae_fp16.yaml", "name": "control_v11p_sd15_normalbae_fp16.yaml"}
268
+ ],
269
+ "5.mlsd": [
270
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_mlsd_fp16.safetensors", "name": "control_v11p_sd15_mlsd_fp16.safetensors"},
271
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_mlsd_fp16.yaml", "name": "control_v11p_sd15_mlsd_fp16.yaml"}
272
+ ],
273
+ "6.lineart": [
274
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart_fp16.safetensors", "name": "control_v11p_sd15_lineart_fp16.safetensors"},
275
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15s2_lineart_anime_fp16.safetensors", "name": "control_v11p_sd15s2_lineart_anime_fp16.safetensors"},
276
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_lineart_fp16.yaml", "name": "control_v11p_sd15_lineart_fp16.yaml"},
277
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15s2_lineart_anime_fp16.yaml", "name": "control_v11p_sd15s2_lineart_anime_fp16.yaml"}
278
+ ],
279
+ "7.soft_edge": [
280
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge_fp16.safetensors", "name": "control_v11p_sd15_softedge_fp16.safetensors"},
281
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_softedge_fp16.yaml", "name": "control_v11p_sd15_softedge_fp16.yaml"}
282
+ ],
283
+ "8.scribble": [
284
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble_fp16.safetensors", "name": "control_v11p_sd15_scribble_fp16.safetensors"},
285
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_scribble_fp16.yaml", "name": "control_v11p_sd15_scribble_fp16.yaml"}
286
+ ],
287
+ "9.segmentation": [
288
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg_fp16.safetensors", "name": "control_v11p_sd15_seg_fp16.safetensors"},
289
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_seg_fp16.yaml", "name": "control_v11p_sd15_seg_fp16.yaml"}
290
+ ],
291
+ "10.shuffle": [
292
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle_fp16.safetensors", "name": "control_v11e_sd15_shuffle_fp16.safetensors"},
293
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_shuffle_fp16.yaml", "name": "control_v11e_sd15_shuffle_fp16.yaml"}
294
+ ],
295
+ "11.tile": [
296
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile_fp16.safetensors", "name": "control_v11f1e_sd15_tile_fp16.safetensors"},
297
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1e_sd15_tile_fp16.yaml", "name": "control_v11f1e_sd15_tile_fp16.yaml"}
298
+ ],
299
+ "12.inpaint": [
300
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_inpaint_fp16.safetensors", "name": "control_v11p_sd15_inpaint_fp16.safetensors"},
301
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_inpaint_fp16.yaml", "name": "control_v11p_sd15_inpaint_fp16.yaml"}
302
+ ],
303
+ "13.instruct_p2p": [
304
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p_fp16.safetensors", "name": "control_v11e_sd15_ip2p_fp16.safetensors"},
305
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_ip2p_fp16.yaml", "name": "control_v11e_sd15_ip2p_fp16.yaml"}
306
+ ]
307
+ }
308
+
309
+ extension_repo = []
310
+ prefixes = [
311
+ "model:",
312
+ "vae:",
313
+ "lora:",
314
+ "embeddings:",
315
+ "extensions:"
316
+ ]
317
+
318
+ get_ipython().system('mkdir -p {models_dir} {vaes_dir} {embeddings_dir} {loras_dir} {control_dir}')
319
+
320
+ url = ""
321
+ hf_token = optional_huggingface_token if optional_huggingface_token else "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"
322
+ user_header = f"\"Authorization: Bearer {hf_token}\""
323
+
324
+ def handle_manual(url):
325
+ original_url = url
326
+ url = url.split(':', 1)[1]
327
+ file_name = re.search(r'\[(.*?)\]', url)
328
+ file_name = file_name.group(1) if file_name else None
329
+ if file_name:
330
+ url = re.sub(r'\[.*?\]', '', url)
331
+
332
+ dir_mapping = {"model": models_dir, "vae": vaes_dir, "lora": loras_dir, "embeddings": embeddings_dir, "extensions": None}
333
+
334
+ for prefix, dir in dir_mapping.items():
335
+ if original_url.startswith(f"{prefix}:"):
336
+ if prefix != "extensions":
337
+ manual_download(url, dir, file_name=file_name)
338
+ else:
339
+ extension_repo.append((url, file_name))
340
+
341
+ def manual_download(url, dst_dir, file_name):
342
+ basename = url.split("/")[-1] if file_name is None else file_name
343
+
344
+ # I do it at my own risk..... Fucking CivitAi >:(
345
+ civitai_token = "62c0c5956b2f9defbd844d754000180b"
346
+ if 'civitai' in url and civitai_token:
347
+ url = f"{url}?token={civitai_token}"
348
+
349
+ # -- GDrive --
350
+ if 'drive.google' in url:
351
+ if 'folders' in url:
352
+ get_ipython().system('gdown --folder "{url}" -O {dst_dir} --fuzzy -c')
353
+ else:
354
+ get_ipython().system('gdown "{url}" -O {dst_dir} --fuzzy -c')
355
+ # -- Huggin Face --
356
+ elif 'huggingface' in url:
357
+ if '/blob/' in url:
358
+ url = url.replace('/blob/', '/resolve/')
359
+ if file_name:
360
+ get_ipython().system('aria2c --optimize-concurrent-downloads --console-log-level=error --summary-interval=10 --header={user_header} -c -j5 -x16 -s16 -k1M -d {dst_dir} -o {basename} {url}')
361
+ else:
362
+ parsed_link = '\n{}\n\tout={}'.format(url, unquote(url.split('/')[-1]))
363
+ get_ipython().system('echo -e "{parsed_link}" | aria2c --header={user_header} --console-log-level=error --summary-interval=10 -i- -j5 -x16 -s16 -k1M -c -d "{dst_dir}" -o {basename}')
364
+ # -- Other --
365
+ elif 'http' in url or 'magnet' in url:
366
+ if file_name:
367
+ get_ipython().system('aria2c --optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c -d {dst_dir} -o {file_name} {url}')
368
+ else:
369
+ parsed_link = '"{}"'.format(url)
370
+ get_ipython().system('aria2c --optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c -d {dst_dir} -Z {parsed_link}')
371
+
372
+ def download(url):
373
+ links_and_paths = url.split(',')
374
+
375
+ for link_or_path in links_and_paths:
376
+ link_or_path = link_or_path.strip()
377
+ if not link_or_path:
378
+ continue
379
+
380
+ if any(link_or_path.startswith(prefix.lower()) for prefix in prefixes):
381
+ handle_manual(link_or_path)
382
+ continue
383
+
384
+ url, dst_dir, file_name = link_or_path.split()
385
+ manual_download(url, dst_dir, file_name)
386
+
387
+ submodels = []
388
+
389
+ def add_submodels(selection, num_selection, model_dict, dst_dir):
390
+ if selection == "none":
391
+ return []
392
+ if selection == "ALL":
393
+ all_models = []
394
+ for models in model_dict.values():
395
+ all_models.extend(models)
396
+ selected_models = all_models
397
+ else:
398
+ selected_models = model_dict[selection]
399
+ selected_nums = map(int, num_selection.replace(',', '').split())
400
+
401
+ for num in selected_nums:
402
+ if 1 <= num <= len(model_dict):
403
+ name = list(model_dict)[num - 1]
404
+ selected_models.extend(model_dict[name])
405
+
406
+ unique_models = list({model['name']: model for model in selected_models}.values())
407
+
408
+ for model in unique_models:
409
+ model['dst_dir'] = dst_dir
410
+
411
+ return unique_models
412
+
413
+ submodels += add_submodels(Model, Model_Num, model_list, models_dir) # model
414
+ submodels += add_submodels(Vae, Vae_Num, vae_list, vaes_dir) # vae
415
+ submodels += add_submodels(controlnet, "" if controlnet == "ALL" else controlnet_Num, controlnet_list, control_dir) # controlnet
416
+
417
+ for submodel in submodels:
418
+ if not Inpainting_Model and "inpainting" in submodel['name']:
419
+ continue
420
+
421
+ url += f"{submodel['url']} {submodel['dst_dir']} {submodel['name']}, "
422
+
423
+ def process_file_download(file_url):
424
+ global Model_url, Vae_url, LoRA_url, Embedding_url, Extensions_url
425
+ urls_dict = {
426
+ 'model': 'Model_url',
427
+ 'vae': 'Vae_url',
428
+ 'embed': 'Embedding_url',
429
+ 'lora': 'LoRA_url',
430
+ 'extension': 'Extensions_url'
431
+ }
432
+
433
+ if file_url.startswith("http"):
434
+ if "blob" in file_url:
435
+ file_url = file_url.replace("blob", "raw")
436
+ response = requests.get(file_url)
437
+ lines = response.text.split('\n')
438
+ else:
439
+ with open(file_url, 'r') as file:
440
+ lines = file.readlines()
441
+
442
+ current_tag = None
443
+ for line in lines:
444
+ if line.strip().startswith('#'):
445
+ current_tag = next((tag for tag in urls_dict if tag in line.lower()), None)
446
+ elif current_tag and line.strip():
447
+ urls = [url.strip() for url in line.split()]
448
+ for url in urls:
449
+ if url.startswith("http"):
450
+ globals()[urls_dict[current_tag]] += ", " + url
451
+
452
+ # fix all possible errors/options and function call
453
+ if custom_file_urls:
454
+ if not custom_file_urls.endswith('.txt'):
455
+ custom_file_urls += '.txt'
456
+ if not custom_file_urls.startswith('http'):
457
+ if not custom_file_urls.startswith(root_path):
458
+ custom_file_urls = f'{root_path}/{custom_file_urls}'
459
+ if custom_file_urls.count('/content') >= 2:
460
+ custom_file_urls = re.sub(r'(/content){2,}', '/content', custom_file_urls)
461
+
462
+ try:
463
+ process_file_download(custom_file_urls)
464
+ except FileNotFoundError:
465
+ pass
466
+
467
+ urls = [Model_url, Vae_url, LoRA_url, Embedding_url, Extensions_url]
468
+
469
+ for i, prefix in enumerate(prefixes):
470
+ if urls[i]:
471
+ prefixed_urls = [f"{prefix}{u}" for u in urls[i].replace(',', '').split()]
472
+ if prefixed_urls:
473
+ url += ", ".join(prefixed_urls) + ", "
474
+
475
+ if detailed_download == "on":
476
+ print("\n\n\033[33m# ====== Detailed Download ====== #\n\033[0m")
477
+ download(url)
478
+ print("\n\033[33m# =============================== #\n\033[0m")
479
+ else:
480
+ with capture.capture_output() as cap:
481
+ download(url)
482
+ del cap
483
+
484
+ print("\r🏁 Download Complete!" + " "*15)
485
+
486
+
487
+ # Cleaning shit after downloading...
488
+ get_ipython().system('find \\( -name ".ipynb_checkpoints" -o -name ".aria2" \\) -type d -exec rm -r {} \\; >/dev/null 2>&1')
489
+
490
+
491
+ ## Install of Custom extensions
492
+ if len(extension_repo) > 0:
493
+ print("✨ Installing custom extensions...", end='', flush=True)
494
+ with capture.capture_output() as cap:
495
+ for repo, repo_name in extension_repo:
496
+ if not repo_name:
497
+ repo_name = repo.split('/')[-1]
498
+ get_ipython().system('cd {extensions_dir} && git clone {repo} {repo_name} && cd {repo_name} && git fetch')
499
+ del cap
500
+ print(f"\r📦 Installed '{len(extension_repo)}', Custom extensions!")
501
+
502
+
503
+ ## List Models and stuff
504
+ if detailed_download == "off":
505
+ print("\n\n\033[33mIf you don't see any downloaded files, enable the 'Detailed Downloads' feature in the widget.")
506
+
507
+ if any(not file.endswith('.txt') for file in os.listdir(models_dir)):
508
+ print("\n\033[33m➤ Models\033[0m")
509
+ get_ipython().system("find {models_dir}/ -mindepth 1 ! -name '*.txt' -printf '%f\\n'")
510
+ if any(not file.endswith('.txt') for file in os.listdir(vaes_dir)):
511
+ print("\n\033[33m➤ VAEs\033[0m")
512
+ get_ipython().system("find {vaes_dir}/ -mindepth 1 ! -name '*.txt' -printf '%f\\n'")
513
+ if any(not file.endswith('.txt') and not os.path.isdir(os.path.join(embeddings_dir, file)) for file in os.listdir(embeddings_dir)):
514
+ print("\n\033[33m➤ Embeddings\033[0m")
515
+ get_ipython().system("find {embeddings_dir}/ -mindepth 1 -maxdepth 1 \\( -name '*.pt' -or -name '*.safetensors' \\) -printf '%f\\n'")
516
+ if any(not file.endswith('.txt') for file in os.listdir(loras_dir)):
517
+ print("\n\033[33m➤ LoRAs\033[0m")
518
+ get_ipython().system("find {loras_dir}/ -mindepth 1 ! -name '*.keep' -printf '%f\\n'")
519
+ print(f"\n\033[33m➤ Extensions\033[0m")
520
+ get_ipython().system("find {extensions_dir}/ -mindepth 1 -maxdepth 1 ! -name '*.txt' -printf '%f\\n'")
521
+ if any(not file.endswith(('.txt', '.yaml')) for file in os.listdir(control_dir)):
522
+ print("\n\033[33m➤ ControlNet\033[0m")
523
+ get_ipython().system("find {control_dir}/ -mindepth 1 ! -name '*.yaml' -printf '%f\\n' | sed 's/^[^_]*_[^_]*_[^_]*_\\(.*\\)_fp16\\.safetensors$/\\1/'")
524
+
525
+
526
+ # === OTHER ===
527
+ # Downlaod discord tags UmiWildcards
528
+ files_umi = [
529
+ "https://huggingface.co/NagisaNao/fast_repo/resolve/main/extensions/UmiWildacrd/discord/200_pan_gen.txt",
530
+ "https://huggingface.co/NagisaNao/fast_repo/resolve/main/extensions/UmiWildacrd/discord/150_bra_gen.txt"
531
+ ]
532
+ save_dir_path = f"{webui_path}/extensions/Umi-AI-Wildcards/wildcards/discord"
533
+
534
+ with capture.capture_output() as cap:
535
+ for file in files_umi:
536
+ get_ipython().system('aria2c --optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c -d {save_dir_path} {file}')
537
+ del cap
538
+
539
+
540
+ # === ONLY SAGEMAKER ===
541
+ if env == "SageMaker Studio Lab":
542
+ with capture.capture_output() as cap:
543
+ get_ipython().system('rm -rf /home/studio-lab-user/.conda/envs/studiolab-safemode')
544
+ get_ipython().system('rm -rf /home/studio-lab-user/.conda/envs/sagemaker-distribution')
545
+ get_ipython().system('rm -rf /home/studio-lab-user/.conda/pkgs/cache')
546
+ get_ipython().system('pip cache purge')
547
+ get_ipython().system('rm -rf ~/.cache')
548
+ del cap
549
+
files_cells/python/en/launch_en.py ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ##~ LAUNCH CODE | BY: ANXETY ~##
2
+
3
+ import os
4
+ import re
5
+ import time
6
+ import json
7
+ import requests
8
+ from datetime import timedelta
9
+
10
+
11
+ # ================= DETECT ENV =================
12
+ def detect_environment():
13
+ environments = {
14
+ 'COLAB_GPU': ('Google Colab', "/content"),
15
+ 'KAGGLE_URL_BASE': ('Kaggle', "/kaggle/working/content"),
16
+ 'SAGEMAKER_INTERNAL_IMAGE_URI': ('SageMaker Studio Lab', "/home/studio-lab-user/content")
17
+ }
18
+
19
+ for env_var, (environment, path) in environments.items():
20
+ if env_var in os.environ:
21
+ return environment, path
22
+
23
+ env, root_path = detect_environment()
24
+ webui_path = f"{root_path}/sdw"
25
+ # ----------------------------------------------
26
+
27
+ def load_settings():
28
+ SETTINGS_FILE = f'{root_path}/settings.json'
29
+ if os.path.exists(SETTINGS_FILE):
30
+ with open(SETTINGS_FILE, 'r') as f:
31
+ settings = json.load(f)
32
+ return settings
33
+
34
+ settings = load_settings()
35
+ ngrok_token = settings['ngrok_token']
36
+ commandline_arguments = settings['commandline_arguments']
37
+
38
+
39
+ # ======================== TUNNEL ========================
40
+ if env != "SageMaker Studio Lab":
41
+ import cloudpickle as pickle
42
+
43
+ password = "x1101"
44
+ def get_public_ip(version='ipv4'):
45
+ try:
46
+ url = f'https://api64.ipify.org?format=json&{version}=true'
47
+ response = requests.get(url)
48
+ data = response.json()
49
+ public_ip = data['ip']
50
+ return public_ip
51
+ except Exception as e:
52
+ print(f"Error getting public {version} address:", e)
53
+
54
+ public_ipv4 = get_public_ip(version='ipv4')
55
+
56
+ tunnel_class = pickle.load(open(f"{root_path}/new_tunnel", "rb"), encoding="utf-8")
57
+ tunnel_port= 1101
58
+ tunnel = tunnel_class(tunnel_port)
59
+ tunnel.add_tunnel(command="cl tunnel --url localhost:{port}", name="cl", pattern=re.compile(r"[\w-]+\.trycloudflare\.com"))
60
+ tunnel.add_tunnel(command="lt --port {port}", name="lt", pattern=re.compile(r"[\w-]+\.loca\.lt"), note="Password : " + "\033[32m" + public_ipv4 + "\033[0m" + " rerun cell if 404 error.")
61
+ # ======================== TUNNEL ========================
62
+
63
+
64
+ # automatic fixing path V2
65
+ get_ipython().system('sed -i \'s#"tagger_hf_cache_dir": ".*models/interrogators"#"tagger_hf_cache_dir": "{root_path}/sdw/models/interrogators"#\' {webui_path}/config.json')
66
+ get_ipython().system('sed -i \'s#"additional_networks_extra_lora_path": ".*models/Lora/"#"additional_networks_extra_lora_path": "{root_path}/sdw/models/Lora/"#\' {webui_path}/config.json')
67
+ # ---
68
+ get_ipython().system('sed -i \'s/"sd_checkpoint_hash": ".*"/"sd_checkpoint_hash": ""/g; s/"sd_model_checkpoint": ".*"/"sd_model_checkpoint": ""/g; s/"sd_vae": ".*"/"sd_vae": "None"/g\' {webui_path}/config.json')
69
+
70
+
71
+ if env != "SageMaker Studio Lab":
72
+ with tunnel:
73
+ get_ipython().system('#python -m http.server 1101')
74
+ get_ipython().run_line_magic('cd', '{webui_path}')
75
+
76
+ if ngrok_token:
77
+ commandline_arguments += ' --ngrok ' + ngrok_token
78
+ commandline_arguments += f" --port=1101 --encrypt-pass=1769" # --encrypt-pass={password}
79
+
80
+ get_ipython().system('COMMANDLINE_ARGS="{commandline_arguments}" python launch.py')
81
+
82
+ start_colab = float(open(f'{webui_path}/static/colabTimer.txt', 'r').read())
83
+ time_since_start = str(timedelta(seconds=time.time()-start_colab)).split('.')[0]
84
+ print(f"\n⌚️ \033[0mYou have been conducting this session for - \033[33m{time_since_start}\033[0m\n\n")
85
+
86
+ else:
87
+ if ngrok_token:
88
+ get_ipython().run_line_magic('cd', '{webui_path}')
89
+
90
+ commandline_arguments += ' --ngrok ' + ngrok_token
91
+
92
+ get_ipython().system('COMMANDLINE_ARGS="{commandline_arguments}" python launch.py')
93
+
94
+ start_colab = float(open(f'{webui_path}/static/colabTimer.txt', 'r').read())
95
+ time_since_start = str(timedelta(seconds=time.time()-start_colab)).split('.')[0]
96
+ print(f"\n⌚️ \033[0mYou have been conducting this session for - \033[33m{time_since_start}\033[0m\n\n")
97
+
98
+ else:
99
+ print("Oops... I think you forgot to insert the token `ngrok`..... go back to widgets and insert it to start webui... no way without it :/\nYou can get the token here:\n\nhttps://dashboard.ngrok.com/get-started/your-authtoken")
100
+
files_cells/python/en/widgets_en.py ADDED
@@ -0,0 +1,420 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ##~ WIDGET CODE | BY: ANXETY ~##
2
+
3
+ import os
4
+ import json
5
+ import ipywidgets as widgets
6
+ from ipywidgets import widgets, Layout, Label, Button, VBox, HBox
7
+ from IPython.display import display, HTML, Javascript, clear_output
8
+
9
+
10
+ # ================= DETECT ENV =================
11
+ def detect_environment():
12
+ environments = {
13
+ 'COLAB_GPU': ('Google Colab', "/content"),
14
+ 'KAGGLE_URL_BASE': ('Kaggle', "/kaggle/working/content"),
15
+ 'SAGEMAKER_INTERNAL_IMAGE_URI': ('SageMaker Studio Lab', "/home/studio-lab-user/content")
16
+ }
17
+
18
+ for env_var, (environment, path) in environments.items():
19
+ if env_var in os.environ:
20
+ return environment, path
21
+
22
+ env, root_path = detect_environment()
23
+ webui_path = f"{root_path}/sdw"
24
+
25
+ get_ipython().system('mkdir -p {root_path}')
26
+ # ----------------------------------------------
27
+
28
+
29
+ # ==================== CSS JS ====================
30
+ CSS = '''
31
+ <style>
32
+ /* General Styles */
33
+ .header {
34
+ font-family: cursive;
35
+ font-size: 20px;
36
+ font-weight: bold;
37
+ color: #ff8cee;
38
+ margin-bottom: 15px;
39
+ user-select: none;
40
+ cursor: default;
41
+ display: inline-block;
42
+ }
43
+
44
+ hr {
45
+ border-color: grey;
46
+ background-color: grey;
47
+ opacity: 0.25;
48
+ }
49
+
50
+
51
+ /* Container style */
52
+
53
+ .container {
54
+ position: relative;
55
+ background-color: #232323;
56
+ width: 1080px;
57
+ padding: 10px 15px;
58
+ border-radius: 15px;
59
+ box-shadow: 0 0 50px rgba(0, 0, 0, 0.3);
60
+ margin-bottom: 5px;
61
+ overflow: visible;
62
+ }
63
+
64
+ .container::after {
65
+ position: absolute;
66
+ top: 5px;
67
+ right: 10px;
68
+ content: "ANXETY";
69
+ font-weight: bold;
70
+ font-size: 24px;
71
+ color: rgba(0, 0, 0, 0.15);
72
+ }
73
+
74
+ .container_custom_downlad {
75
+ height: 55px;
76
+ overflow: hidden;
77
+ transition: all 0.5s;
78
+ }
79
+
80
+ .container_custom_downlad.expanded {
81
+ height: 270px;
82
+ }
83
+
84
+
85
+ /* Element text style */
86
+
87
+ .widget-html,
88
+ .widget-button,
89
+ .widget-text label,
90
+ .widget-checkbox label,
91
+ .widget-dropdown label,
92
+ .widget-dropdown select,
93
+ .widget-text input[type="text"] {
94
+ font-family: cursive;
95
+ font-size: 14px;
96
+ color: white !important;
97
+ user-select: none;
98
+ }
99
+
100
+ .widget-text input[type="text"]::placeholder {
101
+ color: grey;
102
+ }
103
+
104
+
105
+ /* Input field styles */
106
+
107
+ .widget-dropdown select,
108
+ .widget-text input[type="text"] {
109
+ height: 30px;
110
+ background-color: #1c1c1c;
111
+ border: 1px solid #262626;
112
+ border-radius: 10px;
113
+ box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);
114
+ transition: all 0.3s ease-in-out;
115
+ }
116
+
117
+ .widget-dropdown select:focus,
118
+ .widget-text input[type="text"]:focus {
119
+ border-color: #006ee5;
120
+ }
121
+
122
+ .widget-dropdown select:hover,
123
+ .widget-text input[type="text"]:hover {
124
+ transform: scale(1.003);
125
+ background-color: #262626;
126
+ box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);
127
+ }
128
+
129
+
130
+ /* Button styles */
131
+
132
+ .button_save {
133
+ font-size: 15px;
134
+ font-weight: bold;
135
+ width: 120px;
136
+ height: 35px;
137
+ border-radius: 15px;
138
+ background-image: radial-gradient(circle at top left, purple 10%, violet 90%);
139
+ background-size: 200% 200%;
140
+ background-position: left bottom;
141
+ transition: background 0.5s ease-in-out, transform 0.3s ease;
142
+ }
143
+
144
+ .button_save:hover {
145
+ cursor: pointer;
146
+ background-image: radial-gradient(circle at top left, purple 10%, #93ac47 90%);
147
+ background-size: 200% 200%;
148
+ background-position: right bottom;
149
+ transform: translateY(1px);
150
+ }
151
+
152
+ .button_ngrok {
153
+ font-size: 12px;
154
+ height: 30px;
155
+ border-radius: 10px;
156
+ padding: 1px 12px;
157
+ background-image: radial-gradient(circle at top left, purple 10%, violet 90%);
158
+ background-size: 200% 200%;
159
+ background-position: left bottom;
160
+ transition: background 0.5s ease-in-out, transform 0.3s ease;
161
+ white-space: nowrap;
162
+ }
163
+
164
+ .button_ngrok:hover {
165
+ cursor: pointer;
166
+ background-image: radial-gradient(circle at top left, purple 10%, #e2a9a8 90%);
167
+ background-size: 200% 200%;
168
+ background-position: right bottom;
169
+ transform: translateY(1px);
170
+ }
171
+
172
+ .button_save:active,
173
+ .button_ngrok:active {
174
+ filter: brightness(0.75);
175
+ }
176
+
177
+
178
+ /* Popup style of `FAQ` window */
179
+
180
+ .info {
181
+ position: absolute;
182
+ top: -5px;
183
+ right: 95px;
184
+ color: grey;
185
+ font-family: cursive;
186
+ font-size: 14px;
187
+ font-weight: normal;
188
+ user-select: none;
189
+ pointer-events: none;
190
+ opacity: 0;
191
+ transition: opacity 0.3s ease-in-out;
192
+ display: inline-block;
193
+ }
194
+
195
+ .popup {
196
+ position: absolute;
197
+ top: 120px;
198
+ z-index: 999;
199
+ width: auto;
200
+ padding: 10px;
201
+ text-align: center;
202
+ background-color: rgba(255, 255, 255, 0.05);
203
+ backdrop-filter: blur(20px);
204
+ border: 1px solid rgba(255, 255, 255, 0.45);
205
+ border-radius: 8px;
206
+ box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
207
+ opacity: 0;
208
+ color: #fff;
209
+ font-size: 16px;
210
+ font-family: cursive;
211
+ user-select: none;
212
+ cursor: default;
213
+ pointer-events: none;
214
+ transform: rotate(-5deg);
215
+ transition: top 0.3s ease-in-out, opacity 0.3s ease-in-out, transform 0.3s ease-in-out;
216
+ }
217
+
218
+ .sample {
219
+ display: inline-block;
220
+ margin-top: 25px;
221
+ padding: 10px 100px;
222
+ background-color: rgba(255, 255, 255, 0.2);
223
+ color: #c6e2ff;
224
+ border: 2px solid rgba(255, 255, 255, 0.2);
225
+ border-radius: 8px;
226
+ box-shadow: 0 0 10px rgba(255, 255, 255, 0.2), inset 0 0 25px rgba(255, 255, 255, 0.2);
227
+ }
228
+
229
+ .info.showed {
230
+ opacity: 1;
231
+ pointer-events: auto;
232
+ }
233
+
234
+ .info:hover + .popup {
235
+ top: 35px;
236
+ opacity: 1;
237
+ pointer-events: initial;
238
+ transform: rotate(0deg);
239
+ }
240
+
241
+
242
+ /* Animation of elements */
243
+
244
+ .container,
245
+ .button_save {
246
+ animation-name: showedWidgets;
247
+ animation-duration: 1s;
248
+ }
249
+
250
+ @keyframes showedWidgets {
251
+ 0% {
252
+ transform: translate3d(-65%, 15%, 0) scale(0) rotate(15deg);
253
+ filter: blur(25px) grayscale(1) brightness(0.3);
254
+ opacity: 0;
255
+ }
256
+ 100% {
257
+ transform: translate3d(0, 0, 0) scale(1) rotate(0deg);
258
+ filter: blur(0) grayscale(0) brightness(1);
259
+ opacity: 1;
260
+ }
261
+ }
262
+ </style>
263
+
264
+ <!-- TOGGLE 'CustomDL' SCRIPT -->
265
+ <script>
266
+ function toggleContainer() {
267
+ let downloadContainer = document.querySelector('.container_custom_downlad');
268
+ let info = document.querySelector('.info');
269
+
270
+ downloadContainer.classList.toggle('expanded');
271
+ info.classList.toggle('showed');
272
+ }
273
+ </script>
274
+ '''
275
+
276
+ display(HTML(CSS))
277
+ # ==================== CSS JS ====================
278
+
279
+
280
+ # ==================== WIDGETS ====================
281
+ # --- global widgets ---
282
+ style = {'description_width': 'initial'}
283
+ layout = widgets.Layout(min_width='1047px')
284
+
285
+ HR = widgets.HTML('<hr>')
286
+
287
+ # --- MODEL ---
288
+ model_header = widgets.HTML('<div class="header">Model Selection<div>')
289
+ model_options = ['none',
290
+ '1.Anime (by Xpuct) + INP',
291
+ '2.Cetus-Mix [Anime] [V4] + INP',
292
+ '3.Counterfeit [Anime] [V3] + INP',
293
+ '4.CuteColor [Anime] [V3]',
294
+ '5.Dark-Sushi-Mix [Anime]',
295
+ '6.Meina-Mix [Anime] [V11] + INP',
296
+ '7.Mix-Pro [Anime] [V4] + INP',
297
+ '8.BluMix [Anime] [V7]']
298
+ # ---
299
+ Model_widget = widgets.Dropdown(options=model_options, value='3.Counterfeit [Anime] [V3] + INP', description='Model:', style=style, layout=layout)
300
+ Model_Num_widget = widgets.Text(description='Model Number:', placeholder='Enter the model numbers to be downloaded using comma/space.', style=style, layout=layout)
301
+ Inpainting_Model_widget = widgets.Checkbox(value=False, description='Inpainting Models', style=style)
302
+
303
+ display(widgets.VBox([model_header, Model_widget, Model_Num_widget, Inpainting_Model_widget]).add_class("container"))
304
+
305
+ # --- VAE ---
306
+ vae_header = widgets.HTML('<div class="header" >VAE Selection</div>')
307
+ vae_options = ['none',
308
+ '1.Anime.vae',
309
+ '2.Anything.vae',
310
+ '3.Blessed2.vae',
311
+ '4.ClearVae.vae',
312
+ '5.WD.vae']
313
+ Vae_widget = widgets.Dropdown(options=vae_options, value='3.Blessed2.vae', description='Vae:', style=style, layout=layout)
314
+ Vae_Num_widget = widgets.Text(description='Vae number:', placeholder='Enter the vae numbers to be downloaded using comma/space.', style=style, layout=layout)
315
+
316
+ display(widgets.VBox([vae_header, Vae_widget, Vae_Num_widget]).add_class("container"))
317
+
318
+ # --- ADDITIONAL ---
319
+ additional_header = widgets.HTML('<div class="header">Additional</div>')
320
+ latest_webui_widget = widgets.Checkbox(value=True, description='Update WebUI', style=style)
321
+ latest_exstensions_widget = widgets.Checkbox(value=True, description='Update Extensions', style=style)
322
+ detailed_download_widget = widgets.Dropdown(options=['off', 'on'], value='off', description='Detailed Download:', style=style)
323
+ latest_changes_widget = HBox([latest_webui_widget, latest_exstensions_widget, detailed_download_widget], layout=widgets.Layout(justify_content='space-between'))
324
+ controlnet_options = ['none', 'ALL', '1.canny',
325
+ '2.openpose', '3.depth',
326
+ '4.normal_map', '5.mlsd',
327
+ '6.lineart', '7.soft_edge',
328
+ '8.scribble', '9.segmentation',
329
+ '10.shuffle', '11.tile',
330
+ '12.inpaint', '13.instruct_p2p']
331
+ # ---
332
+ controlnet_widget = widgets.Dropdown(options=controlnet_options, value='none', description='ControlNet:', style=style, layout=layout)
333
+ controlnet_Num_widget = widgets.Text(description='ControlNet Number:', placeholder='Enter the ControlNet model numbers to be downloaded using comma/space.', style=style, layout=layout)
334
+ commit_hash_widget = widgets.Text(description='Commit Hash:', style=style, layout=layout)
335
+ optional_huggingface_token_widget = widgets.Text(description='Huggingface token:', style=style, layout=layout)
336
+ ngrok_token_widget = widgets.Text(description='Ngrok token:', style=style, layout=widgets.Layout(width='1047px'))
337
+ ngrock_button = widgets.HTML('<a href="https://dashboard.ngrok.com/get-started/your-authtoken" target="_blank">Get Ngrok Token</a>').add_class("button_ngrok")
338
+ ngrok_widget = widgets.HBox([ngrok_token_widget, ngrock_button], style=style, layout=layout)
339
+ # ---
340
+ commandline_arguments_options = "--listen --enable-insecure-extension-access --theme dark --no-half-vae --disable-console-progressbars --xformers"
341
+ commandline_arguments_widget = widgets.Text(description='Arguments:', value=commandline_arguments_options, style=style, layout=layout)
342
+
343
+ display(widgets.VBox([
344
+ additional_header, latest_changes_widget, HR, controlnet_widget, controlnet_Num_widget, commit_hash_widget, optional_huggingface_token_widget, ngrok_widget, HR, commandline_arguments_widget
345
+ ]).add_class("container"))
346
+
347
+ # --- CUSTOM DOWNLOAD ---
348
+ custom_download_header_popup = widgets.HTML('''
349
+ <style>
350
+ /* Term Colors */
351
+ .sample_label {color: #dbafff;}
352
+ .braces {color: #ffff00;}
353
+ .extension {color: #eb934b;}
354
+ .file_name {color: #ffffd8;}
355
+ </style>
356
+
357
+ <div class="header" style="cursor: pointer;" onclick="toggleContainer()">Custom Download</div>
358
+ <!-- PopUp Window -->
359
+ <div class="info">FAQ?</div>
360
+ <div class="popup">
361
+ Separate multiple URLs with a comma/space. For a <span class="file_name">custom name</span> file/extension, specify it with <span class="braces">[]</span>
362
+ after the URL without spaces.
363
+ <span style="color: #ff9999">For files, be sure to specify</span> - <span class="extension">Filename Extension.</span>
364
+ <div class="sample">
365
+ <span class="sample_label">Example for File:</span>
366
+ https://civitai.com/api/download/models/229782<span class="braces">[</span><span class="file_name">Detailer</span><span class="extension">.safetensors</span><span class="braces">]</span>
367
+ <br>
368
+ <span class="sample_label">Example for Extension:</span>
369
+ https://github.com/hako-mikan/sd-webui-regional-prompter<span class="braces">[</span><span class="file_name">Regional-Prompter</span><span class="braces">]</span>
370
+ </div>
371
+ </div>
372
+ ''')
373
+ # ---
374
+ Model_url_widget = widgets.Text(description='Model:', style=style, layout=layout)
375
+ Vae_url_widget = widgets.Text(description='Vae:', style=style, layout=layout)
376
+ LoRA_url_widget = widgets.Text(description='LoRa:', style=style, layout=layout)
377
+ Embedding_url_widget = widgets.Text(description='Embedding:', style=style, layout=layout)
378
+ Extensions_url_widget = widgets.Text(description='Extensions:', style=style, layout=layout)
379
+ custom_file_urls_widget = widgets.Text(description='File (txt):', style=style, layout=layout)
380
+
381
+ display(widgets.VBox([
382
+ custom_download_header_popup, Model_url_widget, Vae_url_widget, LoRA_url_widget, Embedding_url_widget, Extensions_url_widget, custom_file_urls_widget
383
+ ]).add_class("container").add_class("container_custom_downlad"))
384
+
385
+ # --- Save Button ---
386
+ save_button = widgets.Button(description='Save').add_class("button_save")
387
+ display(save_button)
388
+
389
+
390
+ # ============ Load / Save - Settings V2 ============
391
+ SETTINGS_FILE = f'{root_path}/settings.json'
392
+
393
+ settings_keys = [
394
+ 'Model', 'Model_Num', 'Inpainting_Model',
395
+ 'Vae', 'Vae_Num',
396
+ 'latest_webui', 'latest_exstensions', 'detailed_download',
397
+ 'controlnet', 'controlnet_Num', 'commit_hash', 'optional_huggingface_token',
398
+ 'ngrok_token', 'commandline_arguments',
399
+ 'Model_url', 'Vae_url', 'LoRA_url', 'Embedding_url', 'Extensions_url', 'custom_file_urls'
400
+ ]
401
+
402
+ def save_settings():
403
+ settings = {key: globals()[f"{key}_widget"].value for key in settings_keys}
404
+ with open(SETTINGS_FILE, 'w') as f:
405
+ json.dump(settings, f)
406
+
407
+ def load_settings():
408
+ if os.path.exists(SETTINGS_FILE):
409
+ with open(SETTINGS_FILE, 'r') as f:
410
+ settings = json.load(f)
411
+ for key in settings_keys:
412
+ globals()[f"{key}_widget"].value = settings.get(key)
413
+
414
+ def save_data(button):
415
+ save_settings()
416
+ widgets.Widget.close_all()
417
+
418
+ settings = load_settings()
419
+ save_button.on_click(save_data)
420
+
files_cells/python/ru/auto-cleaner_ru.py ADDED
@@ -0,0 +1,351 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ##~ AutoCleaner V3.6 CODE | BY: ANXETY ~##
2
+
3
+ # --change log--
4
+ """
5
+ V3.6 | 13.03.24
6
+ Fixed selection window
7
+ Dynamic update of memory display
8
+ """
9
+
10
+
11
+ import os
12
+ import time
13
+ import ipywidgets as widgets
14
+ from ipywidgets import Label, Button, VBox, HBox
15
+ from IPython.display import display, HTML
16
+
17
+
18
+ # ================= DETECT ENV =================
19
+ def detect_environment():
20
+ environments = {
21
+ 'COLAB_GPU': ('Google Colab', "/content"),
22
+ 'KAGGLE_URL_BASE': ('Kaggle', "/kaggle/working/content"),
23
+ 'SAGEMAKER_INTERNAL_IMAGE_URI': ('SageMaker Studio Lab', "/home/studio-lab-user/content")
24
+ }
25
+
26
+ for env_var, (environment, path) in environments.items():
27
+ if env_var in os.environ:
28
+ return environment, path
29
+
30
+ env, root_path = detect_environment()
31
+ webui_path = f"{root_path}/sdw"
32
+ # ----------------------------------------------
33
+
34
+
35
+ directories = {
36
+ "Изображения": f"{webui_path}/outputs",
37
+ "Модели": f"{webui_path}/models/Stable-diffusion/",
38
+ "Vae": f"{webui_path}/models/VAE/",
39
+ "LoRa": f"{webui_path}/models/Lora/",
40
+ "ControlNet Модели": f"{webui_path}/models/ControlNet/"
41
+ }
42
+
43
+
44
+ # ==================== CSS ====================
45
+ CSS_AC = """
46
+ <style>
47
+ /* General Styles */
48
+
49
+ hr {
50
+ border-color: grey;
51
+ background-color: grey;
52
+ opacity: 0.25;
53
+ }
54
+
55
+ .instruction_AC {
56
+ font-family: cursive;
57
+ font-size: 18px;
58
+ color: grey;
59
+ user-select: none;
60
+ cursor: default;
61
+ }
62
+
63
+
64
+ /* Container style */
65
+
66
+ .container_AC {
67
+ position: relative;
68
+ background-color: #232323;
69
+ width: 800px;
70
+ height: auto;
71
+ padding: 15px;
72
+ border-radius: 15px;
73
+ box-shadow: 0 0 50px rgba(0, 0, 0, 0.3);
74
+ margin-bottom: 5px;
75
+ overflow: visible;
76
+ }
77
+
78
+ .container_AC::before {
79
+ position: absolute;
80
+ top: 5px;
81
+ right: 10px;
82
+ content: "AutoCleanerV3.6";
83
+ font-weight: bold;
84
+ font-size: 24px;
85
+ color: rgba(0, 0, 0, 0.2);
86
+ }
87
+
88
+ .container_AC::after {
89
+ position: absolute;
90
+ top: 30px;
91
+ right: 10px;
92
+ content: "ANXETY";
93
+ font-weight: bold;
94
+ font-size: 18px;
95
+ color: rgba(0, 0, 0, 0.2);
96
+ }
97
+
98
+ .custom-select-multiple_AC select {
99
+ padding: 10px;
100
+ font-family: cursive;
101
+ border: 1px solid #262626 !important;
102
+ border-radius: 10px;
103
+ color: white;
104
+ background-color: #1c1c1c;
105
+ box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);
106
+ }
107
+
108
+ .output_AC {
109
+ padding: 10px;
110
+ height: auto;
111
+ border: 1px solid #262626;
112
+ border-radius: 10px;
113
+ background-color: #1c1c1c;
114
+ box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);
115
+ width: auto;
116
+ box-sizing: border-box;
117
+ }
118
+
119
+ .output_message_AC {
120
+ font-family: cursive;
121
+ color: white !important;
122
+ font-size: 14px;
123
+ user-select: none;
124
+ cursor: default
125
+ }
126
+
127
+
128
+ .storage_info_AC {
129
+ padding: 5px 20px;
130
+ height: auto;
131
+ border: 1px solid #262626;
132
+ border-radius: 10px;
133
+ background-color: #1c1c1c;
134
+ box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);
135
+ width: auto;
136
+ font-family: cursive;
137
+ color: #B2B2B2 !important;
138
+ font-size: 14px;
139
+ user-select: none;
140
+ cursor: default
141
+ }
142
+
143
+
144
+ /* Button and storage info layout */
145
+ .lower_information_panel_AC {
146
+ display: flex;
147
+ align-items: center;
148
+ justify-content: space-between;
149
+ }
150
+
151
+
152
+ /* Button style */
153
+
154
+ .button_AC {
155
+ width: auto;
156
+ font-family: cursive;
157
+ color: white !important;
158
+ font-size: 14px;
159
+ font-weight: bold;
160
+ height: 35px;
161
+ border-radius: 15px;
162
+ background-image: radial-gradient(circle at top left, purple 10%, violet 90%);
163
+ background-size: 200% 200%;
164
+ background-position: left bottom;
165
+ transition: background 0.5s ease-in-out, transform 0.3s ease;
166
+ }
167
+
168
+ .button_AC:hover {
169
+ cursor: pointer;
170
+ background-size: 200% 200%;
171
+ background-position: right bottom;
172
+ transform: translateY(1px);
173
+ }
174
+
175
+ .button_execute_AC:hover {
176
+ background-image: radial-gradient(circle at top left, purple 10%, #93ac47 90%);
177
+ }
178
+
179
+ .button_clear_AC:hover {
180
+ background-image: radial-gradient(circle at top left, purple 10%, #fc3468 90%);
181
+ }
182
+
183
+ .button_execute_AC:active,
184
+ .button_clear_AC:active {
185
+ filter: brightness(0.75);
186
+ }
187
+
188
+ .jupyter-widgets.lm-Widget:focus {
189
+ outline: none;
190
+ }
191
+
192
+
193
+ /* Animation of elements */
194
+
195
+ /* Emergence */
196
+ .container_AC {
197
+ animation-name: slideInTopBlur;
198
+ animation-duration: 0.7s;
199
+ animation-fill-mode: forwards;
200
+ }
201
+
202
+ @keyframes slideInTopBlur {
203
+ 0% {
204
+ transform: translate3d(0, 50%, 0) scale(0.85) rotate3d(1, 0, 0, -85deg);
205
+ filter: blur(5px) grayscale(1) brightness(0.5);
206
+ opacity: 0;
207
+ }
208
+ 100% {
209
+ transform: translate3d(0, 0, 0) scale(1) rotate3d(1, 0, 0, 0deg);
210
+ filter: blur(0) grayscale(0) brightness(1);
211
+ opacity: 1;
212
+ }
213
+ }
214
+
215
+ /* Leaving */
216
+ .container_AC.hide {
217
+ animation-name: slideOutTopBlur;
218
+ animation-duration: 0.3s;
219
+ animation-fill-mode: forwards;
220
+ }
221
+
222
+ @keyframes slideOutTopBlur {
223
+ 0% {
224
+ transform: translate3d(0, 0, 0) scale(1);
225
+ filter: blur(0) grayscale(0) brightness(1);
226
+ opacity: 1;
227
+ }
228
+ 100% {
229
+ transform: translate3d(0, -100%, 0);
230
+ filter: blur(5px) grayscale(1) brightness(0);
231
+ opacity: 0;
232
+ }
233
+ }
234
+ </style>
235
+ """
236
+
237
+ display(HTML(CSS_AC))
238
+ # ==================== CSS ====================
239
+
240
+
241
+ # ================ AutoCleaner function ================
242
+ def clean_directory(directory):
243
+ deleted_files = 0
244
+ for root, dirs, files in os.walk(directory):
245
+ for file in files:
246
+ if file.endswith((".txt", ".yaml")):
247
+ continue
248
+ os.remove(os.path.join(root, file))
249
+ deleted_files += 1
250
+ return deleted_files
251
+
252
+
253
+ def get_word_variant(n, variants):
254
+ unit = abs(n) % 10
255
+ tens = abs(n) % 100
256
+ if tens in range(11, 15):
257
+ return variants[2]
258
+ elif unit == 1:
259
+ return variants[0]
260
+ elif unit in range(2, 5):
261
+ return variants[1]
262
+ else:
263
+ return variants[2]
264
+
265
+
266
+ def update_memory_info():
267
+ disk_space = psutil.disk_usage(os.getcwd())
268
+ total = disk_space.total / (1024 ** 3)
269
+ used = disk_space.used / (1024 ** 3)
270
+ free = disk_space.free / (1024 ** 3)
271
+
272
+ storage_info.value = f'''
273
+ <div class="storage_info_AC">Всего: {total:.2f} GB <span style="color: #555">|</span> Используется: {used:.2f} GB <span style="color: #555">|</span> Свободно: {free:.2f} GB</div>
274
+ '''
275
+
276
+
277
+ def on_execute_button_press(button):
278
+ selected_cleaners = auto_cleaner_widget.value
279
+ deleted_files_dict = {}
280
+
281
+ for option in selected_cleaners:
282
+ if option in directories:
283
+ deleted_files_dict[option] = clean_directory(directories[option])
284
+
285
+ output.clear_output()
286
+
287
+ with output:
288
+ for message in generate_messages(deleted_files_dict):
289
+ message_widget = HTML(f'<p class="output_message_AC">{message}</p>')
290
+ display(message_widget)
291
+
292
+ update_memory_info()
293
+
294
+
295
+ def on_clear_button_press(button):
296
+ container.add_class("hide")
297
+ time.sleep(0.5)
298
+ widgets.Widget.close_all()
299
+
300
+
301
+ def generate_messages(deleted_files_dict):
302
+ messages = []
303
+ word_variants = {
304
+ "Изображения": ["Изображение", "Изображения", "Изображений"],
305
+ "Модели": ["Модель", "Модели", "Моделей"],
306
+ "Vae": ["VAE", "VAE", "VAE"],
307
+ "LoRa": ["LoRa", "LoRa", "LoRa"],
308
+ "ControlNet Модели": ["ControlNet Модель", "ControlNet Модели", "ControlNet Моделей"]
309
+ }
310
+ deleted_word_variants = ["Удалена", "Удалены", "Удалено"]
311
+ for key, value in deleted_files_dict.items():
312
+ word_variant = word_variants.get(key, ["", "", ""])
313
+ deleted_word = get_word_variant(value, deleted_word_variants)
314
+ object_word = get_word_variant(value, word_variant)
315
+ messages.append(f"{deleted_word} {value} {object_word}")
316
+ return messages
317
+ # ================ AutoCleaner function ================
318
+
319
+
320
+ # --- storage memory ---
321
+ import psutil
322
+ disk_space = psutil.disk_usage(os.getcwd())
323
+ total = disk_space.total / (1024 ** 3)
324
+ used = disk_space.used / (1024 ** 3)
325
+ free = disk_space.free / (1024 ** 3)
326
+
327
+
328
+ # UI Code
329
+ AutoCleaner_options = AutoCleaner_options = list(directories.keys())
330
+ instruction_label = widgets.HTML('''
331
+ <span class="instruction_AC">Используйте <span style="color: #B2B2B2;">ctrl</span> или <span style="color: #B2B2B2;">shift</span> для множественного выбора.</span>
332
+ ''')
333
+ auto_cleaner_widget = widgets.SelectMultiple(options=AutoCleaner_options, layout=widgets.Layout(width="auto")).add_class("custom-select-multiple_AC")
334
+ output = widgets.Output().add_class("output_AC")
335
+ # ---
336
+ execute_button = Button(description='Выполнить Очистку').add_class("button_execute_AC").add_class("button_AC")
337
+ execute_button.on_click(on_execute_button_press)
338
+ clear_button = Button(description='Скрыть Виджет').add_class("button_clear_AC").add_class("button_AC")
339
+ clear_button.on_click(on_clear_button_press)
340
+ # ---
341
+ storage_info = widgets.HTML(f'''
342
+ <div class="storage_info_AC">Всего: {total:.2f} GB <span style="color: #555">|</span> Используется: {used:.2f} GB <span style="color: #555">|</span> Свободно: {free:.2f} GB</div>
343
+ ''')
344
+ # ---
345
+ buttons = widgets.HBox([execute_button, clear_button])
346
+ lower_information_panel = widgets.HBox([buttons, storage_info]).add_class("lower_information_panel_AC")
347
+
348
+ container = VBox([instruction_label, widgets.HTML('<hr>'), auto_cleaner_widget, output, widgets.HTML('<hr>'), lower_information_panel]).add_class("container_AC")
349
+
350
+ display(container)
351
+
files_cells/python/ru/downloading_ru.py ADDED
@@ -0,0 +1,556 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ##~ DOWNLOADING CODE | BY: ANXETY ~##
2
+
3
+ import os
4
+ import re
5
+ import time
6
+ import json
7
+ import requests
8
+ import subprocess
9
+ from datetime import timedelta
10
+ from subprocess import getoutput
11
+ from urllib.parse import unquote
12
+ from IPython.utils import capture
13
+ from IPython.display import clear_output
14
+
15
+
16
+ # ================= DETECT ENV =================
17
+ def check_colab_subscription():
18
+ return (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024. ** 3) <= 20)
19
+ free_plan = check_colab_subscription()
20
+
21
+ def detect_environment():
22
+ environments = {
23
+ 'COLAB_GPU': ('Google Colab', "/root" if free_plan else "/content"),
24
+ 'KAGGLE_URL_BASE': ('Kaggle', "/kaggle/working/content"),
25
+ 'SAGEMAKER_INTERNAL_IMAGE_URI': ('SageMaker Studio Lab', "/home/studio-lab-user/content")
26
+ }
27
+
28
+ for env_var, (environment, path) in environments.items():
29
+ if env_var in os.environ:
30
+ return environment, path
31
+
32
+ env, root_path = detect_environment()
33
+ webui_path = f"{root_path}/sdw"
34
+ # ----------------------------------------------
35
+
36
+
37
+ # === ONLY SAGEMAKER ===
38
+ if env == "SageMaker Studio Lab":
39
+ print("Обновление зависимостей, может занять некоторое время...")
40
+ get_ipython().system('pip install -q --upgrade torchsde')
41
+ get_ipython().system('pip install -q --upgrade pip')
42
+ get_ipython().system('pip install -q --upgrade psutil')
43
+
44
+ clear_output()
45
+
46
+
47
+ # ================ LIBRARIES ================
48
+ flag_file = f"{root_path}/libraries_installed.txt"
49
+
50
+ if not os.path.exists(flag_file):
51
+ # automatic1111 update webui to 1.8.0
52
+ xformers = "xformers==0.0.23.post1 triton==2.1.0"
53
+ torch = "torch==2.1.2+cu121 torchvision==0.16.2+cu121 --extra-index-url https://download.pytorch.org/whl/cu121"
54
+
55
+ print("Установка библиотек, это займет какое-то время...", end='')
56
+ with capture.capture_output() as cap:
57
+ get_ipython().system('apt-get update && apt -y install aria2')
58
+ get_ipython().system('npm install -g localtunnel &> /dev/null')
59
+ get_ipython().system('curl -s -OL https://github.com/DEX-1101/sd-webui-notebook/raw/main/res/new_tunnel --output-dir {root_path}')
60
+ get_ipython().system('curl -s -Lo /usr/bin/cl https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 && chmod +x /usr/bin/cl')
61
+ get_ipython().system('pip install insightface')
62
+
63
+ if env == "SageMaker Studio Lab":
64
+ get_ipython().run_line_magic('pip', 'install -q opencv-python-headless huggingface-hub')
65
+ get_ipython().run_line_magic('conda', 'update -q -n base conda')
66
+ get_ipython().run_line_magic('conda', 'install -q -y aria2')
67
+ get_ipython().run_line_magic('conda', 'install -q -y glib')
68
+ get_ipython().system('pip install tensorflow')
69
+
70
+ get_ipython().system('wget -P /home/studio-lab-user https://huggingface.co/NagisaNao/fast_repo/resolve/main/sagemaker/FULL_DELETED_NOTEBOOK.ipynb')
71
+
72
+ if env == "Google Colab":
73
+ get_ipython().system('pip install -q {xformers} -U')
74
+ else:
75
+ get_ipython().system('pip install -q {torch} -U')
76
+ get_ipython().system('pip install -q {xformers} -U')
77
+
78
+ with open(flag_file, "w") as f:
79
+ f.write("hey ;3")
80
+ del cap
81
+ print("\rБиблиотеки установлены!" + " "*35)
82
+ time.sleep(2)
83
+ clear_output()
84
+
85
+
86
+ # ================= loading settings V4 =================
87
+ def load_settings(path):
88
+ if os.path.exists(path):
89
+ with open(path, 'r') as file:
90
+ return json.load(file)
91
+ return {}
92
+
93
+ settings = load_settings(f'{root_path}/settings.json')
94
+
95
+ variables = [
96
+ 'Model', 'Model_Num', 'Inpainting_Model',
97
+ 'Vae', 'Vae_Num',
98
+ 'latest_webui', 'latest_exstensions', 'detailed_download',
99
+ 'controlnet', 'controlnet_Num', 'commit_hash', 'optional_huggingface_token',
100
+ 'ngrok_token' 'commandline_arguments',
101
+ 'Model_url', 'Vae_url', 'LoRA_url', 'Embedding_url', 'Extensions_url', 'custom_file_urls'
102
+ ]
103
+
104
+ locals().update({key: settings.get(key) for key in variables})
105
+
106
+
107
+ # ================= OTHER =================
108
+ try:
109
+ start_colab
110
+ except:
111
+ start_colab = int(time.time())-5
112
+
113
+ # CONFIG DIR
114
+ models_dir = f"{webui_path}/models/Stable-diffusion"
115
+ vaes_dir = f"{webui_path}/models/VAE"
116
+ embeddings_dir = f"{webui_path}/embeddings"
117
+ loras_dir = f"{webui_path}/models/Lora"
118
+ extensions_dir = f"{webui_path}/extensions"
119
+ control_dir = f"{webui_path}/models/ControlNet"
120
+
121
+
122
+ # ================= MAIN CODE =================
123
+ # --- Obsolescence warning ---
124
+ if env == "SageMaker Studio Lab":
125
+ print("Вы используете среду 'SageMaker' - эта среда устарела, поэтому многие ошибки не будут исправлены, а ее функциональность будет урезана. Для экономии памяти и/или во избежание ошибок.\n\n")
126
+
127
+
128
+ if not os.path.exists(webui_path):
129
+ start_install = int(time.time())
130
+ print("⌚ Распоковка Stable Diffusion...", end='')
131
+ with capture.capture_output() as cap:
132
+ get_ipython().system('aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/NagisaNao/fast_repo/resolve/main/FULL_REPO.zip -o repo.zip')
133
+ get_ipython().system('unzip -q -o repo.zip -d {webui_path}')
134
+ get_ipython().system('rm -rf repo.zip')
135
+
136
+ get_ipython().run_line_magic('cd', '{root_path}')
137
+ os.environ["SAFETENSORS_FAST_GPU"]='1'
138
+ os.environ["CUDA_MODULE_LOADING"]="LAZY"
139
+ os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
140
+ os.environ["PYTHONWARNINGS"] = "ignore"
141
+
142
+ get_ipython().system('echo -n {start_colab} > {webui_path}/static/colabTimer.txt')
143
+ del cap
144
+ install_time = timedelta(seconds=time.time()-start_install)
145
+ print("\r🚀 Распаковка Завершена! За","%02d:%02d:%02d ⚡\n" % (install_time.seconds / 3600, (install_time.seconds / 60) % 60, install_time.seconds % 60), end='', flush=True)
146
+ else:
147
+ get_ipython().system('echo -n {start_colab} > {webui_path}/static/colabTimer.txt')
148
+ print("🚀 Все распакованно... Пропуск. ⚡")
149
+ start_colab = float(open(f'{webui_path}/static/colabTimer.txt', 'r').read())
150
+ time_since_start = str(timedelta(seconds=time.time()-start_colab)).split('.')[0]
151
+ print(f"⌚️ Вы проводите эту сессию в течение - \033[33m{time_since_start}\033[0m")
152
+
153
+
154
+ ## Changes extensions and WebUi
155
+ if latest_webui or latest_exstensions:
156
+ action = "Обновление WebUI и Расширений" if latest_webui and latest_exstensions else ("Обновление WebUI" if latest_webui else "Обновление Расширений")
157
+ print(f"⌚️ {action}...", end='', flush=True)
158
+ with capture.capture_output() as cap:
159
+ get_ipython().system('git config --global user.email "[email protected]"')
160
+ get_ipython().system('git config --global user.name "Your Name"')
161
+
162
+ ## Update Webui
163
+ if latest_webui:
164
+ get_ipython().run_line_magic('cd', '{webui_path}')
165
+ get_ipython().system('git restore .')
166
+ get_ipython().system('git pull -X theirs --rebase --autostash')
167
+
168
+ ## Update extensions
169
+ if latest_exstensions:
170
+ if env != "SageMaker Studio Lab":
171
+ get_ipython().system('{\'for dir in \' + webui_path + \'/extensions/*/; do cd \\"$dir\\" && git reset --hard && git pull; done\'}')
172
+ else:
173
+ get_ipython().system('{\'for dir in /home/studio-lab-user/content/sdw/extensions/*/; do cd \\"$dir\\" && git fetch origin && git pull; done\'}')
174
+
175
+ get_ipython().system('cd {webui_path}/repositories/stable-diffusion-stability-ai && git restore .')
176
+ del cap
177
+ print(f"\r✨ {action} Завершено!")
178
+
179
+
180
+ # === FIXING ERRORS ===
181
+ # --- All ---
182
+ # --- Encrypt-Image ---
183
+ get_ipython().system("sed -i '9,37d' {webui_path}/extensions/Encrypt-Image/javascript/encrypt_images_info.js")
184
+ if env = "Google Colab":
185
+ if os.path.exists(f"{webui_path}/extensions/Encrypt-Image"):
186
+ get_ipython().system('rm -rf {webui_path}/extensions/Encrypt-Image')
187
+
188
+ # --- SageMaker ---
189
+ if env == "SageMaker Studio Lab":
190
+ with capture.capture_output() as cap:
191
+ # --- SuperMerger Remove ---
192
+ if os.path.exists(f"{webui_path}/extensions/supermerger"):
193
+ get_ipython().system('rm -rf {webui_path}/extensions/supermerger')
194
+ # --- Launch (Style) ---
195
+ get_ipython().system('wget -O {webui_path}/modules/styles.py https://huggingface.co/NagisaNao/fast_repo/resolve/main/sagemaker/fixing/webui/styles.py')
196
+ del cap
197
+
198
+
199
+ ## Version switching
200
+ if commit_hash:
201
+ print('⏳ Активация машины времени...', end="", flush=True)
202
+ with capture.capture_output() as cap:
203
+ get_ipython().run_line_magic('cd', '{webui_path}')
204
+ get_ipython().system('git config --global user.email "[email protected]"')
205
+ get_ipython().system('git config --global user.name "Your Name"')
206
+ get_ipython().system('git reset --hard {commit_hash}')
207
+ del cap
208
+ print(f"\r⌛️ Машина времени активированна! Текущий коммит: \033[34m{commit_hash}\033[0m")
209
+
210
+
211
+ ## Downloading model and stuff | oh yeah~ I'm starting to misunderstand my own code ( almost my own ;3 )
212
+ print("📦 Скачивание моделей и прочего...", end='')
213
+ model_list = {
214
+ "1.Anime (by Xpuct) + INP": [
215
+ {"url": "https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2.safetensors", "name": "Anime_v2.safetensors"},
216
+ {"url": "https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2-inpainting.safetensors", "name": "Anime_v2-inpainting.safetensors"}
217
+ ],
218
+ "2.Cetus-Mix [Anime] [V4] + INP": [
219
+ {"url": "https://civitai.com/api/download/models/130298", "name": "CetusMix_V4.safetensors"},
220
+ {"url": "https://civitai.com/api/download/models/139882", "name": "CetusMix_V4-inpainting.safetensors"}
221
+ ],
222
+ "3.Counterfeit [Anime] [V3] + INP": [
223
+ {"url": "https://civitai.com/api/download/models/125050", "name": "Counterfeit_V3.safetensors"},
224
+ {"url": "https://civitai.com/api/download/models/137911", "name": "Counterfeit_V3-inpainting.safetensors"}
225
+ ],
226
+ "4.CuteColor [Anime] [V3]": [
227
+ {"url": "https://civitai.com/api/download/models/138754", "name": "CuteColor_V3.safetensors"}
228
+ ],
229
+ "5.Dark-Sushi-Mix [Anime]": [
230
+ {"url": "https://civitai.com/api/download/models/101640", "name": "DarkSushiMix_2_5D.safetensors"},
231
+ {"url": "https://civitai.com/api/download/models/56071", "name": "DarkSushiMix_colorful.safetensors"}
232
+ ],
233
+ "6.Meina-Mix [Anime] [V11] + INP": [
234
+ {"url": "https://civitai.com/api/download/models/119057", "name": "MeinaMix_V11.safetensors"},
235
+ {"url": "https://civitai.com/api/download/models/120702", "name": "MeinaMix_V11-inpainting.safetensors"}
236
+ ],
237
+ "7.Mix-Pro [Anime] [V4] + INP": [
238
+ {"url": "https://civitai.com/api/download/models/125668", "name": "MixPro_V4.safetensors"},
239
+ {"url": "https://civitai.com/api/download/models/139878", "name": "MixPro_V4-inpainting.safetensors"}
240
+ ],
241
+ "8.BluMix [Anime] [V7]": [
242
+ {"url": "https://civitai.com/api/download/models/361779", "name": "BluMix_v7.safetensors"}
243
+ ]
244
+ }
245
+
246
+ # 1-4 (fp16/cleaned)
247
+ vae_list = {
248
+ "1.Anime.vae": [
249
+ {"url": "https://civitai.com/api/download/models/131654", "name": "Anime.vae.safetensors"},
250
+ {"url": "https://civitai.com/api/download/models/131658", "name": "vae-ft-mse.vae.safetensors"}
251
+ ],
252
+ "2.Anything.vae": [{"url": "https://civitai.com/api/download/models/131656", "name": "Anything.vae.safetensors"}],
253
+ "3.Blessed2.vae": [{"url": "https://civitai.com/api/download/models/142467", "name": "Blessed2.vae.safetensors"}],
254
+ "4.ClearVae.vae": [{"url": "https://civitai.com/api/download/models/133362", "name": "ClearVae_23.vae.safetensors"}],
255
+ "5.WD.vae": [{"url": "https://huggingface.co/NoCrypt/resources/resolve/main/VAE/wd.vae.safetensors", "name": "WD.vae.safetensors"}]
256
+ }
257
+
258
+ controlnet_list = {
259
+ "1.canny": [
260
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny_fp16.safetensors", "name": "control_v11p_sd15_canny_fp16.safetensors"},
261
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_canny_fp16.yaml", "name": "control_v11p_sd15_canny_fp16.yaml"}
262
+ ],
263
+ "2.openpose": [
264
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose_fp16.safetensors", "name": "control_v11p_sd15_openpose_fp16.safetensors"},
265
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_openpose_fp16.yaml", "name": "control_v11p_sd15_openpose_fp16.yaml"}
266
+ ],
267
+ "3.depth": [
268
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth_fp16.safetensors", "name": "control_v11f1p_sd15_depth_fp16.safetensors"},
269
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1p_sd15_depth_fp16.yaml", "name": "control_v11f1p_sd15_depth_fp16.yaml"},
270
+ {"url": "https://huggingface.co/NagisaNao/models/resolve/main/ControlNet_v11/control_v11p_sd15_depth_anything_fp16.safetensors", "name": "control_v11p_sd15_depth_anything_fp16.safetensors"}
271
+ ],
272
+ "4.normal_map": [
273
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_normalbae_fp16.safetensors", "name": "control_v11p_sd15_normalbae_fp16.safetensors"},
274
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_normalbae_fp16.yaml", "name": "control_v11p_sd15_normalbae_fp16.yaml"}
275
+ ],
276
+ "5.mlsd": [
277
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_mlsd_fp16.safetensors", "name": "control_v11p_sd15_mlsd_fp16.safetensors"},
278
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_mlsd_fp16.yaml", "name": "control_v11p_sd15_mlsd_fp16.yaml"}
279
+ ],
280
+ "6.lineart": [
281
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart_fp16.safetensors", "name": "control_v11p_sd15_lineart_fp16.safetensors"},
282
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15s2_lineart_anime_fp16.safetensors", "name": "control_v11p_sd15s2_lineart_anime_fp16.safetensors"},
283
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_lineart_fp16.yaml", "name": "control_v11p_sd15_lineart_fp16.yaml"},
284
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15s2_lineart_anime_fp16.yaml", "name": "control_v11p_sd15s2_lineart_anime_fp16.yaml"}
285
+ ],
286
+ "7.soft_edge": [
287
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge_fp16.safetensors", "name": "control_v11p_sd15_softedge_fp16.safetensors"},
288
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_softedge_fp16.yaml", "name": "control_v11p_sd15_softedge_fp16.yaml"}
289
+ ],
290
+ "8.scribble": [
291
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble_fp16.safetensors", "name": "control_v11p_sd15_scribble_fp16.safetensors"},
292
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_scribble_fp16.yaml", "name": "control_v11p_sd15_scribble_fp16.yaml"}
293
+ ],
294
+ "9.segmentation": [
295
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg_fp16.safetensors", "name": "control_v11p_sd15_seg_fp16.safetensors"},
296
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_seg_fp16.yaml", "name": "control_v11p_sd15_seg_fp16.yaml"}
297
+ ],
298
+ "10.shuffle": [
299
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle_fp16.safetensors", "name": "control_v11e_sd15_shuffle_fp16.safetensors"},
300
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_shuffle_fp16.yaml", "name": "control_v11e_sd15_shuffle_fp16.yaml"}
301
+ ],
302
+ "11.tile": [
303
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile_fp16.safetensors", "name": "control_v11f1e_sd15_tile_fp16.safetensors"},
304
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1e_sd15_tile_fp16.yaml", "name": "control_v11f1e_sd15_tile_fp16.yaml"}
305
+ ],
306
+ "12.inpaint": [
307
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_inpaint_fp16.safetensors", "name": "control_v11p_sd15_inpaint_fp16.safetensors"},
308
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_inpaint_fp16.yaml", "name": "control_v11p_sd15_inpaint_fp16.yaml"}
309
+ ],
310
+ "13.instruct_p2p": [
311
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p_fp16.safetensors", "name": "control_v11e_sd15_ip2p_fp16.safetensors"},
312
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_ip2p_fp16.yaml", "name": "control_v11e_sd15_ip2p_fp16.yaml"}
313
+ ]
314
+ }
315
+
316
+ extension_repo = []
317
+ prefixes = [
318
+ "model:",
319
+ "vae:",
320
+ "lora:",
321
+ "embeddings:",
322
+ "extensions:"
323
+ ]
324
+
325
+ get_ipython().system('mkdir -p {models_dir} {vaes_dir} {embeddings_dir} {loras_dir} {control_dir}')
326
+
327
+ url = ""
328
+ hf_token = optional_huggingface_token if optional_huggingface_token else "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"
329
+ user_header = f"\"Authorization: Bearer {hf_token}\""
330
+
331
+ def handle_manual(url):
332
+ original_url = url
333
+ url = url.split(':', 1)[1]
334
+ file_name = re.search(r'\[(.*?)\]', url)
335
+ file_name = file_name.group(1) if file_name else None
336
+ if file_name:
337
+ url = re.sub(r'\[.*?\]', '', url)
338
+
339
+ dir_mapping = {"model": models_dir, "vae": vaes_dir, "lora": loras_dir, "embeddings": embeddings_dir, "extensions": None}
340
+
341
+ for prefix, dir in dir_mapping.items():
342
+ if original_url.startswith(f"{prefix}:"):
343
+ if prefix != "extensions":
344
+ manual_download(url, dir, file_name=file_name)
345
+ else:
346
+ extension_repo.append((url, file_name))
347
+
348
+ def manual_download(url, dst_dir, file_name):
349
+ basename = url.split("/")[-1] if file_name is None else file_name
350
+
351
+ # I do it at my own risk..... Fucking CivitAi >:(
352
+ civitai_token = "62c0c5956b2f9defbd844d754000180b"
353
+ if 'civitai' in url and civitai_token:
354
+ url = f"{url}?token={civitai_token}"
355
+
356
+ # -- GDrive --
357
+ if 'drive.google' in url:
358
+ if 'folders' in url:
359
+ get_ipython().system('gdown --folder "{url}" -O {dst_dir} --fuzzy -c')
360
+ else:
361
+ get_ipython().system('gdown "{url}" -O {dst_dir} --fuzzy -c')
362
+ # -- Huggin Face --
363
+ elif 'huggingface' in url:
364
+ if '/blob/' in url:
365
+ url = url.replace('/blob/', '/resolve/')
366
+ if file_name:
367
+ get_ipython().system('aria2c --optimize-concurrent-downloads --console-log-level=error --summary-interval=10 --header={user_header} -c -j5 -x16 -s16 -k1M -d {dst_dir} -o {basename} {url}')
368
+ else:
369
+ parsed_link = '\n{}\n\tout={}'.format(url, unquote(url.split('/')[-1]))
370
+ get_ipython().system('echo -e "{parsed_link}" | aria2c --header={user_header} --console-log-level=error --summary-interval=10 -i- -j5 -x16 -s16 -k1M -c -d "{dst_dir}" -o {basename}')
371
+ # -- Other --
372
+ elif 'http' in url or 'magnet' in url:
373
+ if file_name:
374
+ get_ipython().system('aria2c --optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c -d {dst_dir} -o {file_name} {url}')
375
+ else:
376
+ parsed_link = '"{}"'.format(url)
377
+ get_ipython().system('aria2c --optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c -d {dst_dir} -Z {parsed_link}')
378
+
379
+ def download(url):
380
+ links_and_paths = url.split(',')
381
+
382
+ for link_or_path in links_and_paths:
383
+ link_or_path = link_or_path.strip()
384
+ if not link_or_path:
385
+ continue
386
+
387
+ if any(link_or_path.startswith(prefix.lower()) for prefix in prefixes):
388
+ handle_manual(link_or_path)
389
+ continue
390
+
391
+ url, dst_dir, file_name = link_or_path.split()
392
+ manual_download(url, dst_dir, file_name)
393
+
394
+ submodels = []
395
+
396
+ def add_submodels(selection, num_selection, model_dict, dst_dir):
397
+ if selection == "none":
398
+ return []
399
+ if selection == "ALL":
400
+ all_models = []
401
+ for models in model_dict.values():
402
+ all_models.extend(models)
403
+ selected_models = all_models
404
+ else:
405
+ selected_models = model_dict[selection]
406
+ selected_nums = map(int, num_selection.replace(',', '').split())
407
+
408
+ for num in selected_nums:
409
+ if 1 <= num <= len(model_dict):
410
+ name = list(model_dict)[num - 1]
411
+ selected_models.extend(model_dict[name])
412
+
413
+ unique_models = list({model['name']: model for model in selected_models}.values())
414
+
415
+ for model in unique_models:
416
+ model['dst_dir'] = dst_dir
417
+
418
+ return unique_models
419
+
420
+ submodels += add_submodels(Model, Model_Num, model_list, models_dir) # model
421
+ submodels += add_submodels(Vae, Vae_Num, vae_list, vaes_dir) # vae
422
+ submodels += add_submodels(controlnet, "" if controlnet == "ALL" else controlnet_Num, controlnet_list, control_dir) # controlnet
423
+
424
+ for submodel in submodels:
425
+ if not Inpainting_Model and "inpainting" in submodel['name']:
426
+ continue
427
+
428
+ url += f"{submodel['url']} {submodel['dst_dir']} {submodel['name']}, "
429
+
430
+ def process_file_download(file_url):
431
+ global Model_url, Vae_url, LoRA_url, Embedding_url, Extensions_url
432
+ urls_dict = {
433
+ 'model': 'Model_url',
434
+ 'vae': 'Vae_url',
435
+ 'embed': 'Embedding_url',
436
+ 'lora': 'LoRA_url',
437
+ 'extension': 'Extensions_url'
438
+ }
439
+
440
+ if file_url.startswith("http"):
441
+ if "blob" in file_url:
442
+ file_url = file_url.replace("blob", "raw")
443
+ response = requests.get(file_url)
444
+ lines = response.text.split('\n')
445
+ else:
446
+ with open(file_url, 'r') as file:
447
+ lines = file.readlines()
448
+
449
+ current_tag = None
450
+ for line in lines:
451
+ if line.strip().startswith('#'):
452
+ current_tag = next((tag for tag in urls_dict if tag in line.lower()), None)
453
+ elif current_tag and line.strip():
454
+ urls = [url.strip() for url in line.split()]
455
+ for url in urls:
456
+ if url.startswith("http"):
457
+ globals()[urls_dict[current_tag]] += ", " + url
458
+
459
+ # fix all possible errors/options and function call
460
+ if custom_file_urls:
461
+ if not custom_file_urls.endswith('.txt'):
462
+ custom_file_urls += '.txt'
463
+ if not custom_file_urls.startswith('http'):
464
+ if not custom_file_urls.startswith(root_path):
465
+ custom_file_urls = f'{root_path}/{custom_file_urls}'
466
+ if custom_file_urls.count('/content') >= 2:
467
+ custom_file_urls = re.sub(r'(/content){2,}', '/content', custom_file_urls)
468
+
469
+ try:
470
+ process_file_download(custom_file_urls)
471
+ except FileNotFoundError:
472
+ pass
473
+
474
+ urls = [Model_url, Vae_url, LoRA_url, Embedding_url, Extensions_url]
475
+
476
+ for i, prefix in enumerate(prefixes):
477
+ if urls[i]:
478
+ prefixed_urls = [f"{prefix}{u}" for u in urls[i].replace(',', '').split()]
479
+ if prefixed_urls:
480
+ url += ", ".join(prefixed_urls) + ", "
481
+
482
+ if detailed_download == "on":
483
+ print("\n\n\033[33m# ====== Подробная Загрузка ====== #\n\033[0m")
484
+ download(url)
485
+ print("\n\033[33m# =============================== #\n\033[0m")
486
+ else:
487
+ with capture.capture_output() as cap:
488
+ download(url)
489
+ del cap
490
+
491
+ print("\r🏁 Скачивание Завершено!" + " "*15)
492
+
493
+
494
+ # Cleaning shit after downloading...
495
+ get_ipython().system('find \\( -name ".ipynb_checkpoints" -o -name ".aria2" \\) -type d -exec rm -r {} \\; >/dev/null 2>&1')
496
+
497
+
498
+ ## Install of Custom extensions
499
+ if len(extension_repo) > 0:
500
+ print("✨ Устанвока кастомных расширений...", end='', flush=True)
501
+ with capture.capture_output() as cap:
502
+ for repo, repo_name in extension_repo:
503
+ if not repo_name:
504
+ repo_name = repo.split('/')[-1]
505
+ get_ipython().system('cd {extensions_dir} && git clone {repo} {repo_name} && cd {repo_name} && git fetch')
506
+ del cap
507
+ print(f"\r📦 Установлено '{len(extension_repo)}', Кастомных расширений!")
508
+
509
+
510
+ ## List Models and stuff
511
+ if detailed_download == "off":
512
+ print("\n\n\033[33mЕсли вы не видете каких-то скаченных файлов, включит�� в виджетах функцию 'Подробная Загрузка'.")
513
+
514
+ if any(not file.endswith('.txt') for file in os.listdir(models_dir)):
515
+ print("\n\033[33m➤ Models\033[0m")
516
+ get_ipython().system("find {models_dir}/ -mindepth 1 ! -name '*.txt' -printf '%f\\n'")
517
+ if any(not file.endswith('.txt') for file in os.listdir(vaes_dir)):
518
+ print("\n\033[33m➤ VAEs\033[0m")
519
+ get_ipython().system("find {vaes_dir}/ -mindepth 1 ! -name '*.txt' -printf '%f\\n'")
520
+ if any(not file.endswith('.txt') and not os.path.isdir(os.path.join(embeddings_dir, file)) for file in os.listdir(embeddings_dir)):
521
+ print("\n\033[33m➤ Embeddings\033[0m")
522
+ get_ipython().system("find {embeddings_dir}/ -mindepth 1 -maxdepth 1 \\( -name '*.pt' -or -name '*.safetensors' \\) -printf '%f\\n'")
523
+ if any(not file.endswith('.txt') for file in os.listdir(loras_dir)):
524
+ print("\n\033[33m➤ LoRAs\033[0m")
525
+ get_ipython().system("find {loras_dir}/ -mindepth 1 ! -name '*.keep' -printf '%f\\n'")
526
+ print(f"\n\033[33m➤ Extensions\033[0m")
527
+ get_ipython().system("find {extensions_dir}/ -mindepth 1 -maxdepth 1 ! -name '*.txt' -printf '%f\\n'")
528
+ if any(not file.endswith(('.txt', '.yaml')) for file in os.listdir(control_dir)):
529
+ print("\n\033[33m➤ ControlNet\033[0m")
530
+ get_ipython().system("find {control_dir}/ -mindepth 1 ! -name '*.yaml' -printf '%f\\n' | sed 's/^[^_]*_[^_]*_[^_]*_\\(.*\\)_fp16\\.safetensors$/\\1/'")
531
+
532
+
533
+ # === OTHER ===
534
+ # Downlaod discord tags UmiWildcards
535
+ files_umi = [
536
+ "https://huggingface.co/NagisaNao/fast_repo/resolve/main/extensions/UmiWildacrd/discord/200_pan_gen.txt",
537
+ "https://huggingface.co/NagisaNao/fast_repo/resolve/main/extensions/UmiWildacrd/discord/150_bra_gen.txt"
538
+ ]
539
+ save_dir_path = f"{webui_path}/extensions/Umi-AI-Wildcards/wildcards/discord"
540
+
541
+ with capture.capture_output() as cap:
542
+ for file in files_umi:
543
+ get_ipython().system('aria2c --optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c -d {save_dir_path} {file}')
544
+ del cap
545
+
546
+
547
+ # === ONLY SAGEMAKER ===
548
+ if env == "SageMaker Studio Lab":
549
+ with capture.capture_output() as cap:
550
+ get_ipython().system('rm -rf /home/studio-lab-user/.conda/envs/studiolab-safemode')
551
+ get_ipython().system('rm -rf /home/studio-lab-user/.conda/envs/sagemaker-distribution')
552
+ get_ipython().system('rm -rf /home/studio-lab-user/.conda/pkgs/cache')
553
+ get_ipython().system('pip cache purge')
554
+ get_ipython().system('rm -rf ~/.cache')
555
+ del cap
556
+
files_cells/python/ru/launch_ru.py ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ##~ LAUNCH CODE | BY: ANXETY ~##
2
+
3
+ import os
4
+ import re
5
+ import time
6
+ import json
7
+ import requests
8
+ from datetime import timedelta
9
+
10
+
11
+ # ================= DETECT ENV =================
12
+ def check_colab_subscription():
13
+ return (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024. ** 3) <= 20)
14
+ free_plan = check_colab_subscription()
15
+
16
+ def detect_environment():
17
+ environments = {
18
+ 'COLAB_GPU': ('Google Colab', "/root" if free_plan else "/content"),
19
+ 'KAGGLE_URL_BASE': ('Kaggle', "/kaggle/working/content"),
20
+ 'SAGEMAKER_INTERNAL_IMAGE_URI': ('SageMaker Studio Lab', "/home/studio-lab-user/content")
21
+ }
22
+
23
+ for env_var, (environment, path) in environments.items():
24
+ if env_var in os.environ:
25
+ return environment, path
26
+
27
+ env, root_path = detect_environment()
28
+ webui_path = f"{root_path}/sdw"
29
+ # ----------------------------------------------
30
+
31
+ def load_settings():
32
+ SETTINGS_FILE = f'{root_path}/settings.json'
33
+ if os.path.exists(SETTINGS_FILE):
34
+ with open(SETTINGS_FILE, 'r') as f:
35
+ settings = json.load(f)
36
+ return settings
37
+
38
+ settings = load_settings()
39
+ ngrok_token = settings['ngrok_token']
40
+ commandline_arguments = settings['commandline_arguments']
41
+
42
+
43
+ # ======================== TUNNEL ========================
44
+ if env != "SageMaker Studio Lab":
45
+ import cloudpickle as pickle
46
+
47
+ password = "x1101"
48
+ def get_public_ip(version='ipv4'):
49
+ try:
50
+ url = f'https://api64.ipify.org?format=json&{version}=true'
51
+ response = requests.get(url)
52
+ data = response.json()
53
+ public_ip = data['ip']
54
+ return public_ip
55
+ except Exception as e:
56
+ print(f"Error getting public {version} address:", e)
57
+
58
+ public_ipv4 = get_public_ip(version='ipv4')
59
+
60
+ tunnel_class = pickle.load(open(f"{root_path}/new_tunnel", "rb"), encoding="utf-8")
61
+ tunnel_port= 1101
62
+ tunnel = tunnel_class(tunnel_port)
63
+ tunnel.add_tunnel(command="cl tunnel --url localhost:{port}", name="cl", pattern=re.compile(r"[\w-]+\.trycloudflare\.com"))
64
+ tunnel.add_tunnel(command="lt --port {port}", name="lt", pattern=re.compile(r"[\w-]+\.loca\.lt"), note="Password : " + "\033[32m" + public_ipv4 + "\033[0m" + " rerun cell if 404 error.")
65
+ # ======================== TUNNEL ========================
66
+
67
+
68
+ # automatic fixing path V2
69
+ get_ipython().system('sed -i \'s#"tagger_hf_cache_dir": ".*models/interrogators"#"tagger_hf_cache_dir": "{root_path}/sdw/models/interrogators"#\' {webui_path}/config.json')
70
+ get_ipython().system('sed -i \'s#"additional_networks_extra_lora_path": ".*models/Lora/"#"additional_networks_extra_lora_path": "{root_path}/sdw/models/Lora/"#\' {webui_path}/config.json')
71
+ # ---
72
+ get_ipython().system('sed -i \'s/"sd_checkpoint_hash": ".*"/"sd_checkpoint_hash": ""/g; s/"sd_model_checkpoint": ".*"/"sd_model_checkpoint": ""/g; s/"sd_vae": ".*"/"sd_vae": "None"/g\' {webui_path}/config.json')
73
+
74
+
75
+ if env != "SageMaker Studio Lab":
76
+ with tunnel:
77
+ get_ipython().system('#python -m http.server 1101')
78
+ get_ipython().run_line_magic('cd', '{webui_path}')
79
+ commandline_arguments += f" --port=1101"
80
+
81
+ if ngrok_token:
82
+ commandline_arguments += ' --ngrok ' + ngrok_token
83
+ if env != "Google Colab":
84
+ commandline_arguments += f" --encrypt-pass=1769"
85
+
86
+ get_ipython().system('COMMANDLINE_ARGS="{commandline_arguments}" python launch.py')
87
+
88
+ start_colab = float(open(f'{webui_path}/static/colabTimer.txt', 'r').read())
89
+ time_since_start = str(timedelta(seconds=time.time()-start_colab)).split('.')[0]
90
+ print(f"\n⌚️ \033[0mВы проводите эту сессию в течение - \033[33m{time_since_start}\033[0m\n\n")
91
+
92
+ else:
93
+ if ngrok_token:
94
+ get_ipython().run_line_magic('cd', '{webui_path}')
95
+
96
+ commandline_arguments += ' --ngrok ' + ngrok_token
97
+
98
+ get_ipython().system('COMMANDLINE_ARGS="{commandline_arguments}" python launch.py')
99
+
100
+ start_colab = float(open(f'{webui_path}/static/colabTimer.txt', 'r').read())
101
+ time_since_start = str(timedelta(seconds=time.time()-start_colab)).split('.')[0]
102
+ print(f"\n⌚️ \033[0mВы проводите эту сессию в течение - \033[33m{time_since_start}\033[0m\n\n")
103
+
104
+ else:
105
+ print("Упс... Я думаю, вы забыли вставить токен `ngrok`..... вернитесь к виджетам и вставьте его, чтобы запустить webui... без него никак :/\nВы можете получить токен здесь:\n\nhttps://dashboard.ngrok.com/get-started/your-authtoken")
106
+
files_cells/python/ru/widgets_ru.py ADDED
@@ -0,0 +1,424 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ##~ WIDGET CODE | BY: ANXETY ~##
2
+
3
+ import os
4
+ import json
5
+ import ipywidgets as widgets
6
+ from ipywidgets import widgets, Layout, Label, Button, VBox, HBox
7
+ from IPython.display import display, HTML, Javascript, clear_output
8
+
9
+
10
+ # ================= DETECT ENV =================
11
+ def check_colab_subscription():
12
+ return (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024. ** 3) <= 20)
13
+ free_plan = check_colab_subscription()
14
+
15
+ def detect_environment():
16
+ environments = {
17
+ 'COLAB_GPU': ('Google Colab', "/root" if free_plan else "/content"),
18
+ 'KAGGLE_URL_BASE': ('Kaggle', "/kaggle/working/content"),
19
+ 'SAGEMAKER_INTERNAL_IMAGE_URI': ('SageMaker Studio Lab', "/home/studio-lab-user/content")
20
+ }
21
+
22
+ for env_var, (environment, path) in environments.items():
23
+ if env_var in os.environ:
24
+ return environment, path
25
+
26
+ env, root_path = detect_environment()
27
+ webui_path = f"{root_path}/sdw"
28
+
29
+ get_ipython().system('mkdir -p {root_path}')
30
+ # ----------------------------------------------
31
+
32
+
33
+ # ==================== CSS JS ====================
34
+ CSS = '''
35
+ <style>
36
+ /* General Styles */
37
+ .header {
38
+ font-family: cursive;
39
+ font-size: 20px;
40
+ font-weight: bold;
41
+ color: #ff8cee;
42
+ margin-bottom: 15px;
43
+ user-select: none;
44
+ cursor: default;
45
+ display: inline-block;
46
+ }
47
+
48
+ hr {
49
+ border-color: grey;
50
+ background-color: grey;
51
+ opacity: 0.25;
52
+ }
53
+
54
+
55
+ /* Container style */
56
+
57
+ .container {
58
+ position: relative;
59
+ background-color: #232323;
60
+ width: 1080px;
61
+ padding: 10px 15px;
62
+ border-radius: 15px;
63
+ box-shadow: 0 0 50px rgba(0, 0, 0, 0.3);
64
+ margin-bottom: 5px;
65
+ overflow: visible;
66
+ }
67
+
68
+ .container::after {
69
+ position: absolute;
70
+ top: 5px;
71
+ right: 10px;
72
+ content: "ANXETY";
73
+ font-weight: bold;
74
+ font-size: 24px;
75
+ color: rgba(0, 0, 0, 0.15);
76
+ }
77
+
78
+ .container_custom_downlad {
79
+ height: 55px;
80
+ overflow: hidden;
81
+ transition: all 0.5s;
82
+ }
83
+
84
+ .container_custom_downlad.expanded {
85
+ height: 270px;
86
+ }
87
+
88
+
89
+ /* Element text style */
90
+
91
+ .widget-html,
92
+ .widget-button,
93
+ .widget-text label,
94
+ .widget-checkbox label,
95
+ .widget-dropdown label,
96
+ .widget-dropdown select,
97
+ .widget-text input[type="text"] {
98
+ font-family: cursive;
99
+ font-size: 14px;
100
+ color: white !important;
101
+ user-select: none;
102
+ }
103
+
104
+ .widget-text input[type="text"]::placeholder {
105
+ color: grey;
106
+ }
107
+
108
+
109
+ /* Input field styles */
110
+
111
+ .widget-dropdown select,
112
+ .widget-text input[type="text"] {
113
+ height: 30px;
114
+ background-color: #1c1c1c;
115
+ border: 1px solid #262626;
116
+ border-radius: 10px;
117
+ box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);
118
+ transition: all 0.3s ease-in-out;
119
+ }
120
+
121
+ .widget-dropdown select:focus,
122
+ .widget-text input[type="text"]:focus {
123
+ border-color: #006ee5;
124
+ }
125
+
126
+ .widget-dropdown select:hover,
127
+ .widget-text input[type="text"]:hover {
128
+ transform: scale(1.003);
129
+ background-color: #262626;
130
+ box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);
131
+ }
132
+
133
+
134
+ /* Button styles */
135
+
136
+ .button_save {
137
+ font-size: 15px;
138
+ font-weight: bold;
139
+ width: 120px;
140
+ height: 35px;
141
+ border-radius: 15px;
142
+ background-image: radial-gradient(circle at top left, purple 10%, violet 90%);
143
+ background-size: 200% 200%;
144
+ background-position: left bottom;
145
+ transition: background 0.5s ease-in-out, transform 0.3s ease;
146
+ }
147
+
148
+ .button_save:hover {
149
+ cursor: pointer;
150
+ background-image: radial-gradient(circle at top left, purple 10%, #93ac47 90%);
151
+ background-size: 200% 200%;
152
+ background-position: right bottom;
153
+ transform: translateY(1px);
154
+ }
155
+
156
+ .button_ngrok {
157
+ font-size: 12px;
158
+ height: 30px;
159
+ border-radius: 10px;
160
+ padding: 1px 12px;
161
+ background-image: radial-gradient(circle at top left, purple 10%, violet 90%);
162
+ background-size: 200% 200%;
163
+ background-position: left bottom;
164
+ transition: background 0.5s ease-in-out, transform 0.3s ease;
165
+ white-space: nowrap;
166
+ }
167
+
168
+ .button_ngrok:hover {
169
+ cursor: pointer;
170
+ background-image: radial-gradient(circle at top left, purple 10%, #e2a9a8 90%);
171
+ background-size: 200% 200%;
172
+ background-position: right bottom;
173
+ transform: translateY(1px);
174
+ }
175
+
176
+ .button_save:active,
177
+ .button_ngrok:active {
178
+ filter: brightness(0.75);
179
+ }
180
+
181
+
182
+ /* Popup style of `FAQ` window */
183
+
184
+ .info {
185
+ position: absolute;
186
+ top: -5px;
187
+ right: 95px;
188
+ color: grey;
189
+ font-family: cursive;
190
+ font-size: 14px;
191
+ font-weight: normal;
192
+ user-select: none;
193
+ pointer-events: none;
194
+ opacity: 0;
195
+ transition: opacity 0.3s ease-in-out;
196
+ display: inline-block;
197
+ }
198
+
199
+ .popup {
200
+ position: absolute;
201
+ top: 120px;
202
+ z-index: 999;
203
+ width: auto;
204
+ padding: 10px;
205
+ text-align: center;
206
+ background-color: rgba(255, 255, 255, 0.05);
207
+ backdrop-filter: blur(20px);
208
+ border: 1px solid rgba(255, 255, 255, 0.45);
209
+ border-radius: 8px;
210
+ box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
211
+ opacity: 0;
212
+ color: #fff;
213
+ font-size: 16px;
214
+ font-family: cursive;
215
+ user-select: none;
216
+ cursor: default;
217
+ pointer-events: none;
218
+ transform: rotate(-5deg);
219
+ transition: top 0.3s ease-in-out, opacity 0.3s ease-in-out, transform 0.3s ease-in-out;
220
+ }
221
+
222
+ .sample {
223
+ display: inline-block;
224
+ margin-top: 25px;
225
+ padding: 10px 100px;
226
+ background-color: rgba(255, 255, 255, 0.2);
227
+ color: #c6e2ff;
228
+ border: 2px solid rgba(255, 255, 255, 0.2);
229
+ border-radius: 8px;
230
+ box-shadow: 0 0 10px rgba(255, 255, 255, 0.2), inset 0 0 25px rgba(255, 255, 255, 0.2);
231
+ }
232
+
233
+ .info.showed {
234
+ opacity: 1;
235
+ pointer-events: auto;
236
+ }
237
+
238
+ .info:hover + .popup {
239
+ top: 35px;
240
+ opacity: 1;
241
+ pointer-events: initial;
242
+ transform: rotate(0deg);
243
+ }
244
+
245
+
246
+ /* Animation of elements */
247
+
248
+ .container,
249
+ .button_save {
250
+ animation-name: showedWidgets;
251
+ animation-duration: 1s;
252
+ }
253
+
254
+ @keyframes showedWidgets {
255
+ 0% {
256
+ transform: translate3d(-65%, 15%, 0) scale(0) rotate(15deg);
257
+ filter: blur(25px) grayscale(1) brightness(0.3);
258
+ opacity: 0;
259
+ }
260
+ 100% {
261
+ transform: translate3d(0, 0, 0) scale(1) rotate(0deg);
262
+ filter: blur(0) grayscale(0) brightness(1);
263
+ opacity: 1;
264
+ }
265
+ }
266
+ </style>
267
+
268
+ <!-- TOGGLE 'CustomDL' SCRIPT -->
269
+ <script>
270
+ function toggleContainer() {
271
+ let downloadContainer = document.querySelector('.container_custom_downlad');
272
+ let info = document.querySelector('.info');
273
+
274
+ downloadContainer.classList.toggle('expanded');
275
+ info.classList.toggle('showed');
276
+ }
277
+ </script>
278
+ '''
279
+
280
+ display(HTML(CSS))
281
+ # ==================== CSS JS ====================
282
+
283
+
284
+ # ==================== WIDGETS ====================
285
+ # --- global widgets ---
286
+ style = {'description_width': 'initial'}
287
+ layout = widgets.Layout(min_width='1047px')
288
+
289
+ HR = widgets.HTML('<hr>')
290
+
291
+ # --- MODEL ---
292
+ model_header = widgets.HTML('<div class="header">Выбор Модели<div>')
293
+ model_options = ['none',
294
+ '1.Anime (by Xpuct) + INP',
295
+ '2.Cetus-Mix [Anime] [V4] + INP',
296
+ '3.Counterfeit [Anime] [V3] + INP',
297
+ '4.CuteColor [Anime] [V3]',
298
+ '5.Dark-Sushi-Mix [Anime]',
299
+ '6.Meina-Mix [Anime] [V11] + INP',
300
+ '7.Mix-Pro [Anime] [V4] + INP',
301
+ '8.BluMix [Anime] [V7]']
302
+ # ---
303
+ Model_widget = widgets.Dropdown(options=model_options, value='3.Counterfeit [Anime] [V3] + INP', description='Модель:', style=style, layout=layout)
304
+ Model_Num_widget = widgets.Text(description='Номер Модели:', placeholder='Введите номера моделей для скачивания через запятую/пробел.', style=style, layout=layout)
305
+ Inpainting_Model_widget = widgets.Checkbox(value=False, description='Inpainting Модели', style=style)
306
+
307
+ display(widgets.VBox([model_header, Model_widget, Model_Num_widget, Inpainting_Model_widget]).add_class("container"))
308
+
309
+ # --- VAE ---
310
+ vae_header = widgets.HTML('<div class="header" >Выбор VAE</div>')
311
+ vae_options = ['none',
312
+ '1.Anime.vae',
313
+ '2.Anything.vae',
314
+ '3.Blessed2.vae',
315
+ '4.ClearVae.vae',
316
+ '5.WD.vae']
317
+ Vae_widget = widgets.Dropdown(options=vae_options, value='3.Blessed2.vae', description='Vae:', style=style, layout=layout)
318
+ Vae_Num_widget = widgets.Text(description='Номер Vae:', placeholder='Введите номера vae для скачивания через запятую/пробел.', style=style, layout=layout)
319
+
320
+ display(widgets.VBox([vae_header, Vae_widget, Vae_Num_widget]).add_class("container"))
321
+
322
+ # --- ADDITIONAL ---
323
+ additional_header = widgets.HTML('<div class="header">Дополнительно</div>')
324
+ latest_webui_widget = widgets.Checkbox(value=True, description='Обновить WebUI', style=style)
325
+ latest_exstensions_widget = widgets.Checkbox(value=True, description='Обновить Расширения', style=style)
326
+ detailed_download_widget = widgets.Dropdown(options=['off', 'on'], value='off', description='Подробная Загрузка:', style=style)
327
+ latest_changes_widget = HBox([latest_webui_widget, latest_exstensions_widget, detailed_download_widget], layout=widgets.Layout(justify_content='space-between'))
328
+ controlnet_options = ['none', 'ALL', '1.canny',
329
+ '2.openpose', '3.depth',
330
+ '4.normal_map', '5.mlsd',
331
+ '6.lineart', '7.soft_edge',
332
+ '8.scribble', '9.segmentation',
333
+ '10.shuffle', '11.tile',
334
+ '12.inpaint', '13.instruct_p2p']
335
+ # ---
336
+ controlnet_widget = widgets.Dropdown(options=controlnet_options, value='none', description='ControlNet:', style=style, layout=layout)
337
+ controlnet_Num_widget = widgets.Text(description='Номер ControlNet:', placeholder='Введите номера моделей ControlNet для скачивания через запятую/пробел.', style=style, layout=layout)
338
+ commit_hash_widget = widgets.Text(description='Commit Hash:', style=style, layout=layout)
339
+ optional_huggingface_token_widget = widgets.Text(description='Токен HuggingFace:', style=style, layout=layout)
340
+ ngrok_token_widget = widgets.Text(description='Токен Ngrok:', style=style, layout=widgets.Layout(width='1047px'))
341
+ ngrock_button = widgets.HTML('<a href="https://dashboard.ngrok.com/get-started/your-authtoken" target="_blank">Получить Ngrok Токен</a>').add_class("button_ngrok")
342
+ ngrok_widget = widgets.HBox([ngrok_token_widget, ngrock_button], style=style, layout=layout)
343
+ # ---
344
+ commandline_arguments_options = "--listen --enable-insecure-extension-access --theme dark --no-half-vae --disable-console-progressbars --xformers"
345
+ commandline_arguments_widget = widgets.Text(description='Аргументы:', value=commandline_arguments_options, style=style, layout=layout)
346
+
347
+ display(widgets.VBox([
348
+ additional_header, latest_changes_widget, HR, controlnet_widget, controlnet_Num_widget, commit_hash_widget, optional_huggingface_token_widget, ngrok_widget, HR, commandline_arguments_widget
349
+ ]).add_class("container"))
350
+
351
+ # --- CUSTOM DOWNLOAD ---
352
+ custom_download_header_popup = widgets.HTML('''
353
+ <style>
354
+ /* Color */
355
+ .sample_label {color: #dbafff;}
356
+ .braces {color: #ffff00;}
357
+ .extension {color: #eb934b;}
358
+ .file_name {color: #ffffd8;}
359
+ </style>
360
+
361
+ <div class="header" style="cursor: pointer;" onclick="toggleContainer()">Кастомная Загрузка</div>
362
+ <!-- PopUp window -->
363
+ <div class="info" id="info_dl">FAQ?</div>
364
+ <div class="popup">
365
+ Разделите несколько URL-адресов запятой/пробелом. Для <span class="file_name">пользовательского имени</span> файла/расширения укажите его через <span class="braces">[]</span>
366
+ после URL без пробелов.
367
+ <span style="color: #ff9999">Для файлов обязательно укажите</span> - <span class="extension">Расширение Файла.</span>
368
+ <div class="sample">
369
+ <span class="sample_label">Пример для Файла:</span>
370
+ https://civitai.com/api/download/models/229782<span class="braces">[</span><span class="file_name">Detailer</span><span class="extension">.safetensors</span><span class="braces">]</span>
371
+ <br>
372
+ <span class="sample_label">Пример для Расширения:</span>
373
+ https://github.com/hako-mikan/sd-webui-regional-prompter<span class="braces">[</span><span class="file_name">Regional-Prompter</span><span class="braces">]</span>
374
+ </div>
375
+ </div>
376
+ ''')
377
+ # ---
378
+ Model_url_widget = widgets.Text(description='Model:', style=style, layout=layout)
379
+ Vae_url_widget = widgets.Text(description='Vae:', style=style, layout=layout)
380
+ LoRA_url_widget = widgets.Text(description='LoRa:', style=style, layout=layout)
381
+ Embedding_url_widget = widgets.Text(description='Embedding:', style=style, layout=layout)
382
+ Extensions_url_widget = widgets.Text(description='Extensions:', style=style, layout=layout)
383
+ custom_file_urls_widget = widgets.Text(description='Файл (txt):', style=style, layout=layout)
384
+
385
+ display(widgets.VBox([
386
+ custom_download_header_popup, Model_url_widget, Vae_url_widget, LoRA_url_widget, Embedding_url_widget, Extensions_url_widget, custom_file_urls_widget
387
+ ]).add_class("container").add_class("container_custom_downlad"))
388
+
389
+ # --- Save Button ---
390
+ save_button = widgets.Button(description='Сохранить').add_class("button_save")
391
+ display(save_button)
392
+
393
+
394
+ # ============ Load / Save - Settings V2 ============
395
+ SETTINGS_FILE = f'{root_path}/settings.json'
396
+
397
+ settings_keys = [
398
+ 'Model', 'Model_Num', 'Inpainting_Model',
399
+ 'Vae', 'Vae_Num',
400
+ 'latest_webui', 'latest_exstensions', 'detailed_download',
401
+ 'controlnet', 'controlnet_Num', 'commit_hash', 'optional_huggingface_token',
402
+ 'ngrok_token', 'commandline_arguments',
403
+ 'Model_url', 'Vae_url', 'LoRA_url', 'Embedding_url', 'Extensions_url', 'custom_file_urls'
404
+ ]
405
+
406
+ def save_settings():
407
+ settings = {key: globals()[f"{key}_widget"].value for key in settings_keys}
408
+ with open(SETTINGS_FILE, 'w') as f:
409
+ json.dump(settings, f)
410
+
411
+ def load_settings():
412
+ if os.path.exists(SETTINGS_FILE):
413
+ with open(SETTINGS_FILE, 'r') as f:
414
+ settings = json.load(f)
415
+ for key in settings_keys:
416
+ globals()[f"{key}_widget"].value = settings.get(key)
417
+
418
+ def save_data(button):
419
+ save_settings()
420
+ widgets.Widget.close_all()
421
+
422
+ settings = load_settings()
423
+ save_button.on_click(save_data)
424
+