duhking commited on
Commit
a3f9ab9
1 Parent(s): cb7de7b

Upload 4 files

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