Transformers
Inference Endpoints
vorstcavry commited on
Commit
2d1ecea
1 Parent(s): 8bcaa41

Upload 16 files

Browse files
files_cells/notebooks/en/auto-cleaner_en.ipynb ADDED
@@ -0,0 +1,351 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "import os\n",
23
+ "import time\n",
24
+ "import ipywidgets as widgets\n",
25
+ "from ipywidgets import Label, Button, VBox, HBox\n",
26
+ "from IPython.display import display, HTML, Javascript\n",
27
+ "\n",
28
+ "\n",
29
+ "# ================= DETECT ENV =================\n",
30
+ "def detect_environment():\n",
31
+ " free_plan = (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024. ** 3) <= 20)\n",
32
+ " environments = {\n",
33
+ " 'COLAB_GPU': ('Google Colab', \"/root\" if free_plan else \"/content\"),\n",
34
+ " 'KAGGLE_URL_BASE': ('Kaggle', \"/kaggle/working/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, free_plan\n",
40
+ "\n",
41
+ "env, root_path, free_plan = detect_environment()\n",
42
+ "webui_path = f\"{root_path}/sdw\"\n",
43
+ "# ----------------------------------------------\n",
44
+ "\n",
45
+ "\n",
46
+ "# ==================== CSS ====================\n",
47
+ "CSS = \"\"\"\n",
48
+ "<style>\n",
49
+ "/* General Styles */\n",
50
+ "\n",
51
+ "hr {\n",
52
+ " border-color: grey;\n",
53
+ " background-color: grey;\n",
54
+ " opacity: 0.25;\n",
55
+ "}\n",
56
+ "\n",
57
+ ".instruction_AC {\n",
58
+ " font-family: cursive;\n",
59
+ " font-size: 18px;\n",
60
+ " color: grey;\n",
61
+ " user-select: none;\n",
62
+ " cursor: default;\n",
63
+ "}\n",
64
+ "\n",
65
+ "\n",
66
+ "/* Container style */\n",
67
+ "\n",
68
+ ".container_AC {\n",
69
+ " position: relative;\n",
70
+ " background-color: #232323;\n",
71
+ " width: 800px;\n",
72
+ " height: auto;\n",
73
+ " padding: 15px;\n",
74
+ " border-radius: 15px;\n",
75
+ " box-shadow: 0 0 50px rgba(0, 0, 0, 0.3);\n",
76
+ " margin-bottom: 5px;\n",
77
+ " overflow: visible;\n",
78
+ "}\n",
79
+ "\n",
80
+ ".container_AC::before {\n",
81
+ " position: absolute;\n",
82
+ " top: 5px;\n",
83
+ " right: 10px;\n",
84
+ " content: \"AutoCleanerV3.6\";\n",
85
+ " font-weight: bold;\n",
86
+ " font-size: 24px;\n",
87
+ " color: rgba(0, 0, 0, 0.2);\n",
88
+ "}\n",
89
+ "\n",
90
+ ".container_AC::after {\n",
91
+ " position: absolute;\n",
92
+ " top: 30px;\n",
93
+ " right: 10px;\n",
94
+ " content: \"ANXETY\";\n",
95
+ " font-weight: bold;\n",
96
+ " font-size: 18px;\n",
97
+ " color: rgba(0, 0, 0, 0.2);\n",
98
+ "}\n",
99
+ "\n",
100
+ ".custom-select-multiple_AC select {\n",
101
+ " padding: 10px;\n",
102
+ " font-family: cursive;\n",
103
+ " border: 1px solid #262626 !important;\n",
104
+ " border-radius: 10px;\n",
105
+ " color: white;\n",
106
+ " background-color: #1c1c1c;\n",
107
+ " box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);\n",
108
+ "}\n",
109
+ "\n",
110
+ ".output_AC {\n",
111
+ " padding: 10px;\n",
112
+ " height: auto;\n",
113
+ " border: 1px solid #262626;\n",
114
+ " border-radius: 10px;\n",
115
+ " background-color: #1c1c1c;\n",
116
+ " box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);\n",
117
+ " width: auto;\n",
118
+ " box-sizing: border-box;\n",
119
+ "}\n",
120
+ "\n",
121
+ ".output_message_AC {\n",
122
+ " font-family: cursive;\n",
123
+ " color: white !important;\n",
124
+ " font-size: 14px;\n",
125
+ " user-select: none;\n",
126
+ " cursor: default\n",
127
+ "}\n",
128
+ "\n",
129
+ "\n",
130
+ ".storage_info_AC {\n",
131
+ " padding: 5px 20px;\n",
132
+ " height: auto;\n",
133
+ " border: 1px solid #262626;\n",
134
+ " border-radius: 10px;\n",
135
+ " background-color: #1c1c1c;\n",
136
+ " box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);\n",
137
+ " width: auto;\n",
138
+ " font-family: cursive;\n",
139
+ " color: #B2B2B2 !important;\n",
140
+ " font-size: 14px;\n",
141
+ " user-select: none;\n",
142
+ " cursor: default\n",
143
+ "}\n",
144
+ "\n",
145
+ "\n",
146
+ "/* Button and storage info layout */\n",
147
+ ".lower_information_panel_AC {\n",
148
+ " display: flex;\n",
149
+ " align-items: center;\n",
150
+ " justify-content: space-between;\n",
151
+ "}\n",
152
+ "\n",
153
+ "\n",
154
+ "/* Button style */\n",
155
+ "\n",
156
+ ".button_AC {\n",
157
+ " width: auto;\n",
158
+ " font-family: cursive;\n",
159
+ " color: white !important;\n",
160
+ " font-size: 14px;\n",
161
+ " font-weight: bold;\n",
162
+ " height: 35px;\n",
163
+ " border-radius: 15px;\n",
164
+ " background-image: radial-gradient(circle at top left, purple 10%, violet 90%);\n",
165
+ " background-size: 200% 200%;\n",
166
+ " background-position: left bottom;\n",
167
+ " transition: background 0.5s ease-in-out, transform 0.3s ease;\n",
168
+ "}\n",
169
+ "\n",
170
+ ".button_AC:hover {\n",
171
+ " cursor: pointer;\n",
172
+ " background-size: 200% 200%;\n",
173
+ " background-position: right bottom;\n",
174
+ " transform: translateY(1px);\n",
175
+ "}\n",
176
+ "\n",
177
+ ".button_execute_AC:hover {\n",
178
+ " background-image: radial-gradient(circle at top left, purple 10%, #93ac47 90%);\n",
179
+ "}\n",
180
+ "\n",
181
+ ".button_clear_AC:hover {\n",
182
+ " background-image: radial-gradient(circle at top left, purple 10%, #fc3468 90%);\n",
183
+ "}\n",
184
+ "\n",
185
+ ".button_execute_AC:active,\n",
186
+ ".button_clear_AC:active {\n",
187
+ " filter: brightness(0.75);\n",
188
+ "}\n",
189
+ "\n",
190
+ ".jupyter-widgets.lm-Widget:focus {\n",
191
+ " outline: none;\n",
192
+ "}\n",
193
+ "\n",
194
+ "\n",
195
+ "/* Animation of elements */\n",
196
+ "\n",
197
+ "/* Emergence */\n",
198
+ ".container_AC {\n",
199
+ " animation-name: slideInTopBlur;\n",
200
+ " animation-duration: 0.7s;\n",
201
+ " animation-fill-mode: forwards;\n",
202
+ "}\n",
203
+ "\n",
204
+ "@keyframes slideInTopBlur {\n",
205
+ " 0% {\n",
206
+ " transform: translate3d(0, 50%, 0) scale(0.85) rotate3d(1, 0, 0, -85deg);\n",
207
+ " filter: blur(5px) grayscale(1) brightness(0.5);\n",
208
+ " opacity: 0;\n",
209
+ " }\n",
210
+ " 100% {\n",
211
+ " transform: translate3d(0, 0, 0) scale(1) rotate3d(1, 0, 0, 0deg);\n",
212
+ " filter: blur(0) grayscale(0) brightness(1);\n",
213
+ " opacity: 1;\n",
214
+ " }\n",
215
+ "}\n",
216
+ "\n",
217
+ "/* Leaving */\n",
218
+ ".container_AC.hide {\n",
219
+ " animation-name: slideOutTopBlur;\n",
220
+ " animation-duration: 0.5s;\n",
221
+ " animation-fill-mode: forwards;\n",
222
+ "}\n",
223
+ "\n",
224
+ "@keyframes slideOutTopBlur {\n",
225
+ " 0% {\n",
226
+ " transform: translate3d(0, 0, 0) scale(1);\n",
227
+ " filter: blur(0) grayscale(0) brightness(1);\n",
228
+ " opacity: 1;\n",
229
+ " }\n",
230
+ " 100% {\n",
231
+ " transform: translate3d(0, -100%, 0);\n",
232
+ " filter: blur(5px) grayscale(1) brightness(0);\n",
233
+ " opacity: 0;\n",
234
+ " }\n",
235
+ "}\n",
236
+ "</style>\n",
237
+ "\"\"\"\n",
238
+ "\n",
239
+ "display(HTML(CSS))\n",
240
+ "# ==================== CSS ====================\n",
241
+ "\n",
242
+ "\n",
243
+ "# ================ AutoCleaner function ================\n",
244
+ "directories = {\n",
245
+ " \"Images\": f\"{webui_path}/outputs\",\n",
246
+ " \"Models\": f\"{webui_path}/models/Stable-diffusion/\",\n",
247
+ " \"Vae\": f\"{webui_path}/models/VAE/\",\n",
248
+ " \"LoRa\": f\"{webui_path}/models/Lora/\",\n",
249
+ " \"ControlNet Models\": f\"{webui_path}/models/ControlNet/\"\n",
250
+ "}\n",
251
+ "\n",
252
+ "\"\"\" functions \"\"\"\n",
253
+ "def clean_directory(directory):\n",
254
+ " deleted_files = 0\n",
255
+ " for root, dirs, files in os.walk(directory):\n",
256
+ " for file in files:\n",
257
+ " if file.endswith(\".txt\"):\n",
258
+ " continue\n",
259
+ " os.remove(os.path.join(root, file))\n",
260
+ " if not file.endswith(\".yaml\"):\n",
261
+ " deleted_files += 1\n",
262
+ " return deleted_files\n",
263
+ "\n",
264
+ "def update_memory_info():\n",
265
+ " disk_space = psutil.disk_usage(os.getcwd())\n",
266
+ " total = disk_space.total / (1024 ** 3)\n",
267
+ " used = disk_space.used / (1024 ** 3)\n",
268
+ " free = disk_space.free / (1024 ** 3)\n",
269
+ "\n",
270
+ " storage_info.value = f'''\n",
271
+ " <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",
272
+ " '''\n",
273
+ "\n",
274
+ "def on_execute_button_press(button):\n",
275
+ " selected_cleaners = auto_cleaner_widget.value\n",
276
+ " deleted_files_dict = {}\n",
277
+ "\n",
278
+ " for option in selected_cleaners:\n",
279
+ " if option in directories:\n",
280
+ " deleted_files_dict[option] = clean_directory(directories[option])\n",
281
+ "\n",
282
+ " output.clear_output()\n",
283
+ "\n",
284
+ " with output:\n",
285
+ " for message in generate_messages(deleted_files_dict):\n",
286
+ " message_widget = HTML(f'<p class=\"output_message_AC\">{message}</p>')\n",
287
+ " display(message_widget)\n",
288
+ "\n",
289
+ " update_memory_info()\n",
290
+ "\n",
291
+ "def on_clear_button_press(button):\n",
292
+ " container.add_class(\"hide\")\n",
293
+ " time.sleep(0.5)\n",
294
+ " widgets.Widget.close_all()\n",
295
+ "\n",
296
+ "def generate_messages(deleted_files_dict):\n",
297
+ " messages = []\n",
298
+ " word_variants = {\n",
299
+ " \"Images\": \"Images\",\n",
300
+ " \"Models\": \"Models\",\n",
301
+ " \"Vae\": \"Vae\",\n",
302
+ " \"LoRa\": \"LoRa\",\n",
303
+ " \"ControlNet Models\": \"ControlNet Models\"\n",
304
+ " }\n",
305
+ " for key, value in deleted_files_dict.items():\n",
306
+ " object_word = word_variants.get(key)\n",
307
+ " messages.append(f\"Deleted {value} {object_word}\")\n",
308
+ " return messages\n",
309
+ "# ================ AutoCleaner function ================\n",
310
+ "\n",
311
+ "\n",
312
+ "# --- storage memory ---\n",
313
+ "import psutil\n",
314
+ "disk_space = psutil.disk_usage(os.getcwd())\n",
315
+ "total = disk_space.total / (1024 ** 3)\n",
316
+ "used = disk_space.used / (1024 ** 3)\n",
317
+ "free = disk_space.free / (1024 ** 3)\n",
318
+ "\n",
319
+ "\n",
320
+ "# UI Code\n",
321
+ "AutoCleaner_options = AutoCleaner_options = list(directories.keys())\n",
322
+ "instruction_label = widgets.HTML('''\n",
323
+ "<span class=\"instruction_AC\">Use <span style=\"color: #B2B2B2;\">ctrl</span> or <span style=\"color: #B2B2B2;\">shift</span> for multiple selections.</span>\n",
324
+ "''')\n",
325
+ "auto_cleaner_widget = widgets.SelectMultiple(options=AutoCleaner_options, layout=widgets.Layout(width='auto')).add_class(\"custom-select-multiple_AC\")\n",
326
+ "output = widgets.Output().add_class(\"output_AC\")\n",
327
+ "# ---\n",
328
+ "execute_button = Button(description='Execute Cleaning').add_class(\"button_execute_AC\").add_class(\"button_AC\")\n",
329
+ "execute_button.on_click(on_execute_button_press)\n",
330
+ "clear_button = Button(description='Hide Widget').add_class(\"button_clear_AC\").add_class(\"button_AC\")\n",
331
+ "clear_button.on_click(on_clear_button_press)\n",
332
+ "# ---\n",
333
+ "storage_info = widgets.HTML(f'''\n",
334
+ "<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",
335
+ "''')\n",
336
+ "# ---\n",
337
+ "buttons = widgets.HBox([execute_button, clear_button])\n",
338
+ "lower_information_panel = widgets.HBox([buttons, storage_info]).add_class(\"lower_information_panel_AC\")\n",
339
+ "\n",
340
+ "container = VBox([instruction_label, widgets.HTML('<hr>'), auto_cleaner_widget, output, widgets.HTML('<hr>'), lower_information_panel]).add_class(\"container_AC\")\n",
341
+ "\n",
342
+ "display(container)"
343
+ ],
344
+ "metadata": {
345
+ "id": "I22dFg7F2j3G"
346
+ },
347
+ "execution_count": null,
348
+ "outputs": []
349
+ }
350
+ ]
351
+ }
files_cells/notebooks/en/downloading_en.ipynb ADDED
@@ -0,0 +1,568 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ " free_plan = (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024. ** 3) <= 20)\n",
38
+ " environments = {\n",
39
+ " 'COLAB_GPU': ('Google Colab', \"/root\" if free_plan else \"/content\"),\n",
40
+ " 'KAGGLE_URL_BASE': ('Kaggle', \"/kaggle/working/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, free_plan\n",
46
+ "\n",
47
+ "env, root_path, free_plan = detect_environment()\n",
48
+ "webui_path = f\"{root_path}/sdw\"\n",
49
+ "# ----------------------------------------------\n",
50
+ "\n",
51
+ "\n",
52
+ "# ================ LIBRARIES V2 ================\n",
53
+ "flag_file = f\"{root_path}/libraries_installed.txt\"\n",
54
+ "\n",
55
+ "if not os.path.exists(flag_file):\n",
56
+ " print(\"💿 Installing the libraries, it's going to take a while:\\n\")\n",
57
+ "\n",
58
+ " install_lib = {\n",
59
+ " \"gdown\": \"pip install -U gdown\",\n",
60
+ " \"aria2\": \"apt-get update && apt -y install aria2\",\n",
61
+ " \"localtunnel\": \"npm install -g localtunnel &> /dev/null\",\n",
62
+ " \"insightface\": \"pip install insightface\",\n",
63
+ " }\n",
64
+ "\n",
65
+ " # Dictionary of additional libraries specific to certain environments\n",
66
+ " additional_libs = {\n",
67
+ " \"Google Colab\": {\n",
68
+ " \"xformers\": \"pip install xformers==0.0.25 --no-deps\"\n",
69
+ " },\n",
70
+ " \"Kaggle\": {\n",
71
+ " \"xformers\": \"pip install -q xformers==0.0.23.post1 triton==2.1.0\",\n",
72
+ " \"torch\": \"pip install -q torch==2.1.2+cu121 torchvision==0.16.2+cu121 torchaudio==2.1.2 --extra-index-url https://download.pytorch.org/whl/cu121\"\n",
73
+ " }\n",
74
+ " }\n",
75
+ "\n",
76
+ " # If the current environment has additional libraries, update the install_lib dictionary\n",
77
+ " if env in additional_libs:\n",
78
+ " install_lib.update(additional_libs[env])\n",
79
+ "\n",
80
+ " # Loop through libraries and execute install commands\n",
81
+ " for index, (package, install_cmd) in enumerate(install_lib.items(), start=1):\n",
82
+ " print(f\"\\r[{index}/{len(install_lib)}] \\033[32m>>\\033[0m Installing \\033[33m{package}\\033[0m...\" + \" \"*35, end='')\n",
83
+ " subprocess.run(install_cmd, shell=True, capture_output=True)\n",
84
+ "\n",
85
+ " # Additional manual installation steps for specific packages\n",
86
+ " with capture.capture_output() as cap:\n",
87
+ " !curl -s -OL https://github.com/DEX-1101/sd-webui-notebook/raw/main/res/new_tunnel --output-dir {root_path}\n",
88
+ " !curl -s -Lo /usr/bin/cl https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 && chmod +x /usr/bin/cl\n",
89
+ " !curl -sLO https://github.com/openziti/zrok/releases/download/v0.4.23/zrok_0.4.23_linux_amd64.tar.gz && tar -xzf zrok_0.4.23_linux_amd64.tar.gz -C /usr/bin && rm -f zrok_0.4.23_linux_amd64.tar.gz\n",
90
+ " del cap\n",
91
+ "\n",
92
+ " clear_output()\n",
93
+ "\n",
94
+ " # Save file install lib\n",
95
+ " with open(flag_file, \"w\") as f:\n",
96
+ " f.write(\">W<'\")\n",
97
+ "\n",
98
+ " print(\"🍪 Libraries are installed!\" + \" \"*35)\n",
99
+ " time.sleep(2)\n",
100
+ " clear_output()\n",
101
+ "\n",
102
+ "\n",
103
+ "# ================= loading settings V4 =================\n",
104
+ "def load_settings(path):\n",
105
+ " if os.path.exists(path):\n",
106
+ " with open(path, 'r') as file:\n",
107
+ " return json.load(file)\n",
108
+ " return {}\n",
109
+ "\n",
110
+ "settings = load_settings(f'{root_path}/settings.json')\n",
111
+ "\n",
112
+ "variables = [\n",
113
+ " 'Model', 'Model_Num', 'Inpainting_Model',\n",
114
+ " 'Vae', 'Vae_Num',\n",
115
+ " 'latest_webui', 'latest_exstensions', 'detailed_download',\n",
116
+ " 'controlnet', 'controlnet_Num', 'commit_hash', 'optional_huggingface_token',\n",
117
+ " 'ngrok_token', 'zrok_token', 'commandline_arguments',\n",
118
+ " 'Model_url', 'Vae_url', 'LoRA_url', 'Embedding_url', 'Extensions_url', 'custom_file_urls'\n",
119
+ "]\n",
120
+ "\n",
121
+ "locals().update({key: settings.get(key) for key in variables})\n",
122
+ "\n",
123
+ "\n",
124
+ "# ================= OTHER =================\n",
125
+ "try:\n",
126
+ " start_colab\n",
127
+ "except:\n",
128
+ " start_colab = int(time.time())-5\n",
129
+ "\n",
130
+ "# CONFIG DIR\n",
131
+ "models_dir = f\"{webui_path}/models/Stable-diffusion\"\n",
132
+ "vaes_dir = f\"{webui_path}/models/VAE\"\n",
133
+ "embeddings_dir = f\"{webui_path}/embeddings\"\n",
134
+ "loras_dir = f\"{webui_path}/models/Lora\"\n",
135
+ "extensions_dir = f\"{webui_path}/extensions\"\n",
136
+ "control_dir = f\"{webui_path}/models/ControlNet\"\n",
137
+ "\n",
138
+ "\n",
139
+ "# ================= MAIN CODE =================\n",
140
+ "if not os.path.exists(webui_path):\n",
141
+ " start_install = int(time.time())\n",
142
+ " print(\"⌚ Unpacking Stable Diffusion...\", end='')\n",
143
+ " with capture.capture_output() as cap:\n",
144
+ " !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",
145
+ " !unzip -q -o repo.zip -d {webui_path}\n",
146
+ " !rm -rf repo.zip\n",
147
+ "\n",
148
+ " %cd {root_path}\n",
149
+ " os.environ[\"SAFETENSORS_FAST_GPU\"]='1'\n",
150
+ " os.environ[\"CUDA_MODULE_LOADING\"]=\"LAZY\"\n",
151
+ " os.environ[\"TF_CPP_MIN_LOG_LEVEL\"] = \"3\"\n",
152
+ " os.environ[\"PYTHONWARNINGS\"] = \"ignore\"\n",
153
+ "\n",
154
+ " !echo -n {start_colab} > {webui_path}/static/colabTimer.txt\n",
155
+ " del cap\n",
156
+ " install_time = timedelta(seconds=time.time()-start_install)\n",
157
+ " 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",
158
+ "else:\n",
159
+ " print(\"🚀 All unpacked... Skip. ⚡\")\n",
160
+ " start_colab = float(open(f'{webui_path}/static/colabTimer.txt', 'r').read())\n",
161
+ " time_since_start = str(timedelta(seconds=time.time()-start_colab)).split('.')[0]\n",
162
+ " print(f\"⌚️ You have been conducting this session for - \\033[33m{time_since_start}\\033[0m\")\n",
163
+ "\n",
164
+ "\n",
165
+ "## Changes extensions and WebUi\n",
166
+ "if latest_webui or latest_exstensions:\n",
167
+ " action = \"Updating WebUI and Extensions\" if latest_webui and latest_exstensions else (\"WebUI Update\" if latest_webui else \"Update Extensions\")\n",
168
+ " print(f\"⌚️ {action}...\", end='', flush=True)\n",
169
+ " with capture.capture_output() as cap:\n",
170
+ " !git config --global user.email \"[email protected]\"\n",
171
+ " !git config --global user.name \"Your Name\"\n",
172
+ "\n",
173
+ " ## Update Webui\n",
174
+ " if latest_webui:\n",
175
+ " %cd {webui_path}\n",
176
+ " !git restore .\n",
177
+ " !git pull -X theirs --rebase --autostash\n",
178
+ "\n",
179
+ " ## Update extensions\n",
180
+ " if latest_exstensions:\n",
181
+ " !{'for dir in ' + webui_path + '/extensions/*/; do cd \\\"$dir\\\" && git reset --hard && git pull; done'}\n",
182
+ "\n",
183
+ " # My Chinese friend, you broke the images again in the latest update... >W<'\n",
184
+ " %cd {webui_path}/extensions/Encrypt-Image\n",
185
+ " !git reset --hard 376358d8854472b9ea50e9fc8800367d1ca51137 # stable commit :3\n",
186
+ " del cap\n",
187
+ " print(f\"\\r✨ {action} Completed!\")\n",
188
+ "\n",
189
+ "\n",
190
+ "# === FIXING EXTENSIONS ===\n",
191
+ "anxety_repos = \"https://huggingface.co/NagisaNao/fast_repo/resolve/main\"\n",
192
+ "\n",
193
+ "with capture.capture_output() as cap:\n",
194
+ " # --- Encrypt-Image ---\n",
195
+ " !sed -i '9,37d' {webui_path}/extensions/Encrypt-Image/javascript/encrypt_images_info.js\n",
196
+ "\n",
197
+ " # --- Additional-Networks ---\n",
198
+ " !wget -O {webui_path}/extensions/additional-networks/scripts/metadata_editor.py {anxety_repos}/extensions/Additional-Networks/fix/metadata_editor.py\n",
199
+ "del cap\n",
200
+ "\n",
201
+ "\n",
202
+ "## Version switching\n",
203
+ "if commit_hash:\n",
204
+ " print('⏳ Time machine activation...', end=\"\", flush=True)\n",
205
+ " with capture.capture_output() as cap:\n",
206
+ " %cd {webui_path}\n",
207
+ " !git config --global user.email \"[email protected]\"\n",
208
+ " !git config --global user.name \"Your Name\"\n",
209
+ " !git reset --hard {commit_hash}\n",
210
+ " del cap\n",
211
+ " print(f\"\\r⌛️ The time machine has been activated! Current commit: \\033[34m{commit_hash}\\033[0m\")\n",
212
+ "\n",
213
+ "\n",
214
+ "## Downloading model and stuff | oh yeah~ I'm starting to misunderstand my own code ( almost my own ;3 )\n",
215
+ "print(\"📦 Downloading models and stuff...\", end='')\n",
216
+ "model_list = {\n",
217
+ " \"1.Anime (by XpucT) + INP\": [\n",
218
+ " {\"url\": \"https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2.safetensors\", \"name\": \"Anime_v2.safetensors\"},\n",
219
+ " {\"url\": \"https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2-inpainting.safetensors\", \"name\": \"Anime_v2-inpainting.safetensors\"}\n",
220
+ " ],\n",
221
+ " \"2.BluMix [Anime] [V7] + INP\": [\n",
222
+ " {\"url\": \"https://civitai.com/api/download/models/361779\", \"name\": \"BluMix_v7.safetensors\"},\n",
223
+ " {\"url\": \"https://civitai.com/api/download/models/363850\", \"name\": \"BluMix_v7-inpainting.safetensors\"}\n",
224
+ " ],\n",
225
+ " \"3.Cetus-Mix [Anime] [V4] + INP\": [\n",
226
+ " {\"url\": \"https://civitai.com/api/download/models/130298\", \"name\": \"CetusMix_V4.safetensors\"},\n",
227
+ " {\"url\": \"https://civitai.com/api/download/models/139882\", \"name\": \"CetusMix_V4-inpainting.safetensors\"}\n",
228
+ " ],\n",
229
+ " \"4.Counterfeit [Anime] [V3] + INP\": [\n",
230
+ " {\"url\": \"https://civitai.com/api/download/models/125050\", \"name\": \"Counterfeit_V3.safetensors\"},\n",
231
+ " {\"url\": \"https://civitai.com/api/download/models/137911\", \"name\": \"Counterfeit_V3-inpainting.safetensors\"}\n",
232
+ " ],\n",
233
+ " \"5.CuteColor [Anime] [V3]\": [\n",
234
+ " {\"url\": \"https://civitai.com/api/download/models/138754\", \"name\": \"CuteColor_V3.safetensors\"}\n",
235
+ " ],\n",
236
+ " \"6.Dark-Sushi-Mix [Anime]\": [\n",
237
+ " {\"url\": \"https://civitai.com/api/download/models/101640\", \"name\": \"DarkSushiMix_2_5D.safetensors\"},\n",
238
+ " {\"url\": \"https://civitai.com/api/download/models/56071\", \"name\": \"DarkSushiMix_colorful.safetensors\"}\n",
239
+ " ],\n",
240
+ " \"7.Deliberate [Realism] [V6] + INP\": [\n",
241
+ " {\"url\": \"https://huggingface.co/XpucT/Deliberate/resolve/main/Deliberate_v6.safetensors\", \"name\": \"Deliberate_v6.safetensors\"},\n",
242
+ " {\"url\": \"https://huggingface.co/XpucT/Deliberate/resolve/main/Deliberate_v6-inpainting.safetensors\", \"name\": \"Deliberate_v6-inpainting.safetensors\"}\n",
243
+ " ],\n",
244
+ " \"8.Meina-Mix [Anime] [V11] + INP\": [\n",
245
+ " {\"url\": \"https://civitai.com/api/download/models/119057\", \"name\": \"MeinaMix_V11.safetensors\"},\n",
246
+ " {\"url\": \"https://civitai.com/api/download/models/120702\", \"name\": \"MeinaMix_V11-inpainting.safetensors\"}\n",
247
+ " ],\n",
248
+ " \"9.Mix-Pro [Anime] [V4] + INP\": [\n",
249
+ " {\"url\": \"https://civitai.com/api/download/models/125668\", \"name\": \"MixPro_V4.safetensors\"},\n",
250
+ " {\"url\": \"https://civitai.com/api/download/models/139878\", \"name\": \"MixPro_V4-inpainting.safetensors\"}\n",
251
+ " ]\n",
252
+ "}\n",
253
+ "\n",
254
+ "# 1-4 (fp16/cleaned)\n",
255
+ "vae_list = {\n",
256
+ " \"1.Anime.vae\": [\n",
257
+ " {\"url\": \"https://civitai.com/api/download/models/131654\", \"name\": \"Anime.vae.safetensors\"},\n",
258
+ " {\"url\": \"https://civitai.com/api/download/models/131658\", \"name\": \"vae-ft-mse.vae.safetensors\"}\n",
259
+ " ],\n",
260
+ " \"2.Anything.vae\": [{\"url\": \"https://civitai.com/api/download/models/131656\", \"name\": \"Anything.vae.safetensors\"}],\n",
261
+ " \"3.Blessed2.vae\": [{\"url\": \"https://civitai.com/api/download/models/142467\", \"name\": \"Blessed2.vae.safetensors\"}],\n",
262
+ " \"4.ClearVae.vae\": [{\"url\": \"https://civitai.com/api/download/models/133362\", \"name\": \"ClearVae_23.vae.safetensors\"}],\n",
263
+ " \"5.WD.vae\": [{\"url\": \"https://huggingface.co/NoCrypt/resources/resolve/main/VAE/wd.vae.safetensors\", \"name\": \"WD.vae.safetensors\"}]\n",
264
+ "}\n",
265
+ "\n",
266
+ "controlnet_list = {\n",
267
+ " \"1.canny\": [\n",
268
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny_fp16.safetensors\", \"name\": \"control_v11p_sd15_canny_fp16.safetensors\"},\n",
269
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_canny_fp16.yaml\", \"name\": \"control_v11p_sd15_canny_fp16.yaml\"}\n",
270
+ " ],\n",
271
+ " \"2.openpose\": [\n",
272
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose_fp16.safetensors\", \"name\": \"control_v11p_sd15_openpose_fp16.safetensors\"},\n",
273
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_openpose_fp16.yaml\", \"name\": \"control_v11p_sd15_openpose_fp16.yaml\"}\n",
274
+ " ],\n",
275
+ " \"3.depth\": [\n",
276
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth_fp16.safetensors\", \"name\": \"control_v11f1p_sd15_depth_fp16.safetensors\"},\n",
277
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1p_sd15_depth_fp16.yaml\", \"name\": \"control_v11f1p_sd15_depth_fp16.yaml\"},\n",
278
+ " {\"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",
279
+ " ],\n",
280
+ " \"4.normal_map\": [\n",
281
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_normalbae_fp16.safetensors\", \"name\": \"control_v11p_sd15_normalbae_fp16.safetensors\"},\n",
282
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_normalbae_fp16.yaml\", \"name\": \"control_v11p_sd15_normalbae_fp16.yaml\"}\n",
283
+ " ],\n",
284
+ " \"5.mlsd\": [\n",
285
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_mlsd_fp16.safetensors\", \"name\": \"control_v11p_sd15_mlsd_fp16.safetensors\"},\n",
286
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_mlsd_fp16.yaml\", \"name\": \"control_v11p_sd15_mlsd_fp16.yaml\"}\n",
287
+ " ],\n",
288
+ " \"6.lineart\": [\n",
289
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart_fp16.safetensors\", \"name\": \"control_v11p_sd15_lineart_fp16.safetensors\"},\n",
290
+ " {\"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",
291
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_lineart_fp16.yaml\", \"name\": \"control_v11p_sd15_lineart_fp16.yaml\"},\n",
292
+ " {\"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",
293
+ " ],\n",
294
+ " \"7.soft_edge\": [\n",
295
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge_fp16.safetensors\", \"name\": \"control_v11p_sd15_softedge_fp16.safetensors\"},\n",
296
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_softedge_fp16.yaml\", \"name\": \"control_v11p_sd15_softedge_fp16.yaml\"}\n",
297
+ " ],\n",
298
+ " \"8.scribble\": [\n",
299
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble_fp16.safetensors\", \"name\": \"control_v11p_sd15_scribble_fp16.safetensors\"},\n",
300
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_scribble_fp16.yaml\", \"name\": \"control_v11p_sd15_scribble_fp16.yaml\"}\n",
301
+ " ],\n",
302
+ " \"9.segmentation\": [\n",
303
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg_fp16.safetensors\", \"name\": \"control_v11p_sd15_seg_fp16.safetensors\"},\n",
304
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_seg_fp16.yaml\", \"name\": \"control_v11p_sd15_seg_fp16.yaml\"}\n",
305
+ " ],\n",
306
+ " \"10.shuffle\": [\n",
307
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle_fp16.safetensors\", \"name\": \"control_v11e_sd15_shuffle_fp16.safetensors\"},\n",
308
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_shuffle_fp16.yaml\", \"name\": \"control_v11e_sd15_shuffle_fp16.yaml\"}\n",
309
+ " ],\n",
310
+ " \"11.tile\": [\n",
311
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile_fp16.safetensors\", \"name\": \"control_v11f1e_sd15_tile_fp16.safetensors\"},\n",
312
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1e_sd15_tile_fp16.yaml\", \"name\": \"control_v11f1e_sd15_tile_fp16.yaml\"}\n",
313
+ " ],\n",
314
+ " \"12.inpaint\": [\n",
315
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_inpaint_fp16.safetensors\", \"name\": \"control_v11p_sd15_inpaint_fp16.safetensors\"},\n",
316
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_inpaint_fp16.yaml\", \"name\": \"control_v11p_sd15_inpaint_fp16.yaml\"}\n",
317
+ " ],\n",
318
+ " \"13.instruct_p2p\": [\n",
319
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p_fp16.safetensors\", \"name\": \"control_v11e_sd15_ip2p_fp16.safetensors\"},\n",
320
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_ip2p_fp16.yaml\", \"name\": \"control_v11e_sd15_ip2p_fp16.yaml\"}\n",
321
+ " ]\n",
322
+ "}\n",
323
+ "\n",
324
+ "extension_repo = []\n",
325
+ "prefixes = {\n",
326
+ " # It's complicated, but supplementing has become easier\n",
327
+ " \"model\": [models_dir, \"Model_url\"],\n",
328
+ " \"vae\": [vaes_dir, \"Vae_url\"],\n",
329
+ " \"lora\": [loras_dir, \"LoRA_url\"],\n",
330
+ " \"embed\": [embeddings_dir, \"Embedding_url\"],\n",
331
+ " \"extension\": [extensions_dir, \"Extensions_url\"],\n",
332
+ " \"control\": [control_dir, \"ControlNet_url\"]\n",
333
+ "}\n",
334
+ "\n",
335
+ "!mkdir -p {models_dir} {vaes_dir} {loras_dir} {embeddings_dir} {extensions_dir} {control_dir}\n",
336
+ "\n",
337
+ "url = \"\"\n",
338
+ "ControlNet_url = \"\"\n",
339
+ "hf_token = optional_huggingface_token if optional_huggingface_token else \"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\"\n",
340
+ "user_header = f\"\\\"Authorization: Bearer {hf_token}\\\"\"\n",
341
+ "\n",
342
+ "''' main download code '''\n",
343
+ "\n",
344
+ "def handle_manual(url):\n",
345
+ " original_url = url\n",
346
+ " url = url.split(':', 1)[1]\n",
347
+ " file_name = re.search(r'\\[(.*?)\\]', url)\n",
348
+ " file_name = file_name.group(1) if file_name else None\n",
349
+ " if file_name:\n",
350
+ " url = re.sub(r'\\[.*?\\]', '', url)\n",
351
+ "\n",
352
+ " for prefix, (dir, _) in prefixes.items():\n",
353
+ " if original_url.startswith(f\"{prefix}:\"):\n",
354
+ " if prefix != \"extension\":\n",
355
+ " manual_download(url, dir, file_name=file_name)\n",
356
+ " else:\n",
357
+ " extension_repo.append((url, file_name))\n",
358
+ "\n",
359
+ "def manual_download(url, dst_dir, file_name):\n",
360
+ " basename = url.split(\"/\")[-1] if file_name is None else file_name\n",
361
+ " header_option = f\"--header={user_header}\"\n",
362
+ "\n",
363
+ " print(\"\\033[32m---\"*45 + f\"\\n\\033[33mURL: \\033[34m{url}\\n\\033[33mSAVE DIR: \\033[34m{dst_dir}\\n\\033[33mFILE NAME: \\033[34m{file_name}\\033[32m\\n~~~\\033[0m\")\n",
364
+ "\n",
365
+ " # I do it at my own risk..... Fucking CivitAi >:(\n",
366
+ " civitai_token = \"62c0c5956b2f9defbd844d754000180b\"\n",
367
+ " if 'civitai' in url and civitai_token:\n",
368
+ " url = f\"{url}?token={civitai_token}\"\n",
369
+ "\n",
370
+ " # -- GDrive --\n",
371
+ " if 'drive.google' in url:\n",
372
+ " if 'folders' in url:\n",
373
+ " !gdown --folder \"{url}\" -O {dst_dir} --fuzzy -c\n",
374
+ " else:\n",
375
+ " if file_name:\n",
376
+ " !gdown \"{url}\" -O {dst_dir}/{file_name} --fuzzy -c\n",
377
+ " else:\n",
378
+ " !gdown \"{url}\" -O {dst_dir} --fuzzy -c\n",
379
+ " # -- Huggin Face --\n",
380
+ " elif 'huggingface' in url:\n",
381
+ " if '/blob/' in url:\n",
382
+ " url = url.replace('/blob/', '/resolve/')\n",
383
+ " if file_name:\n",
384
+ " !aria2c {header_option} --optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -c -j5 -x16 -s16 -k1M -d {dst_dir} -o {basename} {url}\n",
385
+ " else:\n",
386
+ " parsed_link = f'\\n{url}\\n\\tout={unquote(url.split(\"/\")[-1])}'\n",
387
+ " !echo -e \"{parsed_link}\" | aria2c {header_option} --console-log-level=error --summary-interval=10 -i- -j5 -x16 -s16 -k1M -c -d \"{dst_dir}\" -o {basename}\n",
388
+ " # -- Other --\n",
389
+ " elif 'http' in url or 'magnet' in url:\n",
390
+ " if file_name:\n",
391
+ " !aria2c --optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c -d {dst_dir} -o {file_name} {url}\n",
392
+ " else:\n",
393
+ " parsed_link = '\"{}\"'.format(url)\n",
394
+ " !aria2c --optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c -d {dst_dir} -Z {parsed_link}\n",
395
+ "\n",
396
+ "def download(url):\n",
397
+ " links_and_paths = url.split(',')\n",
398
+ "\n",
399
+ " for link_or_path in links_and_paths:\n",
400
+ " link_or_path = link_or_path.strip()\n",
401
+ " if not link_or_path:\n",
402
+ " continue\n",
403
+ " if any(link_or_path.startswith(prefix.lower()) for prefix in prefixes):\n",
404
+ " handle_manual(link_or_path)\n",
405
+ " continue\n",
406
+ "\n",
407
+ " url, dst_dir, file_name = link_or_path.split()\n",
408
+ " manual_download(url, dst_dir, file_name)\n",
409
+ "\n",
410
+ "''' submodels - added urls '''\n",
411
+ "\n",
412
+ "submodels = []\n",
413
+ "\n",
414
+ "def add_submodels(selection, num_selection, model_dict, dst_dir):\n",
415
+ " if selection == \"none\":\n",
416
+ " return []\n",
417
+ " if selection == \"ALL\":\n",
418
+ " all_models = []\n",
419
+ " for models in model_dict.values():\n",
420
+ " all_models.extend(models)\n",
421
+ " selected_models = all_models\n",
422
+ " else:\n",
423
+ " selected_models = model_dict[selection]\n",
424
+ " selected_nums = map(int, num_selection.replace(',', '').split())\n",
425
+ "\n",
426
+ " for num in selected_nums:\n",
427
+ " if 1 <= num <= len(model_dict):\n",
428
+ " name = list(model_dict)[num - 1]\n",
429
+ " selected_models.extend(model_dict[name])\n",
430
+ "\n",
431
+ " unique_models = list({model['name']: model for model in selected_models}.values())\n",
432
+ "\n",
433
+ " for model in unique_models:\n",
434
+ " model['dst_dir'] = dst_dir\n",
435
+ "\n",
436
+ " return unique_models\n",
437
+ "\n",
438
+ "submodels += add_submodels(Model, Model_Num, model_list, models_dir) # model\n",
439
+ "submodels += add_submodels(Vae, Vae_Num, vae_list, vaes_dir) # vae\n",
440
+ "submodels += add_submodels(controlnet, \"\" if controlnet == \"ALL\" else controlnet_Num, controlnet_list, control_dir) # controlnet\n",
441
+ "\n",
442
+ "for submodel in submodels:\n",
443
+ " if not Inpainting_Model and \"inpainting\" in submodel['name']:\n",
444
+ " continue\n",
445
+ " url += f\"{submodel['url']} {submodel['dst_dir']} {submodel['name']}, \"\n",
446
+ "\n",
447
+ "''' file.txt - added urls '''\n",
448
+ "\n",
449
+ "unique_urls = []\n",
450
+ "\n",
451
+ "def process_file_download(file_url):\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 any(f'# {tag}' in line.lower() for tag in prefixes):\n",
464
+ " current_tag = next((tag for tag in prefixes if tag in line.lower()))\n",
465
+ "\n",
466
+ " urls = [url.strip() for url in line.split(',')]\n",
467
+ " for url in urls:\n",
468
+ " if url.startswith(\"http\") and url not in unique_urls:\n",
469
+ " globals()[prefixes[current_tag][1]] += \", \" + url\n",
470
+ " unique_urls.append(url)\n",
471
+ "\n",
472
+ "# fix all possible errors/options and function call\n",
473
+ "if custom_file_urls:\n",
474
+ " for custom_file_url in custom_file_urls.replace(',', '').split():\n",
475
+ " if not custom_file_url.endswith('.txt'):\n",
476
+ " custom_file_url += '.txt'\n",
477
+ " if not custom_file_url.startswith('http'):\n",
478
+ " if not custom_file_url.startswith(root_path):\n",
479
+ " custom_file_url = f'{root_path}/{custom_file_url}'\n",
480
+ "\n",
481
+ " try:\n",
482
+ " process_file_download(custom_file_url)\n",
483
+ " except FileNotFoundError:\n",
484
+ " pass\n",
485
+ "\n",
486
+ "# url prefixing\n",
487
+ "urls = [globals()[urls[1]] for urls in prefixes.values()]\n",
488
+ "for i, prefix in enumerate(prefixes):\n",
489
+ " if urls[i]:\n",
490
+ " prefixed_urls = [f\"{prefix}:{url}\" for url 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 {webui_path} \\( -type d \\( -name \".ipynb_checkpoints\" -o -name \".aria2\" \\) -o -type f -name \"*.aria2\" \\) -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"
560
+ ],
561
+ "metadata": {
562
+ "id": "2lJmbqrs3Mu8"
563
+ },
564
+ "execution_count": null,
565
+ "outputs": []
566
+ }
567
+ ]
568
+ }
files_cells/notebooks/en/launch_en.ipynb ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ " free_plan = (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024. ** 3) <= 20)\n",
38
+ " environments = {\n",
39
+ " 'COLAB_GPU': ('Google Colab', \"/root\" if free_plan else \"/content\"),\n",
40
+ " 'KAGGLE_URL_BASE': ('Kaggle', \"/kaggle/working/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, free_plan\n",
46
+ "\n",
47
+ "env, root_path, free_plan = 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
+ "zrok_token = settings['zrok_token']\n",
61
+ "commandline_arguments = settings['commandline_arguments']\n",
62
+ "\n",
63
+ "\n",
64
+ "# ======================== TUNNEL ========================\n",
65
+ "import cloudpickle as pickle\n",
66
+ "\n",
67
+ "def get_public_ip(version='ipv4'):\n",
68
+ " try:\n",
69
+ " url = f'https://api64.ipify.org?format=json&{version}=true'\n",
70
+ " response = requests.get(url)\n",
71
+ " data = response.json()\n",
72
+ " public_ip = data['ip']\n",
73
+ " return public_ip\n",
74
+ " except Exception as e:\n",
75
+ " print(f\"Error getting public {version} address:\", e)\n",
76
+ "\n",
77
+ "public_ipv4 = get_public_ip(version='ipv4')\n",
78
+ "\n",
79
+ "tunnel_class = pickle.load(open(f\"{root_path}/new_tunnel\", \"rb\"), encoding=\"utf-8\")\n",
80
+ "tunnel_port= 1769\n",
81
+ "tunnel = tunnel_class(tunnel_port)\n",
82
+ "tunnel.add_tunnel(command=\"cl tunnel --url localhost:{port}\", name=\"cl\", pattern=re.compile(r\"[\\w-]+\\.trycloudflare\\.com\"))\n",
83
+ "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",
84
+ "\n",
85
+ "''' add zrok tunnel '''\n",
86
+ "if zrok_token:\n",
87
+ " get_ipython().system('zrok enable {zrok_token} &> /dev/null')\n",
88
+ " tunnel.add_tunnel(command=\"zrok share public http://localhost:{port}/ --headless\", name=\"zrok\", pattern=re.compile(r\"[\\w-]+\\.share\\.zrok\\.io\"))\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
+ "with tunnel:\n",
100
+ " %cd {webui_path}\n",
101
+ " commandline_arguments += f\" --port=1769\"\n",
102
+ "\n",
103
+ " if ngrok_token:\n",
104
+ " commandline_arguments += ' --ngrok ' + ngrok_token\n",
105
+ " if env != \"Google Colab\":\n",
106
+ " commandline_arguments += f\" --encrypt-pass=1769\"\n",
107
+ "\n",
108
+ " !COMMANDLINE_ARGS=\"{commandline_arguments}\" python launch.py\n",
109
+ "\n",
110
+ " start_colab = float(open(f'{webui_path}/static/colabTimer.txt', 'r').read())\n",
111
+ " time_since_start = str(timedelta(seconds=time.time()-start_colab)).split('.')[0]\n",
112
+ " print(f\"\\n⌚️ \\033[0mYou have been conducting this session for - \\033[33m{time_since_start}\\033[0m\\n\\n\")"
113
+ ]
114
+ }
115
+ ]
116
+ }
files_cells/notebooks/en/widgets_en.ipynb ADDED
@@ -0,0 +1,628 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 time\n",
25
+ "import ipywidgets as widgets\n",
26
+ "from ipywidgets import widgets, Layout, Label, Button, VBox, HBox\n",
27
+ "from IPython.display import display, HTML, Javascript, clear_output\n",
28
+ "\n",
29
+ "\n",
30
+ "# ================= DETECT ENV =================\n",
31
+ "def detect_environment():\n",
32
+ " free_plan = (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024. ** 3) <= 20)\n",
33
+ " environments = {\n",
34
+ " 'COLAB_GPU': ('Google Colab', \"/root\" if free_plan else \"/content\"),\n",
35
+ " 'KAGGLE_URL_BASE': ('Kaggle', \"/kaggle/working/content\")\n",
36
+ " }\n",
37
+ "\n",
38
+ " for env_var, (environment, path) in environments.items():\n",
39
+ " if env_var in os.environ:\n",
40
+ " return environment, path, free_plan\n",
41
+ "\n",
42
+ "env, root_path, free_plan = detect_environment()\n",
43
+ "webui_path = f\"{root_path}/sdw\"\n",
44
+ "\n",
45
+ "!mkdir -p {root_path}\n",
46
+ "# ----------------------------------------------\n",
47
+ "\n",
48
+ "\n",
49
+ "# ==================== CSS JS ====================\n",
50
+ "# custom background images V1.5\n",
51
+ "import argparse\n",
52
+ "parser = argparse.ArgumentParser(description='This script processes an background image.')\n",
53
+ "parser.add_argument('-i', '--image', type=str, help='URL of the image to process', metavar='')\n",
54
+ "parser.add_argument('-o', '--opacity', type=float, help='Opacity level for the image, between 0 and 1', metavar='', default=0.3)\n",
55
+ "parser.add_argument('-b', '--blur', type=str, help='Blur level for the image', metavar='', default=0)\n",
56
+ "parser.add_argument('-y', type=int, help='Y coordinate for the image in px', metavar='', default=0)\n",
57
+ "parser.add_argument('-x', type=int, help='X coordinate for the image in px', metavar='', default=0)\n",
58
+ "parser.add_argument('-s', '--scale', type=int, help='Scale image in %%', metavar='', default=100)\n",
59
+ "parser.add_argument('-m', '--mode', action='store_true', help='Removes repetitive image tiles')\n",
60
+ "parser.add_argument('-t', '--transparent', action='store_true', help='Makes input/selection fields 35%% more transparent')\n",
61
+ "parser.add_argument('-bf', '--blur-fields', type=str, help='Background blur level for input/selection fields', metavar='', default=2)\n",
62
+ "args = parser.parse_args()\n",
63
+ "\"\"\"---\"\"\"\n",
64
+ "url_img = args.image\n",
65
+ "opacity_img = args.opacity\n",
66
+ "blur_img = args.blur\n",
67
+ "y_img = args.y\n",
68
+ "x_img = args.x\n",
69
+ "scale_img = args.scale\n",
70
+ "blur_fields = args.blur_fields\n",
71
+ "\n",
72
+ "## ---\n",
73
+ "\"\"\" WTF KAGGLE - WHAT THE FUCK IS THE DIFFERENCE OF 35 PIXELS!?!?!? \"\"\"\n",
74
+ "fix_heigh_img = \"-810px\" if env == \"Kaggle\" else \"-775px\"\n",
75
+ "\n",
76
+ "\"\"\" transperent fields \"\"\"\n",
77
+ "t_bg_alpha = \"1\" if not args.transparent else \"0.65\"\n",
78
+ "\n",
79
+ "\"\"\" mode img - repeats \"\"\"\n",
80
+ "mode_img = \"repeat\" if not args.mode else \"no-repeat\"\n",
81
+ "## ---\n",
82
+ "\n",
83
+ "container_background = f'''\n",
84
+ "<style>\n",
85
+ ":root {{\n",
86
+ " /* for background container*/\n",
87
+ " --img_background: url({url_img});\n",
88
+ " --img_opacity: {opacity_img};\n",
89
+ " --img_blur: {blur_img}px;\n",
90
+ " --image_y: {y_img}px;\n",
91
+ " --image_x: {x_img}px;\n",
92
+ " --img_scale: {scale_img}%;\n",
93
+ " --img_mode: {mode_img};\n",
94
+ " --img_height_dif: {fix_heigh_img};\n",
95
+ "\n",
96
+ " /* for fields */\n",
97
+ " --bg-field-color: rgba(28, 28, 28, {t_bg_alpha}); /* -> #1c1c1c */\n",
98
+ " --bg-field-color-hover: rgba(38, 38, 38, {t_bg_alpha}); /* -> #262626; */\n",
99
+ " --bg-field-blur-level: {blur_fields}px;\n",
100
+ "}}\n",
101
+ "'''\n",
102
+ "\n",
103
+ "display(HTML(container_background))\n",
104
+ "# ---\n",
105
+ "\n",
106
+ "CSS = '''\n",
107
+ "<style>\n",
108
+ "/* General Styles */\n",
109
+ ".header {\n",
110
+ " font-family: cursive;\n",
111
+ " font-size: 20px;\n",
112
+ " font-weight: bold;\n",
113
+ " color: #ff8cee;\n",
114
+ " margin-bottom: 15px;\n",
115
+ " user-select: none;\n",
116
+ " cursor: default;\n",
117
+ " display: inline-block;\n",
118
+ "}\n",
119
+ "\n",
120
+ "hr {\n",
121
+ " border-color: grey;\n",
122
+ " background-color: grey;\n",
123
+ " opacity: 0.25;\n",
124
+ "}\n",
125
+ "\n",
126
+ "a {\n",
127
+ " text-decoration: none;\n",
128
+ " color: inherit;\n",
129
+ "}\n",
130
+ "\n",
131
+ "\n",
132
+ "/* Container style */\n",
133
+ "\n",
134
+ ".container {\n",
135
+ " position: relative;\n",
136
+ " background-color: #232323;\n",
137
+ " width: 1080px;\n",
138
+ " padding: 10px 15px;\n",
139
+ " border-radius: 15px;\n",
140
+ " box-shadow: 0 0 50px rgba(0, 0, 0, 0.3);\n",
141
+ " margin-bottom: 5px;\n",
142
+ " overflow: hidden;\n",
143
+ "}\n",
144
+ "\n",
145
+ ".container::after {\n",
146
+ " position: absolute;\n",
147
+ " top: 5px;\n",
148
+ " right: 10px;\n",
149
+ " content: \"ANXETY\";\n",
150
+ " font-weight: bold;\n",
151
+ " font-size: 24px;\n",
152
+ " color: rgba(0, 0, 0, 0.2);\n",
153
+ "}\n",
154
+ "\n",
155
+ "/* background img */\n",
156
+ ".container::before {\n",
157
+ " content: \"\";\n",
158
+ " position: absolute;\n",
159
+ " top: 0;\n",
160
+ " left: 0;\n",
161
+ " right: 0;\n",
162
+ " bottom: 0;\n",
163
+ " background-image: var(--img_background);\n",
164
+ " background-size: var(--img_scale);\n",
165
+ " background-repeat: var(--img_mode);\n",
166
+ " opacity: var(--img_opacity);\n",
167
+ " mix-blend-mode: screen;\n",
168
+ " pointer-events: none;\n",
169
+ " filter: blur(var(--img_blur));\n",
170
+ " z-index: -1;\n",
171
+ "}\n",
172
+ "\n",
173
+ ".image_1::before {\n",
174
+ " background-position: var(--image_x) calc(-120px - var(--image_y));\n",
175
+ "}\n",
176
+ ".image_2::before {\n",
177
+ " background-position: var(--image_x) calc(-290px - var(--image_y));\n",
178
+ "}\n",
179
+ ".image_3::before {\n",
180
+ " background-position: var(--image_x) calc(-430px - var(--image_y));\n",
181
+ "}\n",
182
+ ".image_4::before {\n",
183
+ " background-position: var(--image_x) calc(var(--img_height_dif) - var(--image_y));\n",
184
+ "}\n",
185
+ "\n",
186
+ ".container_custom_downlad {\n",
187
+ " height: 55px;\n",
188
+ " transition: all 0.5s;\n",
189
+ "}\n",
190
+ "\n",
191
+ ".container_custom_downlad.expanded {\n",
192
+ " height: 270px;\n",
193
+ "}\n",
194
+ "\n",
195
+ "\n",
196
+ "/* Element text style */\n",
197
+ "\n",
198
+ ".widget-html,\n",
199
+ ".widget-button,\n",
200
+ ".widget-text label,\n",
201
+ ".widget-checkbox label,\n",
202
+ ".widget-dropdown label,\n",
203
+ ".widget-dropdown select,\n",
204
+ ".widget-text input[type=\"text\"] {\n",
205
+ " font-family: cursive;\n",
206
+ " font-size: 14px;\n",
207
+ " color: white !important;\n",
208
+ " user-select: none;\n",
209
+ "}\n",
210
+ "\n",
211
+ ".widget-text input[type=\"text\"]::placeholder {\n",
212
+ " color: grey;\n",
213
+ "}\n",
214
+ "\n",
215
+ "\n",
216
+ "/* Input field styles */\n",
217
+ "\n",
218
+ ".widget-dropdown select,\n",
219
+ ".widget-text input[type=\"text\"] {\n",
220
+ " height: 30px;\n",
221
+ " background-color: var(--bg-field-color);\n",
222
+ " border: 1px solid #262626;\n",
223
+ " border-radius: 10px;\n",
224
+ " box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);\n",
225
+ " transition: all 0.3s ease-in-out;\n",
226
+ " backdrop-filter: blur(var(--bg-field-blur-level));\n",
227
+ "}\n",
228
+ "\n",
229
+ ".widget-dropdown select:focus,\n",
230
+ ".widget-text input[type=\"text\"]:focus {\n",
231
+ " border-color: #006ee5;\n",
232
+ "}\n",
233
+ "\n",
234
+ ".widget-dropdown select:hover,\n",
235
+ ".widget-text input[type=\"text\"]:hover {\n",
236
+ " transform: scale(1.003);\n",
237
+ " background-color: var(--bg-field-color-hover);\n",
238
+ " box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);\n",
239
+ "}\n",
240
+ "\n",
241
+ ".widget-dropdown option {\n",
242
+ " background-color: #1c1c1c;\n",
243
+ "}\n",
244
+ "\n",
245
+ "\n",
246
+ "/* Slider Checkbox style */\n",
247
+ "\n",
248
+ ".widget-checkbox input[type=\"checkbox\"] {\n",
249
+ " appearance: none;\n",
250
+ " position: relative;\n",
251
+ " top: 4px; /* Why is he taller?! */\n",
252
+ " width: 40px;\n",
253
+ " height: 20px;\n",
254
+ " border: none;\n",
255
+ " border-radius: 10px;\n",
256
+ " background-color: #20b2aa;\n",
257
+ " cursor: pointer;\n",
258
+ " box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.3);\n",
259
+ " transition: background-color 0.3s ease;\n",
260
+ "}\n",
261
+ ".widget-checkbox input[type=\"checkbox\"]:checked {\n",
262
+ " background-color: #2196F3;\n",
263
+ "}\n",
264
+ "\n",
265
+ ".widget-checkbox input[type=\"checkbox\"]:before {\n",
266
+ " content: '';\n",
267
+ " position: absolute;\n",
268
+ " top: 50%;\n",
269
+ " left: 3px;\n",
270
+ " width: 16px;\n",
271
+ " height: 16px;\n",
272
+ " border-radius: inherit;\n",
273
+ " background-color: white;\n",
274
+ " box-shadow: 0 0 8px rgba(0, 0, 0, 0.3);\n",
275
+ " transform: translateY(-50%);\n",
276
+ " transition: left 0.3s ease;\n",
277
+ "}\n",
278
+ ".widget-checkbox input[type=\"checkbox\"]:checked:before {\n",
279
+ " left: 21px;\n",
280
+ "}\n",
281
+ "\n",
282
+ "\n",
283
+ "/* Button styles */\n",
284
+ "\n",
285
+ ".button_save {\n",
286
+ " font-size: 15px;\n",
287
+ " font-weight: bold;\n",
288
+ " width: 120px;\n",
289
+ " height: 35px;\n",
290
+ " border-radius: 15px;\n",
291
+ " background-image: radial-gradient(circle at top left, purple 10%, violet 90%);\n",
292
+ " background-size: 200% 200%;\n",
293
+ " background-position: left bottom;\n",
294
+ " transition: background 0.5s ease-in-out, transform 0.3s ease;\n",
295
+ "}\n",
296
+ "\n",
297
+ ".button_save:hover {\n",
298
+ " cursor: pointer;\n",
299
+ " background-image: radial-gradient(circle at top left, purple 10%, #93ac47 90%);\n",
300
+ " background-size: 200% 200%;\n",
301
+ " background-position: right bottom;\n",
302
+ " transform: translateY(1px);\n",
303
+ "}\n",
304
+ "\n",
305
+ ".button_ngrok {\n",
306
+ " font-size: 12px;\n",
307
+ " height: 30px;\n",
308
+ " border-radius: 10px;\n",
309
+ " padding: 1px 12px;\n",
310
+ " background-image: radial-gradient(circle at top left, purple 10%, violet 90%);\n",
311
+ " background-size: 200% 200%;\n",
312
+ " background-position: left bottom;\n",
313
+ " transition: background 0.5s ease-in-out, transform 0.3s ease;\n",
314
+ " white-space: nowrap;\n",
315
+ "}\n",
316
+ "\n",
317
+ ".button_ngrok:hover {\n",
318
+ " cursor: pointer;\n",
319
+ " background-image: radial-gradient(circle at top left, purple 10%, #1D94BB 90%);\n",
320
+ " background-size: 200% 200%;\n",
321
+ " background-position: right bottom;\n",
322
+ " transform: translateY(1px);\n",
323
+ "}\n",
324
+ "\n",
325
+ ".button_save:active,\n",
326
+ ".button_ngrok:active {\n",
327
+ " filter: brightness(0.75) !important;\n",
328
+ "}\n",
329
+ "\n",
330
+ "/* Removes ugly stroke from widget buttons. */\n",
331
+ ".jupyter-widgets.lm-Widget:focus {\n",
332
+ " outline: none;\n",
333
+ "}\n",
334
+ "\n",
335
+ "\n",
336
+ "/* Popup style of `INFO` window */\n",
337
+ "\n",
338
+ ".info {\n",
339
+ " position: absolute;\n",
340
+ " top: -5px;\n",
341
+ " right: 95px;\n",
342
+ " color: grey;\n",
343
+ " font-family: cursive;\n",
344
+ " font-size: 14px;\n",
345
+ " font-weight: normal;\n",
346
+ " user-select: none;\n",
347
+ " pointer-events: none;\n",
348
+ " opacity: 0;\n",
349
+ " transition: opacity 0.3s ease-in-out;\n",
350
+ " display: inline-block;\n",
351
+ "}\n",
352
+ "\n",
353
+ ".popup {\n",
354
+ " position: absolute;\n",
355
+ " top: 120px;\n",
356
+ " z-index: 999;\n",
357
+ " width: auto;\n",
358
+ " padding: 10px;\n",
359
+ " text-align: center;\n",
360
+ " background-color: rgba(255, 255, 255, 0.05);\n",
361
+ " backdrop-filter: blur(20px);\n",
362
+ " border: 1px solid rgba(255, 255, 255, 0.45);\n",
363
+ " border-radius: 8px;\n",
364
+ " box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);\n",
365
+ " opacity: 0;\n",
366
+ " color: #fff;\n",
367
+ " font-size: 16px;\n",
368
+ " font-family: cursive;\n",
369
+ " user-select: none;\n",
370
+ " cursor: default;\n",
371
+ " pointer-events: none;\n",
372
+ " transform: rotate(-5deg);\n",
373
+ " transition: top 0.3s ease-in-out, opacity 0.3s ease-in-out, transform 0.3s ease-in-out;\n",
374
+ "}\n",
375
+ "\n",
376
+ ".sample {\n",
377
+ " display: inline-block;\n",
378
+ " margin-top: 25px;\n",
379
+ " padding: 10px 100px;\n",
380
+ " background-color: rgba(255, 255, 255, 0.2);\n",
381
+ " color: #c6e2ff;\n",
382
+ " border: 2px solid rgba(255, 255, 255, 0.2);\n",
383
+ " border-radius: 8px;\n",
384
+ " box-shadow: 0 0 10px rgba(255, 255, 255, 0.2), inset 0 0 25px rgba(255, 255, 255, 0.2);\n",
385
+ "}\n",
386
+ "\n",
387
+ ".info.showed {\n",
388
+ " opacity: 1;\n",
389
+ " pointer-events: auto;\n",
390
+ "}\n",
391
+ "\n",
392
+ ".info:hover + .popup {\n",
393
+ " top: 35px;\n",
394
+ " opacity: 1;\n",
395
+ " pointer-events: initial;\n",
396
+ " transform: rotate(0deg);\n",
397
+ "}\n",
398
+ "\n",
399
+ "\n",
400
+ "/* Animation of elements */\n",
401
+ "\n",
402
+ ".container,\n",
403
+ ".button_save {\n",
404
+ " animation-name: showedWidgets;\n",
405
+ " animation-duration: 1s;\n",
406
+ " animation-fill-mode: forwards;\n",
407
+ "}\n",
408
+ "\n",
409
+ ".container.hide,\n",
410
+ ".button_save.hide {\n",
411
+ " animation-name: hideWidgets;\n",
412
+ " animation-duration: 0.5s;\n",
413
+ " animation-fill-mode: forwards;\n",
414
+ "}\n",
415
+ "\n",
416
+ "@keyframes showedWidgets {\n",
417
+ " 0% {\n",
418
+ " transform: translate3d(-65%, 15%, 0) scale(0) rotate(15deg);\n",
419
+ " filter: blur(25px) grayscale(1) brightness(0.3);\n",
420
+ " opacity: 0;\n",
421
+ " }\n",
422
+ " 100% {\n",
423
+ " transform: translate3d(0, 0, 0) scale(1) rotate(0deg);\n",
424
+ " filter: blur(0) grayscale(0) brightness(1);\n",
425
+ " opacity: 1;\n",
426
+ " }\n",
427
+ "}\n",
428
+ "\n",
429
+ "@keyframes hideWidgets {\n",
430
+ " 0% {\n",
431
+ " transform: translate3d(0, 0, 0) scale(1) rotate3d(1, 0, 0, 0deg);\n",
432
+ " filter: blur(0) grayscale(0) brightness(1);\n",
433
+ " opacity: 1;\n",
434
+ " }\n",
435
+ " 100% {\n",
436
+ " transform: translate3d(0, 5%, 0) scale(0.9) rotate3d(1, 0, 0, 90deg);\n",
437
+ " filter: blur(15px) grayscale(1) brightness(0.5);\n",
438
+ " opacity: 0;\n",
439
+ " }\n",
440
+ "}\n",
441
+ "</style>\n",
442
+ "\n",
443
+ "<!-- TOGGLE 'CustomDL' SCRIPT -->\n",
444
+ "<script>\n",
445
+ "function toggleContainer() {\n",
446
+ " let downloadContainer = document.querySelector('.container_custom_downlad');\n",
447
+ " let info = document.querySelector('.info');\n",
448
+ "\n",
449
+ " downloadContainer.classList.toggle('expanded');\n",
450
+ " info.classList.toggle('showed');\n",
451
+ "}\n",
452
+ "</script>\n",
453
+ "'''\n",
454
+ "\n",
455
+ "display(HTML(CSS))\n",
456
+ "# ==================== CSS JS ====================\n",
457
+ "\n",
458
+ "\n",
459
+ "# ==================== WIDGETS ====================\n",
460
+ "# --- global widgets ---\n",
461
+ "style = {'description_width': 'initial'}\n",
462
+ "layout = widgets.Layout(min_width='1047px')\n",
463
+ "\n",
464
+ "HR = widgets.HTML('<hr>')\n",
465
+ "\n",
466
+ "# --- MODEL ---\n",
467
+ "model_header = widgets.HTML('<div class=\"header\">Model Selection<div>')\n",
468
+ "model_options = ['none',\n",
469
+ " '1.Anime (by XpucT) + INP',\n",
470
+ " '2.BluMix [Anime] [V7] + INP',\n",
471
+ " '3.Cetus-Mix [Anime] [V4] + INP',\n",
472
+ " '4.Counterfeit [Anime] [V3] + INP',\n",
473
+ " '5.CuteColor [Anime] [V3]',\n",
474
+ " '6.Dark-Sushi-Mix [Anime]',\n",
475
+ " '7.Deliberate [Realism] [V6] + INP',\n",
476
+ " '8.Meina-Mix [Anime] [V11] + INP',\n",
477
+ " '9.Mix-Pro [Anime] [V4] + INP']\n",
478
+ "# ---\n",
479
+ "Model_widget = widgets.Dropdown(options=model_options, value='4.Counterfeit [Anime] [V3] + INP', description='Model:', style=style, layout=layout)\n",
480
+ "Model_Num_widget = widgets.Text(description='Model Number:', placeholder='Enter the model numbers to be downloaded using comma/space.', style=style, layout=layout)\n",
481
+ "Inpainting_Model_widget = widgets.Checkbox(value=False, description='Inpainting Models', style=style)\n",
482
+ "\n",
483
+ "''' Display Model'''\n",
484
+ "all_model_box = widgets.VBox([model_header, Model_widget, Model_Num_widget, Inpainting_Model_widget]).add_class(\"container\").add_class(\"image_1\")\n",
485
+ "display(all_model_box)\n",
486
+ "\n",
487
+ "# --- VAE ---\n",
488
+ "vae_header = widgets.HTML('<div class=\"header\" >VAE Selection</div>')\n",
489
+ "vae_options = ['none',\n",
490
+ " '1.Anime.vae',\n",
491
+ " '2.Anything.vae',\n",
492
+ " '3.Blessed2.vae',\n",
493
+ " '4.ClearVae.vae',\n",
494
+ " '5.WD.vae']\n",
495
+ "Vae_widget = widgets.Dropdown(options=vae_options, value='3.Blessed2.vae', description='Vae:', style=style, layout=layout)\n",
496
+ "Vae_Num_widget = widgets.Text(description='Vae Number:', placeholder='Enter the vae numbers to be downloaded using comma/space.', style=style, layout=layout)\n",
497
+ "\n",
498
+ "''' Display Vae'''\n",
499
+ "all_vae_box= widgets.VBox([vae_header, Vae_widget, Vae_Num_widget]).add_class(\"container\").add_class(\"image_2\")\n",
500
+ "display(all_vae_box)\n",
501
+ "\n",
502
+ "# --- ADDITIONAL ---\n",
503
+ "additional_header = widgets.HTML('<div class=\"header\">Additional</div>')\n",
504
+ "latest_webui_widget = widgets.Checkbox(value=True, description='Update WebUI', style=style)\n",
505
+ "latest_exstensions_widget = widgets.Checkbox(value=True, description='Update Extensions', style=style)\n",
506
+ "detailed_download_widget = widgets.Dropdown(options=['off', 'on'], value='off', description='Detailed Download:', style=style)\n",
507
+ "latest_changes_widget = HBox([latest_webui_widget, latest_exstensions_widget, detailed_download_widget], layout=widgets.Layout(justify_content='space-between'))\n",
508
+ "controlnet_options = ['none', 'ALL', '1.canny',\n",
509
+ " '2.openpose', '3.depth',\n",
510
+ " '4.normal_map', '5.mlsd',\n",
511
+ " '6.lineart', '7.soft_edge',\n",
512
+ " '8.scribble', '9.segmentation',\n",
513
+ " '10.shuffle', '11.tile',\n",
514
+ " '12.inpaint', '13.instruct_p2p']\n",
515
+ "# ---\n",
516
+ "controlnet_widget = widgets.Dropdown(options=controlnet_options, value='none', description='ControlNet:', style=style, layout=layout)\n",
517
+ "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",
518
+ "commit_hash_widget = widgets.Text(description='Commit Hash:', style=style, layout=layout)\n",
519
+ "optional_huggingface_token_widget = widgets.Text(description='HuggingFace Token:', style=style, layout=layout)\n",
520
+ "ngrok_token_widget = widgets.Text(description='Ngrok Token:', style=style, layout=widgets.Layout(width='1047px'))\n",
521
+ "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",
522
+ "ngrok_widget = widgets.HBox([ngrok_token_widget, ngrock_button], style=style, layout=layout)\n",
523
+ "zrok_token_widget = widgets.Text(description='Zrok Token:', style=style, layout=widgets.Layout(width='1047px'))\n",
524
+ "zrok_button = widgets.HTML('<a href=\"https://colab.research.google.com/drive/1d2sjWDJi_GYBUavrHSuQyHTDuLy36WpU\" target=\"_blank\">Reg Zrok Token</a>').add_class(\"button_ngrok\")\n",
525
+ "zrok_widget = widgets.HBox([zrok_token_widget, zrok_button], style=style, layout=layout)\n",
526
+ "# ---\n",
527
+ "commandline_arguments_options = \"--listen --enable-insecure-extension-access --theme dark --no-half-vae --disable-console-progressbars --xformers\"\n",
528
+ "commandline_arguments_widget = widgets.Text(description='Arguments:', value=commandline_arguments_options, style=style, layout=layout)\n",
529
+ "\n",
530
+ "''' Display Additional'''\n",
531
+ "additional_widget_list = [additional_header, latest_changes_widget, HR, controlnet_widget, controlnet_Num_widget, commit_hash_widget, optional_huggingface_token_widget, ngrok_widget, zrok_widget, HR, commandline_arguments_widget]\n",
532
+ "if free_plan and env == \"Google Colab\": # remove ngrok from colab\n",
533
+ " additional_widget_list.remove(ngrok_widget)\n",
534
+ "# ```\n",
535
+ "all_additional_box = widgets.VBox(additional_widget_list).add_class(\"container\").add_class(\"image_3\")\n",
536
+ "display(all_additional_box)\n",
537
+ "\n",
538
+ "# --- CUSTOM DOWNLOAD ---\n",
539
+ "custom_download_header_popup = widgets.HTML('''\n",
540
+ "<style>\n",
541
+ "/* Term Colors */\n",
542
+ ".sample_label {color: #dbafff;}\n",
543
+ ".braces {color: #ffff00;}\n",
544
+ ".extension {color: #eb934b;}\n",
545
+ ".file_name {color: #ffffd8;}\n",
546
+ "</style>\n",
547
+ "\n",
548
+ "<div class=\"header\" style=\"cursor: pointer;\" onclick=\"toggleContainer()\">Custom Download</div>\n",
549
+ "<!-- PopUp Window -->\n",
550
+ "<div class=\"info\">INFO</div>\n",
551
+ "<div class=\"popup\">\n",
552
+ " 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",
553
+ " after the URL without spaces.\n",
554
+ " <span style=\"color: #ff9999\">For files, be sure to specify</span> - <span class=\"extension\">Filename Extension.</span>\n",
555
+ " <div class=\"sample\">\n",
556
+ " <span class=\"sample_label\">Example for File:</span>\n",
557
+ " 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",
558
+ " <br>\n",
559
+ " <span class=\"sample_label\">Example for Extension:</span>\n",
560
+ " 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",
561
+ " </div>\n",
562
+ "</div>\n",
563
+ "''')\n",
564
+ "# ---\n",
565
+ "Model_url_widget = widgets.Text(description='Model:', style=style, layout=layout)\n",
566
+ "Vae_url_widget = widgets.Text(description='Vae:', style=style, layout=layout)\n",
567
+ "LoRA_url_widget = widgets.Text(description='LoRa:', style=style, layout=layout)\n",
568
+ "Embedding_url_widget = widgets.Text(description='Embedding:', style=style, layout=layout)\n",
569
+ "Extensions_url_widget = widgets.Text(description='Extensions:', style=style, layout=layout)\n",
570
+ "custom_file_urls_widget = widgets.Text(description='File (txt):', style=style, layout=layout)\n",
571
+ "\n",
572
+ "''' Display CustomDl'''\n",
573
+ "all_custom_box = widgets.VBox([\n",
574
+ " custom_download_header_popup, Model_url_widget, Vae_url_widget, LoRA_url_widget, Embedding_url_widget, Extensions_url_widget, custom_file_urls_widget\n",
575
+ " ]).add_class(\"container\").add_class(\"image_4\").add_class(\"container_custom_downlad\")\n",
576
+ "display(all_custom_box)\n",
577
+ "\n",
578
+ "# --- Save Button ---\n",
579
+ "save_button = widgets.Button(description='Save').add_class(\"button_save\")\n",
580
+ "display(save_button)\n",
581
+ "\n",
582
+ "\n",
583
+ "# ============ Load / Save - Settings V2 ============\n",
584
+ "SETTINGS_FILE = f'{root_path}/settings.json'\n",
585
+ "\n",
586
+ "settings_keys = [\n",
587
+ " 'Model', 'Model_Num', 'Inpainting_Model',\n",
588
+ " 'Vae', 'Vae_Num',\n",
589
+ " 'latest_webui', 'latest_exstensions', 'detailed_download',\n",
590
+ " 'controlnet', 'controlnet_Num', 'commit_hash', 'optional_huggingface_token',\n",
591
+ " 'ngrok_token', 'zrok_token', 'commandline_arguments',\n",
592
+ " 'Model_url', 'Vae_url', 'LoRA_url', 'Embedding_url', 'Extensions_url', 'custom_file_urls'\n",
593
+ "]\n",
594
+ "\n",
595
+ "def save_settings():\n",
596
+ " settings = {key: globals()[f\"{key}_widget\"].value for key in settings_keys}\n",
597
+ " with open(SETTINGS_FILE, 'w') as f:\n",
598
+ " json.dump(settings, f, indent=2)\n",
599
+ "\n",
600
+ "def load_settings():\n",
601
+ " if os.path.exists(SETTINGS_FILE):\n",
602
+ " with open(SETTINGS_FILE, 'r') as f:\n",
603
+ " settings = json.load(f)\n",
604
+ " for key in settings_keys:\n",
605
+ " globals()[f\"{key}_widget\"].value = settings.get(key)\n",
606
+ "\n",
607
+ "def save_data(button):\n",
608
+ " save_settings()\n",
609
+ "\n",
610
+ " # --- uhh - hide... ---\n",
611
+ " widgets_list = [all_model_box, all_vae_box, all_additional_box, all_custom_box, save_button]\n",
612
+ " for widget in widgets_list:\n",
613
+ " widget.add_class(\"hide\")\n",
614
+ " time.sleep(0.5)\n",
615
+ "\n",
616
+ " widgets.Widget.close_all()\n",
617
+ "\n",
618
+ "settings = load_settings()\n",
619
+ "save_button.on_click(save_data)"
620
+ ],
621
+ "metadata": {
622
+ "id": "2lJmbqrs3Mu8"
623
+ },
624
+ "execution_count": null,
625
+ "outputs": []
626
+ }
627
+ ]
628
+ }
files_cells/notebooks/ru/auto-cleaner_ru.ipynb ADDED
@@ -0,0 +1,351 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "import os\n",
23
+ "import time\n",
24
+ "import ipywidgets as widgets\n",
25
+ "from ipywidgets import Label, Button, VBox, HBox\n",
26
+ "from IPython.display import display, HTML\n",
27
+ "\n",
28
+ "\n",
29
+ "# ================= DETECT ENV =================\n",
30
+ "def detect_environment():\n",
31
+ " free_plan = (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024. ** 3) <= 20)\n",
32
+ " environments = {\n",
33
+ " 'COLAB_GPU': ('Google Colab', \"/root\" if free_plan else \"/content\"),\n",
34
+ " 'KAGGLE_URL_BASE': ('Kaggle', \"/kaggle/working/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, free_plan\n",
40
+ "\n",
41
+ "env, root_path, free_plan = detect_environment()\n",
42
+ "webui_path = f\"{root_path}/sdw\"\n",
43
+ "# ----------------------------------------------\n",
44
+ "\n",
45
+ "\n",
46
+ "# ==================== CSS ====================\n",
47
+ "CSS_AC = \"\"\"\n",
48
+ "<style>\n",
49
+ "/* General Styles */\n",
50
+ "\n",
51
+ "hr {\n",
52
+ " border-color: grey;\n",
53
+ " background-color: grey;\n",
54
+ " opacity: 0.25;\n",
55
+ "}\n",
56
+ "\n",
57
+ ".instruction_AC {\n",
58
+ " font-family: cursive;\n",
59
+ " font-size: 18px;\n",
60
+ " color: grey;\n",
61
+ " user-select: none;\n",
62
+ " cursor: default;\n",
63
+ "}\n",
64
+ "\n",
65
+ "\n",
66
+ "/* Container style */\n",
67
+ "\n",
68
+ ".container_AC {\n",
69
+ " position: relative;\n",
70
+ " background-color: #232323;\n",
71
+ " width: 800px;\n",
72
+ " height: auto;\n",
73
+ " padding: 15px;\n",
74
+ " border-radius: 15px;\n",
75
+ " box-shadow: 0 0 50px rgba(0, 0, 0, 0.3);\n",
76
+ " margin-bottom: 5px;\n",
77
+ " overflow: visible;\n",
78
+ "}\n",
79
+ "\n",
80
+ ".container_AC::before {\n",
81
+ " position: absolute;\n",
82
+ " top: 5px;\n",
83
+ " right: 10px;\n",
84
+ " content: \"AutoCleanerV3.6\";\n",
85
+ " font-weight: bold;\n",
86
+ " font-size: 24px;\n",
87
+ " color: rgba(0, 0, 0, 0.2);\n",
88
+ "}\n",
89
+ "\n",
90
+ ".container_AC::after {\n",
91
+ " position: absolute;\n",
92
+ " top: 30px;\n",
93
+ " right: 10px;\n",
94
+ " content: \"ANXETY\";\n",
95
+ " font-weight: bold;\n",
96
+ " font-size: 18px;\n",
97
+ " color: rgba(0, 0, 0, 0.2);\n",
98
+ "}\n",
99
+ "\n",
100
+ ".custom-select-multiple_AC select {\n",
101
+ " padding: 10px;\n",
102
+ " font-family: cursive;\n",
103
+ " border: 1px solid #262626 !important;\n",
104
+ " border-radius: 10px;\n",
105
+ " color: white;\n",
106
+ " background-color: #1c1c1c;\n",
107
+ " box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);\n",
108
+ "}\n",
109
+ "\n",
110
+ ".output_AC {\n",
111
+ " padding: 10px;\n",
112
+ " height: auto;\n",
113
+ " border: 1px solid #262626;\n",
114
+ " border-radius: 10px;\n",
115
+ " background-color: #1c1c1c;\n",
116
+ " box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);\n",
117
+ " width: auto;\n",
118
+ " box-sizing: border-box;\n",
119
+ "}\n",
120
+ "\n",
121
+ ".output_message_AC {\n",
122
+ " font-family: cursive;\n",
123
+ " color: white !important;\n",
124
+ " font-size: 14px;\n",
125
+ " user-select: none;\n",
126
+ " cursor: default\n",
127
+ "}\n",
128
+ "\n",
129
+ "\n",
130
+ ".storage_info_AC {\n",
131
+ " padding: 5px 20px;\n",
132
+ " height: auto;\n",
133
+ " border: 1px solid #262626;\n",
134
+ " border-radius: 10px;\n",
135
+ " background-color: #1c1c1c;\n",
136
+ " box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);\n",
137
+ " width: auto;\n",
138
+ " font-family: cursive;\n",
139
+ " color: #B2B2B2 !important;\n",
140
+ " font-size: 14px;\n",
141
+ " user-select: none;\n",
142
+ " cursor: default\n",
143
+ "}\n",
144
+ "\n",
145
+ "\n",
146
+ "/* Button and storage info layout */\n",
147
+ ".lower_information_panel_AC {\n",
148
+ " display: flex;\n",
149
+ " align-items: center;\n",
150
+ " justify-content: space-between;\n",
151
+ "}\n",
152
+ "\n",
153
+ "\n",
154
+ "/* Button style */\n",
155
+ "\n",
156
+ ".button_AC {\n",
157
+ " width: auto;\n",
158
+ " font-family: cursive;\n",
159
+ " color: white !important;\n",
160
+ " font-size: 14px;\n",
161
+ " font-weight: bold;\n",
162
+ " height: 35px;\n",
163
+ " border-radius: 15px;\n",
164
+ " background-image: radial-gradient(circle at top left, purple 10%, violet 90%);\n",
165
+ " background-size: 200% 200%;\n",
166
+ " background-position: left bottom;\n",
167
+ " transition: background 0.5s ease-in-out, transform 0.3s ease;\n",
168
+ "}\n",
169
+ "\n",
170
+ ".button_AC:hover {\n",
171
+ " cursor: pointer;\n",
172
+ " background-size: 200% 200%;\n",
173
+ " background-position: right bottom;\n",
174
+ " transform: translateY(1px);\n",
175
+ "}\n",
176
+ "\n",
177
+ ".button_execute_AC:hover {\n",
178
+ " background-image: radial-gradient(circle at top left, purple 10%, #93ac47 90%);\n",
179
+ "}\n",
180
+ "\n",
181
+ ".button_clear_AC:hover {\n",
182
+ " background-image: radial-gradient(circle at top left, purple 10%, #fc3468 90%);\n",
183
+ "}\n",
184
+ "\n",
185
+ ".button_execute_AC:active,\n",
186
+ ".button_clear_AC:active {\n",
187
+ " filter: brightness(0.75);\n",
188
+ "}\n",
189
+ "\n",
190
+ ".jupyter-widgets.lm-Widget:focus {\n",
191
+ " outline: none;\n",
192
+ "}\n",
193
+ "\n",
194
+ "\n",
195
+ "/* Animation of elements */\n",
196
+ "\n",
197
+ "/* Emergence */\n",
198
+ ".container_AC {\n",
199
+ " animation-name: slideInTopBlur;\n",
200
+ " animation-duration: 0.7s;\n",
201
+ " animation-fill-mode: forwards;\n",
202
+ "}\n",
203
+ "\n",
204
+ "@keyframes slideInTopBlur {\n",
205
+ " 0% {\n",
206
+ " transform: translate3d(0, 50%, 0) scale(0.85) rotate3d(1, 0, 0, -85deg);\n",
207
+ " filter: blur(5px) grayscale(1) brightness(0.5);\n",
208
+ " opacity: 0;\n",
209
+ " }\n",
210
+ " 100% {\n",
211
+ " transform: translate3d(0, 0, 0) scale(1) rotate3d(1, 0, 0, 0deg);\n",
212
+ " filter: blur(0) grayscale(0) brightness(1);\n",
213
+ " opacity: 1;\n",
214
+ " }\n",
215
+ "}\n",
216
+ "\n",
217
+ "/* Leaving */\n",
218
+ ".container_AC.hide {\n",
219
+ " animation-name: slideOutTopBlur;\n",
220
+ " animation-duration: 0.3s;\n",
221
+ " animation-fill-mode: forwards;\n",
222
+ "}\n",
223
+ "\n",
224
+ "@keyframes slideOutTopBlur {\n",
225
+ " 0% {\n",
226
+ " transform: translate3d(0, 0, 0) scale(1);\n",
227
+ " filter: blur(0) grayscale(0) brightness(1);\n",
228
+ " opacity: 1;\n",
229
+ " }\n",
230
+ " 100% {\n",
231
+ " transform: translate3d(0, -100%, 0);\n",
232
+ " filter: blur(5px) grayscale(1) brightness(0);\n",
233
+ " opacity: 0;\n",
234
+ " }\n",
235
+ "}\n",
236
+ "</style>\n",
237
+ "\"\"\"\n",
238
+ "\n",
239
+ "display(HTML(CSS_AC))\n",
240
+ "# ==================== CSS ====================\n",
241
+ "\n",
242
+ "\n",
243
+ "# ================ AutoCleaner function ================\n",
244
+ "directories = {\n",
245
+ " \"Изображения\": f\"{webui_path}/outputs\",\n",
246
+ " \"Модели\": f\"{webui_path}/models/Stable-diffusion/\",\n",
247
+ " \"Vae\": f\"{webui_path}/models/VAE/\",\n",
248
+ " \"LoRa\": f\"{webui_path}/models/Lora/\",\n",
249
+ " \"ControlNet Модели\": f\"{webui_path}/models/ControlNet/\"\n",
250
+ "}\n",
251
+ "\n",
252
+ "\"\"\" functions \"\"\"\n",
253
+ "def clean_directory(directory):\n",
254
+ " deleted_files = 0\n",
255
+ " for root, dirs, files in os.walk(directory):\n",
256
+ " for file in files:\n",
257
+ " if file.endswith(\".txt\"):\n",
258
+ " continue\n",
259
+ " os.remove(os.path.join(root, file))\n",
260
+ " if not file.endswith(\".yaml\"):\n",
261
+ " deleted_files += 1\n",
262
+ " return deleted_files\n",
263
+ "\n",
264
+ "def update_memory_info():\n",
265
+ " disk_space = psutil.disk_usage(os.getcwd())\n",
266
+ " total = disk_space.total / (1024 ** 3)\n",
267
+ " used = disk_space.used / (1024 ** 3)\n",
268
+ " free = disk_space.free / (1024 ** 3)\n",
269
+ "\n",
270
+ " storage_info.value = f'''\n",
271
+ " <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",
272
+ " '''\n",
273
+ "\n",
274
+ "def on_execute_button_press(button):\n",
275
+ " selected_cleaners = auto_cleaner_widget.value\n",
276
+ " deleted_files_dict = {}\n",
277
+ "\n",
278
+ " for option in selected_cleaners:\n",
279
+ " if option in directories:\n",
280
+ " deleted_files_dict[option] = clean_directory(directories[option])\n",
281
+ "\n",
282
+ " output.clear_output()\n",
283
+ "\n",
284
+ " with output:\n",
285
+ " for message in generate_messages(deleted_files_dict):\n",
286
+ " message_widget = HTML(f'<p class=\"output_message_AC\">{message}</p>')\n",
287
+ " display(message_widget)\n",
288
+ "\n",
289
+ " update_memory_info()\n",
290
+ "\n",
291
+ "def on_clear_button_press(button):\n",
292
+ " container.add_class(\"hide\")\n",
293
+ " time.sleep(0.5)\n",
294
+ " widgets.Widget.close_all()\n",
295
+ "\n",
296
+ "def generate_messages(deleted_files_dict):\n",
297
+ " messages = []\n",
298
+ " word_variants = {\n",
299
+ " \"Изображения\": \"Изображений\",\n",
300
+ " \"Модели\": \"Моделей\",\n",
301
+ " \"Vae\": \"Vae\",\n",
302
+ " \"LoRa\": \"LoRa\",\n",
303
+ " \"ControlNet Модели\": \"ControlNet Моделей\"\n",
304
+ " }\n",
305
+ " for key, value in deleted_files_dict.items():\n",
306
+ " object_word = word_variants.get(key)\n",
307
+ " messages.append(f\"Удалено {value} {object_word}\")\n",
308
+ " return messages\n",
309
+ "# ================ AutoCleaner function ================\n",
310
+ "\n",
311
+ "\n",
312
+ "# --- storage memory ---\n",
313
+ "import psutil\n",
314
+ "disk_space = psutil.disk_usage(os.getcwd())\n",
315
+ "total = disk_space.total / (1024 ** 3)\n",
316
+ "used = disk_space.used / (1024 ** 3)\n",
317
+ "free = disk_space.free / (1024 ** 3)\n",
318
+ "\n",
319
+ "\n",
320
+ "# UI Code\n",
321
+ "AutoCleaner_options = AutoCleaner_options = list(directories.keys())\n",
322
+ "instruction_label = widgets.HTML('''\n",
323
+ "<span class=\"instruction_AC\">Используйте <span style=\"color: #B2B2B2;\">ctrl</span> или <span style=\"color: #B2B2B2;\">shift</span> для множественного выбора.</span>\n",
324
+ "''')\n",
325
+ "auto_cleaner_widget = widgets.SelectMultiple(options=AutoCleaner_options, layout=widgets.Layout(width=\"auto\")).add_class(\"custom-select-multiple_AC\")\n",
326
+ "output = widgets.Output().add_class(\"output_AC\")\n",
327
+ "# ---\n",
328
+ "execute_button = Button(description='Выполнить Очистку').add_class(\"button_execute_AC\").add_class(\"button_AC\")\n",
329
+ "execute_button.on_click(on_execute_button_press)\n",
330
+ "clear_button = Button(description='Скрыть Виджет').add_class(\"button_clear_AC\").add_class(\"button_AC\")\n",
331
+ "clear_button.on_click(on_clear_button_press)\n",
332
+ "# ---\n",
333
+ "storage_info = widgets.HTML(f'''\n",
334
+ "<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",
335
+ "''')\n",
336
+ "# ---\n",
337
+ "buttons = widgets.HBox([execute_button, clear_button])\n",
338
+ "lower_information_panel = widgets.HBox([buttons, storage_info]).add_class(\"lower_information_panel_AC\")\n",
339
+ "\n",
340
+ "container = VBox([instruction_label, widgets.HTML('<hr>'), auto_cleaner_widget, output, widgets.HTML('<hr>'), lower_information_panel]).add_class(\"container_AC\")\n",
341
+ "\n",
342
+ "display(container)"
343
+ ],
344
+ "metadata": {
345
+ "id": "I22dFg7F2j3G"
346
+ },
347
+ "execution_count": null,
348
+ "outputs": []
349
+ }
350
+ ]
351
+ }
files_cells/notebooks/ru/downloading_ru.ipynb ADDED
@@ -0,0 +1,568 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ " free_plan = (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024. ** 3) <= 20)\n",
38
+ " environments = {\n",
39
+ " 'COLAB_GPU': ('Google Colab', \"/root\" if free_plan else \"/content\"),\n",
40
+ " 'KAGGLE_URL_BASE': ('Kaggle', \"/kaggle/working/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, free_plan\n",
46
+ "\n",
47
+ "env, root_path, free_plan = detect_environment()\n",
48
+ "webui_path = f\"{root_path}/sdw\"\n",
49
+ "# ----------------------------------------------\n",
50
+ "\n",
51
+ "\n",
52
+ "# ================ LIBRARIES V2 ================\n",
53
+ "flag_file = f\"{root_path}/libraries_installed.txt\"\n",
54
+ "\n",
55
+ "if not os.path.exists(flag_file):\n",
56
+ " print(\"💿 Установка библиотек, это займет какое-то время:\\n\")\n",
57
+ "\n",
58
+ " install_lib = {\n",
59
+ " \"gdown\": \"pip install -U gdown\",\n",
60
+ " \"aria2\": \"apt-get update && apt -y install aria2\",\n",
61
+ " \"localtunnel\": \"npm install -g localtunnel &> /dev/null\",\n",
62
+ " \"insightface\": \"pip install insightface\",\n",
63
+ " }\n",
64
+ "\n",
65
+ " # Dictionary of additional libraries specific to certain environments\n",
66
+ " additional_libs = {\n",
67
+ " \"Google Colab\": {\n",
68
+ " \"xformers\": \"pip install xformers==0.0.25 --no-deps\"\n",
69
+ " },\n",
70
+ " \"Kaggle\": {\n",
71
+ " \"xformers\": \"pip install -q xformers==0.0.23.post1 triton==2.1.0\",\n",
72
+ " \"torch\": \"pip install -q torch==2.1.2+cu121 torchvision==0.16.2+cu121 torchaudio==2.1.2 --extra-index-url https://download.pytorch.org/whl/cu121\"\n",
73
+ " }\n",
74
+ " }\n",
75
+ "\n",
76
+ " # If the current environment has additional libraries, update the install_lib dictionary\n",
77
+ " if env in additional_libs:\n",
78
+ " install_lib.update(additional_libs[env])\n",
79
+ "\n",
80
+ " # Loop through libraries and execute install commands\n",
81
+ " for index, (package, install_cmd) in enumerate(install_lib.items(), start=1):\n",
82
+ " print(f\"\\r[{index}/{len(install_lib)}] \\033[32m>>\\033[0m Installing \\033[33m{package}\\033[0m...\" + \" \"*35, end='')\n",
83
+ " subprocess.run(install_cmd, shell=True, capture_output=True)\n",
84
+ "\n",
85
+ " # Additional manual installation steps for specific packages\n",
86
+ " with capture.capture_output() as cap:\n",
87
+ " !curl -s -OL https://github.com/DEX-1101/sd-webui-notebook/raw/main/res/new_tunnel --output-dir {root_path}\n",
88
+ " !curl -s -Lo /usr/bin/cl https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 && chmod +x /usr/bin/cl\n",
89
+ " !curl -sLO https://github.com/openziti/zrok/releases/download/v0.4.23/zrok_0.4.23_linux_amd64.tar.gz && tar -xzf zrok_0.4.23_linux_amd64.tar.gz -C /usr/bin && rm -f zrok_0.4.23_linux_amd64.tar.gz\n",
90
+ " del cap\n",
91
+ "\n",
92
+ " clear_output()\n",
93
+ "\n",
94
+ " # Save file install lib\n",
95
+ " with open(flag_file, \"w\") as f:\n",
96
+ " f.write(\">W<'\")\n",
97
+ "\n",
98
+ " print(\"🍪 Библиотеки установлены!\" + \" \"*35)\n",
99
+ " time.sleep(2)\n",
100
+ " clear_output()\n",
101
+ "\n",
102
+ "\n",
103
+ "# ================= loading settings V4 =================\n",
104
+ "def load_settings(path):\n",
105
+ " if os.path.exists(path):\n",
106
+ " with open(path, 'r') as file:\n",
107
+ " return json.load(file)\n",
108
+ " return {}\n",
109
+ "\n",
110
+ "settings = load_settings(f'{root_path}/settings.json')\n",
111
+ "\n",
112
+ "variables = [\n",
113
+ " 'Model', 'Model_Num', 'Inpainting_Model',\n",
114
+ " 'Vae', 'Vae_Num',\n",
115
+ " 'latest_webui', 'latest_exstensions', 'detailed_download',\n",
116
+ " 'controlnet', 'controlnet_Num', 'commit_hash', 'optional_huggingface_token',\n",
117
+ " 'ngrok_token', 'zrok_token', 'commandline_arguments',\n",
118
+ " 'Model_url', 'Vae_url', 'LoRA_url', 'Embedding_url', 'Extensions_url', 'custom_file_urls'\n",
119
+ "]\n",
120
+ "\n",
121
+ "locals().update({key: settings.get(key) for key in variables})\n",
122
+ "\n",
123
+ "\n",
124
+ "# ================= OTHER =================\n",
125
+ "try:\n",
126
+ " start_colab\n",
127
+ "except:\n",
128
+ " start_colab = int(time.time())-5\n",
129
+ "\n",
130
+ "# CONFIG DIR\n",
131
+ "models_dir = f\"{webui_path}/models/Stable-diffusion\"\n",
132
+ "vaes_dir = f\"{webui_path}/models/VAE\"\n",
133
+ "embeddings_dir = f\"{webui_path}/embeddings\"\n",
134
+ "loras_dir = f\"{webui_path}/models/Lora\"\n",
135
+ "extensions_dir = f\"{webui_path}/extensions\"\n",
136
+ "control_dir = f\"{webui_path}/models/ControlNet\"\n",
137
+ "\n",
138
+ "\n",
139
+ "# ================= MAIN CODE =================\n",
140
+ "if not os.path.exists(webui_path):\n",
141
+ " start_install = int(time.time())\n",
142
+ " print(\"⌚ Распоковка Stable Diffusion...\", end='')\n",
143
+ " with capture.capture_output() as cap:\n",
144
+ " !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",
145
+ " !unzip -q -o repo.zip -d {webui_path}\n",
146
+ " !rm -rf repo.zip\n",
147
+ "\n",
148
+ " %cd {root_path}\n",
149
+ " os.environ[\"SAFETENSORS_FAST_GPU\"]='1'\n",
150
+ " os.environ[\"CUDA_MODULE_LOADING\"]=\"LAZY\"\n",
151
+ " os.environ[\"TF_CPP_MIN_LOG_LEVEL\"] = \"3\"\n",
152
+ " os.environ[\"PYTHONWARNINGS\"] = \"ignore\"\n",
153
+ "\n",
154
+ " !echo -n {start_colab} > {webui_path}/static/colabTimer.txt\n",
155
+ " del cap\n",
156
+ " install_time = timedelta(seconds=time.time()-start_install)\n",
157
+ " print(\"\\r🚀 Распаковка Завершена! За\",\"%02d:%02d:%02d ⚡\\n\" % (install_time.seconds / 3600, (install_time.seconds / 60) % 60, install_time.seconds % 60), end='', flush=True)\n",
158
+ "else:\n",
159
+ " print(\"🚀 Все распакованно... Пропуск. ⚡\")\n",
160
+ " start_colab = float(open(f'{webui_path}/static/colabTimer.txt', 'r').read())\n",
161
+ " time_since_start = str(timedelta(seconds=time.time()-start_colab)).split('.')[0]\n",
162
+ " print(f\"⌚️ Вы проводите эту сессию в течение - \\033[33m{time_since_start}\\033[0m\")\n",
163
+ "\n",
164
+ "\n",
165
+ "## Changes extensions and WebUi\n",
166
+ "if latest_webui or latest_exstensions:\n",
167
+ " action = \"Обновление WebUI и Расширений\" if latest_webui and latest_exstensions else (\"Обновление WebUI\" if latest_webui else \"Обновление Расширений\")\n",
168
+ " print(f\"⌚️ {action}...\", end='', flush=True)\n",
169
+ " with capture.capture_output() as cap:\n",
170
+ " !git config --global user.email \"[email protected]\"\n",
171
+ " !git config --global user.name \"Your Name\"\n",
172
+ "\n",
173
+ " ## Update Webui\n",
174
+ " if latest_webui:\n",
175
+ " %cd {webui_path}\n",
176
+ " !git restore .\n",
177
+ " !git pull -X theirs --rebase --autostash\n",
178
+ "\n",
179
+ " ## Update extensions\n",
180
+ " if latest_exstensions:\n",
181
+ " !{'for dir in ' + webui_path + '/extensions/*/; do cd \\\"$dir\\\" && git reset --hard && git pull; done'}\n",
182
+ "\n",
183
+ " # My Chinese friend, you broke the images again in the latest update... >W<'\n",
184
+ " %cd {webui_path}/extensions/Encrypt-Image\n",
185
+ " !git reset --hard 376358d8854472b9ea50e9fc8800367d1ca51137 # stable commit :3\n",
186
+ " del cap\n",
187
+ " print(f\"\\r✨ {action} Завершено!\")\n",
188
+ "\n",
189
+ "\n",
190
+ "# === FIXING EXTENSIONS ===\n",
191
+ "anxety_repos = \"https://huggingface.co/NagisaNao/fast_repo/resolve/main\"\n",
192
+ "\n",
193
+ "with capture.capture_output() as cap:\n",
194
+ " # --- Encrypt-Image ---\n",
195
+ " !sed -i '9,37d' {webui_path}/extensions/Encrypt-Image/javascript/encrypt_images_info.js\n",
196
+ "\n",
197
+ " # --- Additional-Networks ---\n",
198
+ " !wget -O {webui_path}/extensions/additional-networks/scripts/metadata_editor.py {anxety_repos}/extensions/Additional-Networks/fix/metadata_editor.py\n",
199
+ "del cap\n",
200
+ "\n",
201
+ "\n",
202
+ "## Version switching\n",
203
+ "if commit_hash:\n",
204
+ " print('⏳ Активация машины времени...', end=\"\", flush=True)\n",
205
+ " with capture.capture_output() as cap:\n",
206
+ " %cd {webui_path}\n",
207
+ " !git config --global user.email \"[email protected]\"\n",
208
+ " !git config --global user.name \"Your Name\"\n",
209
+ " !git reset --hard {commit_hash}\n",
210
+ " del cap\n",
211
+ " print(f\"\\r⌛️ Машина времени активированна! Текущий коммит: \\033[34m{commit_hash}\\033[0m\")\n",
212
+ "\n",
213
+ "\n",
214
+ "## Downloading model and stuff | oh yeah~ I'm starting to misunderstand my own code ( almost my own ;3 )\n",
215
+ "print(\"📦 Скачивание моделей и прочего...\", end='')\n",
216
+ "model_list = {\n",
217
+ " \"1.Anime (by XpucT) + INP\": [\n",
218
+ " {\"url\": \"https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2.safetensors\", \"name\": \"Anime_v2.safetensors\"},\n",
219
+ " {\"url\": \"https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2-inpainting.safetensors\", \"name\": \"Anime_v2-inpainting.safetensors\"}\n",
220
+ " ],\n",
221
+ " \"2.BluMix [Anime] [V7] + INP\": [\n",
222
+ " {\"url\": \"https://civitai.com/api/download/models/361779\", \"name\": \"BluMix_v7.safetensors\"},\n",
223
+ " {\"url\": \"https://civitai.com/api/download/models/363850\", \"name\": \"BluMix_v7-inpainting.safetensors\"}\n",
224
+ " ],\n",
225
+ " \"3.Cetus-Mix [Anime] [V4] + INP\": [\n",
226
+ " {\"url\": \"https://civitai.com/api/download/models/130298\", \"name\": \"CetusMix_V4.safetensors\"},\n",
227
+ " {\"url\": \"https://civitai.com/api/download/models/139882\", \"name\": \"CetusMix_V4-inpainting.safetensors\"}\n",
228
+ " ],\n",
229
+ " \"4.Counterfeit [Anime] [V3] + INP\": [\n",
230
+ " {\"url\": \"https://civitai.com/api/download/models/125050\", \"name\": \"Counterfeit_V3.safetensors\"},\n",
231
+ " {\"url\": \"https://civitai.com/api/download/models/137911\", \"name\": \"Counterfeit_V3-inpainting.safetensors\"}\n",
232
+ " ],\n",
233
+ " \"5.CuteColor [Anime] [V3]\": [\n",
234
+ " {\"url\": \"https://civitai.com/api/download/models/138754\", \"name\": \"CuteColor_V3.safetensors\"}\n",
235
+ " ],\n",
236
+ " \"6.Dark-Sushi-Mix [Anime]\": [\n",
237
+ " {\"url\": \"https://civitai.com/api/download/models/101640\", \"name\": \"DarkSushiMix_2_5D.safetensors\"},\n",
238
+ " {\"url\": \"https://civitai.com/api/download/models/56071\", \"name\": \"DarkSushiMix_colorful.safetensors\"}\n",
239
+ " ],\n",
240
+ " \"7.Deliberate [Realism] [V6] + INP\": [\n",
241
+ " {\"url\": \"https://huggingface.co/XpucT/Deliberate/resolve/main/Deliberate_v6.safetensors\", \"name\": \"Deliberate_v6.safetensors\"},\n",
242
+ " {\"url\": \"https://huggingface.co/XpucT/Deliberate/resolve/main/Deliberate_v6-inpainting.safetensors\", \"name\": \"Deliberate_v6-inpainting.safetensors\"}\n",
243
+ " ],\n",
244
+ " \"8.Meina-Mix [Anime] [V11] + INP\": [\n",
245
+ " {\"url\": \"https://civitai.com/api/download/models/119057\", \"name\": \"MeinaMix_V11.safetensors\"},\n",
246
+ " {\"url\": \"https://civitai.com/api/download/models/120702\", \"name\": \"MeinaMix_V11-inpainting.safetensors\"}\n",
247
+ " ],\n",
248
+ " \"9.Mix-Pro [Anime] [V4] + INP\": [\n",
249
+ " {\"url\": \"https://civitai.com/api/download/models/125668\", \"name\": \"MixPro_V4.safetensors\"},\n",
250
+ " {\"url\": \"https://civitai.com/api/download/models/139878\", \"name\": \"MixPro_V4-inpainting.safetensors\"}\n",
251
+ " ]\n",
252
+ "}\n",
253
+ "\n",
254
+ "# 1-4 (fp16/cleaned)\n",
255
+ "vae_list = {\n",
256
+ " \"1.Anime.vae\": [\n",
257
+ " {\"url\": \"https://civitai.com/api/download/models/131654\", \"name\": \"Anime.vae.safetensors\"},\n",
258
+ " {\"url\": \"https://civitai.com/api/download/models/131658\", \"name\": \"vae-ft-mse.vae.safetensors\"}\n",
259
+ " ],\n",
260
+ " \"2.Anything.vae\": [{\"url\": \"https://civitai.com/api/download/models/131656\", \"name\": \"Anything.vae.safetensors\"}],\n",
261
+ " \"3.Blessed2.vae\": [{\"url\": \"https://civitai.com/api/download/models/142467\", \"name\": \"Blessed2.vae.safetensors\"}],\n",
262
+ " \"4.ClearVae.vae\": [{\"url\": \"https://civitai.com/api/download/models/133362\", \"name\": \"ClearVae_23.vae.safetensors\"}],\n",
263
+ " \"5.WD.vae\": [{\"url\": \"https://huggingface.co/NoCrypt/resources/resolve/main/VAE/wd.vae.safetensors\", \"name\": \"WD.vae.safetensors\"}]\n",
264
+ "}\n",
265
+ "\n",
266
+ "controlnet_list = {\n",
267
+ " \"1.canny\": [\n",
268
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny_fp16.safetensors\", \"name\": \"control_v11p_sd15_canny_fp16.safetensors\"},\n",
269
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_canny_fp16.yaml\", \"name\": \"control_v11p_sd15_canny_fp16.yaml\"}\n",
270
+ " ],\n",
271
+ " \"2.openpose\": [\n",
272
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose_fp16.safetensors\", \"name\": \"control_v11p_sd15_openpose_fp16.safetensors\"},\n",
273
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_openpose_fp16.yaml\", \"name\": \"control_v11p_sd15_openpose_fp16.yaml\"}\n",
274
+ " ],\n",
275
+ " \"3.depth\": [\n",
276
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth_fp16.safetensors\", \"name\": \"control_v11f1p_sd15_depth_fp16.safetensors\"},\n",
277
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1p_sd15_depth_fp16.yaml\", \"name\": \"control_v11f1p_sd15_depth_fp16.yaml\"},\n",
278
+ " {\"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",
279
+ " ],\n",
280
+ " \"4.normal_map\": [\n",
281
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_normalbae_fp16.safetensors\", \"name\": \"control_v11p_sd15_normalbae_fp16.safetensors\"},\n",
282
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_normalbae_fp16.yaml\", \"name\": \"control_v11p_sd15_normalbae_fp16.yaml\"}\n",
283
+ " ],\n",
284
+ " \"5.mlsd\": [\n",
285
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_mlsd_fp16.safetensors\", \"name\": \"control_v11p_sd15_mlsd_fp16.safetensors\"},\n",
286
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_mlsd_fp16.yaml\", \"name\": \"control_v11p_sd15_mlsd_fp16.yaml\"}\n",
287
+ " ],\n",
288
+ " \"6.lineart\": [\n",
289
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart_fp16.safetensors\", \"name\": \"control_v11p_sd15_lineart_fp16.safetensors\"},\n",
290
+ " {\"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",
291
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_lineart_fp16.yaml\", \"name\": \"control_v11p_sd15_lineart_fp16.yaml\"},\n",
292
+ " {\"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",
293
+ " ],\n",
294
+ " \"7.soft_edge\": [\n",
295
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge_fp16.safetensors\", \"name\": \"control_v11p_sd15_softedge_fp16.safetensors\"},\n",
296
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_softedge_fp16.yaml\", \"name\": \"control_v11p_sd15_softedge_fp16.yaml\"}\n",
297
+ " ],\n",
298
+ " \"8.scribble\": [\n",
299
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble_fp16.safetensors\", \"name\": \"control_v11p_sd15_scribble_fp16.safetensors\"},\n",
300
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_scribble_fp16.yaml\", \"name\": \"control_v11p_sd15_scribble_fp16.yaml\"}\n",
301
+ " ],\n",
302
+ " \"9.segmentation\": [\n",
303
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg_fp16.safetensors\", \"name\": \"control_v11p_sd15_seg_fp16.safetensors\"},\n",
304
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_seg_fp16.yaml\", \"name\": \"control_v11p_sd15_seg_fp16.yaml\"}\n",
305
+ " ],\n",
306
+ " \"10.shuffle\": [\n",
307
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle_fp16.safetensors\", \"name\": \"control_v11e_sd15_shuffle_fp16.safetensors\"},\n",
308
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_shuffle_fp16.yaml\", \"name\": \"control_v11e_sd15_shuffle_fp16.yaml\"}\n",
309
+ " ],\n",
310
+ " \"11.tile\": [\n",
311
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile_fp16.safetensors\", \"name\": \"control_v11f1e_sd15_tile_fp16.safetensors\"},\n",
312
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1e_sd15_tile_fp16.yaml\", \"name\": \"control_v11f1e_sd15_tile_fp16.yaml\"}\n",
313
+ " ],\n",
314
+ " \"12.inpaint\": [\n",
315
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_inpaint_fp16.safetensors\", \"name\": \"control_v11p_sd15_inpaint_fp16.safetensors\"},\n",
316
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_inpaint_fp16.yaml\", \"name\": \"control_v11p_sd15_inpaint_fp16.yaml\"}\n",
317
+ " ],\n",
318
+ " \"13.instruct_p2p\": [\n",
319
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p_fp16.safetensors\", \"name\": \"control_v11e_sd15_ip2p_fp16.safetensors\"},\n",
320
+ " {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_ip2p_fp16.yaml\", \"name\": \"control_v11e_sd15_ip2p_fp16.yaml\"}\n",
321
+ " ]\n",
322
+ "}\n",
323
+ "\n",
324
+ "extension_repo = []\n",
325
+ "prefixes = {\n",
326
+ " # It's complicated, but supplementing has become easier\n",
327
+ " \"model\": [models_dir, \"Model_url\"],\n",
328
+ " \"vae\": [vaes_dir, \"Vae_url\"],\n",
329
+ " \"lora\": [loras_dir, \"LoRA_url\"],\n",
330
+ " \"embed\": [embeddings_dir, \"Embedding_url\"],\n",
331
+ " \"extension\": [extensions_dir, \"Extensions_url\"],\n",
332
+ " \"control\": [control_dir, \"ControlNet_url\"]\n",
333
+ "}\n",
334
+ "\n",
335
+ "!mkdir -p {models_dir} {vaes_dir} {loras_dir} {embeddings_dir} {extensions_dir} {control_dir}\n",
336
+ "\n",
337
+ "url = \"\"\n",
338
+ "ControlNet_url = \"\"\n",
339
+ "hf_token = optional_huggingface_token if optional_huggingface_token else \"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\"\n",
340
+ "user_header = f\"\\\"Authorization: Bearer {hf_token}\\\"\"\n",
341
+ "\n",
342
+ "''' main download code '''\n",
343
+ "\n",
344
+ "def handle_manual(url):\n",
345
+ " original_url = url\n",
346
+ " url = url.split(':', 1)[1]\n",
347
+ " file_name = re.search(r'\\[(.*?)\\]', url)\n",
348
+ " file_name = file_name.group(1) if file_name else None\n",
349
+ " if file_name:\n",
350
+ " url = re.sub(r'\\[.*?\\]', '', url)\n",
351
+ "\n",
352
+ " for prefix, (dir, _) in prefixes.items():\n",
353
+ " if original_url.startswith(f\"{prefix}:\"):\n",
354
+ " if prefix != \"extension\":\n",
355
+ " manual_download(url, dir, file_name=file_name)\n",
356
+ " else:\n",
357
+ " extension_repo.append((url, file_name))\n",
358
+ "\n",
359
+ "def manual_download(url, dst_dir, file_name):\n",
360
+ " basename = url.split(\"/\")[-1] if file_name is None else file_name\n",
361
+ " header_option = f\"--header={user_header}\"\n",
362
+ "\n",
363
+ " print(\"\\033[32m---\"*45 + f\"\\n\\033[33mURL: \\033[34m{url}\\n\\033[33mSAVE DIR: \\033[34m{dst_dir}\\n\\033[33mFILE NAME: \\033[34m{file_name}\\033[32m\\n~~~\\033[0m\")\n",
364
+ "\n",
365
+ " # I do it at my own risk..... Fucking CivitAi >:(\n",
366
+ " civitai_token = \"62c0c5956b2f9defbd844d754000180b\"\n",
367
+ " if 'civitai' in url and civitai_token:\n",
368
+ " url = f\"{url}?token={civitai_token}\"\n",
369
+ "\n",
370
+ " # -- GDrive --\n",
371
+ " if 'drive.google' in url:\n",
372
+ " if 'folders' in url:\n",
373
+ " !gdown --folder \"{url}\" -O {dst_dir} --fuzzy -c\n",
374
+ " else:\n",
375
+ " if file_name:\n",
376
+ " !gdown \"{url}\" -O {dst_dir}/{file_name} --fuzzy -c\n",
377
+ " else:\n",
378
+ " !gdown \"{url}\" -O {dst_dir} --fuzzy -c\n",
379
+ " # -- Huggin Face --\n",
380
+ " elif 'huggingface' in url:\n",
381
+ " if '/blob/' in url:\n",
382
+ " url = url.replace('/blob/', '/resolve/')\n",
383
+ " if file_name:\n",
384
+ " !aria2c {header_option} --optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -c -j5 -x16 -s16 -k1M -d {dst_dir} -o {basename} {url}\n",
385
+ " else:\n",
386
+ " parsed_link = f'\\n{url}\\n\\tout={unquote(url.split(\"/\")[-1])}'\n",
387
+ " !echo -e \"{parsed_link}\" | aria2c {header_option} --console-log-level=error --summary-interval=10 -i- -j5 -x16 -s16 -k1M -c -d \"{dst_dir}\" -o {basename}\n",
388
+ " # -- Other --\n",
389
+ " elif 'http' in url or 'magnet' in url:\n",
390
+ " if file_name:\n",
391
+ " !aria2c --optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c -d {dst_dir} -o {file_name} {url}\n",
392
+ " else:\n",
393
+ " parsed_link = '\"{}\"'.format(url)\n",
394
+ " !aria2c --optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c -d {dst_dir} -Z {parsed_link}\n",
395
+ "\n",
396
+ "def download(url):\n",
397
+ " links_and_paths = url.split(',')\n",
398
+ "\n",
399
+ " for link_or_path in links_and_paths:\n",
400
+ " link_or_path = link_or_path.strip()\n",
401
+ " if not link_or_path:\n",
402
+ " continue\n",
403
+ " if any(link_or_path.startswith(prefix.lower()) for prefix in prefixes):\n",
404
+ " handle_manual(link_or_path)\n",
405
+ " continue\n",
406
+ "\n",
407
+ " url, dst_dir, file_name = link_or_path.split()\n",
408
+ " manual_download(url, dst_dir, file_name)\n",
409
+ "\n",
410
+ "''' submodels - added urls '''\n",
411
+ "\n",
412
+ "submodels = []\n",
413
+ "\n",
414
+ "def add_submodels(selection, num_selection, model_dict, dst_dir):\n",
415
+ " if selection == \"none\":\n",
416
+ " return []\n",
417
+ " if selection == \"ALL\":\n",
418
+ " all_models = []\n",
419
+ " for models in model_dict.values():\n",
420
+ " all_models.extend(models)\n",
421
+ " selected_models = all_models\n",
422
+ " else:\n",
423
+ " selected_models = model_dict[selection]\n",
424
+ " selected_nums = map(int, num_selection.replace(',', '').split())\n",
425
+ "\n",
426
+ " for num in selected_nums:\n",
427
+ " if 1 <= num <= len(model_dict):\n",
428
+ " name = list(model_dict)[num - 1]\n",
429
+ " selected_models.extend(model_dict[name])\n",
430
+ "\n",
431
+ " unique_models = list({model['name']: model for model in selected_models}.values())\n",
432
+ "\n",
433
+ " for model in unique_models:\n",
434
+ " model['dst_dir'] = dst_dir\n",
435
+ "\n",
436
+ " return unique_models\n",
437
+ "\n",
438
+ "submodels += add_submodels(Model, Model_Num, model_list, models_dir) # model\n",
439
+ "submodels += add_submodels(Vae, Vae_Num, vae_list, vaes_dir) # vae\n",
440
+ "submodels += add_submodels(controlnet, \"\" if controlnet == \"ALL\" else controlnet_Num, controlnet_list, control_dir) # controlnet\n",
441
+ "\n",
442
+ "for submodel in submodels:\n",
443
+ " if not Inpainting_Model and \"inpainting\" in submodel['name']:\n",
444
+ " continue\n",
445
+ " url += f\"{submodel['url']} {submodel['dst_dir']} {submodel['name']}, \"\n",
446
+ "\n",
447
+ "''' file.txt - added urls '''\n",
448
+ "\n",
449
+ "unique_urls = []\n",
450
+ "\n",
451
+ "def process_file_download(file_url):\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 any(f'# {tag}' in line.lower() for tag in prefixes):\n",
464
+ " current_tag = next((tag for tag in prefixes if tag in line.lower()))\n",
465
+ "\n",
466
+ " urls = [url.strip() for url in line.split(',')]\n",
467
+ " for url in urls:\n",
468
+ " if url.startswith(\"http\") and url not in unique_urls:\n",
469
+ " globals()[prefixes[current_tag][1]] += \", \" + url\n",
470
+ " unique_urls.append(url)\n",
471
+ "\n",
472
+ "# fix all possible errors/options and function call\n",
473
+ "if custom_file_urls:\n",
474
+ " for custom_file_url in custom_file_urls.replace(',', '').split():\n",
475
+ " if not custom_file_url.endswith('.txt'):\n",
476
+ " custom_file_url += '.txt'\n",
477
+ " if not custom_file_url.startswith('http'):\n",
478
+ " if not custom_file_url.startswith(root_path):\n",
479
+ " custom_file_url = f'{root_path}/{custom_file_url}'\n",
480
+ "\n",
481
+ " try:\n",
482
+ " process_file_download(custom_file_url)\n",
483
+ " except FileNotFoundError:\n",
484
+ " pass\n",
485
+ "\n",
486
+ "# url prefixing\n",
487
+ "urls = [globals()[urls[1]] for urls in prefixes.values()]\n",
488
+ "for i, prefix in enumerate(prefixes):\n",
489
+ " if urls[i]:\n",
490
+ " prefixed_urls = [f\"{prefix}:{url}\" for url 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# ====== Подробная Загрузка ====== #\\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🏁 Скачивание Завершено!\" + \" \"*15)\n",
504
+ "\n",
505
+ "\n",
506
+ "# Cleaning shit after downloading...\n",
507
+ "!find {webui_path} \\( -type d \\( -name \".ipynb_checkpoints\" -o -name \".aria2\" \\) -o -type f -name \"*.aria2\" \\) -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(\"✨ Устанвока кастомных расширений...\", 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📦 Установлено '{len(extension_repo)}', Кастомных расширений!\")\n",
523
+ "\n",
524
+ "\n",
525
+ "## List Models and stuff\n",
526
+ "if detailed_download == \"off\":\n",
527
+ " print(\"\\n\\n\\033[33mЕсли вы не видете каких-то скаченных файлов, включите в виджетах функцию 'Подробная Загрузка'.\")\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"
560
+ ],
561
+ "metadata": {
562
+ "id": "2lJmbqrs3Mu8"
563
+ },
564
+ "execution_count": null,
565
+ "outputs": []
566
+ }
567
+ ]
568
+ }
files_cells/notebooks/ru/launch_ru.ipynb ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ " free_plan = (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024. ** 3) <= 20)\n",
38
+ " environments = {\n",
39
+ " 'COLAB_GPU': ('Google Colab', \"/root\" if free_plan else \"/content\"),\n",
40
+ " 'KAGGLE_URL_BASE': ('Kaggle', \"/kaggle/working/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, free_plan\n",
46
+ "\n",
47
+ "env, root_path, free_plan = 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
+ "zrok_token = settings['zrok_token']\n",
61
+ "commandline_arguments = settings['commandline_arguments']\n",
62
+ "\n",
63
+ "\n",
64
+ "# ======================== TUNNEL ========================\n",
65
+ "import cloudpickle as pickle\n",
66
+ "\n",
67
+ "def get_public_ip(version='ipv4'):\n",
68
+ " try:\n",
69
+ " url = f'https://api64.ipify.org?format=json&{version}=true'\n",
70
+ " response = requests.get(url)\n",
71
+ " data = response.json()\n",
72
+ " public_ip = data['ip']\n",
73
+ " return public_ip\n",
74
+ " except Exception as e:\n",
75
+ " print(f\"Error getting public {version} address:\", e)\n",
76
+ "\n",
77
+ "public_ipv4 = get_public_ip(version='ipv4')\n",
78
+ "\n",
79
+ "tunnel_class = pickle.load(open(f\"{root_path}/new_tunnel\", \"rb\"), encoding=\"utf-8\")\n",
80
+ "tunnel_port= 1769\n",
81
+ "tunnel = tunnel_class(tunnel_port)\n",
82
+ "tunnel.add_tunnel(command=\"cl tunnel --url localhost:{port}\", name=\"cl\", pattern=re.compile(r\"[\\w-]+\\.trycloudflare\\.com\"))\n",
83
+ "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",
84
+ "\n",
85
+ "''' add zrok tunnel '''\n",
86
+ "if zrok_token:\n",
87
+ " get_ipython().system('zrok enable {zrok_token} &> /dev/null')\n",
88
+ " tunnel.add_tunnel(command=\"zrok share public http://localhost:{port}/ --headless\", name=\"zrok\", pattern=re.compile(r\"[\\w-]+\\.share\\.zrok\\.io\"))\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
+ "with tunnel:\n",
100
+ " %cd {webui_path}\n",
101
+ " commandline_arguments += f\" --port=1769\"\n",
102
+ "\n",
103
+ " if ngrok_token:\n",
104
+ " commandline_arguments += ' --ngrok ' + ngrok_token\n",
105
+ " if env != \"Google Colab\":\n",
106
+ " commandline_arguments += f\" --encrypt-pass=1769\"\n",
107
+ "\n",
108
+ " !COMMANDLINE_ARGS=\"{commandline_arguments}\" python launch.py\n",
109
+ "\n",
110
+ " start_colab = float(open(f'{webui_path}/static/colabTimer.txt', 'r').read())\n",
111
+ " time_since_start = str(timedelta(seconds=time.time()-start_colab)).split('.')[0]\n",
112
+ " print(f\"\\n⌚️ \\033[0mВы проводите эту сессию в течение - \\033[33m{time_since_start}\\033[0m\\n\\n\")"
113
+ ]
114
+ }
115
+ ]
116
+ }
files_cells/notebooks/ru/widgets_ru.ipynb ADDED
@@ -0,0 +1,628 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 time\n",
25
+ "import ipywidgets as widgets\n",
26
+ "from ipywidgets import widgets, Layout, Label, Button, VBox, HBox\n",
27
+ "from IPython.display import display, HTML, Javascript, clear_output\n",
28
+ "\n",
29
+ "\n",
30
+ "# ================= DETECT ENV =================\n",
31
+ "def detect_environment():\n",
32
+ " free_plan = (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024. ** 3) <= 20)\n",
33
+ " environments = {\n",
34
+ " 'COLAB_GPU': ('Google Colab', \"/root\" if free_plan else \"/content\"),\n",
35
+ " 'KAGGLE_URL_BASE': ('Kaggle', \"/kaggle/working/content\")\n",
36
+ " }\n",
37
+ "\n",
38
+ " for env_var, (environment, path) in environments.items():\n",
39
+ " if env_var in os.environ:\n",
40
+ " return environment, path, free_plan\n",
41
+ "\n",
42
+ "env, root_path, free_plan = detect_environment()\n",
43
+ "webui_path = f\"{root_path}/sdw\"\n",
44
+ "\n",
45
+ "!mkdir -p {root_path}\n",
46
+ "# ----------------------------------------------\n",
47
+ "\n",
48
+ "\n",
49
+ "# ==================== CSS JS ====================\n",
50
+ "# custom background images V1.5\n",
51
+ "import argparse\n",
52
+ "parser = argparse.ArgumentParser(description='This script processes an background image.')\n",
53
+ "parser.add_argument('-i', '--image', type=str, help='URL of the image to process', metavar='')\n",
54
+ "parser.add_argument('-o', '--opacity', type=float, help='Opacity level for the image, between 0 and 1', metavar='', default=0.3)\n",
55
+ "parser.add_argument('-b', '--blur', type=str, help='Blur level for the image', metavar='', default=0)\n",
56
+ "parser.add_argument('-y', type=int, help='Y coordinate for the image in px', metavar='', default=0)\n",
57
+ "parser.add_argument('-x', type=int, help='X coordinate for the image in px', metavar='', default=0)\n",
58
+ "parser.add_argument('-s', '--scale', type=int, help='Scale image in %%', metavar='', default=100)\n",
59
+ "parser.add_argument('-m', '--mode',action='store_true', help='Removes repetitive image tiles')\n",
60
+ "parser.add_argument('-t', '--transparent', action='store_true', help='Makes input/selection fields 35%% more transparent')\n",
61
+ "parser.add_argument('-bf', '--blur-fields', type=str, help='Background blur level for input/selection fields', metavar='', default=2)\n",
62
+ "args = parser.parse_args()\n",
63
+ "\"\"\"---\"\"\"\n",
64
+ "url_img = args.image\n",
65
+ "opacity_img = args.opacity\n",
66
+ "blur_img = args.blur\n",
67
+ "y_img = args.y\n",
68
+ "x_img = args.x\n",
69
+ "scale_img = args.scale\n",
70
+ "blur_fields = args.blur_fields\n",
71
+ "\n",
72
+ "## ---\n",
73
+ "\"\"\" WTF KAGGLE - WHAT THE FUCK IS THE DIFFERENCE OF 35 PIXELS!?!?!? \"\"\"\n",
74
+ "fix_heigh_img = \"-810px\" if env == \"Kaggle\" else \"-775px\"\n",
75
+ "\n",
76
+ "\"\"\" transperent fields \"\"\"\n",
77
+ "t_bg_alpha = \"1\" if not args.transparent else \"0.65\"\n",
78
+ "\n",
79
+ "\"\"\" mode img - repeats \"\"\"\n",
80
+ "mode_img = \"repeat\" if not args.mode else \"no-repeat\"\n",
81
+ "## ---\n",
82
+ "\n",
83
+ "container_background = f'''\n",
84
+ "<style>\n",
85
+ ":root {{\n",
86
+ " /* for background container*/\n",
87
+ " --img_background: url({url_img});\n",
88
+ " --img_opacity: {opacity_img};\n",
89
+ " --img_blur: {blur_img}px;\n",
90
+ " --image_y: {y_img}px;\n",
91
+ " --image_x: {x_img}px;\n",
92
+ " --img_scale: {scale_img}%;\n",
93
+ " --img_mode: {mode_img};\n",
94
+ " --img_height_dif: {fix_heigh_img};\n",
95
+ "\n",
96
+ " /* for fields */\n",
97
+ " --bg-field-color: rgba(28, 28, 28, {t_bg_alpha}); /* -> #1c1c1c */\n",
98
+ " --bg-field-color-hover: rgba(38, 38, 38, {t_bg_alpha}); /* -> #262626; */\n",
99
+ " --bg-field-blur-level: {blur_fields}px;\n",
100
+ "}}\n",
101
+ "'''\n",
102
+ "\n",
103
+ "display(HTML(container_background))\n",
104
+ "# ---\n",
105
+ "\n",
106
+ "CSS = '''\n",
107
+ "<style>\n",
108
+ "/* General Styles */\n",
109
+ ".header {\n",
110
+ " font-family: cursive;\n",
111
+ " font-size: 20px;\n",
112
+ " font-weight: bold;\n",
113
+ " color: #ff8cee;\n",
114
+ " margin-bottom: 15px;\n",
115
+ " user-select: none;\n",
116
+ " cursor: default;\n",
117
+ " display: inline-block;\n",
118
+ "}\n",
119
+ "\n",
120
+ "hr {\n",
121
+ " border-color: grey;\n",
122
+ " background-color: grey;\n",
123
+ " opacity: 0.25;\n",
124
+ "}\n",
125
+ "\n",
126
+ "a {\n",
127
+ " text-decoration: none;\n",
128
+ " color: inherit;\n",
129
+ "}\n",
130
+ "\n",
131
+ "\n",
132
+ "/* Container style */\n",
133
+ "\n",
134
+ ".container {\n",
135
+ " position: relative;\n",
136
+ " background-color: #232323;\n",
137
+ " width: 1080px;\n",
138
+ " padding: 10px 15px;\n",
139
+ " border-radius: 15px;\n",
140
+ " box-shadow: 0 0 50px rgba(0, 0, 0, 0.3);\n",
141
+ " margin-bottom: 5px;\n",
142
+ " overflow: hidden;\n",
143
+ "}\n",
144
+ "\n",
145
+ ".container::after {\n",
146
+ " position: absolute;\n",
147
+ " top: 5px;\n",
148
+ " right: 10px;\n",
149
+ " content: \"ANXETY\";\n",
150
+ " font-weight: bold;\n",
151
+ " font-size: 24px;\n",
152
+ " color: rgba(0, 0, 0, 0.2);\n",
153
+ "}\n",
154
+ "\n",
155
+ "/* background img */\n",
156
+ ".container::before {\n",
157
+ " content: \"\";\n",
158
+ " position: absolute;\n",
159
+ " top: 0;\n",
160
+ " left: 0;\n",
161
+ " right: 0;\n",
162
+ " bottom: 0;\n",
163
+ " background-image: var(--img_background);\n",
164
+ " background-size: var(--img_scale);\n",
165
+ " background-repeat: var(--img_mode);\n",
166
+ " opacity: var(--img_opacity);\n",
167
+ " mix-blend-mode: screen;\n",
168
+ " pointer-events: none;\n",
169
+ " filter: blur(var(--img_blur));\n",
170
+ " z-index: -1;\n",
171
+ "}\n",
172
+ "\n",
173
+ ".image_1::before {\n",
174
+ " background-position: var(--image_x) calc(-120px - var(--image_y));\n",
175
+ "}\n",
176
+ ".image_2::before {\n",
177
+ " background-position: var(--image_x) calc(-290px - var(--image_y));\n",
178
+ "}\n",
179
+ ".image_3::before {\n",
180
+ " background-position: var(--image_x) calc(-430px - var(--image_y));\n",
181
+ "}\n",
182
+ ".image_4::before {\n",
183
+ " background-position: var(--image_x) calc(var(--img_height_dif) - var(--image_y));\n",
184
+ "}\n",
185
+ "\n",
186
+ ".container_custom_downlad {\n",
187
+ " height: 55px;\n",
188
+ " transition: all 0.5s;\n",
189
+ "}\n",
190
+ "\n",
191
+ ".container_custom_downlad.expanded {\n",
192
+ " height: 270px;\n",
193
+ "}\n",
194
+ "\n",
195
+ "\n",
196
+ "/* Element text style */\n",
197
+ "\n",
198
+ ".widget-html,\n",
199
+ ".widget-button,\n",
200
+ ".widget-text label,\n",
201
+ ".widget-checkbox label,\n",
202
+ ".widget-dropdown label,\n",
203
+ ".widget-dropdown select,\n",
204
+ ".widget-text input[type=\"text\"] {\n",
205
+ " font-family: cursive;\n",
206
+ " font-size: 14px;\n",
207
+ " color: white !important;\n",
208
+ " user-select: none;\n",
209
+ "}\n",
210
+ "\n",
211
+ ".widget-text input[type=\"text\"]::placeholder {\n",
212
+ " color: grey;\n",
213
+ "}\n",
214
+ "\n",
215
+ "\n",
216
+ "/* Input field styles */\n",
217
+ "\n",
218
+ ".widget-dropdown select,\n",
219
+ ".widget-text input[type=\"text\"] {\n",
220
+ " height: 30px;\n",
221
+ " background-color: var(--bg-field-color);\n",
222
+ " border: 1px solid #262626;\n",
223
+ " border-radius: 10px;\n",
224
+ " box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);\n",
225
+ " transition: all 0.3s ease-in-out;\n",
226
+ " backdrop-filter: blur(var(--bg-field-blur-level));\n",
227
+ "}\n",
228
+ "\n",
229
+ ".widget-dropdown select:focus,\n",
230
+ ".widget-text input[type=\"text\"]:focus {\n",
231
+ " border-color: #006ee5;\n",
232
+ "}\n",
233
+ "\n",
234
+ ".widget-dropdown select:hover,\n",
235
+ ".widget-text input[type=\"text\"]:hover {\n",
236
+ " transform: scale(1.003);\n",
237
+ " background-color: var(--bg-field-color-hover);\n",
238
+ " box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);\n",
239
+ "}\n",
240
+ "\n",
241
+ ".widget-dropdown option {\n",
242
+ " background-color: #1c1c1c;\n",
243
+ "}\n",
244
+ "\n",
245
+ "\n",
246
+ "/* Slider Checkbox style */\n",
247
+ "\n",
248
+ ".widget-checkbox input[type=\"checkbox\"] {\n",
249
+ " appearance: none;\n",
250
+ " position: relative;\n",
251
+ " top: 4px; /* Why is he taller?! */\n",
252
+ " width: 40px;\n",
253
+ " height: 20px;\n",
254
+ " border: none;\n",
255
+ " border-radius: 10px;\n",
256
+ " background-color: #20b2aa;\n",
257
+ " cursor: pointer;\n",
258
+ " box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.3);\n",
259
+ " transition: background-color 0.3s ease;\n",
260
+ "}\n",
261
+ ".widget-checkbox input[type=\"checkbox\"]:checked {\n",
262
+ " background-color: #2196F3;\n",
263
+ "}\n",
264
+ "\n",
265
+ ".widget-checkbox input[type=\"checkbox\"]:before {\n",
266
+ " content: '';\n",
267
+ " position: absolute;\n",
268
+ " top: 50%;\n",
269
+ " left: 3px;\n",
270
+ " width: 16px;\n",
271
+ " height: 16px;\n",
272
+ " border-radius: inherit;\n",
273
+ " background-color: white;\n",
274
+ " box-shadow: 0 0 8px rgba(0, 0, 0, 0.3);\n",
275
+ " transform: translateY(-50%);\n",
276
+ " transition: left 0.3s ease;\n",
277
+ "}\n",
278
+ ".widget-checkbox input[type=\"checkbox\"]:checked:before {\n",
279
+ " left: 21px;\n",
280
+ "}\n",
281
+ "\n",
282
+ "\n",
283
+ "/* Button styles */\n",
284
+ "\n",
285
+ ".button_save {\n",
286
+ " font-size: 15px;\n",
287
+ " font-weight: bold;\n",
288
+ " width: 120px;\n",
289
+ " height: 35px;\n",
290
+ " border-radius: 15px;\n",
291
+ " background-image: radial-gradient(circle at top left, purple 10%, violet 90%);\n",
292
+ " background-size: 200% 200%;\n",
293
+ " background-position: left bottom;\n",
294
+ " transition: background 0.5s ease-in-out, transform 0.3s ease;\n",
295
+ "}\n",
296
+ "\n",
297
+ ".button_save:hover {\n",
298
+ " cursor: pointer;\n",
299
+ " background-image: radial-gradient(circle at top left, purple 10%, #93ac47 90%);\n",
300
+ " background-size: 200% 200%;\n",
301
+ " background-position: right bottom;\n",
302
+ " transform: translateY(1px);\n",
303
+ "}\n",
304
+ "\n",
305
+ ".button_ngrok {\n",
306
+ " font-size: 12px;\n",
307
+ " height: 30px;\n",
308
+ " border-radius: 10px;\n",
309
+ " padding: 1px 12px;\n",
310
+ " background-image: radial-gradient(circle at top left, purple 10%, violet 90%);\n",
311
+ " background-size: 200% 200%;\n",
312
+ " background-position: left bottom;\n",
313
+ " transition: background 0.5s ease-in-out, transform 0.3s ease;\n",
314
+ " white-space: nowrap;\n",
315
+ "}\n",
316
+ "\n",
317
+ ".button_ngrok:hover {\n",
318
+ " cursor: pointer;\n",
319
+ " background-image: radial-gradient(circle at top left, purple 10%, #1D94BB 90%);\n",
320
+ " background-size: 200% 200%;\n",
321
+ " background-position: right bottom;\n",
322
+ " transform: translateY(1px);\n",
323
+ "}\n",
324
+ "\n",
325
+ ".button_save:active,\n",
326
+ ".button_ngrok:active {\n",
327
+ " filter: brightness(0.75) !important;\n",
328
+ "}\n",
329
+ "\n",
330
+ "/* Removes ugly stroke from widget buttons. */\n",
331
+ ".jupyter-widgets.lm-Widget:focus {\n",
332
+ " outline: none;\n",
333
+ "}\n",
334
+ "\n",
335
+ "\n",
336
+ "/* Popup style of `INFO` window */\n",
337
+ "\n",
338
+ ".info {\n",
339
+ " position: absolute;\n",
340
+ " top: -5px;\n",
341
+ " right: 95px;\n",
342
+ " color: grey;\n",
343
+ " font-family: cursive;\n",
344
+ " font-size: 14px;\n",
345
+ " font-weight: normal;\n",
346
+ " user-select: none;\n",
347
+ " pointer-events: none;\n",
348
+ " opacity: 0;\n",
349
+ " transition: opacity 0.3s ease-in-out;\n",
350
+ " display: inline-block;\n",
351
+ "}\n",
352
+ "\n",
353
+ ".popup {\n",
354
+ " position: absolute;\n",
355
+ " top: 120px;\n",
356
+ " z-index: 999;\n",
357
+ " width: auto;\n",
358
+ " padding: 10px;\n",
359
+ " text-align: center;\n",
360
+ " background-color: rgba(255, 255, 255, 0.05);\n",
361
+ " backdrop-filter: blur(20px);\n",
362
+ " border: 1px solid rgba(255, 255, 255, 0.45);\n",
363
+ " border-radius: 8px;\n",
364
+ " box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);\n",
365
+ " opacity: 0;\n",
366
+ " color: #fff;\n",
367
+ " font-size: 16px;\n",
368
+ " font-family: cursive;\n",
369
+ " user-select: none;\n",
370
+ " cursor: default;\n",
371
+ " pointer-events: none;\n",
372
+ " transform: rotate(-5deg);\n",
373
+ " transition: top 0.3s ease-in-out, opacity 0.3s ease-in-out, transform 0.3s ease-in-out;\n",
374
+ "}\n",
375
+ "\n",
376
+ ".sample {\n",
377
+ " display: inline-block;\n",
378
+ " margin-top: 25px;\n",
379
+ " padding: 10px 100px;\n",
380
+ " background-color: rgba(255, 255, 255, 0.2);\n",
381
+ " color: #c6e2ff;\n",
382
+ " border: 2px solid rgba(255, 255, 255, 0.2);\n",
383
+ " border-radius: 8px;\n",
384
+ " box-shadow: 0 0 10px rgba(255, 255, 255, 0.2), inset 0 0 25px rgba(255, 255, 255, 0.2);\n",
385
+ "}\n",
386
+ "\n",
387
+ ".info.showed {\n",
388
+ " opacity: 1;\n",
389
+ " pointer-events: auto;\n",
390
+ "}\n",
391
+ "\n",
392
+ ".info:hover + .popup {\n",
393
+ " top: 35px;\n",
394
+ " opacity: 1;\n",
395
+ " pointer-events: initial;\n",
396
+ " transform: rotate(0deg);\n",
397
+ "}\n",
398
+ "\n",
399
+ "\n",
400
+ "/* Animation of elements */\n",
401
+ "\n",
402
+ ".container,\n",
403
+ ".button_save {\n",
404
+ " animation-name: showedWidgets;\n",
405
+ " animation-duration: 1s;\n",
406
+ " animation-fill-mode: forwards;\n",
407
+ "}\n",
408
+ "\n",
409
+ ".container.hide,\n",
410
+ ".button_save.hide {\n",
411
+ " animation-name: hideWidgets;\n",
412
+ " animation-duration: 0.5s;\n",
413
+ " animation-fill-mode: forwards;\n",
414
+ "}\n",
415
+ "\n",
416
+ "@keyframes showedWidgets {\n",
417
+ " 0% {\n",
418
+ " transform: translate3d(-65%, 15%, 0) scale(0) rotate(15deg);\n",
419
+ " filter: blur(25px) grayscale(1) brightness(0.3);\n",
420
+ " opacity: 0;\n",
421
+ " }\n",
422
+ " 100% {\n",
423
+ " transform: translate3d(0, 0, 0) scale(1) rotate(0deg);\n",
424
+ " filter: blur(0) grayscale(0) brightness(1);\n",
425
+ " opacity: 1;\n",
426
+ " }\n",
427
+ "}\n",
428
+ "\n",
429
+ "@keyframes hideWidgets {\n",
430
+ " 0% {\n",
431
+ " transform: translate3d(0, 0, 0) scale(1) rotate3d(1, 0, 0, 0deg);\n",
432
+ " filter: blur(0) grayscale(0) brightness(1);\n",
433
+ " opacity: 1;\n",
434
+ " }\n",
435
+ " 100% {\n",
436
+ " transform: translate3d(0, 5%, 0) scale(0.9) rotate3d(1, 0, 0, 90deg);\n",
437
+ " filter: blur(15px) grayscale(1) brightness(0.5);\n",
438
+ " opacity: 0;\n",
439
+ " }\n",
440
+ "}\n",
441
+ "</style>\n",
442
+ "\n",
443
+ "<!-- TOGGLE 'CustomDL' SCRIPT -->\n",
444
+ "<script>\n",
445
+ "function toggleContainer() {\n",
446
+ " let downloadContainer = document.querySelector('.container_custom_downlad');\n",
447
+ " let info = document.querySelector('.info');\n",
448
+ "\n",
449
+ " downloadContainer.classList.toggle('expanded');\n",
450
+ " info.classList.toggle('showed');\n",
451
+ "}\n",
452
+ "</script>\n",
453
+ "'''\n",
454
+ "\n",
455
+ "display(HTML(CSS))\n",
456
+ "# ==================== CSS JS ====================\n",
457
+ "\n",
458
+ "\n",
459
+ "# ==================== WIDGETS ====================\n",
460
+ "# --- global widgets ---\n",
461
+ "style = {'description_width': 'initial'}\n",
462
+ "layout = widgets.Layout(min_width='1047px')\n",
463
+ "\n",
464
+ "HR = widgets.HTML('<hr>')\n",
465
+ "\n",
466
+ "# --- MODEL ---\n",
467
+ "model_header = widgets.HTML('<div class=\"header\">Выбор Модели<div>')\n",
468
+ "model_options = ['none',\n",
469
+ " '1.Anime (by XpucT) + INP',\n",
470
+ " '2.BluMix [Anime] [V7] + INP',\n",
471
+ " '3.Cetus-Mix [Anime] [V4] + INP',\n",
472
+ " '4.Counterfeit [Anime] [V3] + INP',\n",
473
+ " '5.CuteColor [Anime] [V3]',\n",
474
+ " '6.Dark-Sushi-Mix [Anime]',\n",
475
+ " '7.Deliberate [Realism] [V6] + INP',\n",
476
+ " '8.Meina-Mix [Anime] [V11] + INP',\n",
477
+ " '9.Mix-Pro [Anime] [V4] + INP']\n",
478
+ "# ---\n",
479
+ "Model_widget = widgets.Dropdown(options=model_options, value='4.Counterfeit [Anime] [V3] + INP', description='Модель:', style=style, layout=layout)\n",
480
+ "Model_Num_widget = widgets.Text(description='Номер Модели:', placeholder='Введите номера моделей для скачивания через запятую/пробел.', style=style, layout=layout)\n",
481
+ "Inpainting_Model_widget = widgets.Checkbox(value=False, description='Inpainting Модели', style=style)\n",
482
+ "\n",
483
+ "''' Display Model'''\n",
484
+ "all_model_box = widgets.VBox([model_header, Model_widget, Model_Num_widget, Inpainting_Model_widget]).add_class(\"container\").add_class(\"image_1\")\n",
485
+ "display(all_model_box)\n",
486
+ "\n",
487
+ "# --- VAE ---\n",
488
+ "vae_header = widgets.HTML('<div class=\"header\" >Выбор VAE</div>')\n",
489
+ "vae_options = ['none',\n",
490
+ " '1.Anime.vae',\n",
491
+ " '2.Anything.vae',\n",
492
+ " '3.Blessed2.vae',\n",
493
+ " '4.ClearVae.vae',\n",
494
+ " '5.WD.vae']\n",
495
+ "Vae_widget = widgets.Dropdown(options=vae_options, value='3.Blessed2.vae', description='Vae:', style=style, layout=layout)\n",
496
+ "Vae_Num_widget = widgets.Text(description='Номер Vae:', placeholder='Введите номера vae для скачивания через запятую/пробел.', style=style, layout=layout)\n",
497
+ "\n",
498
+ "''' Display Vae'''\n",
499
+ "all_vae_box= widgets.VBox([vae_header, Vae_widget, Vae_Num_widget]).add_class(\"container\").add_class(\"image_2\")\n",
500
+ "display(all_vae_box)\n",
501
+ "\n",
502
+ "# --- ADDITIONAL ---\n",
503
+ "additional_header = widgets.HTML('<div class=\"header\">Дополнительно</div>')\n",
504
+ "latest_webui_widget = widgets.Checkbox(value=True, description='Обновить WebUI', style=style)\n",
505
+ "latest_exstensions_widget = widgets.Checkbox(value=True, description='Обновить Расширения', style=style)\n",
506
+ "detailed_download_widget = widgets.Dropdown(options=['off', 'on'], value='off', description='Подробная Загрузка:', style=style)\n",
507
+ "latest_changes_widget = HBox([latest_webui_widget, latest_exstensions_widget, detailed_download_widget], layout=widgets.Layout(justify_content='space-between'))\n",
508
+ "controlnet_options = ['none', 'ALL', '1.canny',\n",
509
+ " '2.openpose', '3.depth',\n",
510
+ " '4.normal_map', '5.mlsd',\n",
511
+ " '6.lineart', '7.soft_edge',\n",
512
+ " '8.scribble', '9.segmentation',\n",
513
+ " '10.shuffle', '11.tile',\n",
514
+ " '12.inpaint', '13.instruct_p2p']\n",
515
+ "# ---\n",
516
+ "controlnet_widget = widgets.Dropdown(options=controlnet_options, value='none', description='ControlNet:', style=style, layout=layout)\n",
517
+ "controlnet_Num_widget = widgets.Text(description='Номер ControlNet:', placeholder='Введите номера моделей ControlNet для скачивания через запятую/пробел.', style=style, layout=layout)\n",
518
+ "commit_hash_widget = widgets.Text(description='Commit Hash:', style=style, layout=layout)\n",
519
+ "optional_huggingface_token_widget = widgets.Text(description='Токен HuggingFace:', style=style, layout=layout)\n",
520
+ "ngrok_token_widget = widgets.Text(description='Токен Ngrok:', style=style, layout=widgets.Layout(width='1047px'))\n",
521
+ "ngrock_button = widgets.HTML('<a href=\"https://dashboard.ngrok.com/get-started/your-authtoken\" target=\"_blank\">Получить Ngrok Токен</a>').add_class(\"button_ngrok\")\n",
522
+ "ngrok_widget = widgets.HBox([ngrok_token_widget, ngrock_button], style=style, layout=layout)\n",
523
+ "zrok_token_widget = widgets.Text(description='Zrok Token:', style=style, layout=widgets.Layout(width='1047px'))\n",
524
+ "zrok_button = widgets.HTML('<a href=\"https://colab.research.google.com/drive/1d2sjWDJi_GYBUavrHSuQyHTDuLy36WpU\" target=\"_blank\">Зарегать Zrok Токен</a>').add_class(\"button_ngrok\")\n",
525
+ "zrok_widget = widgets.HBox([zrok_token_widget, zrok_button], style=style, layout=layout)\n",
526
+ "# ---\n",
527
+ "commandline_arguments_options = \"--listen --enable-insecure-extension-access --theme dark --no-half-vae --disable-console-progressbars --xformers\"\n",
528
+ "commandline_arguments_widget = widgets.Text(description='Аргументы:', value=commandline_arguments_options, style=style, layout=layout)\n",
529
+ "\n",
530
+ "''' Display Additional'''\n",
531
+ "additional_widget_list = [additional_header, latest_changes_widget, HR, controlnet_widget, controlnet_Num_widget, commit_hash_widget, optional_huggingface_token_widget, ngrok_widget, zrok_widget, HR, commandline_arguments_widget]\n",
532
+ "if free_plan and env == \"Google Colab\": # remove ngrok from colab\n",
533
+ " additional_widget_list.remove(ngrok_widget)\n",
534
+ "# ```\n",
535
+ "all_additional_box = widgets.VBox(additional_widget_list).add_class(\"container\").add_class(\"image_3\")\n",
536
+ "display(all_additional_box)\n",
537
+ "\n",
538
+ "# --- CUSTOM DOWNLOAD ---\n",
539
+ "custom_download_header_popup = widgets.HTML('''\n",
540
+ "<style>\n",
541
+ "/* Color */\n",
542
+ ".sample_label {color: #dbafff;}\n",
543
+ ".braces {color: #ffff00;}\n",
544
+ ".extension {color: #eb934b;}\n",
545
+ ".file_name {color: #ffffd8;}\n",
546
+ "</style>\n",
547
+ "\n",
548
+ "<div class=\"header\" style=\"cursor: pointer;\" onclick=\"toggleContainer()\">Кастомная Загрузка</div>\n",
549
+ "<!-- PopUp window -->\n",
550
+ "<div class=\"info\" id=\"info_dl\">INFO</div>\n",
551
+ "<div class=\"popup\">\n",
552
+ " Разделите несколько URL-адресов запятой/пробелом. Для <span class=\"file_name\">пользовательского имени</span> файла/расширения укажите его через <span class=\"braces\">[]</span>\n",
553
+ " после URL без пробелов.\n",
554
+ " <span style=\"color: #ff9999\">Для файлов обязательно укажите</span> - <span class=\"extension\">Расширение Файла.</span>\n",
555
+ " <div class=\"sample\">\n",
556
+ " <span class=\"sample_label\">Пример для Файла:</span>\n",
557
+ " 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",
558
+ " <br>\n",
559
+ " <span class=\"sample_label\">Пример для Расширения:</span>\n",
560
+ " 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",
561
+ " </div>\n",
562
+ "</div>\n",
563
+ "''')\n",
564
+ "# ---\n",
565
+ "Model_url_widget = widgets.Text(description='Model:', style=style, layout=layout)\n",
566
+ "Vae_url_widget = widgets.Text(description='Vae:', style=style, layout=layout)\n",
567
+ "LoRA_url_widget = widgets.Text(description='LoRa:', style=style, layout=layout)\n",
568
+ "Embedding_url_widget = widgets.Text(description='Embedding:', style=style, layout=layout)\n",
569
+ "Extensions_url_widget = widgets.Text(description='Extensions:', style=style, layout=layout)\n",
570
+ "custom_file_urls_widget = widgets.Text(description='Файл (txt):', style=style, layout=layout)\n",
571
+ "\n",
572
+ "''' Display CustomDl'''\n",
573
+ "all_custom_box = widgets.VBox([\n",
574
+ " custom_download_header_popup, Model_url_widget, Vae_url_widget, LoRA_url_widget, Embedding_url_widget, Extensions_url_widget, custom_file_urls_widget\n",
575
+ " ]).add_class(\"container\").add_class(\"image_4\").add_class(\"container_custom_downlad\")\n",
576
+ "display(all_custom_box)\n",
577
+ "\n",
578
+ "# --- Save Button ---\n",
579
+ "save_button = widgets.Button(description='Сохранить').add_class(\"button_save\")\n",
580
+ "display(save_button)\n",
581
+ "\n",
582
+ "\n",
583
+ "# ============ Load / Save - Settings V2 ============\n",
584
+ "SETTINGS_FILE = f'{root_path}/settings.json'\n",
585
+ "\n",
586
+ "settings_keys = [\n",
587
+ " 'Model', 'Model_Num', 'Inpainting_Model',\n",
588
+ " 'Vae', 'Vae_Num',\n",
589
+ " 'latest_webui', 'latest_exstensions', 'detailed_download',\n",
590
+ " 'controlnet', 'controlnet_Num', 'commit_hash', 'optional_huggingface_token',\n",
591
+ " 'ngrok_token', 'zrok_token', 'commandline_arguments',\n",
592
+ " 'Model_url', 'Vae_url', 'LoRA_url', 'Embedding_url', 'Extensions_url', 'custom_file_urls'\n",
593
+ "]\n",
594
+ "\n",
595
+ "def save_settings():\n",
596
+ " settings = {key: globals()[f\"{key}_widget\"].value for key in settings_keys}\n",
597
+ " with open(SETTINGS_FILE, 'w') as f:\n",
598
+ " json.dump(settings, f, indent=2)\n",
599
+ "\n",
600
+ "def load_settings():\n",
601
+ " if os.path.exists(SETTINGS_FILE):\n",
602
+ " with open(SETTINGS_FILE, 'r') as f:\n",
603
+ " settings = json.load(f)\n",
604
+ " for key in settings_keys:\n",
605
+ " globals()[f\"{key}_widget\"].value = settings.get(key)\n",
606
+ "\n",
607
+ "def save_data(button):\n",
608
+ " save_settings()\n",
609
+ "\n",
610
+ " # --- uhh - hide... ---\n",
611
+ " widgets_list = [all_model_box, all_vae_box, all_additional_box, all_custom_box, save_button]\n",
612
+ " for widget in widgets_list:\n",
613
+ " widget.add_class(\"hide\")\n",
614
+ " time.sleep(0.5)\n",
615
+ "\n",
616
+ " widgets.Widget.close_all()\n",
617
+ "\n",
618
+ "settings = load_settings()\n",
619
+ "save_button.on_click(save_data)"
620
+ ],
621
+ "metadata": {
622
+ "id": "2lJmbqrs3Mu8"
623
+ },
624
+ "execution_count": null,
625
+ "outputs": []
626
+ }
627
+ ]
628
+ }
files_cells/python/en/auto-cleaner_en.py ADDED
@@ -0,0 +1,324 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ##~ AutoCleaner V3.6 CODE | BY: ANXETY ~##
2
+
3
+ import os
4
+ import time
5
+ import ipywidgets as widgets
6
+ from ipywidgets import Label, Button, VBox, HBox
7
+ from IPython.display import display, HTML, Javascript
8
+
9
+
10
+ # ================= DETECT ENV =================
11
+ def detect_environment():
12
+ free_plan = (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024. ** 3) <= 20)
13
+ environments = {
14
+ 'COLAB_GPU': ('Google Colab', "/root" if free_plan else "/content"),
15
+ 'KAGGLE_URL_BASE': ('Kaggle', "/kaggle/working/content")
16
+ }
17
+
18
+ for env_var, (environment, path) in environments.items():
19
+ if env_var in os.environ:
20
+ return environment, path, free_plan
21
+
22
+ env, root_path, free_plan = detect_environment()
23
+ webui_path = f"{root_path}/sdw"
24
+ # ----------------------------------------------
25
+
26
+
27
+ # ==================== CSS ====================
28
+ CSS = """
29
+ <style>
30
+ /* General Styles */
31
+
32
+ hr {
33
+ border-color: grey;
34
+ background-color: grey;
35
+ opacity: 0.25;
36
+ }
37
+
38
+ .instruction_AC {
39
+ font-family: cursive;
40
+ font-size: 18px;
41
+ color: grey;
42
+ user-select: none;
43
+ cursor: default;
44
+ }
45
+
46
+
47
+ /* Container style */
48
+
49
+ .container_AC {
50
+ position: relative;
51
+ background-color: #232323;
52
+ width: 800px;
53
+ height: auto;
54
+ padding: 15px;
55
+ border-radius: 15px;
56
+ box-shadow: 0 0 50px rgba(0, 0, 0, 0.3);
57
+ margin-bottom: 5px;
58
+ overflow: visible;
59
+ }
60
+
61
+ .container_AC::before {
62
+ position: absolute;
63
+ top: 5px;
64
+ right: 10px;
65
+ content: "AutoCleanerV3.6";
66
+ font-weight: bold;
67
+ font-size: 24px;
68
+ color: rgba(0, 0, 0, 0.2);
69
+ }
70
+
71
+ .container_AC::after {
72
+ position: absolute;
73
+ top: 30px;
74
+ right: 10px;
75
+ content: "ANXETY";
76
+ font-weight: bold;
77
+ font-size: 18px;
78
+ color: rgba(0, 0, 0, 0.2);
79
+ }
80
+
81
+ .custom-select-multiple_AC select {
82
+ padding: 10px;
83
+ font-family: cursive;
84
+ border: 1px solid #262626 !important;
85
+ border-radius: 10px;
86
+ color: white;
87
+ background-color: #1c1c1c;
88
+ box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);
89
+ }
90
+
91
+ .output_AC {
92
+ padding: 10px;
93
+ height: auto;
94
+ border: 1px solid #262626;
95
+ border-radius: 10px;
96
+ background-color: #1c1c1c;
97
+ box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);
98
+ width: auto;
99
+ box-sizing: border-box;
100
+ }
101
+
102
+ .output_message_AC {
103
+ font-family: cursive;
104
+ color: white !important;
105
+ font-size: 14px;
106
+ user-select: none;
107
+ cursor: default
108
+ }
109
+
110
+
111
+ .storage_info_AC {
112
+ padding: 5px 20px;
113
+ height: auto;
114
+ border: 1px solid #262626;
115
+ border-radius: 10px;
116
+ background-color: #1c1c1c;
117
+ box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);
118
+ width: auto;
119
+ font-family: cursive;
120
+ color: #B2B2B2 !important;
121
+ font-size: 14px;
122
+ user-select: none;
123
+ cursor: default
124
+ }
125
+
126
+
127
+ /* Button and storage info layout */
128
+ .lower_information_panel_AC {
129
+ display: flex;
130
+ align-items: center;
131
+ justify-content: space-between;
132
+ }
133
+
134
+
135
+ /* Button style */
136
+
137
+ .button_AC {
138
+ width: auto;
139
+ font-family: cursive;
140
+ color: white !important;
141
+ font-size: 14px;
142
+ font-weight: bold;
143
+ height: 35px;
144
+ border-radius: 15px;
145
+ background-image: radial-gradient(circle at top left, purple 10%, violet 90%);
146
+ background-size: 200% 200%;
147
+ background-position: left bottom;
148
+ transition: background 0.5s ease-in-out, transform 0.3s ease;
149
+ }
150
+
151
+ .button_AC:hover {
152
+ cursor: pointer;
153
+ background-size: 200% 200%;
154
+ background-position: right bottom;
155
+ transform: translateY(1px);
156
+ }
157
+
158
+ .button_execute_AC:hover {
159
+ background-image: radial-gradient(circle at top left, purple 10%, #93ac47 90%);
160
+ }
161
+
162
+ .button_clear_AC:hover {
163
+ background-image: radial-gradient(circle at top left, purple 10%, #fc3468 90%);
164
+ }
165
+
166
+ .button_execute_AC:active,
167
+ .button_clear_AC:active {
168
+ filter: brightness(0.75);
169
+ }
170
+
171
+ .jupyter-widgets.lm-Widget:focus {
172
+ outline: none;
173
+ }
174
+
175
+
176
+ /* Animation of elements */
177
+
178
+ /* Emergence */
179
+ .container_AC {
180
+ animation-name: slideInTopBlur;
181
+ animation-duration: 0.7s;
182
+ animation-fill-mode: forwards;
183
+ }
184
+
185
+ @keyframes slideInTopBlur {
186
+ 0% {
187
+ transform: translate3d(0, 50%, 0) scale(0.85) rotate3d(1, 0, 0, -85deg);
188
+ filter: blur(5px) grayscale(1) brightness(0.5);
189
+ opacity: 0;
190
+ }
191
+ 100% {
192
+ transform: translate3d(0, 0, 0) scale(1) rotate3d(1, 0, 0, 0deg);
193
+ filter: blur(0) grayscale(0) brightness(1);
194
+ opacity: 1;
195
+ }
196
+ }
197
+
198
+ /* Leaving */
199
+ .container_AC.hide {
200
+ animation-name: slideOutTopBlur;
201
+ animation-duration: 0.5s;
202
+ animation-fill-mode: forwards;
203
+ }
204
+
205
+ @keyframes slideOutTopBlur {
206
+ 0% {
207
+ transform: translate3d(0, 0, 0) scale(1);
208
+ filter: blur(0) grayscale(0) brightness(1);
209
+ opacity: 1;
210
+ }
211
+ 100% {
212
+ transform: translate3d(0, -100%, 0);
213
+ filter: blur(5px) grayscale(1) brightness(0);
214
+ opacity: 0;
215
+ }
216
+ }
217
+ </style>
218
+ """
219
+
220
+ display(HTML(CSS))
221
+ # ==================== CSS ====================
222
+
223
+
224
+ # ================ AutoCleaner function ================
225
+ directories = {
226
+ "Images": f"{webui_path}/outputs",
227
+ "Models": f"{webui_path}/models/Stable-diffusion/",
228
+ "Vae": f"{webui_path}/models/VAE/",
229
+ "LoRa": f"{webui_path}/models/Lora/",
230
+ "ControlNet Models": f"{webui_path}/models/ControlNet/"
231
+ }
232
+
233
+ """ functions """
234
+ def clean_directory(directory):
235
+ deleted_files = 0
236
+ for root, dirs, files in os.walk(directory):
237
+ for file in files:
238
+ if file.endswith(".txt"):
239
+ continue
240
+ os.remove(os.path.join(root, file))
241
+ if not file.endswith(".yaml"):
242
+ deleted_files += 1
243
+ return deleted_files
244
+
245
+ def update_memory_info():
246
+ disk_space = psutil.disk_usage(os.getcwd())
247
+ total = disk_space.total / (1024 ** 3)
248
+ used = disk_space.used / (1024 ** 3)
249
+ free = disk_space.free / (1024 ** 3)
250
+
251
+ storage_info.value = f'''
252
+ <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>
253
+ '''
254
+
255
+ def on_execute_button_press(button):
256
+ selected_cleaners = auto_cleaner_widget.value
257
+ deleted_files_dict = {}
258
+
259
+ for option in selected_cleaners:
260
+ if option in directories:
261
+ deleted_files_dict[option] = clean_directory(directories[option])
262
+
263
+ output.clear_output()
264
+
265
+ with output:
266
+ for message in generate_messages(deleted_files_dict):
267
+ message_widget = HTML(f'<p class="output_message_AC">{message}</p>')
268
+ display(message_widget)
269
+
270
+ update_memory_info()
271
+
272
+ def on_clear_button_press(button):
273
+ container.add_class("hide")
274
+ time.sleep(0.5)
275
+ widgets.Widget.close_all()
276
+
277
+ def generate_messages(deleted_files_dict):
278
+ messages = []
279
+ word_variants = {
280
+ "Images": "Images",
281
+ "Models": "Models",
282
+ "Vae": "Vae",
283
+ "LoRa": "LoRa",
284
+ "ControlNet Models": "ControlNet Models"
285
+ }
286
+ for key, value in deleted_files_dict.items():
287
+ object_word = word_variants.get(key)
288
+ messages.append(f"Deleted {value} {object_word}")
289
+ return messages
290
+ # ================ AutoCleaner function ================
291
+
292
+
293
+ # --- storage memory ---
294
+ import psutil
295
+ disk_space = psutil.disk_usage(os.getcwd())
296
+ total = disk_space.total / (1024 ** 3)
297
+ used = disk_space.used / (1024 ** 3)
298
+ free = disk_space.free / (1024 ** 3)
299
+
300
+
301
+ # UI Code
302
+ AutoCleaner_options = AutoCleaner_options = list(directories.keys())
303
+ instruction_label = widgets.HTML('''
304
+ <span class="instruction_AC">Use <span style="color: #B2B2B2;">ctrl</span> or <span style="color: #B2B2B2;">shift</span> for multiple selections.</span>
305
+ ''')
306
+ auto_cleaner_widget = widgets.SelectMultiple(options=AutoCleaner_options, layout=widgets.Layout(width='auto')).add_class("custom-select-multiple_AC")
307
+ output = widgets.Output().add_class("output_AC")
308
+ # ---
309
+ execute_button = Button(description='Execute Cleaning').add_class("button_execute_AC").add_class("button_AC")
310
+ execute_button.on_click(on_execute_button_press)
311
+ clear_button = Button(description='Hide Widget').add_class("button_clear_AC").add_class("button_AC")
312
+ clear_button.on_click(on_clear_button_press)
313
+ # ---
314
+ storage_info = widgets.HTML(f'''
315
+ <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>
316
+ ''')
317
+ # ---
318
+ buttons = widgets.HBox([execute_button, clear_button])
319
+ lower_information_panel = widgets.HBox([buttons, storage_info]).add_class("lower_information_panel_AC")
320
+
321
+ container = VBox([instruction_label, widgets.HTML('<hr>'), auto_cleaner_widget, output, widgets.HTML('<hr>'), lower_information_panel]).add_class("container_AC")
322
+
323
+ display(container)
324
+
files_cells/python/en/downloading_en.py ADDED
@@ -0,0 +1,538 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ free_plan = (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024. ** 3) <= 20)
19
+ environments = {
20
+ 'COLAB_GPU': ('Google Colab', "/root" if free_plan else "/content"),
21
+ 'KAGGLE_URL_BASE': ('Kaggle', "/kaggle/working/content")
22
+ }
23
+
24
+ for env_var, (environment, path) in environments.items():
25
+ if env_var in os.environ:
26
+ return environment, path, free_plan
27
+
28
+ env, root_path, free_plan = detect_environment()
29
+ webui_path = f"{root_path}/sdw"
30
+ # ----------------------------------------------
31
+
32
+
33
+ # ================ LIBRARIES V2 ================
34
+ flag_file = f"{root_path}/libraries_installed.txt"
35
+
36
+ if not os.path.exists(flag_file):
37
+ print("💿 Installing the libraries, it's going to take a while:\n")
38
+
39
+ install_lib = {
40
+ "gdown": "pip install -U gdown",
41
+ "aria2": "apt-get update && apt -y install aria2",
42
+ "localtunnel": "npm install -g localtunnel &> /dev/null",
43
+ "insightface": "pip install insightface",
44
+ }
45
+
46
+ # Dictionary of additional libraries specific to certain environments
47
+ additional_libs = {
48
+ "Google Colab": {
49
+ "xformers": "pip install xformers==0.0.25 --no-deps"
50
+ },
51
+ "Kaggle": {
52
+ "xformers": "pip install -q xformers==0.0.23.post1 triton==2.1.0",
53
+ "torch": "pip install -q torch==2.1.2+cu121 torchvision==0.16.2+cu121 torchaudio==2.1.2 --extra-index-url https://download.pytorch.org/whl/cu121"
54
+ }
55
+ }
56
+
57
+ # If the current environment has additional libraries, update the install_lib dictionary
58
+ if env in additional_libs:
59
+ install_lib.update(additional_libs[env])
60
+
61
+ # Loop through libraries and execute install commands
62
+ for index, (package, install_cmd) in enumerate(install_lib.items(), start=1):
63
+ print(f"\r[{index}/{len(install_lib)}] \033[32m>>\033[0m Installing \033[33m{package}\033[0m..." + " "*35, end='')
64
+ subprocess.run(install_cmd, shell=True, capture_output=True)
65
+
66
+ # Additional manual installation steps for specific packages
67
+ with capture.capture_output() as cap:
68
+ get_ipython().system('curl -s -OL https://github.com/vorstcavry/tunnel/res/new_tunnel --output-dir {root_path}')
69
+ 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')
70
+ get_ipython().system('curl -sLO https://github.com/openziti/zrok/releases/download/v0.4.23/zrok_0.4.23_linux_amd64.tar.gz && tar -xzf zrok_0.4.23_linux_amd64.tar.gz -C /usr/bin && rm -f zrok_0.4.23_linux_amd64.tar.gz')
71
+ del cap
72
+
73
+ clear_output()
74
+
75
+ # Save file install lib
76
+ with open(flag_file, "w") as f:
77
+ f.write(">W<'")
78
+
79
+ print("🍪 Libraries are installed!" + " "*35)
80
+ time.sleep(2)
81
+ clear_output()
82
+
83
+
84
+ # ================= loading settings V4 =================
85
+ def load_settings(path):
86
+ if os.path.exists(path):
87
+ with open(path, 'r') as file:
88
+ return json.load(file)
89
+ return {}
90
+
91
+ settings = load_settings(f'{root_path}/settings.json')
92
+
93
+ variables = [
94
+ 'Model', 'Model_Num', 'Inpainting_Model',
95
+ 'Vae', 'Vae_Num',
96
+ 'latest_webui', 'latest_exstensions', 'detailed_download',
97
+ 'controlnet', 'controlnet_Num', 'commit_hash', 'optional_huggingface_token',
98
+ 'ngrok_token', 'zrok_token', 'commandline_arguments',
99
+ 'Model_url', 'Vae_url', 'LoRA_url', 'Embedding_url', 'Extensions_url', 'custom_file_urls'
100
+ ]
101
+
102
+ locals().update({key: settings.get(key) for key in variables})
103
+
104
+
105
+ # ================= OTHER =================
106
+ try:
107
+ start_colab
108
+ except:
109
+ start_colab = int(time.time())-5
110
+
111
+ # CONFIG DIR
112
+ models_dir = f"{webui_path}/models/Stable-diffusion"
113
+ vaes_dir = f"{webui_path}/models/VAE"
114
+ embeddings_dir = f"{webui_path}/embeddings"
115
+ loras_dir = f"{webui_path}/models/Lora"
116
+ extensions_dir = f"{webui_path}/extensions"
117
+ control_dir = f"{webui_path}/models/ControlNet"
118
+
119
+
120
+ # ================= MAIN CODE =================
121
+ if not os.path.exists(webui_path):
122
+ start_install = int(time.time())
123
+ print("⌚ Unpacking Stable Diffusion...", end='')
124
+ with capture.capture_output() as cap:
125
+ 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')
126
+ get_ipython().system('unzip -q -o repo.zip -d {webui_path}')
127
+ get_ipython().system('rm -rf repo.zip')
128
+
129
+ get_ipython().run_line_magic('cd', '{root_path}')
130
+ os.environ["SAFETENSORS_FAST_GPU"]='1'
131
+ os.environ["CUDA_MODULE_LOADING"]="LAZY"
132
+ os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
133
+ os.environ["PYTHONWARNINGS"] = "ignore"
134
+
135
+ get_ipython().system('echo -n {start_colab} > {webui_path}/static/colabTimer.txt')
136
+ del cap
137
+ install_time = timedelta(seconds=time.time()-start_install)
138
+ 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)
139
+ else:
140
+ print("🚀 All unpacked... Skip. ⚡")
141
+ start_colab = float(open(f'{webui_path}/static/colabTimer.txt', 'r').read())
142
+ time_since_start = str(timedelta(seconds=time.time()-start_colab)).split('.')[0]
143
+ print(f"⌚️ You have been conducting this session for - \033[33m{time_since_start}\033[0m")
144
+
145
+
146
+ ## Changes extensions and WebUi
147
+ if latest_webui or latest_exstensions:
148
+ action = "Updating WebUI and Extensions" if latest_webui and latest_exstensions else ("WebUI Update" if latest_webui else "Update Extensions")
149
+ print(f"⌚️ {action}...", end='', flush=True)
150
+ with capture.capture_output() as cap:
151
+ get_ipython().system('git config --global user.email "[email protected]"')
152
+ get_ipython().system('git config --global user.name "Your Name"')
153
+
154
+ ## Update Webui
155
+ if latest_webui:
156
+ get_ipython().run_line_magic('cd', '{webui_path}')
157
+ get_ipython().system('git restore .')
158
+ get_ipython().system('git pull -X theirs --rebase --autostash')
159
+
160
+ ## Update extensions
161
+ if latest_exstensions:
162
+ get_ipython().system('{\'for dir in \' + webui_path + \'/extensions/*/; do cd \\"$dir\\" && git reset --hard && git pull; done\'}')
163
+
164
+ # My Chinese friend, you broke the images again in the latest update... >W<'
165
+ get_ipython().run_line_magic('cd', '{webui_path}/extensions/Encrypt-Image')
166
+ get_ipython().system('git reset --hard 376358d8854472b9ea50e9fc8800367d1ca51137 # stable commit :3')
167
+ del cap
168
+ print(f"\r✨ {action} Completed!")
169
+
170
+
171
+ # === FIXING EXTENSIONS ===
172
+ anxety_repos = "https://huggingface.co/NagisaNao/fast_repo/resolve/main"
173
+
174
+ with capture.capture_output() as cap:
175
+ # --- Encrypt-Image ---
176
+ get_ipython().system("sed -i '9,37d' {webui_path}/extensions/Encrypt-Image/javascript/encrypt_images_info.js")
177
+
178
+ # --- Additional-Networks ---
179
+ get_ipython().system('wget -O {webui_path}/extensions/additional-networks/scripts/metadata_editor.py {anxety_repos}/extensions/Additional-Networks/fix/metadata_editor.py')
180
+ del cap
181
+
182
+
183
+ ## Version switching
184
+ if commit_hash:
185
+ print('⏳ Time machine activation...', end="", flush=True)
186
+ with capture.capture_output() as cap:
187
+ get_ipython().run_line_magic('cd', '{webui_path}')
188
+ get_ipython().system('git config --global user.email "[email protected]"')
189
+ get_ipython().system('git config --global user.name "Your Name"')
190
+ get_ipython().system('git reset --hard {commit_hash}')
191
+ del cap
192
+ print(f"\r⌛️ The time machine has been activated! Current commit: \033[34m{commit_hash}\033[0m")
193
+
194
+
195
+ ## Downloading model and stuff | oh yeah~ I'm starting to misunderstand my own code ( almost my own ;3 )
196
+ print("📦 Downloading models and stuff...", end='')
197
+ model_list = {
198
+ "1.Anime (by XpucT) + INP": [
199
+ {"url": "https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2.safetensors", "name": "Anime_v2.safetensors"},
200
+ {"url": "https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2-inpainting.safetensors", "name": "Anime_v2-inpainting.safetensors"}
201
+ ],
202
+ "2.BluMix [Anime] [V7] + INP": [
203
+ {"url": "https://civitai.com/api/download/models/361779", "name": "BluMix_v7.safetensors"},
204
+ {"url": "https://civitai.com/api/download/models/363850", "name": "BluMix_v7-inpainting.safetensors"}
205
+ ],
206
+ "3.Cetus-Mix [Anime] [V4] + INP": [
207
+ {"url": "https://civitai.com/api/download/models/130298", "name": "CetusMix_V4.safetensors"},
208
+ {"url": "https://civitai.com/api/download/models/139882", "name": "CetusMix_V4-inpainting.safetensors"}
209
+ ],
210
+ "4.Counterfeit [Anime] [V3] + INP": [
211
+ {"url": "https://civitai.com/api/download/models/125050", "name": "Counterfeit_V3.safetensors"},
212
+ {"url": "https://civitai.com/api/download/models/137911", "name": "Counterfeit_V3-inpainting.safetensors"}
213
+ ],
214
+ "5.CuteColor [Anime] [V3]": [
215
+ {"url": "https://civitai.com/api/download/models/138754", "name": "CuteColor_V3.safetensors"}
216
+ ],
217
+ "6.Dark-Sushi-Mix [Anime]": [
218
+ {"url": "https://civitai.com/api/download/models/101640", "name": "DarkSushiMix_2_5D.safetensors"},
219
+ {"url": "https://civitai.com/api/download/models/56071", "name": "DarkSushiMix_colorful.safetensors"}
220
+ ],
221
+ "7.Deliberate [Realism] [V6] + INP": [
222
+ {"url": "https://huggingface.co/XpucT/Deliberate/resolve/main/Deliberate_v6.safetensors", "name": "Deliberate_v6.safetensors"},
223
+ {"url": "https://huggingface.co/XpucT/Deliberate/resolve/main/Deliberate_v6-inpainting.safetensors", "name": "Deliberate_v6-inpainting.safetensors"}
224
+ ],
225
+ "8.Meina-Mix [Anime] [V11] + INP": [
226
+ {"url": "https://civitai.com/api/download/models/119057", "name": "MeinaMix_V11.safetensors"},
227
+ {"url": "https://civitai.com/api/download/models/120702", "name": "MeinaMix_V11-inpainting.safetensors"}
228
+ ],
229
+ "9.Mix-Pro [Anime] [V4] + INP": [
230
+ {"url": "https://civitai.com/api/download/models/125668", "name": "MixPro_V4.safetensors"},
231
+ {"url": "https://civitai.com/api/download/models/139878", "name": "MixPro_V4-inpainting.safetensors"}
232
+ ]
233
+ }
234
+
235
+ # 1-4 (fp16/cleaned)
236
+ vae_list = {
237
+ "1.Anime.vae": [
238
+ {"url": "https://civitai.com/api/download/models/131654", "name": "Anime.vae.safetensors"},
239
+ {"url": "https://civitai.com/api/download/models/131658", "name": "vae-ft-mse.vae.safetensors"}
240
+ ],
241
+ "2.Anything.vae": [{"url": "https://civitai.com/api/download/models/131656", "name": "Anything.vae.safetensors"}],
242
+ "3.Blessed2.vae": [{"url": "https://civitai.com/api/download/models/142467", "name": "Blessed2.vae.safetensors"}],
243
+ "4.ClearVae.vae": [{"url": "https://civitai.com/api/download/models/133362", "name": "ClearVae_23.vae.safetensors"}],
244
+ "5.WD.vae": [{"url": "https://huggingface.co/NoCrypt/resources/resolve/main/VAE/wd.vae.safetensors", "name": "WD.vae.safetensors"}]
245
+ }
246
+
247
+ controlnet_list = {
248
+ "1.canny": [
249
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny_fp16.safetensors", "name": "control_v11p_sd15_canny_fp16.safetensors"},
250
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_canny_fp16.yaml", "name": "control_v11p_sd15_canny_fp16.yaml"}
251
+ ],
252
+ "2.openpose": [
253
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose_fp16.safetensors", "name": "control_v11p_sd15_openpose_fp16.safetensors"},
254
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_openpose_fp16.yaml", "name": "control_v11p_sd15_openpose_fp16.yaml"}
255
+ ],
256
+ "3.depth": [
257
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth_fp16.safetensors", "name": "control_v11f1p_sd15_depth_fp16.safetensors"},
258
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1p_sd15_depth_fp16.yaml", "name": "control_v11f1p_sd15_depth_fp16.yaml"},
259
+ {"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"}
260
+ ],
261
+ "4.normal_map": [
262
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_normalbae_fp16.safetensors", "name": "control_v11p_sd15_normalbae_fp16.safetensors"},
263
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_normalbae_fp16.yaml", "name": "control_v11p_sd15_normalbae_fp16.yaml"}
264
+ ],
265
+ "5.mlsd": [
266
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_mlsd_fp16.safetensors", "name": "control_v11p_sd15_mlsd_fp16.safetensors"},
267
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_mlsd_fp16.yaml", "name": "control_v11p_sd15_mlsd_fp16.yaml"}
268
+ ],
269
+ "6.lineart": [
270
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart_fp16.safetensors", "name": "control_v11p_sd15_lineart_fp16.safetensors"},
271
+ {"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"},
272
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_lineart_fp16.yaml", "name": "control_v11p_sd15_lineart_fp16.yaml"},
273
+ {"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"}
274
+ ],
275
+ "7.soft_edge": [
276
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge_fp16.safetensors", "name": "control_v11p_sd15_softedge_fp16.safetensors"},
277
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_softedge_fp16.yaml", "name": "control_v11p_sd15_softedge_fp16.yaml"}
278
+ ],
279
+ "8.scribble": [
280
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble_fp16.safetensors", "name": "control_v11p_sd15_scribble_fp16.safetensors"},
281
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_scribble_fp16.yaml", "name": "control_v11p_sd15_scribble_fp16.yaml"}
282
+ ],
283
+ "9.segmentation": [
284
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg_fp16.safetensors", "name": "control_v11p_sd15_seg_fp16.safetensors"},
285
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_seg_fp16.yaml", "name": "control_v11p_sd15_seg_fp16.yaml"}
286
+ ],
287
+ "10.shuffle": [
288
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle_fp16.safetensors", "name": "control_v11e_sd15_shuffle_fp16.safetensors"},
289
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_shuffle_fp16.yaml", "name": "control_v11e_sd15_shuffle_fp16.yaml"}
290
+ ],
291
+ "11.tile": [
292
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile_fp16.safetensors", "name": "control_v11f1e_sd15_tile_fp16.safetensors"},
293
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1e_sd15_tile_fp16.yaml", "name": "control_v11f1e_sd15_tile_fp16.yaml"}
294
+ ],
295
+ "12.inpaint": [
296
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_inpaint_fp16.safetensors", "name": "control_v11p_sd15_inpaint_fp16.safetensors"},
297
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_inpaint_fp16.yaml", "name": "control_v11p_sd15_inpaint_fp16.yaml"}
298
+ ],
299
+ "13.instruct_p2p": [
300
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p_fp16.safetensors", "name": "control_v11e_sd15_ip2p_fp16.safetensors"},
301
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_ip2p_fp16.yaml", "name": "control_v11e_sd15_ip2p_fp16.yaml"}
302
+ ]
303
+ }
304
+
305
+ extension_repo = []
306
+ prefixes = {
307
+ # It's complicated, but supplementing has become easier
308
+ "model": [models_dir, "Model_url"],
309
+ "vae": [vaes_dir, "Vae_url"],
310
+ "lora": [loras_dir, "LoRA_url"],
311
+ "embed": [embeddings_dir, "Embedding_url"],
312
+ "extension": [extensions_dir, "Extensions_url"],
313
+ "control": [control_dir, "ControlNet_url"]
314
+ }
315
+
316
+ get_ipython().system('mkdir -p {models_dir} {vaes_dir} {loras_dir} {embeddings_dir} {extensions_dir} {control_dir}')
317
+
318
+ url = ""
319
+ ControlNet_url = ""
320
+ hf_token = optional_huggingface_token if optional_huggingface_token else "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"
321
+ user_header = f"\"Authorization: Bearer {hf_token}\""
322
+
323
+ ''' main download code '''
324
+
325
+ def handle_manual(url):
326
+ original_url = url
327
+ url = url.split(':', 1)[1]
328
+ file_name = re.search(r'\[(.*?)\]', url)
329
+ file_name = file_name.group(1) if file_name else None
330
+ if file_name:
331
+ url = re.sub(r'\[.*?\]', '', url)
332
+
333
+ for prefix, (dir, _) in prefixes.items():
334
+ if original_url.startswith(f"{prefix}:"):
335
+ if prefix != "extension":
336
+ manual_download(url, dir, file_name=file_name)
337
+ else:
338
+ extension_repo.append((url, file_name))
339
+
340
+ def manual_download(url, dst_dir, file_name):
341
+ basename = url.split("/")[-1] if file_name is None else file_name
342
+ header_option = f"--header={user_header}"
343
+
344
+ print("\033[32m---"*45 + f"\n\033[33mURL: \033[34m{url}\n\033[33mSAVE DIR: \033[34m{dst_dir}\n\033[33mFILE NAME: \033[34m{file_name}\033[32m\n~~~\033[0m")
345
+
346
+ # I do it at my own risk..... Fucking CivitAi >:(
347
+ civitai_token = "62c0c5956b2f9defbd844d754000180b"
348
+ if 'civitai' in url and civitai_token:
349
+ url = f"{url}?token={civitai_token}"
350
+
351
+ # -- GDrive --
352
+ if 'drive.google' in url:
353
+ if 'folders' in url:
354
+ get_ipython().system('gdown --folder "{url}" -O {dst_dir} --fuzzy -c')
355
+ else:
356
+ if file_name:
357
+ get_ipython().system('gdown "{url}" -O {dst_dir}/{file_name} --fuzzy -c')
358
+ else:
359
+ get_ipython().system('gdown "{url}" -O {dst_dir} --fuzzy -c')
360
+ # -- Huggin Face --
361
+ elif 'huggingface' in url:
362
+ if '/blob/' in url:
363
+ url = url.replace('/blob/', '/resolve/')
364
+ if file_name:
365
+ get_ipython().system('aria2c {header_option} --optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -c -j5 -x16 -s16 -k1M -d {dst_dir} -o {basename} {url}')
366
+ else:
367
+ parsed_link = f'\n{url}\n\tout={unquote(url.split("/")[-1])}'
368
+ get_ipython().system('echo -e "{parsed_link}" | aria2c {header_option} --console-log-level=error --summary-interval=10 -i- -j5 -x16 -s16 -k1M -c -d "{dst_dir}" -o {basename}')
369
+ # -- Other --
370
+ elif 'http' in url or 'magnet' in url:
371
+ if file_name:
372
+ 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}')
373
+ else:
374
+ parsed_link = '"{}"'.format(url)
375
+ 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}')
376
+
377
+ def download(url):
378
+ links_and_paths = url.split(',')
379
+
380
+ for link_or_path in links_and_paths:
381
+ link_or_path = link_or_path.strip()
382
+ if not link_or_path:
383
+ continue
384
+ if any(link_or_path.startswith(prefix.lower()) for prefix in prefixes):
385
+ handle_manual(link_or_path)
386
+ continue
387
+
388
+ url, dst_dir, file_name = link_or_path.split()
389
+ manual_download(url, dst_dir, file_name)
390
+
391
+ ''' submodels - added urls '''
392
+
393
+ submodels = []
394
+
395
+ def add_submodels(selection, num_selection, model_dict, dst_dir):
396
+ if selection == "none":
397
+ return []
398
+ if selection == "ALL":
399
+ all_models = []
400
+ for models in model_dict.values():
401
+ all_models.extend(models)
402
+ selected_models = all_models
403
+ else:
404
+ selected_models = model_dict[selection]
405
+ selected_nums = map(int, num_selection.replace(',', '').split())
406
+
407
+ for num in selected_nums:
408
+ if 1 <= num <= len(model_dict):
409
+ name = list(model_dict)[num - 1]
410
+ selected_models.extend(model_dict[name])
411
+
412
+ unique_models = list({model['name']: model for model in selected_models}.values())
413
+
414
+ for model in unique_models:
415
+ model['dst_dir'] = dst_dir
416
+
417
+ return unique_models
418
+
419
+ submodels += add_submodels(Model, Model_Num, model_list, models_dir) # model
420
+ submodels += add_submodels(Vae, Vae_Num, vae_list, vaes_dir) # vae
421
+ submodels += add_submodels(controlnet, "" if controlnet == "ALL" else controlnet_Num, controlnet_list, control_dir) # controlnet
422
+
423
+ for submodel in submodels:
424
+ if not Inpainting_Model and "inpainting" in submodel['name']:
425
+ continue
426
+ url += f"{submodel['url']} {submodel['dst_dir']} {submodel['name']}, "
427
+
428
+ ''' file.txt - added urls '''
429
+
430
+ unique_urls = []
431
+
432
+ def process_file_download(file_url):
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 any(f'# {tag}' in line.lower() for tag in prefixes):
445
+ current_tag = next((tag for tag in prefixes if tag in line.lower()))
446
+
447
+ urls = [url.strip() for url in line.split(',')]
448
+ for url in urls:
449
+ if url.startswith("http") and url not in unique_urls:
450
+ globals()[prefixes[current_tag][1]] += ", " + url
451
+ unique_urls.append(url)
452
+
453
+ # fix all possible errors/options and function call
454
+ if custom_file_urls:
455
+ for custom_file_url in custom_file_urls.replace(',', '').split():
456
+ if not custom_file_url.endswith('.txt'):
457
+ custom_file_url += '.txt'
458
+ if not custom_file_url.startswith('http'):
459
+ if not custom_file_url.startswith(root_path):
460
+ custom_file_url = f'{root_path}/{custom_file_url}'
461
+
462
+ try:
463
+ process_file_download(custom_file_url)
464
+ except FileNotFoundError:
465
+ pass
466
+
467
+ # url prefixing
468
+ urls = [globals()[urls[1]] for urls in prefixes.values()]
469
+ for i, prefix in enumerate(prefixes):
470
+ if urls[i]:
471
+ prefixed_urls = [f"{prefix}:{url}" for url 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 {webui_path} \\( -type d \\( -name ".ipynb_checkpoints" -o -name ".aria2" \\) -o -type f -name "*.aria2" \\) -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
+
files_cells/python/en/launch_en.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ free_plan = (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024. ** 3) <= 20)
14
+ environments = {
15
+ 'COLAB_GPU': ('Google Colab', "/root" if free_plan else "/content"),
16
+ 'KAGGLE_URL_BASE': ('Kaggle', "/kaggle/working/content")
17
+ }
18
+
19
+ for env_var, (environment, path) in environments.items():
20
+ if env_var in os.environ:
21
+ return environment, path, free_plan
22
+
23
+ env, root_path, free_plan = 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
+ zrok_token = settings['zrok_token']
37
+ commandline_arguments = settings['commandline_arguments']
38
+
39
+
40
+ # ======================== TUNNEL ========================
41
+ import cloudpickle as pickle
42
+
43
+ def get_public_ip(version='ipv4'):
44
+ try:
45
+ url = f'https://api64.ipify.org?format=json&{version}=true'
46
+ response = requests.get(url)
47
+ data = response.json()
48
+ public_ip = data['ip']
49
+ return public_ip
50
+ except Exception as e:
51
+ print(f"Error getting public {version} address:", e)
52
+
53
+ public_ipv4 = get_public_ip(version='ipv4')
54
+
55
+ tunnel_class = pickle.load(open(f"{root_path}/new_tunnel", "rb"), encoding="utf-8")
56
+ tunnel_port= 1769
57
+ tunnel = tunnel_class(tunnel_port)
58
+ tunnel.add_tunnel(command="cl tunnel --url localhost:{port}", name="cl", pattern=re.compile(r"[\w-]+\.trycloudflare\.com"))
59
+ 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.")
60
+
61
+ ''' add zrok tunnel '''
62
+ if zrok_token:
63
+ get_ipython().system('zrok enable {zrok_token} &> /dev/null')
64
+ tunnel.add_tunnel(command="zrok share public http://localhost:{port}/ --headless", name="zrok", pattern=re.compile(r"[\w-]+\.share\.zrok\.io"))
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
+ with tunnel:
76
+ get_ipython().run_line_magic('cd', '{webui_path}')
77
+ commandline_arguments += f" --port=1769"
78
+
79
+ if ngrok_token:
80
+ commandline_arguments += ' --ngrok ' + ngrok_token
81
+ if env != "Google Colab":
82
+ commandline_arguments += f" --encrypt-pass=1769"
83
+
84
+ get_ipython().system('COMMANDLINE_ARGS="{commandline_arguments}" python launch.py')
85
+
86
+ start_colab = float(open(f'{webui_path}/static/colabTimer.txt', 'r').read())
87
+ time_since_start = str(timedelta(seconds=time.time()-start_colab)).split('.')[0]
88
+ print(f"\n⌚️ \033[0mYou have been conducting this session for - \033[33m{time_since_start}\033[0m\n\n")
89
+
files_cells/python/en/widgets_en.py ADDED
@@ -0,0 +1,601 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ##~ WIDGET CODE | BY: ANXETY ~##
2
+
3
+ import os
4
+ import json
5
+ import time
6
+ import ipywidgets as widgets
7
+ from ipywidgets import widgets, Layout, Label, Button, VBox, HBox
8
+ from IPython.display import display, HTML, Javascript, clear_output
9
+
10
+
11
+ # ================= DETECT ENV =================
12
+ def detect_environment():
13
+ free_plan = (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024. ** 3) <= 20)
14
+ environments = {
15
+ 'COLAB_GPU': ('Google Colab', "/root" if free_plan else "/content"),
16
+ 'KAGGLE_URL_BASE': ('Kaggle', "/kaggle/working/content")
17
+ }
18
+
19
+ for env_var, (environment, path) in environments.items():
20
+ if env_var in os.environ:
21
+ return environment, path, free_plan
22
+
23
+ env, root_path, free_plan = detect_environment()
24
+ webui_path = f"{root_path}/sdw"
25
+
26
+ get_ipython().system('mkdir -p {root_path}')
27
+ # ----------------------------------------------
28
+
29
+
30
+ # ==================== CSS JS ====================
31
+ # custom background images V1.5
32
+ import argparse
33
+ parser = argparse.ArgumentParser(description='This script processes an background image.')
34
+ parser.add_argument('-i', '--image', type=str, help='URL of the image to process', metavar='')
35
+ parser.add_argument('-o', '--opacity', type=float, help='Opacity level for the image, between 0 and 1', metavar='', default=0.3)
36
+ parser.add_argument('-b', '--blur', type=str, help='Blur level for the image', metavar='', default=0)
37
+ parser.add_argument('-y', type=int, help='Y coordinate for the image in px', metavar='', default=0)
38
+ parser.add_argument('-x', type=int, help='X coordinate for the image in px', metavar='', default=0)
39
+ parser.add_argument('-s', '--scale', type=int, help='Scale image in %%', metavar='', default=100)
40
+ parser.add_argument('-m', '--mode', action='store_true', help='Removes repetitive image tiles')
41
+ parser.add_argument('-t', '--transparent', action='store_true', help='Makes input/selection fields 35%% more transparent')
42
+ parser.add_argument('-bf', '--blur-fields', type=str, help='Background blur level for input/selection fields', metavar='', default=2)
43
+ args = parser.parse_args()
44
+ """---"""
45
+ url_img = args.image
46
+ opacity_img = args.opacity
47
+ blur_img = args.blur
48
+ y_img = args.y
49
+ x_img = args.x
50
+ scale_img = args.scale
51
+ blur_fields = args.blur_fields
52
+
53
+ ## ---
54
+ """ WTF KAGGLE - WHAT THE FUCK IS THE DIFFERENCE OF 35 PIXELS!?!?!? """
55
+ fix_heigh_img = "-810px" if env == "Kaggle" else "-775px"
56
+
57
+ """ transperent fields """
58
+ t_bg_alpha = "1" if not args.transparent else "0.65"
59
+
60
+ """ mode img - repeats """
61
+ mode_img = "repeat" if not args.mode else "no-repeat"
62
+ ## ---
63
+
64
+ container_background = f'''
65
+ <style>
66
+ :root {{
67
+ /* for background container*/
68
+ --img_background: url({url_img});
69
+ --img_opacity: {opacity_img};
70
+ --img_blur: {blur_img}px;
71
+ --image_y: {y_img}px;
72
+ --image_x: {x_img}px;
73
+ --img_scale: {scale_img}%;
74
+ --img_mode: {mode_img};
75
+ --img_height_dif: {fix_heigh_img};
76
+
77
+ /* for fields */
78
+ --bg-field-color: rgba(28, 28, 28, {t_bg_alpha}); /* -> #1c1c1c */
79
+ --bg-field-color-hover: rgba(38, 38, 38, {t_bg_alpha}); /* -> #262626; */
80
+ --bg-field-blur-level: {blur_fields}px;
81
+ }}
82
+ '''
83
+
84
+ display(HTML(container_background))
85
+ # ---
86
+
87
+ CSS = '''
88
+ <style>
89
+ /* General Styles */
90
+ .header {
91
+ font-family: cursive;
92
+ font-size: 20px;
93
+ font-weight: bold;
94
+ color: #ff8cee;
95
+ margin-bottom: 15px;
96
+ user-select: none;
97
+ cursor: default;
98
+ display: inline-block;
99
+ }
100
+
101
+ hr {
102
+ border-color: grey;
103
+ background-color: grey;
104
+ opacity: 0.25;
105
+ }
106
+
107
+ a {
108
+ text-decoration: none;
109
+ color: inherit;
110
+ }
111
+
112
+
113
+ /* Container style */
114
+
115
+ .container {
116
+ position: relative;
117
+ background-color: #232323;
118
+ width: 1080px;
119
+ padding: 10px 15px;
120
+ border-radius: 15px;
121
+ box-shadow: 0 0 50px rgba(0, 0, 0, 0.3);
122
+ margin-bottom: 5px;
123
+ overflow: hidden;
124
+ }
125
+
126
+ .container::after {
127
+ position: absolute;
128
+ top: 5px;
129
+ right: 10px;
130
+ content: "Vorst Cavry";
131
+ font-weight: bold;
132
+ font-size: 24px;
133
+ color: rgba(0, 0, 0, 0.2);
134
+ }
135
+
136
+ /* background img */
137
+ .container::before {
138
+ content: "";
139
+ position: absolute;
140
+ top: 0;
141
+ left: 0;
142
+ right: 0;
143
+ bottom: 0;
144
+ background-image: var(--img_background);
145
+ background-size: var(--img_scale);
146
+ background-repeat: var(--img_mode);
147
+ opacity: var(--img_opacity);
148
+ mix-blend-mode: screen;
149
+ pointer-events: none;
150
+ filter: blur(var(--img_blur));
151
+ z-index: -1;
152
+ }
153
+
154
+ .image_1::before {
155
+ background-position: var(--image_x) calc(-120px - var(--image_y));
156
+ }
157
+ .image_2::before {
158
+ background-position: var(--image_x) calc(-290px - var(--image_y));
159
+ }
160
+ .image_3::before {
161
+ background-position: var(--image_x) calc(-430px - var(--image_y));
162
+ }
163
+ .image_4::before {
164
+ background-position: var(--image_x) calc(var(--img_height_dif) - var(--image_y));
165
+ }
166
+
167
+ .container_custom_downlad {
168
+ height: 55px;
169
+ transition: all 0.5s;
170
+ }
171
+
172
+ .container_custom_downlad.expanded {
173
+ height: 270px;
174
+ }
175
+
176
+
177
+ /* Element text style */
178
+
179
+ .widget-html,
180
+ .widget-button,
181
+ .widget-text label,
182
+ .widget-checkbox label,
183
+ .widget-dropdown label,
184
+ .widget-dropdown select,
185
+ .widget-text input[type="text"] {
186
+ font-family: cursive;
187
+ font-size: 14px;
188
+ color: white !important;
189
+ user-select: none;
190
+ }
191
+
192
+ .widget-text input[type="text"]::placeholder {
193
+ color: grey;
194
+ }
195
+
196
+
197
+ /* Input field styles */
198
+
199
+ .widget-dropdown select,
200
+ .widget-text input[type="text"] {
201
+ height: 30px;
202
+ background-color: var(--bg-field-color);
203
+ border: 1px solid #262626;
204
+ border-radius: 10px;
205
+ box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);
206
+ transition: all 0.3s ease-in-out;
207
+ backdrop-filter: blur(var(--bg-field-blur-level));
208
+ }
209
+
210
+ .widget-dropdown select:focus,
211
+ .widget-text input[type="text"]:focus {
212
+ border-color: #006ee5;
213
+ }
214
+
215
+ .widget-dropdown select:hover,
216
+ .widget-text input[type="text"]:hover {
217
+ transform: scale(1.003);
218
+ background-color: var(--bg-field-color-hover);
219
+ box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);
220
+ }
221
+
222
+ .widget-dropdown option {
223
+ background-color: #1c1c1c;
224
+ }
225
+
226
+
227
+ /* Slider Checkbox style */
228
+
229
+ .widget-checkbox input[type="checkbox"] {
230
+ appearance: none;
231
+ position: relative;
232
+ top: 4px; /* Why is he taller?! */
233
+ width: 40px;
234
+ height: 20px;
235
+ border: none;
236
+ border-radius: 10px;
237
+ background-color: #20b2aa;
238
+ cursor: pointer;
239
+ box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.3);
240
+ transition: background-color 0.3s ease;
241
+ }
242
+ .widget-checkbox input[type="checkbox"]:checked {
243
+ background-color: #2196F3;
244
+ }
245
+
246
+ .widget-checkbox input[type="checkbox"]:before {
247
+ content: '';
248
+ position: absolute;
249
+ top: 50%;
250
+ left: 3px;
251
+ width: 16px;
252
+ height: 16px;
253
+ border-radius: inherit;
254
+ background-color: white;
255
+ box-shadow: 0 0 8px rgba(0, 0, 0, 0.3);
256
+ transform: translateY(-50%);
257
+ transition: left 0.3s ease;
258
+ }
259
+ .widget-checkbox input[type="checkbox"]:checked:before {
260
+ left: 21px;
261
+ }
262
+
263
+
264
+ /* Button styles */
265
+
266
+ .button_save {
267
+ font-size: 15px;
268
+ font-weight: bold;
269
+ width: 120px;
270
+ height: 35px;
271
+ border-radius: 15px;
272
+ background-image: radial-gradient(circle at top left, purple 10%, violet 90%);
273
+ background-size: 200% 200%;
274
+ background-position: left bottom;
275
+ transition: background 0.5s ease-in-out, transform 0.3s ease;
276
+ }
277
+
278
+ .button_save:hover {
279
+ cursor: pointer;
280
+ background-image: radial-gradient(circle at top left, purple 10%, #93ac47 90%);
281
+ background-size: 200% 200%;
282
+ background-position: right bottom;
283
+ transform: translateY(1px);
284
+ }
285
+
286
+ .button_ngrok {
287
+ font-size: 12px;
288
+ height: 30px;
289
+ border-radius: 10px;
290
+ padding: 1px 12px;
291
+ background-image: radial-gradient(circle at top left, purple 10%, violet 90%);
292
+ background-size: 200% 200%;
293
+ background-position: left bottom;
294
+ transition: background 0.5s ease-in-out, transform 0.3s ease;
295
+ white-space: nowrap;
296
+ }
297
+
298
+ .button_ngrok:hover {
299
+ cursor: pointer;
300
+ background-image: radial-gradient(circle at top left, purple 10%, #1D94BB 90%);
301
+ background-size: 200% 200%;
302
+ background-position: right bottom;
303
+ transform: translateY(1px);
304
+ }
305
+
306
+ .button_save:active,
307
+ .button_ngrok:active {
308
+ filter: brightness(0.75) !important;
309
+ }
310
+
311
+ /* Removes ugly stroke from widget buttons. */
312
+ .jupyter-widgets.lm-Widget:focus {
313
+ outline: none;
314
+ }
315
+
316
+
317
+ /* Popup style of `INFO` window */
318
+
319
+ .info {
320
+ position: absolute;
321
+ top: -5px;
322
+ right: 95px;
323
+ color: grey;
324
+ font-family: cursive;
325
+ font-size: 14px;
326
+ font-weight: normal;
327
+ user-select: none;
328
+ pointer-events: none;
329
+ opacity: 0;
330
+ transition: opacity 0.3s ease-in-out;
331
+ display: inline-block;
332
+ }
333
+
334
+ .popup {
335
+ position: absolute;
336
+ top: 120px;
337
+ z-index: 999;
338
+ width: auto;
339
+ padding: 10px;
340
+ text-align: center;
341
+ background-color: rgba(255, 255, 255, 0.05);
342
+ backdrop-filter: blur(20px);
343
+ border: 1px solid rgba(255, 255, 255, 0.45);
344
+ border-radius: 8px;
345
+ box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
346
+ opacity: 0;
347
+ color: #fff;
348
+ font-size: 16px;
349
+ font-family: cursive;
350
+ user-select: none;
351
+ cursor: default;
352
+ pointer-events: none;
353
+ transform: rotate(-5deg);
354
+ transition: top 0.3s ease-in-out, opacity 0.3s ease-in-out, transform 0.3s ease-in-out;
355
+ }
356
+
357
+ .sample {
358
+ display: inline-block;
359
+ margin-top: 25px;
360
+ padding: 10px 100px;
361
+ background-color: rgba(255, 255, 255, 0.2);
362
+ color: #c6e2ff;
363
+ border: 2px solid rgba(255, 255, 255, 0.2);
364
+ border-radius: 8px;
365
+ box-shadow: 0 0 10px rgba(255, 255, 255, 0.2), inset 0 0 25px rgba(255, 255, 255, 0.2);
366
+ }
367
+
368
+ .info.showed {
369
+ opacity: 1;
370
+ pointer-events: auto;
371
+ }
372
+
373
+ .info:hover + .popup {
374
+ top: 35px;
375
+ opacity: 1;
376
+ pointer-events: initial;
377
+ transform: rotate(0deg);
378
+ }
379
+
380
+
381
+ /* Animation of elements */
382
+
383
+ .container,
384
+ .button_save {
385
+ animation-name: showedWidgets;
386
+ animation-duration: 1s;
387
+ animation-fill-mode: forwards;
388
+ }
389
+
390
+ .container.hide,
391
+ .button_save.hide {
392
+ animation-name: hideWidgets;
393
+ animation-duration: 0.5s;
394
+ animation-fill-mode: forwards;
395
+ }
396
+
397
+ @keyframes showedWidgets {
398
+ 0% {
399
+ transform: translate3d(-65%, 15%, 0) scale(0) rotate(15deg);
400
+ filter: blur(25px) grayscale(1) brightness(0.3);
401
+ opacity: 0;
402
+ }
403
+ 100% {
404
+ transform: translate3d(0, 0, 0) scale(1) rotate(0deg);
405
+ filter: blur(0) grayscale(0) brightness(1);
406
+ opacity: 1;
407
+ }
408
+ }
409
+
410
+ @keyframes hideWidgets {
411
+ 0% {
412
+ transform: translate3d(0, 0, 0) scale(1) rotate3d(1, 0, 0, 0deg);
413
+ filter: blur(0) grayscale(0) brightness(1);
414
+ opacity: 1;
415
+ }
416
+ 100% {
417
+ transform: translate3d(0, 5%, 0) scale(0.9) rotate3d(1, 0, 0, 90deg);
418
+ filter: blur(15px) grayscale(1) brightness(0.5);
419
+ opacity: 0;
420
+ }
421
+ }
422
+ </style>
423
+
424
+ <!-- TOGGLE 'CustomDL' SCRIPT -->
425
+ <script>
426
+ function toggleContainer() {
427
+ let downloadContainer = document.querySelector('.container_custom_downlad');
428
+ let info = document.querySelector('.info');
429
+
430
+ downloadContainer.classList.toggle('expanded');
431
+ info.classList.toggle('showed');
432
+ }
433
+ </script>
434
+ '''
435
+
436
+ display(HTML(CSS))
437
+ # ==================== CSS JS ====================
438
+
439
+
440
+ # ==================== WIDGETS ====================
441
+ # --- global widgets ---
442
+ style = {'description_width': 'initial'}
443
+ layout = widgets.Layout(min_width='1047px')
444
+
445
+ HR = widgets.HTML('<hr>')
446
+
447
+ # --- MODEL ---
448
+ model_header = widgets.HTML('<div class="header">Model Selection<div>')
449
+ model_options = ['none',
450
+ '1.Anime (by XpucT) + INP',
451
+ '2.BluMix [Anime] [V7] + INP',
452
+ '3.Cetus-Mix [Anime] [V4] + INP',
453
+ '4.Counterfeit [Anime] [V3] + INP',
454
+ '5.CuteColor [Anime] [V3]',
455
+ '6.Dark-Sushi-Mix [Anime]',
456
+ '7.Deliberate [Realism] [V6] + INP',
457
+ '8.Meina-Mix [Anime] [V11] + INP',
458
+ '9.Mix-Pro [Anime] [V4] + INP']
459
+ # ---
460
+ Model_widget = widgets.Dropdown(options=model_options, value='4.Counterfeit [Anime] [V3] + INP', description='Model:', style=style, layout=layout)
461
+ Model_Num_widget = widgets.Text(description='Model Number:', placeholder='Enter the model numbers to be downloaded using comma/space.', style=style, layout=layout)
462
+ Inpainting_Model_widget = widgets.Checkbox(value=False, description='Inpainting Models', style=style)
463
+
464
+ ''' Display Model'''
465
+ all_model_box = widgets.VBox([model_header, Model_widget, Model_Num_widget, Inpainting_Model_widget]).add_class("container").add_class("image_1")
466
+ display(all_model_box)
467
+
468
+ # --- VAE ---
469
+ vae_header = widgets.HTML('<div class="header" >VAE Selection</div>')
470
+ vae_options = ['none',
471
+ '1.Anime.vae',
472
+ '2.Anything.vae',
473
+ '3.Blessed2.vae',
474
+ '4.ClearVae.vae',
475
+ '5.WD.vae']
476
+ Vae_widget = widgets.Dropdown(options=vae_options, value='3.Blessed2.vae', description='Vae:', style=style, layout=layout)
477
+ Vae_Num_widget = widgets.Text(description='Vae Number:', placeholder='Enter the vae numbers to be downloaded using comma/space.', style=style, layout=layout)
478
+
479
+ ''' Display Vae'''
480
+ all_vae_box= widgets.VBox([vae_header, Vae_widget, Vae_Num_widget]).add_class("container").add_class("image_2")
481
+ display(all_vae_box)
482
+
483
+ # --- ADDITIONAL ---
484
+ additional_header = widgets.HTML('<div class="header">Additional</div>')
485
+ latest_webui_widget = widgets.Checkbox(value=True, description='Update WebUI', style=style)
486
+ latest_exstensions_widget = widgets.Checkbox(value=True, description='Update Extensions', style=style)
487
+ detailed_download_widget = widgets.Dropdown(options=['off', 'on'], value='off', description='Detailed Download:', style=style)
488
+ latest_changes_widget = HBox([latest_webui_widget, latest_exstensions_widget, detailed_download_widget], layout=widgets.Layout(justify_content='space-between'))
489
+ controlnet_options = ['none', 'ALL', '1.canny',
490
+ '2.openpose', '3.depth',
491
+ '4.normal_map', '5.mlsd',
492
+ '6.lineart', '7.soft_edge',
493
+ '8.scribble', '9.segmentation',
494
+ '10.shuffle', '11.tile',
495
+ '12.inpaint', '13.instruct_p2p']
496
+ # ---
497
+ controlnet_widget = widgets.Dropdown(options=controlnet_options, value='none', description='ControlNet:', style=style, layout=layout)
498
+ controlnet_Num_widget = widgets.Text(description='ControlNet Number:', placeholder='Enter the ControlNet model numbers to be downloaded using comma/space.', style=style, layout=layout)
499
+ commit_hash_widget = widgets.Text(description='Commit Hash:', style=style, layout=layout)
500
+ optional_huggingface_token_widget = widgets.Text(description='HuggingFace Token:', style=style, layout=layout)
501
+ ngrok_token_widget = widgets.Text(description='Ngrok Token:', style=style, layout=widgets.Layout(width='1047px'))
502
+ ngrock_button = widgets.HTML('<a href="https://dashboard.ngrok.com/get-started/your-authtoken" target="_blank">Get Ngrok Token</a>').add_class("button_ngrok")
503
+ ngrok_widget = widgets.HBox([ngrok_token_widget, ngrock_button], style=style, layout=layout)
504
+ zrok_token_widget = widgets.Text(description='Zrok Token:', style=style, layout=widgets.Layout(width='1047px'))
505
+ zrok_button = widgets.HTML('<a href="https://colab.research.google.com/drive/1d2sjWDJi_GYBUavrHSuQyHTDuLy36WpU" target="_blank">Reg Zrok Token</a>').add_class("button_ngrok")
506
+ zrok_widget = widgets.HBox([zrok_token_widget, zrok_button], style=style, layout=layout)
507
+ # ---
508
+ commandline_arguments_options = "--listen --enable-insecure-extension-access --theme dark --no-half-vae --disable-console-progressbars --xformers"
509
+ commandline_arguments_widget = widgets.Text(description='Arguments:', value=commandline_arguments_options, style=style, layout=layout)
510
+
511
+ ''' Display Additional'''
512
+ additional_widget_list = [additional_header, latest_changes_widget, HR, controlnet_widget, controlnet_Num_widget, commit_hash_widget, optional_huggingface_token_widget, ngrok_widget, zrok_widget, HR, commandline_arguments_widget]
513
+ if free_plan and env == "Google Colab": # remove ngrok from colab
514
+ additional_widget_list.remove(ngrok_widget)
515
+ # ```
516
+ all_additional_box = widgets.VBox(additional_widget_list).add_class("container").add_class("image_3")
517
+ display(all_additional_box)
518
+
519
+ # --- CUSTOM DOWNLOAD ---
520
+ custom_download_header_popup = widgets.HTML('''
521
+ <style>
522
+ /* Term Colors */
523
+ .sample_label {color: #dbafff;}
524
+ .braces {color: #ffff00;}
525
+ .extension {color: #eb934b;}
526
+ .file_name {color: #ffffd8;}
527
+ </style>
528
+
529
+ <div class="header" style="cursor: pointer;" onclick="toggleContainer()">Custom Download</div>
530
+ <!-- PopUp Window -->
531
+ <div class="info">INFO</div>
532
+ <div class="popup">
533
+ 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>
534
+ after the URL without spaces.
535
+ <span style="color: #ff9999">For files, be sure to specify</span> - <span class="extension">Filename Extension.</span>
536
+ <div class="sample">
537
+ <span class="sample_label">Example for File:</span>
538
+ 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>
539
+ <br>
540
+ <span class="sample_label">Example for Extension:</span>
541
+ https://github.com/hako-mikan/sd-webui-regional-prompter<span class="braces">[</span><span class="file_name">Regional-Prompter</span><span class="braces">]</span>
542
+ </div>
543
+ </div>
544
+ ''')
545
+ # ---
546
+ Model_url_widget = widgets.Text(description='Model:', style=style, layout=layout)
547
+ Vae_url_widget = widgets.Text(description='Vae:', style=style, layout=layout)
548
+ LoRA_url_widget = widgets.Text(description='LoRa:', style=style, layout=layout)
549
+ Embedding_url_widget = widgets.Text(description='Embedding:', style=style, layout=layout)
550
+ Extensions_url_widget = widgets.Text(description='Extensions:', style=style, layout=layout)
551
+ custom_file_urls_widget = widgets.Text(description='File (txt):', style=style, layout=layout)
552
+
553
+ ''' Display CustomDl'''
554
+ all_custom_box = widgets.VBox([
555
+ custom_download_header_popup, Model_url_widget, Vae_url_widget, LoRA_url_widget, Embedding_url_widget, Extensions_url_widget, custom_file_urls_widget
556
+ ]).add_class("container").add_class("image_4").add_class("container_custom_downlad")
557
+ display(all_custom_box)
558
+
559
+ # --- Save Button ---
560
+ save_button = widgets.Button(description='Save').add_class("button_save")
561
+ display(save_button)
562
+
563
+
564
+ # ============ Load / Save - Settings V2 ============
565
+ SETTINGS_FILE = f'{root_path}/settings.json'
566
+
567
+ settings_keys = [
568
+ 'Model', 'Model_Num', 'Inpainting_Model',
569
+ 'Vae', 'Vae_Num',
570
+ 'latest_webui', 'latest_exstensions', 'detailed_download',
571
+ 'controlnet', 'controlnet_Num', 'commit_hash', 'optional_huggingface_token',
572
+ 'ngrok_token', 'zrok_token', 'commandline_arguments',
573
+ 'Model_url', 'Vae_url', 'LoRA_url', 'Embedding_url', 'Extensions_url', 'custom_file_urls'
574
+ ]
575
+
576
+ def save_settings():
577
+ settings = {key: globals()[f"{key}_widget"].value for key in settings_keys}
578
+ with open(SETTINGS_FILE, 'w') as f:
579
+ json.dump(settings, f, indent=2)
580
+
581
+ def load_settings():
582
+ if os.path.exists(SETTINGS_FILE):
583
+ with open(SETTINGS_FILE, 'r') as f:
584
+ settings = json.load(f)
585
+ for key in settings_keys:
586
+ globals()[f"{key}_widget"].value = settings.get(key)
587
+
588
+ def save_data(button):
589
+ save_settings()
590
+
591
+ # --- uhh - hide... ---
592
+ widgets_list = [all_model_box, all_vae_box, all_additional_box, all_custom_box, save_button]
593
+ for widget in widgets_list:
594
+ widget.add_class("hide")
595
+ time.sleep(0.5)
596
+
597
+ widgets.Widget.close_all()
598
+
599
+ settings = load_settings()
600
+ save_button.on_click(save_data)
601
+
files_cells/python/ru/files_cells_python_ru_auto-cleaner_ru.py ADDED
@@ -0,0 +1,324 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ##~ AutoCleaner V3.6 CODE | BY: ANXETY ~##
2
+
3
+ import os
4
+ import time
5
+ import ipywidgets as widgets
6
+ from ipywidgets import Label, Button, VBox, HBox
7
+ from IPython.display import display, HTML
8
+
9
+
10
+ # ================= DETECT ENV =================
11
+ def detect_environment():
12
+ free_plan = (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024. ** 3) <= 20)
13
+ environments = {
14
+ 'COLAB_GPU': ('Google Colab', "/root" if free_plan else "/content"),
15
+ 'KAGGLE_URL_BASE': ('Kaggle', "/kaggle/working/content")
16
+ }
17
+
18
+ for env_var, (environment, path) in environments.items():
19
+ if env_var in os.environ:
20
+ return environment, path, free_plan
21
+
22
+ env, root_path, free_plan = detect_environment()
23
+ webui_path = f"{root_path}/sdw"
24
+ # ----------------------------------------------
25
+
26
+
27
+ # ==================== CSS ====================
28
+ CSS_AC = """
29
+ <style>
30
+ /* General Styles */
31
+
32
+ hr {
33
+ border-color: grey;
34
+ background-color: grey;
35
+ opacity: 0.25;
36
+ }
37
+
38
+ .instruction_AC {
39
+ font-family: cursive;
40
+ font-size: 18px;
41
+ color: grey;
42
+ user-select: none;
43
+ cursor: default;
44
+ }
45
+
46
+
47
+ /* Container style */
48
+
49
+ .container_AC {
50
+ position: relative;
51
+ background-color: #232323;
52
+ width: 800px;
53
+ height: auto;
54
+ padding: 15px;
55
+ border-radius: 15px;
56
+ box-shadow: 0 0 50px rgba(0, 0, 0, 0.3);
57
+ margin-bottom: 5px;
58
+ overflow: visible;
59
+ }
60
+
61
+ .container_AC::before {
62
+ position: absolute;
63
+ top: 5px;
64
+ right: 10px;
65
+ content: "AutoCleanerV3.6";
66
+ font-weight: bold;
67
+ font-size: 24px;
68
+ color: rgba(0, 0, 0, 0.2);
69
+ }
70
+
71
+ .container_AC::after {
72
+ position: absolute;
73
+ top: 30px;
74
+ right: 10px;
75
+ content: "ANXETY";
76
+ font-weight: bold;
77
+ font-size: 18px;
78
+ color: rgba(0, 0, 0, 0.2);
79
+ }
80
+
81
+ .custom-select-multiple_AC select {
82
+ padding: 10px;
83
+ font-family: cursive;
84
+ border: 1px solid #262626 !important;
85
+ border-radius: 10px;
86
+ color: white;
87
+ background-color: #1c1c1c;
88
+ box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);
89
+ }
90
+
91
+ .output_AC {
92
+ padding: 10px;
93
+ height: auto;
94
+ border: 1px solid #262626;
95
+ border-radius: 10px;
96
+ background-color: #1c1c1c;
97
+ box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);
98
+ width: auto;
99
+ box-sizing: border-box;
100
+ }
101
+
102
+ .output_message_AC {
103
+ font-family: cursive;
104
+ color: white !important;
105
+ font-size: 14px;
106
+ user-select: none;
107
+ cursor: default
108
+ }
109
+
110
+
111
+ .storage_info_AC {
112
+ padding: 5px 20px;
113
+ height: auto;
114
+ border: 1px solid #262626;
115
+ border-radius: 10px;
116
+ background-color: #1c1c1c;
117
+ box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);
118
+ width: auto;
119
+ font-family: cursive;
120
+ color: #B2B2B2 !important;
121
+ font-size: 14px;
122
+ user-select: none;
123
+ cursor: default
124
+ }
125
+
126
+
127
+ /* Button and storage info layout */
128
+ .lower_information_panel_AC {
129
+ display: flex;
130
+ align-items: center;
131
+ justify-content: space-between;
132
+ }
133
+
134
+
135
+ /* Button style */
136
+
137
+ .button_AC {
138
+ width: auto;
139
+ font-family: cursive;
140
+ color: white !important;
141
+ font-size: 14px;
142
+ font-weight: bold;
143
+ height: 35px;
144
+ border-radius: 15px;
145
+ background-image: radial-gradient(circle at top left, purple 10%, violet 90%);
146
+ background-size: 200% 200%;
147
+ background-position: left bottom;
148
+ transition: background 0.5s ease-in-out, transform 0.3s ease;
149
+ }
150
+
151
+ .button_AC:hover {
152
+ cursor: pointer;
153
+ background-size: 200% 200%;
154
+ background-position: right bottom;
155
+ transform: translateY(1px);
156
+ }
157
+
158
+ .button_execute_AC:hover {
159
+ background-image: radial-gradient(circle at top left, purple 10%, #93ac47 90%);
160
+ }
161
+
162
+ .button_clear_AC:hover {
163
+ background-image: radial-gradient(circle at top left, purple 10%, #fc3468 90%);
164
+ }
165
+
166
+ .button_execute_AC:active,
167
+ .button_clear_AC:active {
168
+ filter: brightness(0.75);
169
+ }
170
+
171
+ .jupyter-widgets.lm-Widget:focus {
172
+ outline: none;
173
+ }
174
+
175
+
176
+ /* Animation of elements */
177
+
178
+ /* Emergence */
179
+ .container_AC {
180
+ animation-name: slideInTopBlur;
181
+ animation-duration: 0.7s;
182
+ animation-fill-mode: forwards;
183
+ }
184
+
185
+ @keyframes slideInTopBlur {
186
+ 0% {
187
+ transform: translate3d(0, 50%, 0) scale(0.85) rotate3d(1, 0, 0, -85deg);
188
+ filter: blur(5px) grayscale(1) brightness(0.5);
189
+ opacity: 0;
190
+ }
191
+ 100% {
192
+ transform: translate3d(0, 0, 0) scale(1) rotate3d(1, 0, 0, 0deg);
193
+ filter: blur(0) grayscale(0) brightness(1);
194
+ opacity: 1;
195
+ }
196
+ }
197
+
198
+ /* Leaving */
199
+ .container_AC.hide {
200
+ animation-name: slideOutTopBlur;
201
+ animation-duration: 0.3s;
202
+ animation-fill-mode: forwards;
203
+ }
204
+
205
+ @keyframes slideOutTopBlur {
206
+ 0% {
207
+ transform: translate3d(0, 0, 0) scale(1);
208
+ filter: blur(0) grayscale(0) brightness(1);
209
+ opacity: 1;
210
+ }
211
+ 100% {
212
+ transform: translate3d(0, -100%, 0);
213
+ filter: blur(5px) grayscale(1) brightness(0);
214
+ opacity: 0;
215
+ }
216
+ }
217
+ </style>
218
+ """
219
+
220
+ display(HTML(CSS_AC))
221
+ # ==================== CSS ====================
222
+
223
+
224
+ # ================ AutoCleaner function ================
225
+ directories = {
226
+ "Изображения": f"{webui_path}/outputs",
227
+ "Модели": f"{webui_path}/models/Stable-diffusion/",
228
+ "Vae": f"{webui_path}/models/VAE/",
229
+ "LoRa": f"{webui_path}/models/Lora/",
230
+ "ControlNet Модели": f"{webui_path}/models/ControlNet/"
231
+ }
232
+
233
+ """ functions """
234
+ def clean_directory(directory):
235
+ deleted_files = 0
236
+ for root, dirs, files in os.walk(directory):
237
+ for file in files:
238
+ if file.endswith(".txt"):
239
+ continue
240
+ os.remove(os.path.join(root, file))
241
+ if not file.endswith(".yaml"):
242
+ deleted_files += 1
243
+ return deleted_files
244
+
245
+ def update_memory_info():
246
+ disk_space = psutil.disk_usage(os.getcwd())
247
+ total = disk_space.total / (1024 ** 3)
248
+ used = disk_space.used / (1024 ** 3)
249
+ free = disk_space.free / (1024 ** 3)
250
+
251
+ storage_info.value = f'''
252
+ <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>
253
+ '''
254
+
255
+ def on_execute_button_press(button):
256
+ selected_cleaners = auto_cleaner_widget.value
257
+ deleted_files_dict = {}
258
+
259
+ for option in selected_cleaners:
260
+ if option in directories:
261
+ deleted_files_dict[option] = clean_directory(directories[option])
262
+
263
+ output.clear_output()
264
+
265
+ with output:
266
+ for message in generate_messages(deleted_files_dict):
267
+ message_widget = HTML(f'<p class="output_message_AC">{message}</p>')
268
+ display(message_widget)
269
+
270
+ update_memory_info()
271
+
272
+ def on_clear_button_press(button):
273
+ container.add_class("hide")
274
+ time.sleep(0.5)
275
+ widgets.Widget.close_all()
276
+
277
+ def generate_messages(deleted_files_dict):
278
+ messages = []
279
+ word_variants = {
280
+ "Изображения": "Изображений",
281
+ "Модели": "Моделей",
282
+ "Vae": "Vae",
283
+ "LoRa": "LoRa",
284
+ "ControlNet Модели": "ControlNet Моделей"
285
+ }
286
+ for key, value in deleted_files_dict.items():
287
+ object_word = word_variants.get(key)
288
+ messages.append(f"Удалено {value} {object_word}")
289
+ return messages
290
+ # ================ AutoCleaner function ================
291
+
292
+
293
+ # --- storage memory ---
294
+ import psutil
295
+ disk_space = psutil.disk_usage(os.getcwd())
296
+ total = disk_space.total / (1024 ** 3)
297
+ used = disk_space.used / (1024 ** 3)
298
+ free = disk_space.free / (1024 ** 3)
299
+
300
+
301
+ # UI Code
302
+ AutoCleaner_options = AutoCleaner_options = list(directories.keys())
303
+ instruction_label = widgets.HTML('''
304
+ <span class="instruction_AC">Используйте <span style="color: #B2B2B2;">ctrl</span> или <span style="color: #B2B2B2;">shift</span> для множественного выбора.</span>
305
+ ''')
306
+ auto_cleaner_widget = widgets.SelectMultiple(options=AutoCleaner_options, layout=widgets.Layout(width="auto")).add_class("custom-select-multiple_AC")
307
+ output = widgets.Output().add_class("output_AC")
308
+ # ---
309
+ execute_button = Button(description='Выполнить Очистку').add_class("button_execute_AC").add_class("button_AC")
310
+ execute_button.on_click(on_execute_button_press)
311
+ clear_button = Button(description='Скрыть Виджет').add_class("button_clear_AC").add_class("button_AC")
312
+ clear_button.on_click(on_clear_button_press)
313
+ # ---
314
+ storage_info = widgets.HTML(f'''
315
+ <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>
316
+ ''')
317
+ # ---
318
+ buttons = widgets.HBox([execute_button, clear_button])
319
+ lower_information_panel = widgets.HBox([buttons, storage_info]).add_class("lower_information_panel_AC")
320
+
321
+ container = VBox([instruction_label, widgets.HTML('<hr>'), auto_cleaner_widget, output, widgets.HTML('<hr>'), lower_information_panel]).add_class("container_AC")
322
+
323
+ display(container)
324
+
files_cells/python/ru/files_cells_python_ru_downloading_ru.py ADDED
@@ -0,0 +1,538 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ free_plan = (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024. ** 3) <= 20)
19
+ environments = {
20
+ 'COLAB_GPU': ('Google Colab', "/root" if free_plan else "/content"),
21
+ 'KAGGLE_URL_BASE': ('Kaggle', "/kaggle/working/content")
22
+ }
23
+
24
+ for env_var, (environment, path) in environments.items():
25
+ if env_var in os.environ:
26
+ return environment, path, free_plan
27
+
28
+ env, root_path, free_plan = detect_environment()
29
+ webui_path = f"{root_path}/sdw"
30
+ # ----------------------------------------------
31
+
32
+
33
+ # ================ LIBRARIES V2 ================
34
+ flag_file = f"{root_path}/libraries_installed.txt"
35
+
36
+ if not os.path.exists(flag_file):
37
+ print("💿 Установка библиотек, это займет какое-то время:\n")
38
+
39
+ install_lib = {
40
+ "gdown": "pip install -U gdown",
41
+ "aria2": "apt-get update && apt -y install aria2",
42
+ "localtunnel": "npm install -g localtunnel &> /dev/null",
43
+ "insightface": "pip install insightface",
44
+ }
45
+
46
+ # Dictionary of additional libraries specific to certain environments
47
+ additional_libs = {
48
+ "Google Colab": {
49
+ "xformers": "pip install xformers==0.0.25 --no-deps"
50
+ },
51
+ "Kaggle": {
52
+ "xformers": "pip install -q xformers==0.0.23.post1 triton==2.1.0",
53
+ "torch": "pip install -q torch==2.1.2+cu121 torchvision==0.16.2+cu121 torchaudio==2.1.2 --extra-index-url https://download.pytorch.org/whl/cu121"
54
+ }
55
+ }
56
+
57
+ # If the current environment has additional libraries, update the install_lib dictionary
58
+ if env in additional_libs:
59
+ install_lib.update(additional_libs[env])
60
+
61
+ # Loop through libraries and execute install commands
62
+ for index, (package, install_cmd) in enumerate(install_lib.items(), start=1):
63
+ print(f"\r[{index}/{len(install_lib)}] \033[32m>>\033[0m Installing \033[33m{package}\033[0m..." + " "*35, end='')
64
+ subprocess.run(install_cmd, shell=True, capture_output=True)
65
+
66
+ # Additional manual installation steps for specific packages
67
+ with capture.capture_output() as cap:
68
+ get_ipython().system('curl -s -OL https://github.com/DEX-1101/sd-webui-notebook/raw/main/res/new_tunnel --output-dir {root_path}')
69
+ 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')
70
+ get_ipython().system('curl -sLO https://github.com/openziti/zrok/releases/download/v0.4.23/zrok_0.4.23_linux_amd64.tar.gz && tar -xzf zrok_0.4.23_linux_amd64.tar.gz -C /usr/bin && rm -f zrok_0.4.23_linux_amd64.tar.gz')
71
+ del cap
72
+
73
+ clear_output()
74
+
75
+ # Save file install lib
76
+ with open(flag_file, "w") as f:
77
+ f.write(">W<'")
78
+
79
+ print("🍪 Библиотеки установлены!" + " "*35)
80
+ time.sleep(2)
81
+ clear_output()
82
+
83
+
84
+ # ================= loading settings V4 =================
85
+ def load_settings(path):
86
+ if os.path.exists(path):
87
+ with open(path, 'r') as file:
88
+ return json.load(file)
89
+ return {}
90
+
91
+ settings = load_settings(f'{root_path}/settings.json')
92
+
93
+ variables = [
94
+ 'Model', 'Model_Num', 'Inpainting_Model',
95
+ 'Vae', 'Vae_Num',
96
+ 'latest_webui', 'latest_exstensions', 'detailed_download',
97
+ 'controlnet', 'controlnet_Num', 'commit_hash', 'optional_huggingface_token',
98
+ 'ngrok_token', 'zrok_token', 'commandline_arguments',
99
+ 'Model_url', 'Vae_url', 'LoRA_url', 'Embedding_url', 'Extensions_url', 'custom_file_urls'
100
+ ]
101
+
102
+ locals().update({key: settings.get(key) for key in variables})
103
+
104
+
105
+ # ================= OTHER =================
106
+ try:
107
+ start_colab
108
+ except:
109
+ start_colab = int(time.time())-5
110
+
111
+ # CONFIG DIR
112
+ models_dir = f"{webui_path}/models/Stable-diffusion"
113
+ vaes_dir = f"{webui_path}/models/VAE"
114
+ embeddings_dir = f"{webui_path}/embeddings"
115
+ loras_dir = f"{webui_path}/models/Lora"
116
+ extensions_dir = f"{webui_path}/extensions"
117
+ control_dir = f"{webui_path}/models/ControlNet"
118
+
119
+
120
+ # ================= MAIN CODE =================
121
+ if not os.path.exists(webui_path):
122
+ start_install = int(time.time())
123
+ print("⌚ Распоковка Stable Diffusion...", end='')
124
+ with capture.capture_output() as cap:
125
+ 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')
126
+ get_ipython().system('unzip -q -o repo.zip -d {webui_path}')
127
+ get_ipython().system('rm -rf repo.zip')
128
+
129
+ get_ipython().run_line_magic('cd', '{root_path}')
130
+ os.environ["SAFETENSORS_FAST_GPU"]='1'
131
+ os.environ["CUDA_MODULE_LOADING"]="LAZY"
132
+ os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
133
+ os.environ["PYTHONWARNINGS"] = "ignore"
134
+
135
+ get_ipython().system('echo -n {start_colab} > {webui_path}/static/colabTimer.txt')
136
+ del cap
137
+ install_time = timedelta(seconds=time.time()-start_install)
138
+ print("\r🚀 Распаковка Завершена! За","%02d:%02d:%02d ⚡\n" % (install_time.seconds / 3600, (install_time.seconds / 60) % 60, install_time.seconds % 60), end='', flush=True)
139
+ else:
140
+ print("🚀 Все распакованно... Пропуск. ⚡")
141
+ start_colab = float(open(f'{webui_path}/static/colabTimer.txt', 'r').read())
142
+ time_since_start = str(timedelta(seconds=time.time()-start_colab)).split('.')[0]
143
+ print(f"⌚️ Вы проводите эту сессию в течение - \033[33m{time_since_start}\033[0m")
144
+
145
+
146
+ ## Changes extensions and WebUi
147
+ if latest_webui or latest_exstensions:
148
+ action = "Обновление WebUI и Расширений" if latest_webui and latest_exstensions else ("Обновление WebUI" if latest_webui else "Обновление Расширений")
149
+ print(f"⌚️ {action}...", end='', flush=True)
150
+ with capture.capture_output() as cap:
151
+ get_ipython().system('git config --global user.email "[email protected]"')
152
+ get_ipython().system('git config --global user.name "Your Name"')
153
+
154
+ ## Update Webui
155
+ if latest_webui:
156
+ get_ipython().run_line_magic('cd', '{webui_path}')
157
+ get_ipython().system('git restore .')
158
+ get_ipython().system('git pull -X theirs --rebase --autostash')
159
+
160
+ ## Update extensions
161
+ if latest_exstensions:
162
+ get_ipython().system('{\'for dir in \' + webui_path + \'/extensions/*/; do cd \\"$dir\\" && git reset --hard && git pull; done\'}')
163
+
164
+ # My Chinese friend, you broke the images again in the latest update... >W<'
165
+ get_ipython().run_line_magic('cd', '{webui_path}/extensions/Encrypt-Image')
166
+ get_ipython().system('git reset --hard 376358d8854472b9ea50e9fc8800367d1ca51137 # stable commit :3')
167
+ del cap
168
+ print(f"\r✨ {action} Завершено!")
169
+
170
+
171
+ # === FIXING EXTENSIONS ===
172
+ anxety_repos = "https://huggingface.co/NagisaNao/fast_repo/resolve/main"
173
+
174
+ with capture.capture_output() as cap:
175
+ # --- Encrypt-Image ---
176
+ get_ipython().system("sed -i '9,37d' {webui_path}/extensions/Encrypt-Image/javascript/encrypt_images_info.js")
177
+
178
+ # --- Additional-Networks ---
179
+ get_ipython().system('wget -O {webui_path}/extensions/additional-networks/scripts/metadata_editor.py {anxety_repos}/extensions/Additional-Networks/fix/metadata_editor.py')
180
+ del cap
181
+
182
+
183
+ ## Version switching
184
+ if commit_hash:
185
+ print('⏳ Активация машины времени...', end="", flush=True)
186
+ with capture.capture_output() as cap:
187
+ get_ipython().run_line_magic('cd', '{webui_path}')
188
+ get_ipython().system('git config --global user.email "[email protected]"')
189
+ get_ipython().system('git config --global user.name "Your Name"')
190
+ get_ipython().system('git reset --hard {commit_hash}')
191
+ del cap
192
+ print(f"\r⌛️ Машина времени активированна! Текущий коммит: \033[34m{commit_hash}\033[0m")
193
+
194
+
195
+ ## Downloading model and stuff | oh yeah~ I'm starting to misunderstand my own code ( almost my own ;3 )
196
+ print("📦 Скачивание моделей и прочего...", end='')
197
+ model_list = {
198
+ "1.Anime (by XpucT) + INP": [
199
+ {"url": "https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2.safetensors", "name": "Anime_v2.safetensors"},
200
+ {"url": "https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2-inpainting.safetensors", "name": "Anime_v2-inpainting.safetensors"}
201
+ ],
202
+ "2.BluMix [Anime] [V7] + INP": [
203
+ {"url": "https://civitai.com/api/download/models/361779", "name": "BluMix_v7.safetensors"},
204
+ {"url": "https://civitai.com/api/download/models/363850", "name": "BluMix_v7-inpainting.safetensors"}
205
+ ],
206
+ "3.Cetus-Mix [Anime] [V4] + INP": [
207
+ {"url": "https://civitai.com/api/download/models/130298", "name": "CetusMix_V4.safetensors"},
208
+ {"url": "https://civitai.com/api/download/models/139882", "name": "CetusMix_V4-inpainting.safetensors"}
209
+ ],
210
+ "4.Counterfeit [Anime] [V3] + INP": [
211
+ {"url": "https://civitai.com/api/download/models/125050", "name": "Counterfeit_V3.safetensors"},
212
+ {"url": "https://civitai.com/api/download/models/137911", "name": "Counterfeit_V3-inpainting.safetensors"}
213
+ ],
214
+ "5.CuteColor [Anime] [V3]": [
215
+ {"url": "https://civitai.com/api/download/models/138754", "name": "CuteColor_V3.safetensors"}
216
+ ],
217
+ "6.Dark-Sushi-Mix [Anime]": [
218
+ {"url": "https://civitai.com/api/download/models/101640", "name": "DarkSushiMix_2_5D.safetensors"},
219
+ {"url": "https://civitai.com/api/download/models/56071", "name": "DarkSushiMix_colorful.safetensors"}
220
+ ],
221
+ "7.Deliberate [Realism] [V6] + INP": [
222
+ {"url": "https://huggingface.co/XpucT/Deliberate/resolve/main/Deliberate_v6.safetensors", "name": "Deliberate_v6.safetensors"},
223
+ {"url": "https://huggingface.co/XpucT/Deliberate/resolve/main/Deliberate_v6-inpainting.safetensors", "name": "Deliberate_v6-inpainting.safetensors"}
224
+ ],
225
+ "8.Meina-Mix [Anime] [V11] + INP": [
226
+ {"url": "https://civitai.com/api/download/models/119057", "name": "MeinaMix_V11.safetensors"},
227
+ {"url": "https://civitai.com/api/download/models/120702", "name": "MeinaMix_V11-inpainting.safetensors"}
228
+ ],
229
+ "9.Mix-Pro [Anime] [V4] + INP": [
230
+ {"url": "https://civitai.com/api/download/models/125668", "name": "MixPro_V4.safetensors"},
231
+ {"url": "https://civitai.com/api/download/models/139878", "name": "MixPro_V4-inpainting.safetensors"}
232
+ ]
233
+ }
234
+
235
+ # 1-4 (fp16/cleaned)
236
+ vae_list = {
237
+ "1.Anime.vae": [
238
+ {"url": "https://civitai.com/api/download/models/131654", "name": "Anime.vae.safetensors"},
239
+ {"url": "https://civitai.com/api/download/models/131658", "name": "vae-ft-mse.vae.safetensors"}
240
+ ],
241
+ "2.Anything.vae": [{"url": "https://civitai.com/api/download/models/131656", "name": "Anything.vae.safetensors"}],
242
+ "3.Blessed2.vae": [{"url": "https://civitai.com/api/download/models/142467", "name": "Blessed2.vae.safetensors"}],
243
+ "4.ClearVae.vae": [{"url": "https://civitai.com/api/download/models/133362", "name": "ClearVae_23.vae.safetensors"}],
244
+ "5.WD.vae": [{"url": "https://huggingface.co/NoCrypt/resources/resolve/main/VAE/wd.vae.safetensors", "name": "WD.vae.safetensors"}]
245
+ }
246
+
247
+ controlnet_list = {
248
+ "1.canny": [
249
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny_fp16.safetensors", "name": "control_v11p_sd15_canny_fp16.safetensors"},
250
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_canny_fp16.yaml", "name": "control_v11p_sd15_canny_fp16.yaml"}
251
+ ],
252
+ "2.openpose": [
253
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose_fp16.safetensors", "name": "control_v11p_sd15_openpose_fp16.safetensors"},
254
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_openpose_fp16.yaml", "name": "control_v11p_sd15_openpose_fp16.yaml"}
255
+ ],
256
+ "3.depth": [
257
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth_fp16.safetensors", "name": "control_v11f1p_sd15_depth_fp16.safetensors"},
258
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1p_sd15_depth_fp16.yaml", "name": "control_v11f1p_sd15_depth_fp16.yaml"},
259
+ {"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"}
260
+ ],
261
+ "4.normal_map": [
262
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_normalbae_fp16.safetensors", "name": "control_v11p_sd15_normalbae_fp16.safetensors"},
263
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_normalbae_fp16.yaml", "name": "control_v11p_sd15_normalbae_fp16.yaml"}
264
+ ],
265
+ "5.mlsd": [
266
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_mlsd_fp16.safetensors", "name": "control_v11p_sd15_mlsd_fp16.safetensors"},
267
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_mlsd_fp16.yaml", "name": "control_v11p_sd15_mlsd_fp16.yaml"}
268
+ ],
269
+ "6.lineart": [
270
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart_fp16.safetensors", "name": "control_v11p_sd15_lineart_fp16.safetensors"},
271
+ {"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"},
272
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_lineart_fp16.yaml", "name": "control_v11p_sd15_lineart_fp16.yaml"},
273
+ {"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"}
274
+ ],
275
+ "7.soft_edge": [
276
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge_fp16.safetensors", "name": "control_v11p_sd15_softedge_fp16.safetensors"},
277
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_softedge_fp16.yaml", "name": "control_v11p_sd15_softedge_fp16.yaml"}
278
+ ],
279
+ "8.scribble": [
280
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble_fp16.safetensors", "name": "control_v11p_sd15_scribble_fp16.safetensors"},
281
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_scribble_fp16.yaml", "name": "control_v11p_sd15_scribble_fp16.yaml"}
282
+ ],
283
+ "9.segmentation": [
284
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg_fp16.safetensors", "name": "control_v11p_sd15_seg_fp16.safetensors"},
285
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_seg_fp16.yaml", "name": "control_v11p_sd15_seg_fp16.yaml"}
286
+ ],
287
+ "10.shuffle": [
288
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle_fp16.safetensors", "name": "control_v11e_sd15_shuffle_fp16.safetensors"},
289
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_shuffle_fp16.yaml", "name": "control_v11e_sd15_shuffle_fp16.yaml"}
290
+ ],
291
+ "11.tile": [
292
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile_fp16.safetensors", "name": "control_v11f1e_sd15_tile_fp16.safetensors"},
293
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1e_sd15_tile_fp16.yaml", "name": "control_v11f1e_sd15_tile_fp16.yaml"}
294
+ ],
295
+ "12.inpaint": [
296
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_inpaint_fp16.safetensors", "name": "control_v11p_sd15_inpaint_fp16.safetensors"},
297
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_inpaint_fp16.yaml", "name": "control_v11p_sd15_inpaint_fp16.yaml"}
298
+ ],
299
+ "13.instruct_p2p": [
300
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p_fp16.safetensors", "name": "control_v11e_sd15_ip2p_fp16.safetensors"},
301
+ {"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_ip2p_fp16.yaml", "name": "control_v11e_sd15_ip2p_fp16.yaml"}
302
+ ]
303
+ }
304
+
305
+ extension_repo = []
306
+ prefixes = {
307
+ # It's complicated, but supplementing has become easier
308
+ "model": [models_dir, "Model_url"],
309
+ "vae": [vaes_dir, "Vae_url"],
310
+ "lora": [loras_dir, "LoRA_url"],
311
+ "embed": [embeddings_dir, "Embedding_url"],
312
+ "extension": [extensions_dir, "Extensions_url"],
313
+ "control": [control_dir, "ControlNet_url"]
314
+ }
315
+
316
+ get_ipython().system('mkdir -p {models_dir} {vaes_dir} {loras_dir} {embeddings_dir} {extensions_dir} {control_dir}')
317
+
318
+ url = ""
319
+ ControlNet_url = ""
320
+ hf_token = optional_huggingface_token if optional_huggingface_token else "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"
321
+ user_header = f"\"Authorization: Bearer {hf_token}\""
322
+
323
+ ''' main download code '''
324
+
325
+ def handle_manual(url):
326
+ original_url = url
327
+ url = url.split(':', 1)[1]
328
+ file_name = re.search(r'\[(.*?)\]', url)
329
+ file_name = file_name.group(1) if file_name else None
330
+ if file_name:
331
+ url = re.sub(r'\[.*?\]', '', url)
332
+
333
+ for prefix, (dir, _) in prefixes.items():
334
+ if original_url.startswith(f"{prefix}:"):
335
+ if prefix != "extension":
336
+ manual_download(url, dir, file_name=file_name)
337
+ else:
338
+ extension_repo.append((url, file_name))
339
+
340
+ def manual_download(url, dst_dir, file_name):
341
+ basename = url.split("/")[-1] if file_name is None else file_name
342
+ header_option = f"--header={user_header}"
343
+
344
+ print("\033[32m---"*45 + f"\n\033[33mURL: \033[34m{url}\n\033[33mSAVE DIR: \033[34m{dst_dir}\n\033[33mFILE NAME: \033[34m{file_name}\033[32m\n~~~\033[0m")
345
+
346
+ # I do it at my own risk..... Fucking CivitAi >:(
347
+ civitai_token = "62c0c5956b2f9defbd844d754000180b"
348
+ if 'civitai' in url and civitai_token:
349
+ url = f"{url}?token={civitai_token}"
350
+
351
+ # -- GDrive --
352
+ if 'drive.google' in url:
353
+ if 'folders' in url:
354
+ get_ipython().system('gdown --folder "{url}" -O {dst_dir} --fuzzy -c')
355
+ else:
356
+ if file_name:
357
+ get_ipython().system('gdown "{url}" -O {dst_dir}/{file_name} --fuzzy -c')
358
+ else:
359
+ get_ipython().system('gdown "{url}" -O {dst_dir} --fuzzy -c')
360
+ # -- Huggin Face --
361
+ elif 'huggingface' in url:
362
+ if '/blob/' in url:
363
+ url = url.replace('/blob/', '/resolve/')
364
+ if file_name:
365
+ get_ipython().system('aria2c {header_option} --optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -c -j5 -x16 -s16 -k1M -d {dst_dir} -o {basename} {url}')
366
+ else:
367
+ parsed_link = f'\n{url}\n\tout={unquote(url.split("/")[-1])}'
368
+ get_ipython().system('echo -e "{parsed_link}" | aria2c {header_option} --console-log-level=error --summary-interval=10 -i- -j5 -x16 -s16 -k1M -c -d "{dst_dir}" -o {basename}')
369
+ # -- Other --
370
+ elif 'http' in url or 'magnet' in url:
371
+ if file_name:
372
+ 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}')
373
+ else:
374
+ parsed_link = '"{}"'.format(url)
375
+ 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}')
376
+
377
+ def download(url):
378
+ links_and_paths = url.split(',')
379
+
380
+ for link_or_path in links_and_paths:
381
+ link_or_path = link_or_path.strip()
382
+ if not link_or_path:
383
+ continue
384
+ if any(link_or_path.startswith(prefix.lower()) for prefix in prefixes):
385
+ handle_manual(link_or_path)
386
+ continue
387
+
388
+ url, dst_dir, file_name = link_or_path.split()
389
+ manual_download(url, dst_dir, file_name)
390
+
391
+ ''' submodels - added urls '''
392
+
393
+ submodels = []
394
+
395
+ def add_submodels(selection, num_selection, model_dict, dst_dir):
396
+ if selection == "none":
397
+ return []
398
+ if selection == "ALL":
399
+ all_models = []
400
+ for models in model_dict.values():
401
+ all_models.extend(models)
402
+ selected_models = all_models
403
+ else:
404
+ selected_models = model_dict[selection]
405
+ selected_nums = map(int, num_selection.replace(',', '').split())
406
+
407
+ for num in selected_nums:
408
+ if 1 <= num <= len(model_dict):
409
+ name = list(model_dict)[num - 1]
410
+ selected_models.extend(model_dict[name])
411
+
412
+ unique_models = list({model['name']: model for model in selected_models}.values())
413
+
414
+ for model in unique_models:
415
+ model['dst_dir'] = dst_dir
416
+
417
+ return unique_models
418
+
419
+ submodels += add_submodels(Model, Model_Num, model_list, models_dir) # model
420
+ submodels += add_submodels(Vae, Vae_Num, vae_list, vaes_dir) # vae
421
+ submodels += add_submodels(controlnet, "" if controlnet == "ALL" else controlnet_Num, controlnet_list, control_dir) # controlnet
422
+
423
+ for submodel in submodels:
424
+ if not Inpainting_Model and "inpainting" in submodel['name']:
425
+ continue
426
+ url += f"{submodel['url']} {submodel['dst_dir']} {submodel['name']}, "
427
+
428
+ ''' file.txt - added urls '''
429
+
430
+ unique_urls = []
431
+
432
+ def process_file_download(file_url):
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 any(f'# {tag}' in line.lower() for tag in prefixes):
445
+ current_tag = next((tag for tag in prefixes if tag in line.lower()))
446
+
447
+ urls = [url.strip() for url in line.split(',')]
448
+ for url in urls:
449
+ if url.startswith("http") and url not in unique_urls:
450
+ globals()[prefixes[current_tag][1]] += ", " + url
451
+ unique_urls.append(url)
452
+
453
+ # fix all possible errors/options and function call
454
+ if custom_file_urls:
455
+ for custom_file_url in custom_file_urls.replace(',', '').split():
456
+ if not custom_file_url.endswith('.txt'):
457
+ custom_file_url += '.txt'
458
+ if not custom_file_url.startswith('http'):
459
+ if not custom_file_url.startswith(root_path):
460
+ custom_file_url = f'{root_path}/{custom_file_url}'
461
+
462
+ try:
463
+ process_file_download(custom_file_url)
464
+ except FileNotFoundError:
465
+ pass
466
+
467
+ # url prefixing
468
+ urls = [globals()[urls[1]] for urls in prefixes.values()]
469
+ for i, prefix in enumerate(prefixes):
470
+ if urls[i]:
471
+ prefixed_urls = [f"{prefix}:{url}" for url 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# ====== Подробная Загрузка ====== #\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🏁 Скачивание Завершено!" + " "*15)
485
+
486
+
487
+ # Cleaning shit after downloading...
488
+ get_ipython().system('find {webui_path} \\( -type d \\( -name ".ipynb_checkpoints" -o -name ".aria2" \\) -o -type f -name "*.aria2" \\) -exec rm -r {{}} \\; >/dev/null 2>&1')
489
+
490
+
491
+ ## Install of Custom extensions
492
+ if len(extension_repo) > 0:
493
+ print("✨ Устанвока кастомных расширений...", 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📦 Установлено '{len(extension_repo)}', Кастомных расширений!")
501
+
502
+
503
+ ## List Models and stuff
504
+ if detailed_download == "off":
505
+ print("\n\n\033[33mЕсли вы не видете каких-то скаченных файлов, включите в виджетах функцию 'Подробная Загрузка'.")
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
+
files_cells/python/ru/files_cells_python_ru_launch_ru.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ free_plan = (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024. ** 3) <= 20)
14
+ environments = {
15
+ 'COLAB_GPU': ('Google Colab', "/root" if free_plan else "/content"),
16
+ 'KAGGLE_URL_BASE': ('Kaggle', "/kaggle/working/content")
17
+ }
18
+
19
+ for env_var, (environment, path) in environments.items():
20
+ if env_var in os.environ:
21
+ return environment, path, free_plan
22
+
23
+ env, root_path, free_plan = 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
+ zrok_token = settings['zrok_token']
37
+ commandline_arguments = settings['commandline_arguments']
38
+
39
+
40
+ # ======================== TUNNEL ========================
41
+ import cloudpickle as pickle
42
+
43
+ def get_public_ip(version='ipv4'):
44
+ try:
45
+ url = f'https://api64.ipify.org?format=json&{version}=true'
46
+ response = requests.get(url)
47
+ data = response.json()
48
+ public_ip = data['ip']
49
+ return public_ip
50
+ except Exception as e:
51
+ print(f"Error getting public {version} address:", e)
52
+
53
+ public_ipv4 = get_public_ip(version='ipv4')
54
+
55
+ tunnel_class = pickle.load(open(f"{root_path}/new_tunnel", "rb"), encoding="utf-8")
56
+ tunnel_port= 1769
57
+ tunnel = tunnel_class(tunnel_port)
58
+ tunnel.add_tunnel(command="cl tunnel --url localhost:{port}", name="cl", pattern=re.compile(r"[\w-]+\.trycloudflare\.com"))
59
+ 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.")
60
+
61
+ ''' add zrok tunnel '''
62
+ if zrok_token:
63
+ get_ipython().system('zrok enable {zrok_token} &> /dev/null')
64
+ tunnel.add_tunnel(command="zrok share public http://localhost:{port}/ --headless", name="zrok", pattern=re.compile(r"[\w-]+\.share\.zrok\.io"))
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
+ with tunnel:
76
+ get_ipython().run_line_magic('cd', '{webui_path}')
77
+ commandline_arguments += f" --port=1769"
78
+
79
+ if ngrok_token:
80
+ commandline_arguments += ' --ngrok ' + ngrok_token
81
+ if env != "Google Colab":
82
+ commandline_arguments += f" --encrypt-pass=1769"
83
+
84
+ get_ipython().system('COMMANDLINE_ARGS="{commandline_arguments}" python launch.py')
85
+
86
+ start_colab = float(open(f'{webui_path}/static/colabTimer.txt', 'r').read())
87
+ time_since_start = str(timedelta(seconds=time.time()-start_colab)).split('.')[0]
88
+ print(f"\n⌚️ \033[0mВы проводите эту сессию в течение - \033[33m{time_since_start}\033[0m\n\n")
89
+
files_cells/python/ru/files_cells_python_ru_widgets_ru.py ADDED
@@ -0,0 +1,601 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ##~ WIDGET CODE | BY: ANXETY ~##
2
+
3
+ import os
4
+ import json
5
+ import time
6
+ import ipywidgets as widgets
7
+ from ipywidgets import widgets, Layout, Label, Button, VBox, HBox
8
+ from IPython.display import display, HTML, Javascript, clear_output
9
+
10
+
11
+ # ================= DETECT ENV =================
12
+ def detect_environment():
13
+ free_plan = (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024. ** 3) <= 20)
14
+ environments = {
15
+ 'COLAB_GPU': ('Google Colab', "/root" if free_plan else "/content"),
16
+ 'KAGGLE_URL_BASE': ('Kaggle', "/kaggle/working/content")
17
+ }
18
+
19
+ for env_var, (environment, path) in environments.items():
20
+ if env_var in os.environ:
21
+ return environment, path, free_plan
22
+
23
+ env, root_path, free_plan = detect_environment()
24
+ webui_path = f"{root_path}/sdw"
25
+
26
+ get_ipython().system('mkdir -p {root_path}')
27
+ # ----------------------------------------------
28
+
29
+
30
+ # ==================== CSS JS ====================
31
+ # custom background images V1.5
32
+ import argparse
33
+ parser = argparse.ArgumentParser(description='This script processes an background image.')
34
+ parser.add_argument('-i', '--image', type=str, help='URL of the image to process', metavar='')
35
+ parser.add_argument('-o', '--opacity', type=float, help='Opacity level for the image, between 0 and 1', metavar='', default=0.3)
36
+ parser.add_argument('-b', '--blur', type=str, help='Blur level for the image', metavar='', default=0)
37
+ parser.add_argument('-y', type=int, help='Y coordinate for the image in px', metavar='', default=0)
38
+ parser.add_argument('-x', type=int, help='X coordinate for the image in px', metavar='', default=0)
39
+ parser.add_argument('-s', '--scale', type=int, help='Scale image in %%', metavar='', default=100)
40
+ parser.add_argument('-m', '--mode',action='store_true', help='Removes repetitive image tiles')
41
+ parser.add_argument('-t', '--transparent', action='store_true', help='Makes input/selection fields 35%% more transparent')
42
+ parser.add_argument('-bf', '--blur-fields', type=str, help='Background blur level for input/selection fields', metavar='', default=2)
43
+ args = parser.parse_args()
44
+ """---"""
45
+ url_img = args.image
46
+ opacity_img = args.opacity
47
+ blur_img = args.blur
48
+ y_img = args.y
49
+ x_img = args.x
50
+ scale_img = args.scale
51
+ blur_fields = args.blur_fields
52
+
53
+ ## ---
54
+ """ WTF KAGGLE - WHAT THE FUCK IS THE DIFFERENCE OF 35 PIXELS!?!?!? """
55
+ fix_heigh_img = "-810px" if env == "Kaggle" else "-775px"
56
+
57
+ """ transperent fields """
58
+ t_bg_alpha = "1" if not args.transparent else "0.65"
59
+
60
+ """ mode img - repeats """
61
+ mode_img = "repeat" if not args.mode else "no-repeat"
62
+ ## ---
63
+
64
+ container_background = f'''
65
+ <style>
66
+ :root {{
67
+ /* for background container*/
68
+ --img_background: url({url_img});
69
+ --img_opacity: {opacity_img};
70
+ --img_blur: {blur_img}px;
71
+ --image_y: {y_img}px;
72
+ --image_x: {x_img}px;
73
+ --img_scale: {scale_img}%;
74
+ --img_mode: {mode_img};
75
+ --img_height_dif: {fix_heigh_img};
76
+
77
+ /* for fields */
78
+ --bg-field-color: rgba(28, 28, 28, {t_bg_alpha}); /* -> #1c1c1c */
79
+ --bg-field-color-hover: rgba(38, 38, 38, {t_bg_alpha}); /* -> #262626; */
80
+ --bg-field-blur-level: {blur_fields}px;
81
+ }}
82
+ '''
83
+
84
+ display(HTML(container_background))
85
+ # ---
86
+
87
+ CSS = '''
88
+ <style>
89
+ /* General Styles */
90
+ .header {
91
+ font-family: cursive;
92
+ font-size: 20px;
93
+ font-weight: bold;
94
+ color: #ff8cee;
95
+ margin-bottom: 15px;
96
+ user-select: none;
97
+ cursor: default;
98
+ display: inline-block;
99
+ }
100
+
101
+ hr {
102
+ border-color: grey;
103
+ background-color: grey;
104
+ opacity: 0.25;
105
+ }
106
+
107
+ a {
108
+ text-decoration: none;
109
+ color: inherit;
110
+ }
111
+
112
+
113
+ /* Container style */
114
+
115
+ .container {
116
+ position: relative;
117
+ background-color: #232323;
118
+ width: 1080px;
119
+ padding: 10px 15px;
120
+ border-radius: 15px;
121
+ box-shadow: 0 0 50px rgba(0, 0, 0, 0.3);
122
+ margin-bottom: 5px;
123
+ overflow: hidden;
124
+ }
125
+
126
+ .container::after {
127
+ position: absolute;
128
+ top: 5px;
129
+ right: 10px;
130
+ content: "ANXETY";
131
+ font-weight: bold;
132
+ font-size: 24px;
133
+ color: rgba(0, 0, 0, 0.2);
134
+ }
135
+
136
+ /* background img */
137
+ .container::before {
138
+ content: "";
139
+ position: absolute;
140
+ top: 0;
141
+ left: 0;
142
+ right: 0;
143
+ bottom: 0;
144
+ background-image: var(--img_background);
145
+ background-size: var(--img_scale);
146
+ background-repeat: var(--img_mode);
147
+ opacity: var(--img_opacity);
148
+ mix-blend-mode: screen;
149
+ pointer-events: none;
150
+ filter: blur(var(--img_blur));
151
+ z-index: -1;
152
+ }
153
+
154
+ .image_1::before {
155
+ background-position: var(--image_x) calc(-120px - var(--image_y));
156
+ }
157
+ .image_2::before {
158
+ background-position: var(--image_x) calc(-290px - var(--image_y));
159
+ }
160
+ .image_3::before {
161
+ background-position: var(--image_x) calc(-430px - var(--image_y));
162
+ }
163
+ .image_4::before {
164
+ background-position: var(--image_x) calc(var(--img_height_dif) - var(--image_y));
165
+ }
166
+
167
+ .container_custom_downlad {
168
+ height: 55px;
169
+ transition: all 0.5s;
170
+ }
171
+
172
+ .container_custom_downlad.expanded {
173
+ height: 270px;
174
+ }
175
+
176
+
177
+ /* Element text style */
178
+
179
+ .widget-html,
180
+ .widget-button,
181
+ .widget-text label,
182
+ .widget-checkbox label,
183
+ .widget-dropdown label,
184
+ .widget-dropdown select,
185
+ .widget-text input[type="text"] {
186
+ font-family: cursive;
187
+ font-size: 14px;
188
+ color: white !important;
189
+ user-select: none;
190
+ }
191
+
192
+ .widget-text input[type="text"]::placeholder {
193
+ color: grey;
194
+ }
195
+
196
+
197
+ /* Input field styles */
198
+
199
+ .widget-dropdown select,
200
+ .widget-text input[type="text"] {
201
+ height: 30px;
202
+ background-color: var(--bg-field-color);
203
+ border: 1px solid #262626;
204
+ border-radius: 10px;
205
+ box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);
206
+ transition: all 0.3s ease-in-out;
207
+ backdrop-filter: blur(var(--bg-field-blur-level));
208
+ }
209
+
210
+ .widget-dropdown select:focus,
211
+ .widget-text input[type="text"]:focus {
212
+ border-color: #006ee5;
213
+ }
214
+
215
+ .widget-dropdown select:hover,
216
+ .widget-text input[type="text"]:hover {
217
+ transform: scale(1.003);
218
+ background-color: var(--bg-field-color-hover);
219
+ box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);
220
+ }
221
+
222
+ .widget-dropdown option {
223
+ background-color: #1c1c1c;
224
+ }
225
+
226
+
227
+ /* Slider Checkbox style */
228
+
229
+ .widget-checkbox input[type="checkbox"] {
230
+ appearance: none;
231
+ position: relative;
232
+ top: 4px; /* Why is he taller?! */
233
+ width: 40px;
234
+ height: 20px;
235
+ border: none;
236
+ border-radius: 10px;
237
+ background-color: #20b2aa;
238
+ cursor: pointer;
239
+ box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.3);
240
+ transition: background-color 0.3s ease;
241
+ }
242
+ .widget-checkbox input[type="checkbox"]:checked {
243
+ background-color: #2196F3;
244
+ }
245
+
246
+ .widget-checkbox input[type="checkbox"]:before {
247
+ content: '';
248
+ position: absolute;
249
+ top: 50%;
250
+ left: 3px;
251
+ width: 16px;
252
+ height: 16px;
253
+ border-radius: inherit;
254
+ background-color: white;
255
+ box-shadow: 0 0 8px rgba(0, 0, 0, 0.3);
256
+ transform: translateY(-50%);
257
+ transition: left 0.3s ease;
258
+ }
259
+ .widget-checkbox input[type="checkbox"]:checked:before {
260
+ left: 21px;
261
+ }
262
+
263
+
264
+ /* Button styles */
265
+
266
+ .button_save {
267
+ font-size: 15px;
268
+ font-weight: bold;
269
+ width: 120px;
270
+ height: 35px;
271
+ border-radius: 15px;
272
+ background-image: radial-gradient(circle at top left, purple 10%, violet 90%);
273
+ background-size: 200% 200%;
274
+ background-position: left bottom;
275
+ transition: background 0.5s ease-in-out, transform 0.3s ease;
276
+ }
277
+
278
+ .button_save:hover {
279
+ cursor: pointer;
280
+ background-image: radial-gradient(circle at top left, purple 10%, #93ac47 90%);
281
+ background-size: 200% 200%;
282
+ background-position: right bottom;
283
+ transform: translateY(1px);
284
+ }
285
+
286
+ .button_ngrok {
287
+ font-size: 12px;
288
+ height: 30px;
289
+ border-radius: 10px;
290
+ padding: 1px 12px;
291
+ background-image: radial-gradient(circle at top left, purple 10%, violet 90%);
292
+ background-size: 200% 200%;
293
+ background-position: left bottom;
294
+ transition: background 0.5s ease-in-out, transform 0.3s ease;
295
+ white-space: nowrap;
296
+ }
297
+
298
+ .button_ngrok:hover {
299
+ cursor: pointer;
300
+ background-image: radial-gradient(circle at top left, purple 10%, #1D94BB 90%);
301
+ background-size: 200% 200%;
302
+ background-position: right bottom;
303
+ transform: translateY(1px);
304
+ }
305
+
306
+ .button_save:active,
307
+ .button_ngrok:active {
308
+ filter: brightness(0.75) !important;
309
+ }
310
+
311
+ /* Removes ugly stroke from widget buttons. */
312
+ .jupyter-widgets.lm-Widget:focus {
313
+ outline: none;
314
+ }
315
+
316
+
317
+ /* Popup style of `INFO` window */
318
+
319
+ .info {
320
+ position: absolute;
321
+ top: -5px;
322
+ right: 95px;
323
+ color: grey;
324
+ font-family: cursive;
325
+ font-size: 14px;
326
+ font-weight: normal;
327
+ user-select: none;
328
+ pointer-events: none;
329
+ opacity: 0;
330
+ transition: opacity 0.3s ease-in-out;
331
+ display: inline-block;
332
+ }
333
+
334
+ .popup {
335
+ position: absolute;
336
+ top: 120px;
337
+ z-index: 999;
338
+ width: auto;
339
+ padding: 10px;
340
+ text-align: center;
341
+ background-color: rgba(255, 255, 255, 0.05);
342
+ backdrop-filter: blur(20px);
343
+ border: 1px solid rgba(255, 255, 255, 0.45);
344
+ border-radius: 8px;
345
+ box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
346
+ opacity: 0;
347
+ color: #fff;
348
+ font-size: 16px;
349
+ font-family: cursive;
350
+ user-select: none;
351
+ cursor: default;
352
+ pointer-events: none;
353
+ transform: rotate(-5deg);
354
+ transition: top 0.3s ease-in-out, opacity 0.3s ease-in-out, transform 0.3s ease-in-out;
355
+ }
356
+
357
+ .sample {
358
+ display: inline-block;
359
+ margin-top: 25px;
360
+ padding: 10px 100px;
361
+ background-color: rgba(255, 255, 255, 0.2);
362
+ color: #c6e2ff;
363
+ border: 2px solid rgba(255, 255, 255, 0.2);
364
+ border-radius: 8px;
365
+ box-shadow: 0 0 10px rgba(255, 255, 255, 0.2), inset 0 0 25px rgba(255, 255, 255, 0.2);
366
+ }
367
+
368
+ .info.showed {
369
+ opacity: 1;
370
+ pointer-events: auto;
371
+ }
372
+
373
+ .info:hover + .popup {
374
+ top: 35px;
375
+ opacity: 1;
376
+ pointer-events: initial;
377
+ transform: rotate(0deg);
378
+ }
379
+
380
+
381
+ /* Animation of elements */
382
+
383
+ .container,
384
+ .button_save {
385
+ animation-name: showedWidgets;
386
+ animation-duration: 1s;
387
+ animation-fill-mode: forwards;
388
+ }
389
+
390
+ .container.hide,
391
+ .button_save.hide {
392
+ animation-name: hideWidgets;
393
+ animation-duration: 0.5s;
394
+ animation-fill-mode: forwards;
395
+ }
396
+
397
+ @keyframes showedWidgets {
398
+ 0% {
399
+ transform: translate3d(-65%, 15%, 0) scale(0) rotate(15deg);
400
+ filter: blur(25px) grayscale(1) brightness(0.3);
401
+ opacity: 0;
402
+ }
403
+ 100% {
404
+ transform: translate3d(0, 0, 0) scale(1) rotate(0deg);
405
+ filter: blur(0) grayscale(0) brightness(1);
406
+ opacity: 1;
407
+ }
408
+ }
409
+
410
+ @keyframes hideWidgets {
411
+ 0% {
412
+ transform: translate3d(0, 0, 0) scale(1) rotate3d(1, 0, 0, 0deg);
413
+ filter: blur(0) grayscale(0) brightness(1);
414
+ opacity: 1;
415
+ }
416
+ 100% {
417
+ transform: translate3d(0, 5%, 0) scale(0.9) rotate3d(1, 0, 0, 90deg);
418
+ filter: blur(15px) grayscale(1) brightness(0.5);
419
+ opacity: 0;
420
+ }
421
+ }
422
+ </style>
423
+
424
+ <!-- TOGGLE 'CustomDL' SCRIPT -->
425
+ <script>
426
+ function toggleContainer() {
427
+ let downloadContainer = document.querySelector('.container_custom_downlad');
428
+ let info = document.querySelector('.info');
429
+
430
+ downloadContainer.classList.toggle('expanded');
431
+ info.classList.toggle('showed');
432
+ }
433
+ </script>
434
+ '''
435
+
436
+ display(HTML(CSS))
437
+ # ==================== CSS JS ====================
438
+
439
+
440
+ # ==================== WIDGETS ====================
441
+ # --- global widgets ---
442
+ style = {'description_width': 'initial'}
443
+ layout = widgets.Layout(min_width='1047px')
444
+
445
+ HR = widgets.HTML('<hr>')
446
+
447
+ # --- MODEL ---
448
+ model_header = widgets.HTML('<div class="header">Выбор Модели<div>')
449
+ model_options = ['none',
450
+ '1.Anime (by XpucT) + INP',
451
+ '2.BluMix [Anime] [V7] + INP',
452
+ '3.Cetus-Mix [Anime] [V4] + INP',
453
+ '4.Counterfeit [Anime] [V3] + INP',
454
+ '5.CuteColor [Anime] [V3]',
455
+ '6.Dark-Sushi-Mix [Anime]',
456
+ '7.Deliberate [Realism] [V6] + INP',
457
+ '8.Meina-Mix [Anime] [V11] + INP',
458
+ '9.Mix-Pro [Anime] [V4] + INP']
459
+ # ---
460
+ Model_widget = widgets.Dropdown(options=model_options, value='4.Counterfeit [Anime] [V3] + INP', description='Модель:', style=style, layout=layout)
461
+ Model_Num_widget = widgets.Text(description='Номер Модели:', placeholder='Введите номера моделей для скачивания через запятую/пробел.', style=style, layout=layout)
462
+ Inpainting_Model_widget = widgets.Checkbox(value=False, description='Inpainting Модели', style=style)
463
+
464
+ ''' Display Model'''
465
+ all_model_box = widgets.VBox([model_header, Model_widget, Model_Num_widget, Inpainting_Model_widget]).add_class("container").add_class("image_1")
466
+ display(all_model_box)
467
+
468
+ # --- VAE ---
469
+ vae_header = widgets.HTML('<div class="header" >Выбор VAE</div>')
470
+ vae_options = ['none',
471
+ '1.Anime.vae',
472
+ '2.Anything.vae',
473
+ '3.Blessed2.vae',
474
+ '4.ClearVae.vae',
475
+ '5.WD.vae']
476
+ Vae_widget = widgets.Dropdown(options=vae_options, value='3.Blessed2.vae', description='Vae:', style=style, layout=layout)
477
+ Vae_Num_widget = widgets.Text(description='Номер Vae:', placeholder='Введите номера vae для скачивания через запятую/пробел.', style=style, layout=layout)
478
+
479
+ ''' Display Vae'''
480
+ all_vae_box= widgets.VBox([vae_header, Vae_widget, Vae_Num_widget]).add_class("container").add_class("image_2")
481
+ display(all_vae_box)
482
+
483
+ # --- ADDITIONAL ---
484
+ additional_header = widgets.HTML('<div class="header">Дополнительно</div>')
485
+ latest_webui_widget = widgets.Checkbox(value=True, description='Обновить WebUI', style=style)
486
+ latest_exstensions_widget = widgets.Checkbox(value=True, description='Обновить Расширения', style=style)
487
+ detailed_download_widget = widgets.Dropdown(options=['off', 'on'], value='off', description='Подробная Загрузка:', style=style)
488
+ latest_changes_widget = HBox([latest_webui_widget, latest_exstensions_widget, detailed_download_widget], layout=widgets.Layout(justify_content='space-between'))
489
+ controlnet_options = ['none', 'ALL', '1.canny',
490
+ '2.openpose', '3.depth',
491
+ '4.normal_map', '5.mlsd',
492
+ '6.lineart', '7.soft_edge',
493
+ '8.scribble', '9.segmentation',
494
+ '10.shuffle', '11.tile',
495
+ '12.inpaint', '13.instruct_p2p']
496
+ # ---
497
+ controlnet_widget = widgets.Dropdown(options=controlnet_options, value='none', description='ControlNet:', style=style, layout=layout)
498
+ controlnet_Num_widget = widgets.Text(description='Номер ControlNet:', placeholder='Введите номера моделей ControlNet для скачивания через запятую/пробел.', style=style, layout=layout)
499
+ commit_hash_widget = widgets.Text(description='Commit Hash:', style=style, layout=layout)
500
+ optional_huggingface_token_widget = widgets.Text(description='Токен HuggingFace:', style=style, layout=layout)
501
+ ngrok_token_widget = widgets.Text(description='Токен Ngrok:', style=style, layout=widgets.Layout(width='1047px'))
502
+ ngrock_button = widgets.HTML('<a href="https://dashboard.ngrok.com/get-started/your-authtoken" target="_blank">Получить Ngrok Токен</a>').add_class("button_ngrok")
503
+ ngrok_widget = widgets.HBox([ngrok_token_widget, ngrock_button], style=style, layout=layout)
504
+ zrok_token_widget = widgets.Text(description='Zrok Token:', style=style, layout=widgets.Layout(width='1047px'))
505
+ zrok_button = widgets.HTML('<a href="https://colab.research.google.com/drive/1d2sjWDJi_GYBUavrHSuQyHTDuLy36WpU" target="_blank">Зарегать Zrok Токен</a>').add_class("button_ngrok")
506
+ zrok_widget = widgets.HBox([zrok_token_widget, zrok_button], style=style, layout=layout)
507
+ # ---
508
+ commandline_arguments_options = "--listen --enable-insecure-extension-access --theme dark --no-half-vae --disable-console-progressbars --xformers"
509
+ commandline_arguments_widget = widgets.Text(description='Аргументы:', value=commandline_arguments_options, style=style, layout=layout)
510
+
511
+ ''' Display Additional'''
512
+ additional_widget_list = [additional_header, latest_changes_widget, HR, controlnet_widget, controlnet_Num_widget, commit_hash_widget, optional_huggingface_token_widget, ngrok_widget, zrok_widget, HR, commandline_arguments_widget]
513
+ if free_plan and env == "Google Colab": # remove ngrok from colab
514
+ additional_widget_list.remove(ngrok_widget)
515
+ # ```
516
+ all_additional_box = widgets.VBox(additional_widget_list).add_class("container").add_class("image_3")
517
+ display(all_additional_box)
518
+
519
+ # --- CUSTOM DOWNLOAD ---
520
+ custom_download_header_popup = widgets.HTML('''
521
+ <style>
522
+ /* Color */
523
+ .sample_label {color: #dbafff;}
524
+ .braces {color: #ffff00;}
525
+ .extension {color: #eb934b;}
526
+ .file_name {color: #ffffd8;}
527
+ </style>
528
+
529
+ <div class="header" style="cursor: pointer;" onclick="toggleContainer()">Кастомная Загрузка</div>
530
+ <!-- PopUp window -->
531
+ <div class="info" id="info_dl">INFO</div>
532
+ <div class="popup">
533
+ Разделите несколько URL-адресов запятой/пробелом. Для <span class="file_name">пользовательского имени</span> файла/расширения укажите его через <span class="braces">[]</span>
534
+ после URL без пробелов.
535
+ <span style="color: #ff9999">Для файлов обязательно укажите</span> - <span class="extension">Расширение Файла.</span>
536
+ <div class="sample">
537
+ <span class="sample_label">Пример для Файла:</span>
538
+ 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>
539
+ <br>
540
+ <span class="sample_label">Пример для Расширения:</span>
541
+ https://github.com/hako-mikan/sd-webui-regional-prompter<span class="braces">[</span><span class="file_name">Regional-Prompter</span><span class="braces">]</span>
542
+ </div>
543
+ </div>
544
+ ''')
545
+ # ---
546
+ Model_url_widget = widgets.Text(description='Model:', style=style, layout=layout)
547
+ Vae_url_widget = widgets.Text(description='Vae:', style=style, layout=layout)
548
+ LoRA_url_widget = widgets.Text(description='LoRa:', style=style, layout=layout)
549
+ Embedding_url_widget = widgets.Text(description='Embedding:', style=style, layout=layout)
550
+ Extensions_url_widget = widgets.Text(description='Extensions:', style=style, layout=layout)
551
+ custom_file_urls_widget = widgets.Text(description='Файл (txt):', style=style, layout=layout)
552
+
553
+ ''' Display CustomDl'''
554
+ all_custom_box = widgets.VBox([
555
+ custom_download_header_popup, Model_url_widget, Vae_url_widget, LoRA_url_widget, Embedding_url_widget, Extensions_url_widget, custom_file_urls_widget
556
+ ]).add_class("container").add_class("image_4").add_class("container_custom_downlad")
557
+ display(all_custom_box)
558
+
559
+ # --- Save Button ---
560
+ save_button = widgets.Button(description='Сохранить').add_class("button_save")
561
+ display(save_button)
562
+
563
+
564
+ # ============ Load / Save - Settings V2 ============
565
+ SETTINGS_FILE = f'{root_path}/settings.json'
566
+
567
+ settings_keys = [
568
+ 'Model', 'Model_Num', 'Inpainting_Model',
569
+ 'Vae', 'Vae_Num',
570
+ 'latest_webui', 'latest_exstensions', 'detailed_download',
571
+ 'controlnet', 'controlnet_Num', 'commit_hash', 'optional_huggingface_token',
572
+ 'ngrok_token', 'zrok_token', 'commandline_arguments',
573
+ 'Model_url', 'Vae_url', 'LoRA_url', 'Embedding_url', 'Extensions_url', 'custom_file_urls'
574
+ ]
575
+
576
+ def save_settings():
577
+ settings = {key: globals()[f"{key}_widget"].value for key in settings_keys}
578
+ with open(SETTINGS_FILE, 'w') as f:
579
+ json.dump(settings, f, indent=2)
580
+
581
+ def load_settings():
582
+ if os.path.exists(SETTINGS_FILE):
583
+ with open(SETTINGS_FILE, 'r') as f:
584
+ settings = json.load(f)
585
+ for key in settings_keys:
586
+ globals()[f"{key}_widget"].value = settings.get(key)
587
+
588
+ def save_data(button):
589
+ save_settings()
590
+
591
+ # --- uhh - hide... ---
592
+ widgets_list = [all_model_box, all_vae_box, all_additional_box, all_custom_box, save_button]
593
+ for widget in widgets_list:
594
+ widget.add_class("hide")
595
+ time.sleep(0.5)
596
+
597
+ widgets.Widget.close_all()
598
+
599
+ settings = load_settings()
600
+ save_button.on_click(save_data)
601
+