✨ This seems to work without error :3
Browse files- 👽️ Updated CivitAi API code;
- ⚡️ New tag for file.txt: ‘config’;
- 🐛 Fixed some links..
- files_cells/notebooks/en/auto_cleaner_en.ipynb +164 -164
- files_cells/notebooks/en/downloading_en.ipynb +695 -640
- files_cells/notebooks/en/launch_en.ipynb +144 -155
- files_cells/notebooks/en/widgets_en.ipynb +348 -348
- files_cells/notebooks/ru/auto_cleaner_ru.ipynb +164 -164
- files_cells/notebooks/ru/downloading_ru.ipynb +695 -640
- files_cells/notebooks/ru/launch_ru.ipynb +144 -155
- files_cells/notebooks/ru/widgets_ru.ipynb +348 -348
- files_cells/python/en/auto_cleaner_en.py +138 -138
- files_cells/python/en/downloading_en.py +666 -611
- files_cells/python/en/launch_en.py +118 -129
- files_cells/python/en/widgets_en.py +322 -322
- files_cells/python/ru/auto_cleaner_ru.py +138 -138
- files_cells/python/ru/downloading_ru.py +666 -611
- files_cells/python/ru/launch_ru.py +118 -129
- files_cells/python/ru/widgets_ru.py +322 -322
- special/dl_display_results.py +1 -1
files_cells/notebooks/en/auto_cleaner_en.ipynb
CHANGED
@@ -1,165 +1,165 @@
|
|
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 |
-
" for env_var, (environment, path) in environments.items():\n",
|
37 |
-
" if env_var in os.environ:\n",
|
38 |
-
" return environment, path, free_plan\n",
|
39 |
-
"\n",
|
40 |
-
"env, root_path, free_plan = detect_environment()\n",
|
41 |
-
"webui_path = f\"{root_path}/sdw\"\n",
|
42 |
-
"\n",
|
43 |
-
"\n",
|
44 |
-
"# ==================== CSS ====================\n",
|
45 |
-
"# Main CSS\n",
|
46 |
-
"css_file_path = f\"{root_path}/CSS/auto_cleaner.css\"\n",
|
47 |
-
"with open(css_file_path , \"r\") as f:\n",
|
48 |
-
" CSS_AC = f.read()\n",
|
49 |
-
"display(HTML(f\"<style>{CSS_AC}</style>\"))\n",
|
50 |
-
"\n",
|
51 |
-
"\n",
|
52 |
-
"# ================ AutoCleaner function ================\n",
|
53 |
-
"directories = {\n",
|
54 |
-
" \"Images\": f\"{webui_path}/output\",\n",
|
55 |
-
" \"Models\": f\"{webui_path}/models/Stable-diffusion/\",\n",
|
56 |
-
" \"Vae\": f\"{webui_path}/models/VAE/\",\n",
|
57 |
-
" \"LoRa\": f\"{webui_path}/models/Lora/\",\n",
|
58 |
-
" \"ControlNet Models\": f\"{webui_path}/models/ControlNet/\"\n",
|
59 |
-
"}\n",
|
60 |
-
"\n",
|
61 |
-
"\"\"\" functions \"\"\"\n",
|
62 |
-
"def clean_directory(directory):\n",
|
63 |
-
" deleted_files = 0\n",
|
64 |
-
" image_dir = directories['Images']\n",
|
65 |
-
"\n",
|
66 |
-
" for root, dirs, files in os.walk(directory):\n",
|
67 |
-
" for file in files:\n",
|
68 |
-
" file_path = os.path.join(root, file)\n",
|
69 |
-
"\n",
|
70 |
-
" if file.endswith(\".txt\"):\n",
|
71 |
-
" continue\n",
|
72 |
-
" if file.endswith((\".safetensors\", \".pt\")) or root == image_dir: # fix for image counter\n",
|
73 |
-
" deleted_files += 1\n",
|
74 |
-
"\n",
|
75 |
-
" os.remove(file_path)\n",
|
76 |
-
" return deleted_files\n",
|
77 |
-
"\n",
|
78 |
-
"def update_memory_info():\n",
|
79 |
-
" disk_space = psutil.disk_usage(os.getcwd())\n",
|
80 |
-
" total = disk_space.total / (1024 ** 3)\n",
|
81 |
-
" used = disk_space.used / (1024 ** 3)\n",
|
82 |
-
" free = disk_space.free / (1024 ** 3)\n",
|
83 |
-
"\n",
|
84 |
-
" storage_info.value = f'''\n",
|
85 |
-
" <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",
|
86 |
-
" '''\n",
|
87 |
-
"\n",
|
88 |
-
"def on_execute_button_press(button):\n",
|
89 |
-
" selected_cleaners = auto_cleaner_widget.value\n",
|
90 |
-
" deleted_files_dict = {}\n",
|
91 |
-
"\n",
|
92 |
-
" for option in selected_cleaners:\n",
|
93 |
-
" if option in directories:\n",
|
94 |
-
" deleted_files_dict[option] = clean_directory(directories[option])\n",
|
95 |
-
"\n",
|
96 |
-
" output.clear_output()\n",
|
97 |
-
"\n",
|
98 |
-
" with output:\n",
|
99 |
-
" for message in generate_messages(deleted_files_dict):\n",
|
100 |
-
" message_widget = HTML(f'<p class=\"output_message_AC\">{message}</p>')\n",
|
101 |
-
" display(message_widget)\n",
|
102 |
-
"\n",
|
103 |
-
" update_memory_info()\n",
|
104 |
-
"\n",
|
105 |
-
"def on_clear_button_press(button):\n",
|
106 |
-
" container.add_class(\"hide\")\n",
|
107 |
-
" time.sleep(0.5)\n",
|
108 |
-
" widgets.Widget.close_all()\n",
|
109 |
-
"\n",
|
110 |
-
"def generate_messages(deleted_files_dict):\n",
|
111 |
-
" messages = []\n",
|
112 |
-
" word_variants = {\n",
|
113 |
-
" \"Images\": \"Images\",\n",
|
114 |
-
" \"Models\": \"Models\",\n",
|
115 |
-
" \"Vae\": \"Vae\",\n",
|
116 |
-
" \"LoRa\": \"LoRa\",\n",
|
117 |
-
" \"ControlNet Models\": \"ControlNet Models\"\n",
|
118 |
-
" }\n",
|
119 |
-
" for key, value in deleted_files_dict.items():\n",
|
120 |
-
" object_word = word_variants.get(key)\n",
|
121 |
-
" messages.append(f\"Deleted {value} {object_word}\")\n",
|
122 |
-
" return messages\n",
|
123 |
-
"# ================ AutoCleaner function ================\n",
|
124 |
-
"\n",
|
125 |
-
"\n",
|
126 |
-
"# --- storage memory ---\n",
|
127 |
-
"import psutil\n",
|
128 |
-
"disk_space = psutil.disk_usage(os.getcwd())\n",
|
129 |
-
"total = disk_space.total / (1024 ** 3)\n",
|
130 |
-
"used = disk_space.used / (1024 ** 3)\n",
|
131 |
-
"free = disk_space.free / (1024 ** 3)\n",
|
132 |
-
"\n",
|
133 |
-
"\n",
|
134 |
-
"# UI Code\n",
|
135 |
-
"AutoCleaner_options = AutoCleaner_options = list(directories.keys())\n",
|
136 |
-
"instruction_label = widgets.HTML('''\n",
|
137 |
-
"<span class=\"instruction_AC\">Use <span style=\"color: #B2B2B2;\">ctrl</span> or <span style=\"color: #B2B2B2;\">shift</span> for multiple selections.</span>\n",
|
138 |
-
"''')\n",
|
139 |
-
"auto_cleaner_widget = widgets.SelectMultiple(options=AutoCleaner_options, layout=widgets.Layout(width='auto')).add_class(\"custom-select-multiple_AC\")\n",
|
140 |
-
"output = widgets.Output().add_class(\"output_AC\")\n",
|
141 |
-
"# ---\n",
|
142 |
-
"execute_button = Button(description='Execute Cleaning').add_class(\"button_execute_AC\").add_class(\"button_AC\")\n",
|
143 |
-
"execute_button.on_click(on_execute_button_press)\n",
|
144 |
-
"clear_button = Button(description='Hide Widget').add_class(\"button_clear_AC\").add_class(\"button_AC\")\n",
|
145 |
-
"clear_button.on_click(on_clear_button_press)\n",
|
146 |
-
"# ---\n",
|
147 |
-
"storage_info = widgets.HTML(f'''\n",
|
148 |
-
"<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",
|
149 |
-
"''')\n",
|
150 |
-
"# ---\n",
|
151 |
-
"buttons = widgets.HBox([execute_button, clear_button])\n",
|
152 |
-
"lower_information_panel = widgets.HBox([buttons, storage_info]).add_class(\"lower_information_panel_AC\")\n",
|
153 |
-
"\n",
|
154 |
-
"container = VBox([instruction_label, widgets.HTML('<hr>'), auto_cleaner_widget, output, widgets.HTML('<hr>'), lower_information_panel]).add_class(\"container_AC\")\n",
|
155 |
-
"\n",
|
156 |
-
"display(container)"
|
157 |
-
],
|
158 |
-
"metadata": {
|
159 |
-
"id": "I22dFg7F2j3G"
|
160 |
-
},
|
161 |
-
"execution_count": null,
|
162 |
-
"outputs": []
|
163 |
-
}
|
164 |
-
]
|
165 |
}
|
|
|
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 |
+
" for env_var, (environment, path) in environments.items():\n",
|
37 |
+
" if env_var in os.environ:\n",
|
38 |
+
" return environment, path, free_plan\n",
|
39 |
+
"\n",
|
40 |
+
"env, root_path, free_plan = detect_environment()\n",
|
41 |
+
"webui_path = f\"{root_path}/sdw\"\n",
|
42 |
+
"\n",
|
43 |
+
"\n",
|
44 |
+
"# ==================== CSS ====================\n",
|
45 |
+
"# Main CSS\n",
|
46 |
+
"css_file_path = f\"{root_path}/CSS/auto_cleaner.css\"\n",
|
47 |
+
"with open(css_file_path , \"r\") as f:\n",
|
48 |
+
" CSS_AC = f.read()\n",
|
49 |
+
"display(HTML(f\"<style>{CSS_AC}</style>\"))\n",
|
50 |
+
"\n",
|
51 |
+
"\n",
|
52 |
+
"# ================ AutoCleaner function ================\n",
|
53 |
+
"directories = {\n",
|
54 |
+
" \"Images\": f\"{webui_path}/output\",\n",
|
55 |
+
" \"Models\": f\"{webui_path}/models/Stable-diffusion/\",\n",
|
56 |
+
" \"Vae\": f\"{webui_path}/models/VAE/\",\n",
|
57 |
+
" \"LoRa\": f\"{webui_path}/models/Lora/\",\n",
|
58 |
+
" \"ControlNet Models\": f\"{webui_path}/models/ControlNet/\"\n",
|
59 |
+
"}\n",
|
60 |
+
"\n",
|
61 |
+
"\"\"\" functions \"\"\"\n",
|
62 |
+
"def clean_directory(directory):\n",
|
63 |
+
" deleted_files = 0\n",
|
64 |
+
" image_dir = directories['Images']\n",
|
65 |
+
"\n",
|
66 |
+
" for root, dirs, files in os.walk(directory):\n",
|
67 |
+
" for file in files:\n",
|
68 |
+
" file_path = os.path.join(root, file)\n",
|
69 |
+
"\n",
|
70 |
+
" if file.endswith(\".txt\"):\n",
|
71 |
+
" continue\n",
|
72 |
+
" if file.endswith((\".safetensors\", \".pt\")) or root == image_dir: # fix for image counter\n",
|
73 |
+
" deleted_files += 1\n",
|
74 |
+
"\n",
|
75 |
+
" os.remove(file_path)\n",
|
76 |
+
" return deleted_files\n",
|
77 |
+
"\n",
|
78 |
+
"def update_memory_info():\n",
|
79 |
+
" disk_space = psutil.disk_usage(os.getcwd())\n",
|
80 |
+
" total = disk_space.total / (1024 ** 3)\n",
|
81 |
+
" used = disk_space.used / (1024 ** 3)\n",
|
82 |
+
" free = disk_space.free / (1024 ** 3)\n",
|
83 |
+
"\n",
|
84 |
+
" storage_info.value = f'''\n",
|
85 |
+
" <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",
|
86 |
+
" '''\n",
|
87 |
+
"\n",
|
88 |
+
"def on_execute_button_press(button):\n",
|
89 |
+
" selected_cleaners = auto_cleaner_widget.value\n",
|
90 |
+
" deleted_files_dict = {}\n",
|
91 |
+
"\n",
|
92 |
+
" for option in selected_cleaners:\n",
|
93 |
+
" if option in directories:\n",
|
94 |
+
" deleted_files_dict[option] = clean_directory(directories[option])\n",
|
95 |
+
"\n",
|
96 |
+
" output.clear_output()\n",
|
97 |
+
"\n",
|
98 |
+
" with output:\n",
|
99 |
+
" for message in generate_messages(deleted_files_dict):\n",
|
100 |
+
" message_widget = HTML(f'<p class=\"output_message_AC\">{message}</p>')\n",
|
101 |
+
" display(message_widget)\n",
|
102 |
+
"\n",
|
103 |
+
" update_memory_info()\n",
|
104 |
+
"\n",
|
105 |
+
"def on_clear_button_press(button):\n",
|
106 |
+
" container.add_class(\"hide\")\n",
|
107 |
+
" time.sleep(0.5)\n",
|
108 |
+
" widgets.Widget.close_all()\n",
|
109 |
+
"\n",
|
110 |
+
"def generate_messages(deleted_files_dict):\n",
|
111 |
+
" messages = []\n",
|
112 |
+
" word_variants = {\n",
|
113 |
+
" \"Images\": \"Images\",\n",
|
114 |
+
" \"Models\": \"Models\",\n",
|
115 |
+
" \"Vae\": \"Vae\",\n",
|
116 |
+
" \"LoRa\": \"LoRa\",\n",
|
117 |
+
" \"ControlNet Models\": \"ControlNet Models\"\n",
|
118 |
+
" }\n",
|
119 |
+
" for key, value in deleted_files_dict.items():\n",
|
120 |
+
" object_word = word_variants.get(key)\n",
|
121 |
+
" messages.append(f\"Deleted {value} {object_word}\")\n",
|
122 |
+
" return messages\n",
|
123 |
+
"# ================ AutoCleaner function ================\n",
|
124 |
+
"\n",
|
125 |
+
"\n",
|
126 |
+
"# --- storage memory ---\n",
|
127 |
+
"import psutil\n",
|
128 |
+
"disk_space = psutil.disk_usage(os.getcwd())\n",
|
129 |
+
"total = disk_space.total / (1024 ** 3)\n",
|
130 |
+
"used = disk_space.used / (1024 ** 3)\n",
|
131 |
+
"free = disk_space.free / (1024 ** 3)\n",
|
132 |
+
"\n",
|
133 |
+
"\n",
|
134 |
+
"# UI Code\n",
|
135 |
+
"AutoCleaner_options = AutoCleaner_options = list(directories.keys())\n",
|
136 |
+
"instruction_label = widgets.HTML('''\n",
|
137 |
+
"<span class=\"instruction_AC\">Use <span style=\"color: #B2B2B2;\">ctrl</span> or <span style=\"color: #B2B2B2;\">shift</span> for multiple selections.</span>\n",
|
138 |
+
"''')\n",
|
139 |
+
"auto_cleaner_widget = widgets.SelectMultiple(options=AutoCleaner_options, layout=widgets.Layout(width='auto')).add_class(\"custom-select-multiple_AC\")\n",
|
140 |
+
"output = widgets.Output().add_class(\"output_AC\")\n",
|
141 |
+
"# ---\n",
|
142 |
+
"execute_button = Button(description='Execute Cleaning').add_class(\"button_execute_AC\").add_class(\"button_AC\")\n",
|
143 |
+
"execute_button.on_click(on_execute_button_press)\n",
|
144 |
+
"clear_button = Button(description='Hide Widget').add_class(\"button_clear_AC\").add_class(\"button_AC\")\n",
|
145 |
+
"clear_button.on_click(on_clear_button_press)\n",
|
146 |
+
"# ---\n",
|
147 |
+
"storage_info = widgets.HTML(f'''\n",
|
148 |
+
"<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",
|
149 |
+
"''')\n",
|
150 |
+
"# ---\n",
|
151 |
+
"buttons = widgets.HBox([execute_button, clear_button])\n",
|
152 |
+
"lower_information_panel = widgets.HBox([buttons, storage_info]).add_class(\"lower_information_panel_AC\")\n",
|
153 |
+
"\n",
|
154 |
+
"container = VBox([instruction_label, widgets.HTML('<hr>'), auto_cleaner_widget, output, widgets.HTML('<hr>'), lower_information_panel]).add_class(\"container_AC\")\n",
|
155 |
+
"\n",
|
156 |
+
"display(container)"
|
157 |
+
],
|
158 |
+
"metadata": {
|
159 |
+
"id": "I22dFg7F2j3G"
|
160 |
+
},
|
161 |
+
"execution_count": null,
|
162 |
+
"outputs": []
|
163 |
+
}
|
164 |
+
]
|
165 |
}
|
files_cells/notebooks/en/downloading_en.ipynb
CHANGED
@@ -1,641 +1,696 @@
|
|
1 |
-
{
|
2 |
-
"cells": [
|
3 |
-
{
|
4 |
-
"cell_type": "code",
|
5 |
-
"execution_count": null,
|
6 |
-
"metadata": {
|
7 |
-
"id": "2lJmbqrs3Mu8"
|
8 |
-
},
|
9 |
-
"outputs": [],
|
10 |
-
"source": [
|
11 |
-
"##~ DOWNLOADING CODE | BY: ANXETY ~##\n",
|
12 |
-
"\n",
|
13 |
-
"import os\n",
|
14 |
-
"import re\n",
|
15 |
-
"import time\n",
|
16 |
-
"import json\n",
|
17 |
-
"import shutil\n",
|
18 |
-
"import zipfile\n",
|
19 |
-
"import requests\n",
|
20 |
-
"import subprocess\n",
|
21 |
-
"from datetime import timedelta\n",
|
22 |
-
"from subprocess import getoutput\n",
|
23 |
-
"from IPython.utils import capture\n",
|
24 |
-
"from IPython.display import clear_output\n",
|
25 |
-
"from urllib.parse import urlparse, parse_qs\n",
|
26 |
-
"\n",
|
27 |
-
"\n",
|
28 |
-
"# ================= DETECT ENV =================\n",
|
29 |
-
"def detect_environment():\n",
|
30 |
-
" free_plan = (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024 ** 3) <= 20)\n",
|
31 |
-
" environments = {\n",
|
32 |
-
" 'COLAB_GPU': ('Google Colab', \"/root\" if free_plan else \"/content\"),\n",
|
33 |
-
" 'KAGGLE_URL_BASE': ('Kaggle', \"/kaggle/working/content\")\n",
|
34 |
-
" }\n",
|
35 |
-
" for env_var, (environment, path) in environments.items():\n",
|
36 |
-
" if env_var in os.environ:\n",
|
37 |
-
" return environment, path, free_plan\n",
|
38 |
-
"\n",
|
39 |
-
"env, root_path, free_plan = detect_environment()\n",
|
40 |
-
"webui_path = f\"{root_path}/sdw\"\n",
|
41 |
-
"\n",
|
42 |
-
"\n",
|
43 |
-
"# ================ LIBRARIES V2 ================\n",
|
44 |
-
"flag_file = f\"{root_path}/libraries_installed.txt\"\n",
|
45 |
-
"\n",
|
46 |
-
"if not os.path.exists(flag_file):\n",
|
47 |
-
" print(\"💿 Installing the libraries, it's going to take a while:\\n\")\n",
|
48 |
-
"\n",
|
49 |
-
" install_lib = {\n",
|
50 |
-
" \"aria2\": \"apt -y install aria2\",\n",
|
51 |
-
" \"localtunnel\": \"npm install -g localtunnel\",\n",
|
52 |
-
" \"insightface\": \"pip install insightface\"\n",
|
53 |
-
" }\n",
|
54 |
-
"\n",
|
55 |
-
" additional_libs = {\n",
|
56 |
-
" \"Google Colab\": {\n",
|
57 |
-
" \"xformers\": \"pip install xformers==0.0.26.post1 --no-deps\"\n",
|
58 |
-
" },\n",
|
59 |
-
" \"Kaggle\": {\n",
|
60 |
-
" \"xformers\": \"pip install xformers==0.0.26.post1\",\n",
|
61 |
-
" # \"torch\": \"pip install torch==2.1.2+cu121 torchvision==0.16.2+cu121 torchaudio==2.1.2 --extra-index-url https://download.pytorch.org/whl/cu121\",\n",
|
62 |
-
" \"aiohttp\": \"pip install trash-cli && trash-put /opt/conda/lib/python3.10/site-packages/aiohttp*\" # fix install req\n",
|
63 |
-
" }\n",
|
64 |
-
" }\n",
|
65 |
-
"\n",
|
66 |
-
" if env in additional_libs:\n",
|
67 |
-
" install_lib.update(additional_libs[env])\n",
|
68 |
-
"\n",
|
69 |
-
" # Loop through libraries\n",
|
70 |
-
" for index, (package, install_cmd) in enumerate(install_lib.items(), start=1):\n",
|
71 |
-
" print(f\"\\r[{index}/{len(install_lib)}] \\033[32m>>\\033[0m Installing \\033[33m{package}\\033[0m...\" + \" \"*35, end='')\n",
|
72 |
-
" subprocess.run(install_cmd, shell=True, capture_output=True)\n",
|
73 |
-
"\n",
|
74 |
-
" # Additional specific packages\n",
|
75 |
-
" with capture.capture_output() as cap:\n",
|
76 |
-
" !curl -s -OL https://github.com/DEX-1101/sd-webui-notebook/raw/main/res/new_tunnel --output-dir {root_path}\n",
|
77 |
-
" !curl -s -Lo /usr/bin/cl https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 && chmod +x /usr/bin/cl\n",
|
78 |
-
" !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",
|
79 |
-
" del cap\n",
|
80 |
-
"\n",
|
81 |
-
" clear_output()\n",
|
82 |
-
"\n",
|
83 |
-
" # Save file install lib\n",
|
84 |
-
" with open(flag_file, \"w\") as f:\n",
|
85 |
-
" f.write(\">W<'\")\n",
|
86 |
-
"\n",
|
87 |
-
" print(\"🍪 Libraries are installed!\" + \" \"*35)\n",
|
88 |
-
" time.sleep(2)\n",
|
89 |
-
" clear_output()\n",
|
90 |
-
"\n",
|
91 |
-
"\n",
|
92 |
-
"# ================= loading settings V4 =================\n",
|
93 |
-
"def load_settings(path):\n",
|
94 |
-
" if os.path.exists(path):\n",
|
95 |
-
" with open(path, 'r') as file:\n",
|
96 |
-
" return json.load(file)\n",
|
97 |
-
" return {}\n",
|
98 |
-
"\n",
|
99 |
-
"settings = load_settings(f'{root_path}/settings.json')\n",
|
100 |
-
"\n",
|
101 |
-
"VARIABLES = [\n",
|
102 |
-
" 'model', 'model_num', 'inpainting_model',\n",
|
103 |
-
" 'vae', 'vae_num', 'latest_webui', 'latest_exstensions',\n",
|
104 |
-
" 'change_webui', 'detailed_download', 'controlnet',\n",
|
105 |
-
" 'controlnet_num', 'commit_hash', 'huggingface_token',\n",
|
106 |
-
" 'ngrok_token', 'zrok_token', 'commandline_arguments',\n",
|
107 |
-
" 'Model_url', 'Vae_url', 'LoRA_url', 'Embedding_url',\n",
|
108 |
-
" 'Extensions_url', 'custom_file_urls'\n",
|
109 |
-
"]\n",
|
110 |
-
"\n",
|
111 |
-
"locals().update({key: settings.get(key) for key in VARIABLES})\n",
|
112 |
-
"\n",
|
113 |
-
"\n",
|
114 |
-
"# ================= OTHER =================\n",
|
115 |
-
"try:\n",
|
116 |
-
" start_colab\n",
|
117 |
-
"except:\n",
|
118 |
-
" start_colab = int(time.time())-5\n",
|
119 |
-
"\n",
|
120 |
-
"# CONFIG DIR\n",
|
121 |
-
"models_dir = f\"{webui_path}/models/Stable-diffusion\"\n",
|
122 |
-
"vaes_dir = f\"{webui_path}/models/VAE\"\n",
|
123 |
-
"embeddings_dir = f\"{webui_path}/embeddings\"\n",
|
124 |
-
"loras_dir = f\"{webui_path}/models/Lora\"\n",
|
125 |
-
"extensions_dir = f\"{webui_path}/extensions\"\n",
|
126 |
-
"control_dir = f\"{webui_path}/models/ControlNet\"\n",
|
127 |
-
"adetailer_dir = f\"{webui_path}/models/adetailer\"\n",
|
128 |
-
"\n",
|
129 |
-
"\n",
|
130 |
-
"# ================= MAIN CODE =================\n",
|
131 |
-
"if not os.path.exists(webui_path):\n",
|
132 |
-
" start_install = int(time.time())\n",
|
133 |
-
" print(\"⌚ Unpacking Stable Diffusion...\" if change_webui != 'Forge' else \"⌚ Unpacking Stable Diffusion (Forge)...\", end='')\n",
|
134 |
-
" with capture.capture_output() as cap:\n",
|
135 |
-
" aria2_command = \"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M\"\n",
|
136 |
-
" url = \"https://huggingface.co/NagisaNao/fast_repo/resolve/main/FULL_REPO.zip\" if change_webui != 'Forge' else \"https://huggingface.co/NagisaNao/fast_repo/resolve/main/FULL_REPO_forge.zip\"\n",
|
137 |
-
" !{aria2_command} {url} -o repo.zip\n",
|
138 |
-
"\n",
|
139 |
-
" !unzip -q -o repo.zip -d {webui_path}\n",
|
140 |
-
" !rm -rf repo.zip\n",
|
141 |
-
"\n",
|
142 |
-
" %cd {root_path}\n",
|
143 |
-
" os.environ[\"SAFETENSORS_FAST_GPU\"]='1'\n",
|
144 |
-
" os.environ[\"CUDA_MODULE_LOADING\"]=\"LAZY\"\n",
|
145 |
-
" os.environ[\"TF_CPP_MIN_LOG_LEVEL\"] = \"3\"\n",
|
146 |
-
" os.environ[\"PYTHONWARNINGS\"] = \"ignore\"\n",
|
147 |
-
"\n",
|
148 |
-
" !echo -n {start_colab} > {webui_path}/static/colabTimer.txt\n",
|
149 |
-
" del cap\n",
|
150 |
-
" install_time = timedelta(seconds=time.time()-start_install)\n",
|
151 |
-
" 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",
|
152 |
-
"else:\n",
|
153 |
-
" print(\"🚀 All unpacked... Skip. ⚡\")\n",
|
154 |
-
" start_colab = float(open(f'{webui_path}/static/colabTimer.txt', 'r').read())\n",
|
155 |
-
" time_since_start = str(timedelta(seconds=time.time()-start_colab)).split('.')[0]\n",
|
156 |
-
" print(f\"⌚️ You have been conducting this session for - \\033[33m{time_since_start}\\033[0m\")\n",
|
157 |
-
"\n",
|
158 |
-
"\n",
|
159 |
-
"## Changes extensions and WebUi\n",
|
160 |
-
"if latest_webui or latest_exstensions:\n",
|
161 |
-
" action = \"Updating WebUI and Extensions\" if latest_webui and latest_exstensions else (\"WebUI Update\" if latest_webui else \"Update Extensions\")\n",
|
162 |
-
" print(f\"⌚️ {action}...\", end='', flush=True)\n",
|
163 |
-
" with capture.capture_output() as cap:\n",
|
164 |
-
" !git config --global user.email \"[email protected]\"\n",
|
165 |
-
" !git config --global user.name \"Your Name\"\n",
|
166 |
-
"\n",
|
167 |
-
" ## Update Webui\n",
|
168 |
-
" if latest_webui:\n",
|
169 |
-
" %cd {webui_path}\n",
|
170 |
-
" !git restore .\n",
|
171 |
-
" !git pull -X theirs --rebase --autostash\n",
|
172 |
-
"\n",
|
173 |
-
" ## Update extensions\n",
|
174 |
-
" if latest_exstensions:\n",
|
175 |
-
" !{'for dir in ' + webui_path + '/extensions/*/; do cd \\\"$dir\\\" && git reset --hard && git pull; done'}\n",
|
176 |
-
" del cap\n",
|
177 |
-
" print(f\"\\r✨ {action} Completed!\")\n",
|
178 |
-
"\n",
|
179 |
-
"\n",
|
180 |
-
"# === FIXING EXTENSIONS ===\n",
|
181 |
-
"anxety_repos = \"https://huggingface.co/NagisaNao/fast_repo/resolve/main\"\n",
|
182 |
-
"\n",
|
183 |
-
"with capture.capture_output() as cap:\n",
|
184 |
-
" # --- Umi-Wildcard ---\n",
|
185 |
-
" !sed -i '521s/open=\\(False\\|True\\)/open=False/' {webui_path}/extensions/Umi-AI-Wildcards/scripts/wildcard_recursive.py # Closed accordion by default\n",
|
186 |
-
"\n",
|
187 |
-
" # --- Encrypt-Image ---\n",
|
188 |
-
" !sed -i '9,37d' {webui_path}/extensions/Encrypt-Image/javascript/encrypt_images_info.js # Removes the weird text in webui\n",
|
189 |
-
"\n",
|
190 |
-
" # --- Additional-Networks ---\n",
|
191 |
-
" !wget -O {webui_path}/extensions/additional-networks/scripts/metadata_editor.py {anxety_repos}/extensions/Additional-Networks/fix/metadata_editor.py # Fixing an error due to old style\n",
|
192 |
-
"del cap\n",
|
193 |
-
"\n",
|
194 |
-
"\n",
|
195 |
-
"## Version switching\n",
|
196 |
-
"if commit_hash:\n",
|
197 |
-
" print('⏳ Time machine activation...', end=\"\", flush=True)\n",
|
198 |
-
" with capture.capture_output() as cap:\n",
|
199 |
-
" %cd {webui_path}\n",
|
200 |
-
" !git config --global user.email \"[email protected]\"\n",
|
201 |
-
" !git config --global user.name \"Your Name\"\n",
|
202 |
-
" !git reset --hard {commit_hash}\n",
|
203 |
-
" del cap\n",
|
204 |
-
" print(f\"\\r⌛️ The time machine has been activated! Current commit: \\033[34m{commit_hash}\\033[0m\")\n",
|
205 |
-
"\n",
|
206 |
-
"\n",
|
207 |
-
"## Downloading model and stuff | oh~ Hey! If you're freaked out by that code too, don't worry, me too!\n",
|
208 |
-
"print(\"📦 Downloading models and stuff...\", end='')\n",
|
209 |
-
"model_list = {\n",
|
210 |
-
" \"1.Anime (by XpucT) + INP\": [\n",
|
211 |
-
" {\"url\": \"https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2.safetensors\", \"name\": \"
|
212 |
-
" {\"url\": \"https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2-inpainting.safetensors\", \"name\": \"
|
213 |
-
" ],\n",
|
214 |
-
" \"2.BluMix [Anime] [V7] + INP\": [\n",
|
215 |
-
" {\"url\": \"https://civitai.com/api/download/models/361779\", \"name\": \"
|
216 |
-
" {\"url\": \"https://civitai.com/api/download/models/363850\", \"name\": \"
|
217 |
-
" ],\n",
|
218 |
-
" \"3.Cetus-Mix [Anime] [V4] + INP\": [\n",
|
219 |
-
" {\"url\": \"https://civitai.com/api/download/models/130298\", \"name\": \"CetusMix_V4.safetensors\"},\n",
|
220 |
-
" {\"url\": \"https://civitai.com/api/download/models/139882\", \"name\": \"CetusMix_V4-inpainting.safetensors\"}\n",
|
221 |
-
" ],\n",
|
222 |
-
" \"4.Counterfeit [Anime] [V3] + INP\": [\n",
|
223 |
-
" {\"url\": \"https://
|
224 |
-
" {\"url\": \"https://civitai.com/api/download/models/137911\", \"name\": \"Counterfeit_V3-inpainting.safetensors\"}\n",
|
225 |
-
" ],\n",
|
226 |
-
" \"5.CuteColor [Anime] [V3]\": [\n",
|
227 |
-
" {\"url\": \"https://civitai.com/api/download/models/138754\", \"name\": \"CuteColor_V3.safetensors\"}\n",
|
228 |
-
" ],\n",
|
229 |
-
" \"6.Dark-Sushi-Mix [Anime]\": [\n",
|
230 |
-
" {\"url\": \"https://civitai.com/api/download/models/101640\", \"name\": \"DarkSushiMix_2_5D.safetensors\"},\n",
|
231 |
-
" {\"url\": \"https://civitai.com/api/download/models/56071\", \"name\": \"DarkSushiMix_colorful.safetensors\"}\n",
|
232 |
-
" ],\n",
|
233 |
-
" \"7.Deliberate [Realism] [V6] + INP\": [\n",
|
234 |
-
" {\"url\": \"https://huggingface.co/XpucT/Deliberate/resolve/main/Deliberate_v6.safetensors\", \"name\": \"
|
235 |
-
" {\"url\": \"https://huggingface.co/XpucT/Deliberate/resolve/main/Deliberate_v6-inpainting.safetensors\", \"name\": \"
|
236 |
-
" ],\n",
|
237 |
-
" \"8.Meina-Mix [Anime] [V11] + INP\": [\n",
|
238 |
-
" {\"url\": \"https://civitai.com/api/download/models/119057\", \"name\": \"MeinaMix_V11.safetensors\"},\n",
|
239 |
-
" {\"url\": \"https://civitai.com/api/download/models/120702\", \"name\": \"MeinaMix_V11-inpainting.safetensors\"}\n",
|
240 |
-
" ],\n",
|
241 |
-
" \"9.Mix-Pro [Anime] [V4] + INP\": [\n",
|
242 |
-
" {\"url\": \"https://civitai.com/api/download/models/125668\", \"name\": \"MixPro_V4.safetensors\"},\n",
|
243 |
-
" {\"url\": \"https://civitai.com/api/download/models/139878\", \"name\": \"MixPro_V4-inpainting.safetensors\"}\n",
|
244 |
-
" ]\n",
|
245 |
-
"}\n",
|
246 |
-
"\n",
|
247 |
-
"vae_list = {\n",
|
248 |
-
" \"1.Anime.vae\": [{\"url\": \"https://civitai.com/api/download/models/311162\", \"name\": \"vae-ft-mse-840000-ema-pruned.vae.safetensors\"}],\n",
|
249 |
-
" \"2.Anything.vae\": [{\"url\": \"https://
|
250 |
-
" \"3.Blessed2.vae\": [{\"url\": \"https://huggingface.co/NoCrypt/
|
251 |
-
" \"4.ClearVae.vae\": [{\"url\": \"https://civitai.com/api/download/models/88156\", \"name\": \"ClearVae_23.vae.safetensors\"}],\n",
|
252 |
-
" \"5.WD.vae\": [{\"url\": \"https://huggingface.co/NoCrypt/resources/resolve/main/VAE/wd.vae.safetensors\", \"name\": \"WD.vae.safetensors\"}]\n",
|
253 |
-
"}\n",
|
254 |
-
"\n",
|
255 |
-
"controlnet_list = {\n",
|
256 |
-
" \"1.canny\": [\n",
|
257 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny_fp16.safetensors\", \"name\": \"control_v11p_sd15_canny_fp16.safetensors\"},\n",
|
258 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_canny_fp16.yaml\", \"name\": \"control_v11p_sd15_canny_fp16.yaml\"}\n",
|
259 |
-
" ],\n",
|
260 |
-
" \"2.openpose\": [\n",
|
261 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose_fp16.safetensors\", \"name\": \"control_v11p_sd15_openpose_fp16.safetensors\"},\n",
|
262 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_openpose_fp16.yaml\", \"name\": \"control_v11p_sd15_openpose_fp16.yaml\"}\n",
|
263 |
-
" ],\n",
|
264 |
-
" \"3.depth\": [\n",
|
265 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth_fp16.safetensors\", \"name\": \"control_v11f1p_sd15_depth_fp16.safetensors\"},\n",
|
266 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1p_sd15_depth_fp16.yaml\", \"name\": \"control_v11f1p_sd15_depth_fp16.yaml\"},\n",
|
267 |
-
" {\"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",
|
268 |
-
" ],\n",
|
269 |
-
" \"4.normal_map\": [\n",
|
270 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_normalbae_fp16.safetensors\", \"name\": \"control_v11p_sd15_normalbae_fp16.safetensors\"},\n",
|
271 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_normalbae_fp16.yaml\", \"name\": \"control_v11p_sd15_normalbae_fp16.yaml\"}\n",
|
272 |
-
" ],\n",
|
273 |
-
" \"5.mlsd\": [\n",
|
274 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_mlsd_fp16.safetensors\", \"name\": \"control_v11p_sd15_mlsd_fp16.safetensors\"},\n",
|
275 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_mlsd_fp16.yaml\", \"name\": \"control_v11p_sd15_mlsd_fp16.yaml\"}\n",
|
276 |
-
" ],\n",
|
277 |
-
" \"6.lineart\": [\n",
|
278 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart_fp16.safetensors\", \"name\": \"control_v11p_sd15_lineart_fp16.safetensors\"},\n",
|
279 |
-
" {\"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",
|
280 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_lineart_fp16.yaml\", \"name\": \"control_v11p_sd15_lineart_fp16.yaml\"},\n",
|
281 |
-
" {\"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",
|
282 |
-
" ],\n",
|
283 |
-
" \"7.soft_edge\": [\n",
|
284 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge_fp16.safetensors\", \"name\": \"control_v11p_sd15_softedge_fp16.safetensors\"},\n",
|
285 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_softedge_fp16.yaml\", \"name\": \"control_v11p_sd15_softedge_fp16.yaml\"}\n",
|
286 |
-
" ],\n",
|
287 |
-
" \"8.scribble\": [\n",
|
288 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble_fp16.safetensors\", \"name\": \"control_v11p_sd15_scribble_fp16.safetensors\"},\n",
|
289 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_scribble_fp16.yaml\", \"name\": \"control_v11p_sd15_scribble_fp16.yaml\"}\n",
|
290 |
-
" ],\n",
|
291 |
-
" \"9.segmentation\": [\n",
|
292 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg_fp16.safetensors\", \"name\": \"control_v11p_sd15_seg_fp16.safetensors\"},\n",
|
293 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_seg_fp16.yaml\", \"name\": \"control_v11p_sd15_seg_fp16.yaml\"}\n",
|
294 |
-
" ],\n",
|
295 |
-
" \"10.shuffle\": [\n",
|
296 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle_fp16.safetensors\", \"name\": \"control_v11e_sd15_shuffle_fp16.safetensors\"},\n",
|
297 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_shuffle_fp16.yaml\", \"name\": \"control_v11e_sd15_shuffle_fp16.yaml\"}\n",
|
298 |
-
" ],\n",
|
299 |
-
" \"11.tile\": [\n",
|
300 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile_fp16.safetensors\", \"name\": \"control_v11f1e_sd15_tile_fp16.safetensors\"},\n",
|
301 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1e_sd15_tile_fp16.yaml\", \"name\": \"control_v11f1e_sd15_tile_fp16.yaml\"}\n",
|
302 |
-
" ],\n",
|
303 |
-
" \"12.inpaint\": [\n",
|
304 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_inpaint_fp16.safetensors\", \"name\": \"control_v11p_sd15_inpaint_fp16.safetensors\"},\n",
|
305 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_inpaint_fp16.yaml\", \"name\": \"control_v11p_sd15_inpaint_fp16.yaml\"}\n",
|
306 |
-
" ],\n",
|
307 |
-
" \"13.instruct_p2p\": [\n",
|
308 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p_fp16.safetensors\", \"name\": \"control_v11e_sd15_ip2p_fp16.safetensors\"},\n",
|
309 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_ip2p_fp16.yaml\", \"name\": \"control_v11e_sd15_ip2p_fp16.yaml\"}\n",
|
310 |
-
" ]\n",
|
311 |
-
"}\n",
|
312 |
-
"\n",
|
313 |
-
"url = \"\"\n",
|
314 |
-
"prefixes = {\n",
|
315 |
-
" \"model\": models_dir,\n",
|
316 |
-
" \"vae\": vaes_dir,\n",
|
317 |
-
" \"lora\": loras_dir,\n",
|
318 |
-
" \"embed\": embeddings_dir,\n",
|
319 |
-
" \"extension\": extensions_dir,\n",
|
320 |
-
" \"control\": control_dir,\n",
|
321 |
-
" \"adetailer\": adetailer_dir
|
322 |
-
"
|
323 |
-
"\n",
|
324 |
-
"
|
325 |
-
"
|
326 |
-
"
|
327 |
-
"\n",
|
328 |
-
"
|
329 |
-
"
|
330 |
-
"\n",
|
331 |
-
"
|
332 |
-
"\n",
|
333 |
-
"
|
334 |
-
"\n",
|
335 |
-
"
|
336 |
-
"
|
337 |
-
"
|
338 |
-
"
|
339 |
-
"
|
340 |
-
"\n",
|
341 |
-
"
|
342 |
-
"
|
343 |
-
" info =
|
344 |
-
"\n",
|
345 |
-
"
|
346 |
-
" print(f\"\\
|
347 |
-
" print(f\"\\033[
|
348 |
-
" print(f\"\\033[
|
349 |
-
"\n",
|
350 |
-
"
|
351 |
-
"\n",
|
352 |
-
"
|
353 |
-
"
|
354 |
-
"
|
355 |
-
"
|
356 |
-
"
|
357 |
-
"
|
358 |
-
"
|
359 |
-
" return
|
360 |
-
"
|
361 |
-
"
|
362 |
-
"
|
363 |
-
"\n",
|
364 |
-
"
|
365 |
-
"
|
366 |
-
"
|
367 |
-
"
|
368 |
-
"
|
369 |
-
"
|
370 |
-
"
|
371 |
-
"
|
372 |
-
"\n",
|
373 |
-
"
|
374 |
-
"
|
375 |
-
" if
|
376 |
-
"
|
377 |
-
"
|
378 |
-
"
|
379 |
-
"\n",
|
380 |
-
"
|
381 |
-
"\n",
|
382 |
-
"
|
383 |
-
"
|
384 |
-
"
|
385 |
-
"
|
386 |
-
"
|
387 |
-
"\n",
|
388 |
-
"
|
389 |
-
"\n",
|
390 |
-
"
|
391 |
-
"
|
392 |
-
"
|
393 |
-
"
|
394 |
-
"\n",
|
395 |
-
"
|
396 |
-
"
|
397 |
-
" if
|
398 |
-
"
|
399 |
-
"\n",
|
400 |
-
"
|
401 |
-
"
|
402 |
-
" if
|
403 |
-
"
|
404 |
-
"
|
405 |
-
"
|
406 |
-
"
|
407 |
-
"
|
408 |
-
"
|
409 |
-
"\n",
|
410 |
-
"
|
411 |
-
"
|
412 |
-
"
|
413 |
-
"
|
414 |
-
"
|
415 |
-
"
|
416 |
-
"
|
417 |
-
"
|
418 |
-
"\n",
|
419 |
-
"
|
420 |
-
"
|
421 |
-
"
|
422 |
-
"
|
423 |
-
"\n",
|
424 |
-
"
|
425 |
-
"
|
426 |
-
"
|
427 |
-
"
|
428 |
-
"
|
429 |
-
"
|
430 |
-
"
|
431 |
-
"
|
432 |
-
"
|
433 |
-
"
|
434 |
-
"
|
435 |
-
"
|
436 |
-
"
|
437 |
-
"\n",
|
438 |
-
"
|
439 |
-
"
|
440 |
-
"
|
441 |
-
"
|
442 |
-
"
|
443 |
-
"
|
444 |
-
"
|
445 |
-
"
|
446 |
-
"\n",
|
447 |
-
"
|
448 |
-
"
|
449 |
-
"
|
450 |
-
"
|
451 |
-
"
|
452 |
-
"
|
453 |
-
"
|
454 |
-
"\n",
|
455 |
-
"
|
456 |
-
"
|
457 |
-
"
|
458 |
-
"
|
459 |
-
"
|
460 |
-
"
|
461 |
-
"
|
462 |
-
"\n",
|
463 |
-
"
|
464 |
-
"
|
465 |
-
"
|
466 |
-
"
|
467 |
-
"
|
468 |
-
"
|
469 |
-
"
|
470 |
-
"
|
471 |
-
"
|
472 |
-
"\n",
|
473 |
-
"
|
474 |
-
"
|
475 |
-
"\n",
|
476 |
-
"
|
477 |
-
"
|
478 |
-
"
|
479 |
-
"
|
480 |
-
"
|
481 |
-
"
|
482 |
-
"
|
483 |
-
"\n",
|
484 |
-
"
|
485 |
-
"
|
486 |
-
"\n",
|
487 |
-
"
|
488 |
-
"\n",
|
489 |
-
"
|
490 |
-
"
|
491 |
-
"
|
492 |
-
"
|
493 |
-
"
|
494 |
-
"
|
495 |
-
"
|
496 |
-
"
|
497 |
-
"
|
498 |
-
"
|
499 |
-
"
|
500 |
-
"\n",
|
501 |
-
"
|
502 |
-
"
|
503 |
-
"
|
504 |
-
"
|
505 |
-
"
|
506 |
-
"
|
507 |
-
"
|
508 |
-
"
|
509 |
-
"
|
510 |
-
"
|
511 |
-
"
|
512 |
-
"
|
513 |
-
"
|
514 |
-
"
|
515 |
-
"
|
516 |
-
"
|
517 |
-
"
|
518 |
-
"\n",
|
519 |
-
"
|
520 |
-
"
|
521 |
-
"
|
522 |
-
"\n",
|
523 |
-
"
|
524 |
-
"
|
525 |
-
"
|
526 |
-
"
|
527 |
-
"
|
528 |
-
"
|
529 |
-
"
|
530 |
-
"
|
531 |
-
"
|
532 |
-
"
|
533 |
-
"
|
534 |
-
"
|
535 |
-
"
|
536 |
-
"
|
537 |
-
"
|
538 |
-
"\n",
|
539 |
-
"
|
540 |
-
"
|
541 |
-
"\n",
|
542 |
-
"
|
543 |
-
"
|
544 |
-
"
|
545 |
-
"
|
546 |
-
"
|
547 |
-
"
|
548 |
-
"
|
549 |
-
"
|
550 |
-
"\n",
|
551 |
-
"
|
552 |
-
"
|
553 |
-
"
|
554 |
-
"
|
555 |
-
"
|
556 |
-
"\n",
|
557 |
-
"
|
558 |
-
"
|
559 |
-
"
|
560 |
-
"\n",
|
561 |
-
"
|
562 |
-
"
|
563 |
-
"
|
564 |
-
"\n",
|
565 |
-
"
|
566 |
-
"
|
567 |
-
"
|
568 |
-
"
|
569 |
-
"
|
570 |
-
"if
|
571 |
-
"
|
572 |
-
"
|
573 |
-
"
|
574 |
-
"
|
575 |
-
"
|
576 |
-
"
|
577 |
-
"\n",
|
578 |
-
"
|
579 |
-
"
|
580 |
-
"
|
581 |
-
"
|
582 |
-
"
|
583 |
-
"
|
584 |
-
"
|
585 |
-
"
|
586 |
-
"url
|
587 |
-
"\n",
|
588 |
-
"
|
589 |
-
"
|
590 |
-
"
|
591 |
-
"
|
592 |
-
"
|
593 |
-
"
|
594 |
-
"
|
595 |
-
"
|
596 |
-
"\n",
|
597 |
-
"
|
598 |
-
"\n",
|
599 |
-
"\n",
|
600 |
-
"
|
601 |
-
"
|
602 |
-
"
|
603 |
-
"
|
604 |
-
"
|
605 |
-
"
|
606 |
-
"
|
607 |
-
"
|
608 |
-
"
|
609 |
-
"
|
610 |
-
"
|
611 |
-
"
|
612 |
-
"
|
613 |
-
"
|
614 |
-
"
|
615 |
-
"
|
616 |
-
"
|
617 |
-
"\n",
|
618 |
-
"\n",
|
619 |
-
"
|
620 |
-
"
|
621 |
-
"
|
622 |
-
"\n",
|
623 |
-
"
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
641 |
}
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": null,
|
6 |
+
"metadata": {
|
7 |
+
"id": "2lJmbqrs3Mu8"
|
8 |
+
},
|
9 |
+
"outputs": [],
|
10 |
+
"source": [
|
11 |
+
"##~ DOWNLOADING CODE | BY: ANXETY ~##\n",
|
12 |
+
"\n",
|
13 |
+
"import os\n",
|
14 |
+
"import re\n",
|
15 |
+
"import time\n",
|
16 |
+
"import json\n",
|
17 |
+
"import shutil\n",
|
18 |
+
"import zipfile\n",
|
19 |
+
"import requests\n",
|
20 |
+
"import subprocess\n",
|
21 |
+
"from datetime import timedelta\n",
|
22 |
+
"from subprocess import getoutput\n",
|
23 |
+
"from IPython.utils import capture\n",
|
24 |
+
"from IPython.display import clear_output\n",
|
25 |
+
"from urllib.parse import urlparse, parse_qs\n",
|
26 |
+
"\n",
|
27 |
+
"\n",
|
28 |
+
"# ================= DETECT ENV =================\n",
|
29 |
+
"def detect_environment():\n",
|
30 |
+
" free_plan = (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024 ** 3) <= 20)\n",
|
31 |
+
" environments = {\n",
|
32 |
+
" 'COLAB_GPU': ('Google Colab', \"/root\" if free_plan else \"/content\"),\n",
|
33 |
+
" 'KAGGLE_URL_BASE': ('Kaggle', \"/kaggle/working/content\")\n",
|
34 |
+
" }\n",
|
35 |
+
" for env_var, (environment, path) in environments.items():\n",
|
36 |
+
" if env_var in os.environ:\n",
|
37 |
+
" return environment, path, free_plan\n",
|
38 |
+
"\n",
|
39 |
+
"env, root_path, free_plan = detect_environment()\n",
|
40 |
+
"webui_path = f\"{root_path}/sdw\"\n",
|
41 |
+
"\n",
|
42 |
+
"\n",
|
43 |
+
"# ================ LIBRARIES V2 ================\n",
|
44 |
+
"flag_file = f\"{root_path}/libraries_installed.txt\"\n",
|
45 |
+
"\n",
|
46 |
+
"if not os.path.exists(flag_file):\n",
|
47 |
+
" print(\"💿 Installing the libraries, it's going to take a while:\\n\")\n",
|
48 |
+
"\n",
|
49 |
+
" install_lib = {\n",
|
50 |
+
" \"aria2\": \"apt -y install aria2\",\n",
|
51 |
+
" \"localtunnel\": \"npm install -g localtunnel\",\n",
|
52 |
+
" \"insightface\": \"pip install insightface\"\n",
|
53 |
+
" }\n",
|
54 |
+
"\n",
|
55 |
+
" additional_libs = {\n",
|
56 |
+
" \"Google Colab\": {\n",
|
57 |
+
" \"xformers\": \"pip install xformers==0.0.26.post1 --no-deps\"\n",
|
58 |
+
" },\n",
|
59 |
+
" \"Kaggle\": {\n",
|
60 |
+
" \"xformers\": \"pip install xformers==0.0.26.post1\",\n",
|
61 |
+
" # \"torch\": \"pip install torch==2.1.2+cu121 torchvision==0.16.2+cu121 torchaudio==2.1.2 --extra-index-url https://download.pytorch.org/whl/cu121\",\n",
|
62 |
+
" \"aiohttp\": \"pip install trash-cli && trash-put /opt/conda/lib/python3.10/site-packages/aiohttp*\" # fix install req\n",
|
63 |
+
" }\n",
|
64 |
+
" }\n",
|
65 |
+
"\n",
|
66 |
+
" if env in additional_libs:\n",
|
67 |
+
" install_lib.update(additional_libs[env])\n",
|
68 |
+
"\n",
|
69 |
+
" # Loop through libraries\n",
|
70 |
+
" for index, (package, install_cmd) in enumerate(install_lib.items(), start=1):\n",
|
71 |
+
" print(f\"\\r[{index}/{len(install_lib)}] \\033[32m>>\\033[0m Installing \\033[33m{package}\\033[0m...\" + \" \"*35, end='')\n",
|
72 |
+
" subprocess.run(install_cmd, shell=True, capture_output=True)\n",
|
73 |
+
"\n",
|
74 |
+
" # Additional specific packages\n",
|
75 |
+
" with capture.capture_output() as cap:\n",
|
76 |
+
" !curl -s -OL https://github.com/DEX-1101/sd-webui-notebook/raw/main/res/new_tunnel --output-dir {root_path}\n",
|
77 |
+
" !curl -s -Lo /usr/bin/cl https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 && chmod +x /usr/bin/cl\n",
|
78 |
+
" !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",
|
79 |
+
" del cap\n",
|
80 |
+
"\n",
|
81 |
+
" clear_output()\n",
|
82 |
+
"\n",
|
83 |
+
" # Save file install lib\n",
|
84 |
+
" with open(flag_file, \"w\") as f:\n",
|
85 |
+
" f.write(\">W<'\")\n",
|
86 |
+
"\n",
|
87 |
+
" print(\"🍪 Libraries are installed!\" + \" \"*35)\n",
|
88 |
+
" time.sleep(2)\n",
|
89 |
+
" clear_output()\n",
|
90 |
+
"\n",
|
91 |
+
"\n",
|
92 |
+
"# ================= loading settings V4 =================\n",
|
93 |
+
"def load_settings(path):\n",
|
94 |
+
" if os.path.exists(path):\n",
|
95 |
+
" with open(path, 'r') as file:\n",
|
96 |
+
" return json.load(file)\n",
|
97 |
+
" return {}\n",
|
98 |
+
"\n",
|
99 |
+
"settings = load_settings(f'{root_path}/settings.json')\n",
|
100 |
+
"\n",
|
101 |
+
"VARIABLES = [\n",
|
102 |
+
" 'model', 'model_num', 'inpainting_model',\n",
|
103 |
+
" 'vae', 'vae_num', 'latest_webui', 'latest_exstensions',\n",
|
104 |
+
" 'change_webui', 'detailed_download', 'controlnet',\n",
|
105 |
+
" 'controlnet_num', 'commit_hash', 'huggingface_token',\n",
|
106 |
+
" 'ngrok_token', 'zrok_token', 'commandline_arguments',\n",
|
107 |
+
" 'Model_url', 'Vae_url', 'LoRA_url', 'Embedding_url',\n",
|
108 |
+
" 'Extensions_url', 'custom_file_urls'\n",
|
109 |
+
"]\n",
|
110 |
+
"\n",
|
111 |
+
"locals().update({key: settings.get(key) for key in VARIABLES})\n",
|
112 |
+
"\n",
|
113 |
+
"\n",
|
114 |
+
"# ================= OTHER =================\n",
|
115 |
+
"try:\n",
|
116 |
+
" start_colab\n",
|
117 |
+
"except:\n",
|
118 |
+
" start_colab = int(time.time())-5\n",
|
119 |
+
"\n",
|
120 |
+
"# CONFIG DIR\n",
|
121 |
+
"models_dir = f\"{webui_path}/models/Stable-diffusion\"\n",
|
122 |
+
"vaes_dir = f\"{webui_path}/models/VAE\"\n",
|
123 |
+
"embeddings_dir = f\"{webui_path}/embeddings\"\n",
|
124 |
+
"loras_dir = f\"{webui_path}/models/Lora\"\n",
|
125 |
+
"extensions_dir = f\"{webui_path}/extensions\"\n",
|
126 |
+
"control_dir = f\"{webui_path}/models/ControlNet\"\n",
|
127 |
+
"adetailer_dir = f\"{webui_path}/models/adetailer\"\n",
|
128 |
+
"\n",
|
129 |
+
"\n",
|
130 |
+
"# ================= MAIN CODE =================\n",
|
131 |
+
"if not os.path.exists(webui_path):\n",
|
132 |
+
" start_install = int(time.time())\n",
|
133 |
+
" print(\"⌚ Unpacking Stable Diffusion...\" if change_webui != 'Forge' else \"⌚ Unpacking Stable Diffusion (Forge)...\", end='')\n",
|
134 |
+
" with capture.capture_output() as cap:\n",
|
135 |
+
" aria2_command = \"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M\"\n",
|
136 |
+
" url = \"https://huggingface.co/NagisaNao/fast_repo/resolve/main/FULL_REPO.zip\" if change_webui != 'Forge' else \"https://huggingface.co/NagisaNao/fast_repo/resolve/main/FULL_REPO_forge.zip\"\n",
|
137 |
+
" !{aria2_command} {url} -o repo.zip\n",
|
138 |
+
"\n",
|
139 |
+
" !unzip -q -o repo.zip -d {webui_path}\n",
|
140 |
+
" !rm -rf repo.zip\n",
|
141 |
+
"\n",
|
142 |
+
" %cd {root_path}\n",
|
143 |
+
" os.environ[\"SAFETENSORS_FAST_GPU\"]='1'\n",
|
144 |
+
" os.environ[\"CUDA_MODULE_LOADING\"]=\"LAZY\"\n",
|
145 |
+
" os.environ[\"TF_CPP_MIN_LOG_LEVEL\"] = \"3\"\n",
|
146 |
+
" os.environ[\"PYTHONWARNINGS\"] = \"ignore\"\n",
|
147 |
+
"\n",
|
148 |
+
" !echo -n {start_colab} > {webui_path}/static/colabTimer.txt\n",
|
149 |
+
" del cap\n",
|
150 |
+
" install_time = timedelta(seconds=time.time()-start_install)\n",
|
151 |
+
" 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",
|
152 |
+
"else:\n",
|
153 |
+
" print(\"🚀 All unpacked... Skip. ⚡\")\n",
|
154 |
+
" start_colab = float(open(f'{webui_path}/static/colabTimer.txt', 'r').read())\n",
|
155 |
+
" time_since_start = str(timedelta(seconds=time.time()-start_colab)).split('.')[0]\n",
|
156 |
+
" print(f\"⌚️ You have been conducting this session for - \\033[33m{time_since_start}\\033[0m\")\n",
|
157 |
+
"\n",
|
158 |
+
"\n",
|
159 |
+
"## Changes extensions and WebUi\n",
|
160 |
+
"if latest_webui or latest_exstensions:\n",
|
161 |
+
" action = \"Updating WebUI and Extensions\" if latest_webui and latest_exstensions else (\"WebUI Update\" if latest_webui else \"Update Extensions\")\n",
|
162 |
+
" print(f\"⌚️ {action}...\", end='', flush=True)\n",
|
163 |
+
" with capture.capture_output() as cap:\n",
|
164 |
+
" !git config --global user.email \"[email protected]\"\n",
|
165 |
+
" !git config --global user.name \"Your Name\"\n",
|
166 |
+
"\n",
|
167 |
+
" ## Update Webui\n",
|
168 |
+
" if latest_webui:\n",
|
169 |
+
" %cd {webui_path}\n",
|
170 |
+
" !git restore .\n",
|
171 |
+
" !git pull -X theirs --rebase --autostash\n",
|
172 |
+
"\n",
|
173 |
+
" ## Update extensions\n",
|
174 |
+
" if latest_exstensions:\n",
|
175 |
+
" !{'for dir in ' + webui_path + '/extensions/*/; do cd \\\"$dir\\\" && git reset --hard && git pull; done'}\n",
|
176 |
+
" del cap\n",
|
177 |
+
" print(f\"\\r✨ {action} Completed!\")\n",
|
178 |
+
"\n",
|
179 |
+
"\n",
|
180 |
+
"# === FIXING EXTENSIONS ===\n",
|
181 |
+
"anxety_repos = \"https://huggingface.co/NagisaNao/fast_repo/resolve/main\"\n",
|
182 |
+
"\n",
|
183 |
+
"with capture.capture_output() as cap:\n",
|
184 |
+
" # --- Umi-Wildcard ---\n",
|
185 |
+
" !sed -i '521s/open=\\(False\\|True\\)/open=False/' {webui_path}/extensions/Umi-AI-Wildcards/scripts/wildcard_recursive.py # Closed accordion by default\n",
|
186 |
+
"\n",
|
187 |
+
" # --- Encrypt-Image ---\n",
|
188 |
+
" !sed -i '9,37d' {webui_path}/extensions/Encrypt-Image/javascript/encrypt_images_info.js # Removes the weird text in webui\n",
|
189 |
+
"\n",
|
190 |
+
" # --- Additional-Networks ---\n",
|
191 |
+
" !wget -O {webui_path}/extensions/additional-networks/scripts/metadata_editor.py {anxety_repos}/extensions/Additional-Networks/fix/metadata_editor.py # Fixing an error due to old style\n",
|
192 |
+
"del cap\n",
|
193 |
+
"\n",
|
194 |
+
"\n",
|
195 |
+
"## Version switching\n",
|
196 |
+
"if commit_hash:\n",
|
197 |
+
" print('⏳ Time machine activation...', end=\"\", flush=True)\n",
|
198 |
+
" with capture.capture_output() as cap:\n",
|
199 |
+
" %cd {webui_path}\n",
|
200 |
+
" !git config --global user.email \"[email protected]\"\n",
|
201 |
+
" !git config --global user.name \"Your Name\"\n",
|
202 |
+
" !git reset --hard {commit_hash}\n",
|
203 |
+
" del cap\n",
|
204 |
+
" print(f\"\\r⌛️ The time machine has been activated! Current commit: \\033[34m{commit_hash}\\033[0m\")\n",
|
205 |
+
"\n",
|
206 |
+
"\n",
|
207 |
+
"## Downloading model and stuff | oh~ Hey! If you're freaked out by that code too, don't worry, me too!\n",
|
208 |
+
"print(\"📦 Downloading models and stuff...\", end='')\n",
|
209 |
+
"model_list = {\n",
|
210 |
+
" \"1.Anime (by XpucT) + INP\": [\n",
|
211 |
+
" {\"url\": \"https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2.safetensors\", \"name\": \"Anime_V2.safetensors\"},\n",
|
212 |
+
" {\"url\": \"https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2-inpainting.safetensors\", \"name\": \"Anime_V2-inpainting.safetensors\"}\n",
|
213 |
+
" ],\n",
|
214 |
+
" \"2.BluMix [Anime] [V7] + INP\": [\n",
|
215 |
+
" {\"url\": \"https://civitai.com/api/download/models/361779\", \"name\": \"BluMix_V7.safetensors\"},\n",
|
216 |
+
" {\"url\": \"https://civitai.com/api/download/models/363850\", \"name\": \"BluMix_V7-inpainting.safetensors\"}\n",
|
217 |
+
" ],\n",
|
218 |
+
" \"3.Cetus-Mix [Anime] [V4] + INP\": [\n",
|
219 |
+
" {\"url\": \"https://civitai.com/api/download/models/130298\", \"name\": \"CetusMix_V4.safetensors\"},\n",
|
220 |
+
" {\"url\": \"https://civitai.com/api/download/models/139882\", \"name\": \"CetusMix_V4-inpainting.safetensors\"}\n",
|
221 |
+
" ],\n",
|
222 |
+
" \"4.Counterfeit [Anime] [V3] + INP\": [\n",
|
223 |
+
" {\"url\": \"https://huggingface.co/gsdf/Counterfeit-V3.0/resolve/main/Counterfeit-V3.0_fix_fp16.safetensors\", \"name\": \"Counterfeit_V3.safetensors\"},\n",
|
224 |
+
" {\"url\": \"https://civitai.com/api/download/models/137911\", \"name\": \"Counterfeit_V3-inpainting.safetensors\"}\n",
|
225 |
+
" ],\n",
|
226 |
+
" \"5.CuteColor [Anime] [V3]\": [\n",
|
227 |
+
" {\"url\": \"https://civitai.com/api/download/models/138754\", \"name\": \"CuteColor_V3.safetensors\"}\n",
|
228 |
+
" ],\n",
|
229 |
+
" \"6.Dark-Sushi-Mix [Anime]\": [\n",
|
230 |
+
" {\"url\": \"https://civitai.com/api/download/models/101640\", \"name\": \"DarkSushiMix_2_5D.safetensors\"},\n",
|
231 |
+
" {\"url\": \"https://civitai.com/api/download/models/56071\", \"name\": \"DarkSushiMix_colorful.safetensors\"}\n",
|
232 |
+
" ],\n",
|
233 |
+
" \"7.Deliberate [Realism] [V6] + INP\": [\n",
|
234 |
+
" {\"url\": \"https://huggingface.co/XpucT/Deliberate/resolve/main/Deliberate_v6.safetensors\", \"name\": \"Deliberate_V6.safetensors\"},\n",
|
235 |
+
" {\"url\": \"https://huggingface.co/XpucT/Deliberate/resolve/main/Deliberate_v6-inpainting.safetensors\", \"name\": \"Deliberate_V6-inpainting.safetensors\"}\n",
|
236 |
+
" ],\n",
|
237 |
+
" \"8.Meina-Mix [Anime] [V11] + INP\": [\n",
|
238 |
+
" {\"url\": \"https://civitai.com/api/download/models/119057\", \"name\": \"MeinaMix_V11.safetensors\"},\n",
|
239 |
+
" {\"url\": \"https://civitai.com/api/download/models/120702\", \"name\": \"MeinaMix_V11-inpainting.safetensors\"}\n",
|
240 |
+
" ],\n",
|
241 |
+
" \"9.Mix-Pro [Anime] [V4] + INP\": [\n",
|
242 |
+
" {\"url\": \"https://civitai.com/api/download/models/125668\", \"name\": \"MixPro_V4.safetensors\"},\n",
|
243 |
+
" {\"url\": \"https://civitai.com/api/download/models/139878\", \"name\": \"MixPro_V4-inpainting.safetensors\"}\n",
|
244 |
+
" ]\n",
|
245 |
+
"}\n",
|
246 |
+
"\n",
|
247 |
+
"vae_list = {\n",
|
248 |
+
" \"1.Anime.vae\": [{\"url\": \"https://civitai.com/api/download/models/311162\", \"name\": \"vae-ft-mse-840000-ema-pruned.vae.safetensors\"}],\n",
|
249 |
+
" \"2.Anything.vae\": [{\"url\": \"https://huggingface.co/NoCrypt/resources/resolve/main/VAE/any.vae.safetensors\", \"name\": \"Anything.vae.safetensors\"}],\n",
|
250 |
+
" \"3.Blessed2.vae\": [{\"url\": \"https://huggingface.co/NoCrypt/resources/resolve/main/VAE/blessed2.vae.safetensors\", \"name\": \"Blessed2.vae.safetensors\"}],\n",
|
251 |
+
" \"4.ClearVae.vae\": [{\"url\": \"https://civitai.com/api/download/models/88156\", \"name\": \"ClearVae_23.vae.safetensors\"}],\n",
|
252 |
+
" \"5.WD.vae\": [{\"url\": \"https://huggingface.co/NoCrypt/resources/resolve/main/VAE/wd.vae.safetensors\", \"name\": \"WD.vae.safetensors\"}]\n",
|
253 |
+
"}\n",
|
254 |
+
"\n",
|
255 |
+
"controlnet_list = {\n",
|
256 |
+
" \"1.canny\": [\n",
|
257 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny_fp16.safetensors\", \"name\": \"control_v11p_sd15_canny_fp16.safetensors\"},\n",
|
258 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_canny_fp16.yaml\", \"name\": \"control_v11p_sd15_canny_fp16.yaml\"}\n",
|
259 |
+
" ],\n",
|
260 |
+
" \"2.openpose\": [\n",
|
261 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose_fp16.safetensors\", \"name\": \"control_v11p_sd15_openpose_fp16.safetensors\"},\n",
|
262 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_openpose_fp16.yaml\", \"name\": \"control_v11p_sd15_openpose_fp16.yaml\"}\n",
|
263 |
+
" ],\n",
|
264 |
+
" \"3.depth\": [\n",
|
265 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth_fp16.safetensors\", \"name\": \"control_v11f1p_sd15_depth_fp16.safetensors\"},\n",
|
266 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1p_sd15_depth_fp16.yaml\", \"name\": \"control_v11f1p_sd15_depth_fp16.yaml\"},\n",
|
267 |
+
" {\"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",
|
268 |
+
" ],\n",
|
269 |
+
" \"4.normal_map\": [\n",
|
270 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_normalbae_fp16.safetensors\", \"name\": \"control_v11p_sd15_normalbae_fp16.safetensors\"},\n",
|
271 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_normalbae_fp16.yaml\", \"name\": \"control_v11p_sd15_normalbae_fp16.yaml\"}\n",
|
272 |
+
" ],\n",
|
273 |
+
" \"5.mlsd\": [\n",
|
274 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_mlsd_fp16.safetensors\", \"name\": \"control_v11p_sd15_mlsd_fp16.safetensors\"},\n",
|
275 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_mlsd_fp16.yaml\", \"name\": \"control_v11p_sd15_mlsd_fp16.yaml\"}\n",
|
276 |
+
" ],\n",
|
277 |
+
" \"6.lineart\": [\n",
|
278 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart_fp16.safetensors\", \"name\": \"control_v11p_sd15_lineart_fp16.safetensors\"},\n",
|
279 |
+
" {\"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",
|
280 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_lineart_fp16.yaml\", \"name\": \"control_v11p_sd15_lineart_fp16.yaml\"},\n",
|
281 |
+
" {\"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",
|
282 |
+
" ],\n",
|
283 |
+
" \"7.soft_edge\": [\n",
|
284 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge_fp16.safetensors\", \"name\": \"control_v11p_sd15_softedge_fp16.safetensors\"},\n",
|
285 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_softedge_fp16.yaml\", \"name\": \"control_v11p_sd15_softedge_fp16.yaml\"}\n",
|
286 |
+
" ],\n",
|
287 |
+
" \"8.scribble\": [\n",
|
288 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble_fp16.safetensors\", \"name\": \"control_v11p_sd15_scribble_fp16.safetensors\"},\n",
|
289 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_scribble_fp16.yaml\", \"name\": \"control_v11p_sd15_scribble_fp16.yaml\"}\n",
|
290 |
+
" ],\n",
|
291 |
+
" \"9.segmentation\": [\n",
|
292 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg_fp16.safetensors\", \"name\": \"control_v11p_sd15_seg_fp16.safetensors\"},\n",
|
293 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_seg_fp16.yaml\", \"name\": \"control_v11p_sd15_seg_fp16.yaml\"}\n",
|
294 |
+
" ],\n",
|
295 |
+
" \"10.shuffle\": [\n",
|
296 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle_fp16.safetensors\", \"name\": \"control_v11e_sd15_shuffle_fp16.safetensors\"},\n",
|
297 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_shuffle_fp16.yaml\", \"name\": \"control_v11e_sd15_shuffle_fp16.yaml\"}\n",
|
298 |
+
" ],\n",
|
299 |
+
" \"11.tile\": [\n",
|
300 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile_fp16.safetensors\", \"name\": \"control_v11f1e_sd15_tile_fp16.safetensors\"},\n",
|
301 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1e_sd15_tile_fp16.yaml\", \"name\": \"control_v11f1e_sd15_tile_fp16.yaml\"}\n",
|
302 |
+
" ],\n",
|
303 |
+
" \"12.inpaint\": [\n",
|
304 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_inpaint_fp16.safetensors\", \"name\": \"control_v11p_sd15_inpaint_fp16.safetensors\"},\n",
|
305 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_inpaint_fp16.yaml\", \"name\": \"control_v11p_sd15_inpaint_fp16.yaml\"}\n",
|
306 |
+
" ],\n",
|
307 |
+
" \"13.instruct_p2p\": [\n",
|
308 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p_fp16.safetensors\", \"name\": \"control_v11e_sd15_ip2p_fp16.safetensors\"},\n",
|
309 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_ip2p_fp16.yaml\", \"name\": \"control_v11e_sd15_ip2p_fp16.yaml\"}\n",
|
310 |
+
" ]\n",
|
311 |
+
"}\n",
|
312 |
+
"\n",
|
313 |
+
"url = \"\"\n",
|
314 |
+
"prefixes = {\n",
|
315 |
+
" \"model\": models_dir,\n",
|
316 |
+
" \"vae\": vaes_dir,\n",
|
317 |
+
" \"lora\": loras_dir,\n",
|
318 |
+
" \"embed\": embeddings_dir,\n",
|
319 |
+
" \"extension\": extensions_dir,\n",
|
320 |
+
" \"control\": control_dir,\n",
|
321 |
+
" \"adetailer\": adetailer_dir,\n",
|
322 |
+
" \"config\": webui_path\n",
|
323 |
+
"}\n",
|
324 |
+
"\n",
|
325 |
+
"extension_repo = []\n",
|
326 |
+
"directories = [value for key, value in prefixes.items()] # for unpucking zip files\n",
|
327 |
+
"!mkdir -p {\" \".join(directories)}\n",
|
328 |
+
"\n",
|
329 |
+
"hf_token = huggingface_token if huggingface_token else \"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\"\n",
|
330 |
+
"user_header = f\"\\\"Authorization: Bearer {hf_token}\\\"\"\n",
|
331 |
+
"\n",
|
332 |
+
"''' Formatted Info Output '''\n",
|
333 |
+
"\n",
|
334 |
+
"from math import floor\n",
|
335 |
+
"\n",
|
336 |
+
"def center_text(text, terminal_width=45):\n",
|
337 |
+
" text_length = len(text)\n",
|
338 |
+
" left_padding = floor((terminal_width - text_length) / 2)\n",
|
339 |
+
" right_padding = terminal_width - text_length - left_padding\n",
|
340 |
+
" return f\"\\033[1m\\033[36m{' ' * left_padding}{text}{' ' * right_padding}\\033[0m\\033[32m\"\n",
|
341 |
+
"\n",
|
342 |
+
"def format_output(url, dst_dir, file_name):\n",
|
343 |
+
" info = f\"[{file_name.split('.')[0]}]\"\n",
|
344 |
+
" info = center_text(info)\n",
|
345 |
+
"\n",
|
346 |
+
" print(f\"\\n\\033[32m{'---'*20}]{info}[{'---'*20}\")\n",
|
347 |
+
" print(f\"\\033[33mURL: \\033[34m{url}\")\n",
|
348 |
+
" print(f\"\\033[33mSAVE DIR: \\033[34m{dst_dir}\")\n",
|
349 |
+
" print(f\"\\033[33mFILE NAME: \\033[34m{file_name}\\033[0m\")\n",
|
350 |
+
"\n",
|
351 |
+
"''' GET CivitAi API - DATA '''\n",
|
352 |
+
"\n",
|
353 |
+
"def strip_(url, file_name=None):\n",
|
354 |
+
" if 'github.com' in url:\n",
|
355 |
+
" if '/blob/' in url:\n",
|
356 |
+
" url = url.replace('/blob/', '/raw/')\n",
|
357 |
+
"\n",
|
358 |
+
" elif \"civitai.com\" in url:\n",
|
359 |
+
" return CivitAi_API(url, file_name)\n",
|
360 |
+
"\n",
|
361 |
+
" elif \"huggingface.co\" in url:\n",
|
362 |
+
" if '/blob/' in url:\n",
|
363 |
+
" url = url.replace('/blob/', '/resolve/')\n",
|
364 |
+
" if '?' in url:\n",
|
365 |
+
" url = url.split('?')[0]\n",
|
366 |
+
"\n",
|
367 |
+
" return url\n",
|
368 |
+
"\n",
|
369 |
+
"def CivitAi_API(url, file_name=None):\n",
|
370 |
+
" support_types = ('Checkpoint', 'Model', 'TextualInversion', 'LORA')\n",
|
371 |
+
" civitai_token = \"62c0c5956b2f9defbd844d754000180b\"\n",
|
372 |
+
"\n",
|
373 |
+
" if '?token=' in url:\n",
|
374 |
+
" url = url.split('?token=')[0]\n",
|
375 |
+
" if '?type=' in url:\n",
|
376 |
+
" url = url.replace('?type=', f'?token={civitai_token}&type=')\n",
|
377 |
+
" else:\n",
|
378 |
+
" url = f\"{url}?token={civitai_token}\"\n",
|
379 |
+
"\n",
|
380 |
+
" # Determine model or version id\n",
|
381 |
+
" if \"civitai.com/models/\" in url:\n",
|
382 |
+
" if '?modelVersionId=' in url:\n",
|
383 |
+
" version_id = url.split('?modelVersionId=')[1]\n",
|
384 |
+
" response = requests.get(f\"https://civitai.com/api/v1/model-versions/{version_id}\")\n",
|
385 |
+
" # print(f\"end - https://civitai.com/api/v1/model-versions/{version_id}\")\n",
|
386 |
+
" else:\n",
|
387 |
+
" model_id = url.split('/models/')[1].split('/')[0]\n",
|
388 |
+
" response = requests.get(f\"https://civitai.com/api/v1/models/{model_id}\")\n",
|
389 |
+
" # print(f\"end - https://civitai.com/api/v1/models/{model_id}\")\n",
|
390 |
+
" else:\n",
|
391 |
+
" version_id = url.split('/models/')[1].split('/')[0]\n",
|
392 |
+
" response = requests.get(f\"https://civitai.com/api/v1/model-versions/{version_id}\")\n",
|
393 |
+
" # print(f\"end - https://civitai.com/api/v1/model-versions/{version_id}\")\n",
|
394 |
+
"\n",
|
395 |
+
" data = response.json()\n",
|
396 |
+
"\n",
|
397 |
+
" if response.status_code != 200:\n",
|
398 |
+
" return None, None, None, None, None, None, None\n",
|
399 |
+
"\n",
|
400 |
+
" # Define model type and name\n",
|
401 |
+
" if \"civitai.com/models/\" in url:\n",
|
402 |
+
" if '?modelVersionId=' in url:\n",
|
403 |
+
" model_type = data['model']['type']\n",
|
404 |
+
" model_name = data['files'][0]['name']\n",
|
405 |
+
" else:\n",
|
406 |
+
" model_type = data['type']\n",
|
407 |
+
" model_name = data['modelVersions'][0]['files'][0]['name']\n",
|
408 |
+
" elif 'type=' in url:\n",
|
409 |
+
" model_type = parse_qs(urlparse(url).query).get('type', [''])[0]\n",
|
410 |
+
" if 'model' in model_type.lower():\n",
|
411 |
+
" model_name = data['files'][0]['name']\n",
|
412 |
+
" else:\n",
|
413 |
+
" model_name = data['files'][1]['name']\n",
|
414 |
+
" else:\n",
|
415 |
+
" model_type = data['model']['type']\n",
|
416 |
+
" model_name = data['files'][0]['name']\n",
|
417 |
+
"\n",
|
418 |
+
" model_name = file_name or model_name\n",
|
419 |
+
"\n",
|
420 |
+
" # Determine DownloadUrl\n",
|
421 |
+
" if \"civitai.com/models/\" in url:\n",
|
422 |
+
" if '?modelVersionId=' in url:\n",
|
423 |
+
" download_url = data.get('downloadUrl')\n",
|
424 |
+
" else:\n",
|
425 |
+
" download_url = data[\"modelVersions\"][0].get(\"downloadUrl\", \"\")\n",
|
426 |
+
" elif 'type=' in url:\n",
|
427 |
+
" if any(t.lower() in model_type.lower() for t in support_types):\n",
|
428 |
+
" download_url = data['files'][0]['downloadUrl']\n",
|
429 |
+
" else:\n",
|
430 |
+
" download_url = data['files'][1]['downloadUrl']\n",
|
431 |
+
" else:\n",
|
432 |
+
" download_url = data.get('downloadUrl')\n",
|
433 |
+
"\n",
|
434 |
+
" clean_url = re.sub(r'[?&]token=[^&]*', '', download_url) # hide token\n",
|
435 |
+
"\n",
|
436 |
+
" # Find a safe image: level less than 4 | Kaggle\n",
|
437 |
+
" image_url, image_name = None, None\n",
|
438 |
+
" if any(t in model_type for t in support_types):\n",
|
439 |
+
" try:\n",
|
440 |
+
" images = data.get('images') or data['modelVersions'][0].get('images', [])\n",
|
441 |
+
" if env == 'Kaggle':\n",
|
442 |
+
" image_url = next((image['url'] for image in images if image['nsfwLevel'] < 4), None)\n",
|
443 |
+
" else:\n",
|
444 |
+
" image_url = images[0]['url'] if images else None\n",
|
445 |
+
" except KeyError:\n",
|
446 |
+
" pass\n",
|
447 |
+
"\n",
|
448 |
+
" # Generate a name to save the image\n",
|
449 |
+
" image_name = f\"{model_name.split('.')[0]}.preview.{image_url.split('.')[-1]}\" if image_url else None\n",
|
450 |
+
"\n",
|
451 |
+
" return f\"{download_url}{'&' if '?' in download_url else '?'}token={civitai_token}\", clean_url, model_type, model_name, image_url, image_name, data\n",
|
452 |
+
"\n",
|
453 |
+
"''' Main Download Code '''\n",
|
454 |
+
"\n",
|
455 |
+
"def download(url):\n",
|
456 |
+
" links_and_paths = [link_or_path.strip() for link_or_path in url.split(',') if link_or_path.strip()]\n",
|
457 |
+
"\n",
|
458 |
+
" for link_or_path in links_and_paths:\n",
|
459 |
+
" if any(link_or_path.lower().startswith(prefix) for prefix in prefixes):\n",
|
460 |
+
" handle_manual(link_or_path)\n",
|
461 |
+
" else:\n",
|
462 |
+
" url, dst_dir, file_name = link_or_path.split()\n",
|
463 |
+
" manual_download(url, dst_dir, file_name)\n",
|
464 |
+
"\n",
|
465 |
+
" unpack_zip_files()\n",
|
466 |
+
"\n",
|
467 |
+
"def unpack_zip_files():\n",
|
468 |
+
" for directory in directories:\n",
|
469 |
+
" for root, _, files in os.walk(directory):\n",
|
470 |
+
" for file in files:\n",
|
471 |
+
" if file.endswith(\".zip\"):\n",
|
472 |
+
" zip_path = os.path.join(root, file)\n",
|
473 |
+
" extract_path = os.path.splitext(zip_path)[0]\n",
|
474 |
+
" with zipfile.ZipFile(zip_path, 'r') as zip_ref:\n",
|
475 |
+
" zip_ref.extractall(extract_path)\n",
|
476 |
+
" os.remove(zip_path)\n",
|
477 |
+
"\n",
|
478 |
+
"def handle_manual(url):\n",
|
479 |
+
" url_parts = url.split(':', 1)\n",
|
480 |
+
" prefix, path = url_parts[0], url_parts[1]\n",
|
481 |
+
"\n",
|
482 |
+
" file_name_match = re.search(r'\\[(.*?)\\]', path)\n",
|
483 |
+
" file_name = file_name_match.group(1) if file_name_match else None\n",
|
484 |
+
" if file_name:\n",
|
485 |
+
" path = re.sub(r'\\[.*?\\]', '', path)\n",
|
486 |
+
"\n",
|
487 |
+
" if prefix in prefixes:\n",
|
488 |
+
" dir = prefixes[prefix]\n",
|
489 |
+
" if prefix != \"extension\":\n",
|
490 |
+
" try:\n",
|
491 |
+
" manual_download(path, dir, file_name=file_name)\n",
|
492 |
+
" except Exception as e:\n",
|
493 |
+
" print(f\"Error downloading file: {e}\")\n",
|
494 |
+
" else:\n",
|
495 |
+
" extension_repo.append((path, file_name))\n",
|
496 |
+
"\n",
|
497 |
+
"def manual_download(url, dst_dir, file_name):\n",
|
498 |
+
" aria2_args = '--optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c'\n",
|
499 |
+
" basename = url.split(\"/\")[-1] if file_name is None else file_name\n",
|
500 |
+
" header_option = f\"--header={user_header}\"\n",
|
501 |
+
"\n",
|
502 |
+
" if 'github.com' in url:\n",
|
503 |
+
" url = strip_(url)\n",
|
504 |
+
"\n",
|
505 |
+
" # -- CivitAi APi+ V2 --\n",
|
506 |
+
" elif 'civitai' in url:\n",
|
507 |
+
" url, clean_url, model_type, file_name, image_url, image_name, data = strip_(url, file_name)\n",
|
508 |
+
"\n",
|
509 |
+
" if image_url and image_name:\n",
|
510 |
+
" with capture.capture_output() as cap:\n",
|
511 |
+
" !aria2c {aria2_args} -d {dst_dir} -o '{image_name}' '{image_url}'\n",
|
512 |
+
" del cap\n",
|
513 |
+
"\n",
|
514 |
+
" elif \"huggingface.co\" in url:\n",
|
515 |
+
" clean_url = strip_(url)\n",
|
516 |
+
"\n",
|
517 |
+
" \"\"\" Formatted info output \"\"\"\n",
|
518 |
+
" model_name_or_basename = file_name if not 'huggingface' in url else basename\n",
|
519 |
+
" format_output(clean_url or url, dst_dir, model_name_or_basename)\n",
|
520 |
+
"\n",
|
521 |
+
" # ## -- for my tests --\n",
|
522 |
+
" # print(url, dst_dir, model_name_or_basename)\n",
|
523 |
+
" print(f\"\\033[31m[Data Info]:\\033[0m Failed to retrieve data from the API.\\n\") if 'civitai' in url and not data else None\n",
|
524 |
+
" if 'civitai' in url and data and image_name:\n",
|
525 |
+
" print(f\"\\033[32m[Preview DL]:\\033[0m {image_name} - {image_url}\\n\")\n",
|
526 |
+
" # =====================\n",
|
527 |
+
"\n",
|
528 |
+
" # # -- Git Hub --\n",
|
529 |
+
" if 'github.com' in url or 'githubusercontent.com' in url:\n",
|
530 |
+
" !aria2c {aria2_args} -d {dst_dir} -o '{basename}' '{url}'\n",
|
531 |
+
"\n",
|
532 |
+
" # -- GDrive --\n",
|
533 |
+
" elif 'drive.google' in url:\n",
|
534 |
+
" try:\n",
|
535 |
+
" have_drive_link\n",
|
536 |
+
" except:\n",
|
537 |
+
" !pip install -U gdown > /dev/null\n",
|
538 |
+
" have_drive_link = True\n",
|
539 |
+
"\n",
|
540 |
+
" if 'folders' in url:\n",
|
541 |
+
" !gdown --folder \"{url}\" -O {dst_dir} --fuzzy -c\n",
|
542 |
+
" else:\n",
|
543 |
+
" if file_name:\n",
|
544 |
+
" !gdown \"{url}\" -O {dst_dir}/{file_name} --fuzzy -c\n",
|
545 |
+
" else:\n",
|
546 |
+
" !gdown \"{url}\" -O {dst_dir} --fuzzy -c\n",
|
547 |
+
"\n",
|
548 |
+
" # -- Hugging Face --\n",
|
549 |
+
" elif 'huggingface' in url:\n",
|
550 |
+
" !aria2c {header_option} {aria2_args} -d {dst_dir} -o '{basename}' '{url}'\n",
|
551 |
+
"\n",
|
552 |
+
" # -- Other --\n",
|
553 |
+
" elif 'http' in url:\n",
|
554 |
+
" !aria2c {aria2_args} -d {dst_dir} '{'-o' + file_name if file_name else ''}' '{url}'\n",
|
555 |
+
"\n",
|
556 |
+
"''' SubModels - Added URLs '''\n",
|
557 |
+
"\n",
|
558 |
+
"def add_submodels(selection, num_selection, model_dict, dst_dir):\n",
|
559 |
+
" if selection == \"none\":\n",
|
560 |
+
" return []\n",
|
561 |
+
" if selection == \"ALL\":\n",
|
562 |
+
" all_models = []\n",
|
563 |
+
" for models in model_dict.values():\n",
|
564 |
+
" all_models.extend(models)\n",
|
565 |
+
" selected_models = all_models\n",
|
566 |
+
" else:\n",
|
567 |
+
" selected_models = model_dict[selection]\n",
|
568 |
+
" selected_nums = map(int, num_selection.replace(',', '').split())\n",
|
569 |
+
" for num in selected_nums:\n",
|
570 |
+
" if 1 <= num <= len(model_dict):\n",
|
571 |
+
" name = list(model_dict)[num - 1]\n",
|
572 |
+
" selected_models.extend(model_dict[name])\n",
|
573 |
+
"\n",
|
574 |
+
" unique_models = list({model['name']: model for model in selected_models}.values())\n",
|
575 |
+
" for model in unique_models:\n",
|
576 |
+
" model['dst_dir'] = dst_dir\n",
|
577 |
+
"\n",
|
578 |
+
" return unique_models\n",
|
579 |
+
"\n",
|
580 |
+
"def handle_submodels(selection, num_selection, model_dict, dst_dir, url):\n",
|
581 |
+
" submodels = add_submodels(selection, num_selection, model_dict, dst_dir)\n",
|
582 |
+
" for submodel in submodels:\n",
|
583 |
+
" if not inpainting_model and \"inpainting\" in submodel['name']:\n",
|
584 |
+
" continue\n",
|
585 |
+
" url += f\"{submodel['url']} {submodel['dst_dir']} {submodel['name']}, \"\n",
|
586 |
+
" return url\n",
|
587 |
+
"\n",
|
588 |
+
"url = handle_submodels(model, model_num, model_list, models_dir, url)\n",
|
589 |
+
"url = handle_submodels(vae, vae_num, vae_list, vaes_dir, url)\n",
|
590 |
+
"url = handle_submodels(controlnet, controlnet_num, controlnet_list, control_dir, url)\n",
|
591 |
+
"\n",
|
592 |
+
"''' file.txt - added urls '''\n",
|
593 |
+
"\n",
|
594 |
+
"def process_file_download(file_url, prefixes, unique_urls):\n",
|
595 |
+
" files_urls = \"\"\n",
|
596 |
+
"\n",
|
597 |
+
" if file_url.startswith(\"http\"):\n",
|
598 |
+
" if \"blob\" in file_url:\n",
|
599 |
+
" file_url = file_url.replace(\"blob\", \"raw\")\n",
|
600 |
+
" response = requests.get(file_url)\n",
|
601 |
+
" lines = response.text.split('\\n')\n",
|
602 |
+
" else:\n",
|
603 |
+
" with open(file_url, 'r') as file:\n",
|
604 |
+
" lines = file.readlines()\n",
|
605 |
+
"\n",
|
606 |
+
" current_tag = None\n",
|
607 |
+
" for line in lines:\n",
|
608 |
+
" line = line.strip()\n",
|
609 |
+
" if any(f'# {tag}' in line.lower() for tag in prefixes):\n",
|
610 |
+
" current_tag = next((tag for tag in prefixes if tag in line.lower()))\n",
|
611 |
+
"\n",
|
612 |
+
" urls = [url.split('#')[0].strip() for url in line.split(',')] # filter urls\n",
|
613 |
+
" for url in urls:\n",
|
614 |
+
" filter_url = url.split('[')[0] # same url filter\n",
|
615 |
+
"\n",
|
616 |
+
" if url.startswith(\"http\") and filter_url not in unique_urls:\n",
|
617 |
+
" files_urls += f\"{current_tag}:{url}, \"\n",
|
618 |
+
" unique_urls.add(filter_url)\n",
|
619 |
+
"\n",
|
620 |
+
" return files_urls\n",
|
621 |
+
"\n",
|
622 |
+
"file_urls = \"\"\n",
|
623 |
+
"unique_urls = set()\n",
|
624 |
+
"\n",
|
625 |
+
"if custom_file_urls:\n",
|
626 |
+
" for custom_file_url in custom_file_urls.replace(',', '').split():\n",
|
627 |
+
" if not custom_file_url.endswith('.txt'):\n",
|
628 |
+
" custom_file_url += '.txt'\n",
|
629 |
+
" if not custom_file_url.startswith('http'):\n",
|
630 |
+
" if not custom_file_url.startswith(root_path):\n",
|
631 |
+
" custom_file_url = f'{root_path}/{custom_file_url}'\n",
|
632 |
+
"\n",
|
633 |
+
" try:\n",
|
634 |
+
" file_urls += process_file_download(custom_file_url, prefixes, unique_urls)\n",
|
635 |
+
" except FileNotFoundError:\n",
|
636 |
+
" pass\n",
|
637 |
+
"\n",
|
638 |
+
"# url prefixing\n",
|
639 |
+
"urls = (Model_url, Vae_url, LoRA_url, Embedding_url, Extensions_url)\n",
|
640 |
+
"prefixed_urls = (f\"{prefix}:{url}\" for prefix, url in zip(prefixes.keys(), urls) if url for url in url.replace(',', '').split())\n",
|
641 |
+
"url += \", \".join(prefixed_urls) + \", \" + file_urls\n",
|
642 |
+
"\n",
|
643 |
+
"if detailed_download == \"on\":\n",
|
644 |
+
" print(\"\\n\\n\\033[33m# ====== Detailed Download ====== #\\n\\033[0m\")\n",
|
645 |
+
" download(url)\n",
|
646 |
+
" print(\"\\n\\033[33m# =============================== #\\n\\033[0m\")\n",
|
647 |
+
"else:\n",
|
648 |
+
" with capture.capture_output() as cap:\n",
|
649 |
+
" download(url)\n",
|
650 |
+
" del cap\n",
|
651 |
+
"\n",
|
652 |
+
"print(\"\\r🏁 Download Complete!\" + \" \"*15)\n",
|
653 |
+
"\n",
|
654 |
+
"\n",
|
655 |
+
"# Cleaning shit after downloading...\n",
|
656 |
+
"!find {webui_path} \\( -type d \\( -name \".ipynb_checkpoints\" -o -name \".aria2\" \\) -o -type f -name \"*.aria2\" \\) -exec rm -r {{}} \\; >/dev/null 2>&1\n",
|
657 |
+
"\n",
|
658 |
+
"\n",
|
659 |
+
"## Install of Custom extensions\n",
|
660 |
+
"if len(extension_repo) > 0:\n",
|
661 |
+
" print(\"✨ Installing custom extensions...\", end='', flush=True)\n",
|
662 |
+
" with capture.capture_output() as cap:\n",
|
663 |
+
" for repo, repo_name in extension_repo:\n",
|
664 |
+
" if not repo_name:\n",
|
665 |
+
" repo_name = repo.split('/')[-1]\n",
|
666 |
+
" !cd {extensions_dir} \\\n",
|
667 |
+
" && git clone {repo} {repo_name} \\\n",
|
668 |
+
" && cd {repo_name} \\\n",
|
669 |
+
" && git fetch\n",
|
670 |
+
" del cap\n",
|
671 |
+
" print(f\"\\r📦 Installed '{len(extension_repo)}', Custom extensions!\")\n",
|
672 |
+
"\n",
|
673 |
+
"\n",
|
674 |
+
"## List Models and stuff V2\n",
|
675 |
+
"if detailed_download == \"off\":\n",
|
676 |
+
" print(\"\\n\\n\\033[33mIf you don't see any downloaded files, enable the 'Detailed Downloads' feature in the widget.\")\n",
|
677 |
+
"\n",
|
678 |
+
"%run {root_path}/file_cell/special/dl_display_results.py # display widgets result"
|
679 |
+
]
|
680 |
+
}
|
681 |
+
],
|
682 |
+
"metadata": {
|
683 |
+
"colab": {
|
684 |
+
"provenance": []
|
685 |
+
},
|
686 |
+
"kernelspec": {
|
687 |
+
"display_name": "Python 3",
|
688 |
+
"name": "python3"
|
689 |
+
},
|
690 |
+
"language_info": {
|
691 |
+
"name": "python"
|
692 |
+
}
|
693 |
+
},
|
694 |
+
"nbformat": 4,
|
695 |
+
"nbformat_minor": 0
|
696 |
}
|
files_cells/notebooks/en/launch_en.ipynb
CHANGED
@@ -1,156 +1,145 @@
|
|
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 |
-
"import cloudpickle as pickle\n",
|
33 |
-
"from datetime import timedelta\n",
|
34 |
-
"from IPython.display import clear_output\n",
|
35 |
-
"\n",
|
36 |
-
"
|
37 |
-
"
|
38 |
-
"
|
39 |
-
"
|
40 |
-
"
|
41 |
-
" '
|
42 |
-
"
|
43 |
-
"
|
44 |
-
"
|
45 |
-
"
|
46 |
-
"
|
47 |
-
"
|
48 |
-
"\n",
|
49 |
-
"env, root_path, free_plan = detect_environment()\n",
|
50 |
-
"webui_path = f\"{root_path}/sdw\"\n",
|
51 |
-
"
|
52 |
-
"
|
53 |
-
"
|
54 |
-
"
|
55 |
-
"
|
56 |
-
"
|
57 |
-
"
|
58 |
-
"
|
59 |
-
"\n",
|
60 |
-
"
|
61 |
-
"
|
62 |
-
"
|
63 |
-
"
|
64 |
-
"
|
65 |
-
"
|
66 |
-
"\n",
|
67 |
-
"
|
68 |
-
"
|
69 |
-
"
|
70 |
-
"
|
71 |
-
"
|
72 |
-
"
|
73 |
-
"
|
74 |
-
"
|
75 |
-
"
|
76 |
-
"
|
77 |
-
"
|
78 |
-
"
|
79 |
-
"
|
80 |
-
"
|
81 |
-
"
|
82 |
-
"
|
83 |
-
"
|
84 |
-
"
|
85 |
-
"
|
86 |
-
"
|
87 |
-
"
|
88 |
-
"\n",
|
89 |
-
"
|
90 |
-
"
|
91 |
-
"
|
92 |
-
"
|
93 |
-
"
|
94 |
-
"\n",
|
95 |
-
"
|
96 |
-
"
|
97 |
-
"
|
98 |
-
"
|
99 |
-
"\n",
|
100 |
-
"
|
101 |
-
"\n",
|
102 |
-
"\n",
|
103 |
-
"
|
104 |
-
"
|
105 |
-
"
|
106 |
-
"
|
107 |
-
"
|
108 |
-
"
|
109 |
-
"
|
110 |
-
"
|
111 |
-
"
|
112 |
-
"\n",
|
113 |
-
"
|
114 |
-
"
|
115 |
-
"
|
116 |
-
"
|
117 |
-
"\n",
|
118 |
-
"
|
119 |
-
" if
|
120 |
-
"
|
121 |
-
"
|
122 |
-
"
|
123 |
-
"
|
124 |
-
"
|
125 |
-
"
|
126 |
-
"
|
127 |
-
"\n",
|
128 |
-
"\n",
|
129 |
-
"
|
130 |
-
"
|
131 |
-
"
|
132 |
-
"
|
133 |
-
"
|
134 |
-
"
|
135 |
-
"
|
136 |
-
"
|
137 |
-
"\n",
|
138 |
-
"
|
139 |
-
"
|
140 |
-
"
|
141 |
-
"
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
"# after runnig\n",
|
146 |
-
"start_colab = float(open(f'{webui_path}/static/colabTimer.txt', 'r').read())\n",
|
147 |
-
"time_since_start = str(timedelta(seconds=time.time()-start_colab)).split('.')[0]\n",
|
148 |
-
"print(f\"\\n⌚️ \\033[0mYou have been conducting this session for - \\033[33m{time_since_start}\\033[0m\\n\\n\")\n",
|
149 |
-
"\n",
|
150 |
-
"''' del zrok tunnel '''\n",
|
151 |
-
"if zrok_token:\n",
|
152 |
-
" !zrok disable &> /dev/null"
|
153 |
-
]
|
154 |
-
}
|
155 |
-
]
|
156 |
}
|
|
|
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 |
+
"import cloudpickle as pickle\n",
|
33 |
+
"from datetime import timedelta\n",
|
34 |
+
"from IPython.display import clear_output\n",
|
35 |
+
"\n",
|
36 |
+
"# ================= DETECT ENV =================\n",
|
37 |
+
"def detect_environment():\n",
|
38 |
+
" free_plan = (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024 ** 3) <= 20)\n",
|
39 |
+
" environments = {\n",
|
40 |
+
" 'COLAB_GPU': ('Google Colab', \"/root\" if free_plan else \"/content\"),\n",
|
41 |
+
" 'KAGGLE_URL_BASE': ('Kaggle', \"/kaggle/working/content\")\n",
|
42 |
+
" }\n",
|
43 |
+
"\n",
|
44 |
+
" for env_var, (environment, path) in environments.items():\n",
|
45 |
+
" if env_var in os.environ:\n",
|
46 |
+
" return environment, path, free_plan\n",
|
47 |
+
" return 'Unknown', '/unknown/path', free_plan\n",
|
48 |
+
"\n",
|
49 |
+
"env, root_path, free_plan = detect_environment()\n",
|
50 |
+
"webui_path = f\"{root_path}/sdw\"\n",
|
51 |
+
"\n",
|
52 |
+
"def load_settings():\n",
|
53 |
+
" SETTINGS_FILE = f'{root_path}/settings.json'\n",
|
54 |
+
" if os.path.exists(SETTINGS_FILE):\n",
|
55 |
+
" with open(SETTINGS_FILE, 'r') as f:\n",
|
56 |
+
" return json.load(f)\n",
|
57 |
+
" return {}\n",
|
58 |
+
"\n",
|
59 |
+
"settings = load_settings()\n",
|
60 |
+
"ngrok_token = settings.get('ngrok_token', \"\")\n",
|
61 |
+
"zrok_token = settings.get('zrok_token', \"\")\n",
|
62 |
+
"commandline_arguments = settings.get('commandline_arguments', \"\")\n",
|
63 |
+
"change_webui = settings.get('change_webui', \"\")\n",
|
64 |
+
"\n",
|
65 |
+
"# ======================== TUNNEL V2 ========================\n",
|
66 |
+
"print('Please Wait...')\n",
|
67 |
+
"\n",
|
68 |
+
"def get_public_ip(version='ipv4'):\n",
|
69 |
+
" try:\n",
|
70 |
+
" url = f'https://api64.ipify.org?format=json&{version}=true'\n",
|
71 |
+
" response = requests.get(url)\n",
|
72 |
+
" return response.json().get('ip', 'N/A')\n",
|
73 |
+
" except Exception as e:\n",
|
74 |
+
" print(f\"Error getting public {version} address:\", e)\n",
|
75 |
+
"\n",
|
76 |
+
"# Check if public IP is already saved, if not then get it\n",
|
77 |
+
"public_ip_file = f\"{root_path}/public_ip.txt\"\n",
|
78 |
+
"if os.path.exists(public_ip_file):\n",
|
79 |
+
" with open(public_ip_file, 'r') as file:\n",
|
80 |
+
" public_ipv4 = file.read().strip()\n",
|
81 |
+
"else:\n",
|
82 |
+
" public_ipv4 = get_public_ip(version='ipv4')\n",
|
83 |
+
" with open(public_ip_file, 'w') as file:\n",
|
84 |
+
" file.write(public_ipv4)\n",
|
85 |
+
"\n",
|
86 |
+
"tunnel_class = pickle.load(open(f\"{root_path}/new_tunnel\", \"rb\"), encoding=\"utf-8\")\n",
|
87 |
+
"tunnel_port = 1834\n",
|
88 |
+
"tunnel = tunnel_class(tunnel_port)\n",
|
89 |
+
"tunnel.add_tunnel(command=\"cl tunnel --url localhost:{port}\", name=\"cl\", pattern=re.compile(r\"[\\w-]+\\.trycloudflare\\.com\"))\n",
|
90 |
+
"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",
|
91 |
+
"\n",
|
92 |
+
"if zrok_token:\n",
|
93 |
+
" !zrok enable {zrok_token} &> /dev/null\n",
|
94 |
+
" tunnel.add_tunnel(command=\"zrok share public http://localhost:{port}/ --headless\", name=\"zrok\", pattern=re.compile(r\"[\\w-]+\\.share\\.zrok\\.io\"))\n",
|
95 |
+
"\n",
|
96 |
+
"clear_output()\n",
|
97 |
+
"\n",
|
98 |
+
"# =============== Automatic Fixing Path V3 ===============\n",
|
99 |
+
"paths_to_check = {\n",
|
100 |
+
" \"tagger_hf_cache_dir\": f\"{webui_path}/models/interrogators/\",\n",
|
101 |
+
" \"additional_networks_extra_lora_path\": f\"{webui_path}/models/Lora/\",\n",
|
102 |
+
" \"ad_extra_models_dir\": f\"{webui_path}/models/adetailer/\",\n",
|
103 |
+
" \"sd_checkpoint_hash\": \"\",\n",
|
104 |
+
" \"sd_model_checkpoint\": \"\",\n",
|
105 |
+
" \"sd_vae\": \"None\"\n",
|
106 |
+
"}\n",
|
107 |
+
"\n",
|
108 |
+
"config_path = f'{webui_path}/ui-config.json'\n",
|
109 |
+
"\n",
|
110 |
+
"if os.path.exists(config_path):\n",
|
111 |
+
" with open(config_path, 'r') as file:\n",
|
112 |
+
" config_data = json.load(file)\n",
|
113 |
+
"\n",
|
114 |
+
" for key, value in paths_to_check.items():\n",
|
115 |
+
" if key in config_data and config_data[key] != value:\n",
|
116 |
+
" sed_command = f\"sed -i 's|\\\"{key}\\\": \\\".*\\\"|\\\"{key}\\\": \\\"{value}\\\"|' {config_path}\"\n",
|
117 |
+
" os.system(sed_command)\n",
|
118 |
+
"\n",
|
119 |
+
" if env == 'Kaggle':\n",
|
120 |
+
" get_ipython().system('sed -i \\'s/\"civitai_interface\\\\/NSFW content\\\\/value\":.*/\"civitai_interface\\\\/NSFW content\\\\/value\": false/g\\' {webui_path}/ui-config.json')\n",
|
121 |
+
"\n",
|
122 |
+
"with tunnel:\n",
|
123 |
+
" %cd {webui_path}\n",
|
124 |
+
"\n",
|
125 |
+
" commandline_arguments += f' --port={tunnel_port}'\n",
|
126 |
+
" if ngrok_token:\n",
|
127 |
+
" commandline_arguments += f' --ngrok {ngrok_token}'\n",
|
128 |
+
" if env != \"Google Colab\":\n",
|
129 |
+
" commandline_arguments += f' --encrypt-pass={tunnel_port} --api'\n",
|
130 |
+
"\n",
|
131 |
+
" if change_webui == 'Forge':\n",
|
132 |
+
" commandline_arguments += ' --cuda-stream --pin-shared-memory'\n",
|
133 |
+
"\n",
|
134 |
+
" !COMMANDLINE_ARGS=\"{commandline_arguments}\" python launch.py\n",
|
135 |
+
"\n",
|
136 |
+
"start_colab = float(open(f'{webui_path}/static/colabTimer.txt', 'r').read())\n",
|
137 |
+
"time_since_start = str(timedelta(seconds=time.time()-start_colab)).split('.')[0]\n",
|
138 |
+
"print(f\"\\n⌚️ \\033[0mYou have been conducting this session for - \\033[33m{time_since_start}\\033[0m\\n\\n\")\n",
|
139 |
+
"\n",
|
140 |
+
"if zrok_token:\n",
|
141 |
+
" !zrok disable &> /dev/null"
|
142 |
+
]
|
143 |
+
}
|
144 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
}
|
files_cells/notebooks/en/widgets_en.ipynb
CHANGED
@@ -1,349 +1,349 @@
|
|
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 |
-
"##~ WIDGET CODE | BY: ANXETY ~##\n",
|
26 |
-
"\n",
|
27 |
-
"import os\n",
|
28 |
-
"import json\n",
|
29 |
-
"import time\n",
|
30 |
-
"import ipywidgets as widgets\n",
|
31 |
-
"from ipywidgets import widgets, Layout, Label, Button, VBox, HBox\n",
|
32 |
-
"from IPython.display import display, HTML, Javascript, 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 |
-
" for env_var, (environment, path) in environments.items():\n",
|
43 |
-
" if env_var in os.environ:\n",
|
44 |
-
" return environment, path, free_plan\n",
|
45 |
-
"\n",
|
46 |
-
"env, root_path, free_plan = detect_environment()\n",
|
47 |
-
"webui_path = f\"{root_path}/sdw\"\n",
|
48 |
-
"!mkdir -p {root_path}\n",
|
49 |
-
"\n",
|
50 |
-
"\n",
|
51 |
-
"# ==================== CSS JS ====================\n",
|
52 |
-
"##~ custom background images V1.5 ~##\n",
|
53 |
-
"import argparse\n",
|
54 |
-
"parser = argparse.ArgumentParser(description='This script processes an background image.')\n",
|
55 |
-
"parser.add_argument('-i', '--image', type=str, help='URL of the image to process', metavar='')\n",
|
56 |
-
"parser.add_argument('-o', '--opacity', type=float, help='Opacity level for the image, between 0 and 1', metavar='', default=0.3)\n",
|
57 |
-
"parser.add_argument('-b', '--blur', type=str, help='Blur level for the image', metavar='', default=0)\n",
|
58 |
-
"parser.add_argument('-y', type=int, help='Y coordinate for the image in px', metavar='', default=0)\n",
|
59 |
-
"parser.add_argument('-x', type=int, help='X coordinate for the image in px', metavar='', default=0)\n",
|
60 |
-
"parser.add_argument('-s', '--scale', type=int, help='Scale image in %%', metavar='', default=100)\n",
|
61 |
-
"parser.add_argument('-m', '--mode', action='store_true', help='Removes repetitive image tiles')\n",
|
62 |
-
"parser.add_argument('-t', '--transparent', action='store_true', help='Makes input/selection fields 35%% more transparent')\n",
|
63 |
-
"parser.add_argument('-bf', '--blur-fields', type=str, help='Background blur level for input/selection fields', metavar='', default=2)\n",
|
64 |
-
"\n",
|
65 |
-
"args = parser.parse_args()\n",
|
66 |
-
"\n",
|
67 |
-
"url_img = args.image\n",
|
68 |
-
"opacity_img = args.opacity\n",
|
69 |
-
"blur_img = args.blur\n",
|
70 |
-
"y_img = args.y\n",
|
71 |
-
"x_img = args.x\n",
|
72 |
-
"scale_img = args.scale\n",
|
73 |
-
"blur_fields = args.blur_fields\n",
|
74 |
-
"\n",
|
75 |
-
"## ---\n",
|
76 |
-
"\"\"\" WTF KAGGLE - WHAT THE FUCK IS THE DIFFERENCE OF 35 PIXELS!?!?!? \"\"\"\n",
|
77 |
-
"fix_heigh_img = \"-810px\" if env == \"Kaggle\" else \"-775px\"\n",
|
78 |
-
"\n",
|
79 |
-
"\"\"\" transperent fields \"\"\"\n",
|
80 |
-
"t_bg_alpha = \"1\" if not args.transparent else \"0.65\"\n",
|
81 |
-
"\n",
|
82 |
-
"\"\"\" mode img - repeats \"\"\"\n",
|
83 |
-
"mode_img = \"repeat\" if not args.mode else \"no-repeat\"\n",
|
84 |
-
"\n",
|
85 |
-
"container_background = f'''\n",
|
86 |
-
"<style>\n",
|
87 |
-
":root {{\n",
|
88 |
-
" /* for background container*/\n",
|
89 |
-
" --img_background: url({url_img});\n",
|
90 |
-
" --img_opacity: {opacity_img};\n",
|
91 |
-
" --img_blur: {blur_img}px;\n",
|
92 |
-
" --image_y: {y_img}px;\n",
|
93 |
-
" --image_x: {x_img}px;\n",
|
94 |
-
" --img_scale: {scale_img}%;\n",
|
95 |
-
" --img_mode: {mode_img};\n",
|
96 |
-
" --img_height_dif: {fix_heigh_img};\n",
|
97 |
-
"\n",
|
98 |
-
" /* for fields */\n",
|
99 |
-
" --bg-field-color: rgba(28, 28, 28, {t_bg_alpha}); /* -> #1c1c1c */\n",
|
100 |
-
" --bg-field-color-hover: rgba(38, 38, 38, {t_bg_alpha}); /* -> #262626; */\n",
|
101 |
-
" --bg-field-blur-level: {blur_fields}px;\n",
|
102 |
-
"}}\n",
|
103 |
-
"'''\n",
|
104 |
-
"\n",
|
105 |
-
"display(HTML(container_background))\n",
|
106 |
-
"\n",
|
107 |
-
"# Main CSS\n",
|
108 |
-
"css_file_path = f\"{root_path}/CSS/main_widgets.css\"\n",
|
109 |
-
"with open(css_file_path , \"r\") as f:\n",
|
110 |
-
" CSS = f.read()\n",
|
111 |
-
"display(HTML(f\"<style>{CSS}</style>\"))\n",
|
112 |
-
"\n",
|
113 |
-
"# Main JS\n",
|
114 |
-
"JS = '''\n",
|
115 |
-
"<!-- TOGGLE 'CustomDL' SCRIPT -->\n",
|
116 |
-
"<script>\n",
|
117 |
-
"function toggleContainer() {\n",
|
118 |
-
" let downloadContainer = document.querySelector('.container_custom_downlad');\n",
|
119 |
-
" let info = document.querySelector('.info');\n",
|
120 |
-
"\n",
|
121 |
-
" downloadContainer.classList.toggle('expanded');\n",
|
122 |
-
" info.classList.toggle('showed');\n",
|
123 |
-
"}\n",
|
124 |
-
"</script>\n",
|
125 |
-
"'''\n",
|
126 |
-
"display(HTML(JS))\n",
|
127 |
-
"\n",
|
128 |
-
"# ==================== WIDGETS V2 ====================\n",
|
129 |
-
"HR = widgets.HTML('<hr>')\n",
|
130 |
-
"\n",
|
131 |
-
"class WidgetFactory:\n",
|
132 |
-
" def __init__(self, style=None, layout=None):\n",
|
133 |
-
" self.style = style if style else {'description_width': 'initial'}\n",
|
134 |
-
" self.layout = layout if layout else widgets.Layout(max_width='1080px', width='100%')\n",
|
135 |
-
"\n",
|
136 |
-
" def create_html(self, content, class_name=None):\n",
|
137 |
-
" html_widget = widgets.HTML(content)\n",
|
138 |
-
" if class_name:\n",
|
139 |
-
" html_widget.add_class(class_name)\n",
|
140 |
-
" return html_widget\n",
|
141 |
-
"\n",
|
142 |
-
" def create_header(self, name):\n",
|
143 |
-
" return widgets.HTML(f'<div class=\"header\">{name}<div>')\n",
|
144 |
-
"\n",
|
145 |
-
" def create_dropdown(self, options, value, description):\n",
|
146 |
-
" return widgets.Dropdown(options=options, value=value, description=description, style=self.style, layout=self.layout)\n",
|
147 |
-
"\n",
|
148 |
-
" def create_text(self, description, placeholder='', value=''):\n",
|
149 |
-
" return widgets.Text(description=description, placeholder=placeholder, value=value, style=self.style, layout=self.layout)\n",
|
150 |
-
"\n",
|
151 |
-
" def create_checkbox(self, value, description):\n",
|
152 |
-
" return widgets.Checkbox(value=value, description=description, style=self.style, layout=self.layout)\n",
|
153 |
-
"\n",
|
154 |
-
" def create_button(self, description, class_name=None):\n",
|
155 |
-
" button = widgets.Button(description=description)\n",
|
156 |
-
" if class_name:\n",
|
157 |
-
" button.add_class(class_name)\n",
|
158 |
-
" return button\n",
|
159 |
-
"\n",
|
160 |
-
" def create_hbox(self, children):\n",
|
161 |
-
" return widgets.HBox(children)\n",
|
162 |
-
"\n",
|
163 |
-
" def create_vbox(self, children, class_names=None):\n",
|
164 |
-
" vbox = widgets.VBox(children)\n",
|
165 |
-
" if class_names:\n",
|
166 |
-
" for class_name in class_names:\n",
|
167 |
-
" vbox.add_class(class_name)\n",
|
168 |
-
" return vbox\n",
|
169 |
-
"\n",
|
170 |
-
" def display(self, widget):\n",
|
171 |
-
" display(widget)\n",
|
172 |
-
"\n",
|
173 |
-
"# Instantiate the factory\n",
|
174 |
-
"factory = WidgetFactory()\n",
|
175 |
-
"\n",
|
176 |
-
"# --- MODEL ---\n",
|
177 |
-
"model_header = factory.create_header('Model Selection')\n",
|
178 |
-
"model_options = ['none',\n",
|
179 |
-
" '1.Anime (by XpucT) + INP',\n",
|
180 |
-
" '2.BluMix [Anime] [V7] + INP',\n",
|
181 |
-
" '3.Cetus-Mix [Anime] [V4] + INP',\n",
|
182 |
-
" '4.Counterfeit [Anime] [V3] + INP',\n",
|
183 |
-
" '5.CuteColor [Anime] [V3]',\n",
|
184 |
-
" '6.Dark-Sushi-Mix [Anime]',\n",
|
185 |
-
" '7.Deliberate [Realism] [V6] + INP',\n",
|
186 |
-
" '8.Meina-Mix [Anime] [V11] + INP',\n",
|
187 |
-
" '9.Mix-Pro [Anime] [V4] + INP']\n",
|
188 |
-
"model_widget = factory.create_dropdown(model_options, '4.Counterfeit [Anime] [V3] + INP', 'Model:')\n",
|
189 |
-
"model_num_widget = factory.create_text('Model Number:', 'Enter the model numbers to be downloaded using comma/space.')\n",
|
190 |
-
"inpainting_model_widget = factory.create_checkbox(False, 'Inpainting Models')\n",
|
191 |
-
"\n",
|
192 |
-
"# Display Model\n",
|
193 |
-
"all_model_box = factory.create_vbox([model_header, model_widget, model_num_widget, inpainting_model_widget], class_names=[\"container\", \"image_1\"])\n",
|
194 |
-
"factory.display(all_model_box)\n",
|
195 |
-
"\n",
|
196 |
-
"# --- VAE ---\n",
|
197 |
-
"vae_header = factory.create_header('VAE Selection')\n",
|
198 |
-
"vae_options = ['none',\n",
|
199 |
-
" '1.Anime.vae',\n",
|
200 |
-
" '2.Anything.vae',\n",
|
201 |
-
" '3.Blessed2.vae',\n",
|
202 |
-
" '4.ClearVae.vae',\n",
|
203 |
-
" '5.WD.vae']\n",
|
204 |
-
"vae_widget = factory.create_dropdown(vae_options, '3.Blessed2.vae', 'Vae:')\n",
|
205 |
-
"vae_num_widget = factory.create_text('Vae Number:', 'Enter the vae numbers to be downloaded using comma/space.')\n",
|
206 |
-
"\n",
|
207 |
-
"# Display Vae\n",
|
208 |
-
"all_vae_box = factory.create_vbox([vae_header, vae_widget, vae_num_widget], class_names=[\"container\", \"image_2\"])\n",
|
209 |
-
"factory.display(all_vae_box)\n",
|
210 |
-
"\n",
|
211 |
-
"# --- ADDITIONAL ---\n",
|
212 |
-
"additional_header = factory.create_header('Additional')\n",
|
213 |
-
"latest_webui_widget = factory.create_checkbox(True, 'Update WebUI')\n",
|
214 |
-
"latest_exstensions_widget = factory.create_checkbox(True, 'Update Extensions')\n",
|
215 |
-
"change_webui_widget = factory.create_dropdown(['A1111', 'Forge'], 'A1111', 'Change WebUI:')\n",
|
216 |
-
"detailed_download_widget = factory.create_dropdown(['off', 'on'], 'off', 'Detailed Download:')\n",
|
217 |
-
"choose_changes_widget = factory.create_hbox([latest_webui_widget, latest_exstensions_widget, change_webui_widget, detailed_download_widget])\n",
|
218 |
-
"\n",
|
219 |
-
"controlnet_options = ['none', 'ALL', '1.canny',\n",
|
220 |
-
" '2.openpose', '3.depth',\n",
|
221 |
-
" '4.normal_map', '5.mlsd',\n",
|
222 |
-
" '6.lineart', '7.soft_edge',\n",
|
223 |
-
" '8.scribble', '9.segmentation',\n",
|
224 |
-
" '10.shuffle', '11.tile',\n",
|
225 |
-
" '12.inpaint', '13.instruct_p2p']\n",
|
226 |
-
"controlnet_widget = factory.create_dropdown(controlnet_options, 'none', 'ControlNet:')\n",
|
227 |
-
"controlnet_num_widget = factory.create_text('ControlNet Number:', 'Enter the ControlNet model numbers to be downloaded using comma/space.')\n",
|
228 |
-
"commit_hash_widget = factory.create_text('Commit Hash:')\n",
|
229 |
-
"huggingface_token_widget = factory.create_text('HuggingFace Token:')\n",
|
230 |
-
"\n",
|
231 |
-
"ngrok_token_widget = factory.create_text('Ngrok Token:')\n",
|
232 |
-
"ngrock_button = factory.create_html('<a href=\"https://dashboard.ngrok.com/get-started/your-authtoken\" target=\"_blank\">Получить Ngrok Токен</a>', class_name=\"button_ngrok\")\n",
|
233 |
-
"ngrok_widget = factory.create_hbox([ngrok_token_widget, ngrock_button])\n",
|
234 |
-
"\n",
|
235 |
-
"zrok_token_widget = factory.create_text('Zrok Token:')\n",
|
236 |
-
"zrok_button = factory.create_html('<a href=\"https://colab.research.google.com/drive/1d2sjWDJi_GYBUavrHSuQyHTDuLy36WpU\" target=\"_blank\">Зарегать Zrok Токен</a>', class_name=\"button_ngrok\")\n",
|
237 |
-
"zrok_widget = factory.create_hbox([zrok_token_widget, zrok_button])\n",
|
238 |
-
"\n",
|
239 |
-
"commandline_arguments_options = \"--listen --enable-insecure-extension-access --theme dark --no-half-vae --disable-console-progressbars --xformers\"\n",
|
240 |
-
"commandline_arguments_widget = factory.create_text('Arguments:', value=commandline_arguments_options)\n",
|
241 |
-
"\n",
|
242 |
-
"# Display Additional\n",
|
243 |
-
"additional_widget_list = [additional_header,\n",
|
244 |
-
" choose_changes_widget,\n",
|
245 |
-
" HR,\n",
|
246 |
-
" controlnet_widget,\n",
|
247 |
-
" controlnet_num_widget,\n",
|
248 |
-
" commit_hash_widget,\n",
|
249 |
-
" huggingface_token_widget,\n",
|
250 |
-
" ngrok_widget,\n",
|
251 |
-
" zrok_widget,\n",
|
252 |
-
" HR,\n",
|
253 |
-
" commandline_arguments_widget]\n",
|
254 |
-
"\n",
|
255 |
-
"if free_plan and env == \"Google Colab\": # remove ngrok from colab\n",
|
256 |
-
" additional_widget_list.remove(ngrok_widget)\n",
|
257 |
-
"if os.path.exists(webui_path): # remove selection after selection ;3\n",
|
258 |
-
" choose_changes_widget.children = [widget for widget in choose_changes_widget.children if widget != change_webui_widget]\n",
|
259 |
-
"\n",
|
260 |
-
"all_additional_box = factory.create_vbox(additional_widget_list, class_names=[\"container\", \"image_3\"])\n",
|
261 |
-
"factory.display(all_additional_box)\n",
|
262 |
-
"\n",
|
263 |
-
"# --- CUSTOM DOWNLOAD ---\n",
|
264 |
-
"custom_download_header_popup = factory.create_html('''\n",
|
265 |
-
"<style>\n",
|
266 |
-
"/* Term Colors */\n",
|
267 |
-
".sample_label {color: #dbafff;}\n",
|
268 |
-
".braces {color: #ffff00;}\n",
|
269 |
-
".extension {color: #eb934b;}\n",
|
270 |
-
".file_name {color: #ffffd8;}\n",
|
271 |
-
"</style>\n",
|
272 |
-
"\n",
|
273 |
-
"<div class=\"header\" style=\"cursor: pointer;\" onclick=\"toggleContainer()\">Custom Download</div>\n",
|
274 |
-
"<!-- PopUp Window -->\n",
|
275 |
-
"<div class=\"info\">INFO</div>\n",
|
276 |
-
"<div class=\"popup\">\n",
|
277 |
-
" 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",
|
278 |
-
" after the URL without spaces.\n",
|
279 |
-
" <span style=\"color: #ff9999\">For files, be sure to specify</span> - <span class=\"extension\">Filename Extension.</span>\n",
|
280 |
-
" <div class=\"sample\">\n",
|
281 |
-
" <span class=\"sample_label\">Example for File:</span>\n",
|
282 |
-
" 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",
|
283 |
-
" <br>\n",
|
284 |
-
" <span class=\"sample_label\">Example for Extension:</span>\n",
|
285 |
-
" 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",
|
286 |
-
" </div>\n",
|
287 |
-
"</div>\n",
|
288 |
-
"''')\n",
|
289 |
-
"\n",
|
290 |
-
"Model_url_widget = factory.create_text('Model:')\n",
|
291 |
-
"Vae_url_widget = factory.create_text('Vae:')\n",
|
292 |
-
"LoRA_url_widget = factory.create_text('LoRa:')\n",
|
293 |
-
"Embedding_url_widget = factory.create_text('Embedding:')\n",
|
294 |
-
"Extensions_url_widget = factory.create_text('Extensions:')\n",
|
295 |
-
"custom_file_urls_widget = factory.create_text('File (txt):')\n",
|
296 |
-
"\n",
|
297 |
-
"# Display CustomDl\n",
|
298 |
-
"all_custom_box = factory.create_vbox([\n",
|
299 |
-
" custom_download_header_popup, Model_url_widget, Vae_url_widget, LoRA_url_widget, Embedding_url_widget, Extensions_url_widget, custom_file_urls_widget\n",
|
300 |
-
"], class_names=[\"container\", \"image_4\", \"container_custom_downlad\"])\n",
|
301 |
-
"factory.display(all_custom_box)\n",
|
302 |
-
"\n",
|
303 |
-
"# --- Save Button ---\n",
|
304 |
-
"save_button = factory.create_button('Save', class_name=\"button_save\")\n",
|
305 |
-
"factory.display(save_button)\n",
|
306 |
-
"\n",
|
307 |
-
"\n",
|
308 |
-
"# ============ Load / Save - Settings V2 ============\n",
|
309 |
-
"SETTINGS_FILE = f'{root_path}/settings.json'\n",
|
310 |
-
"\n",
|
311 |
-
"SETTINGS_KEYS = [\n",
|
312 |
-
" 'model', 'model_num', 'inpainting_model',\n",
|
313 |
-
" 'vae', 'vae_num', 'latest_webui', 'latest_exstensions',\n",
|
314 |
-
" 'change_webui', 'detailed_download', 'controlnet',\n",
|
315 |
-
" 'controlnet_num', 'commit_hash', 'huggingface_token',\n",
|
316 |
-
" 'ngrok_token', 'zrok_token', 'commandline_arguments',\n",
|
317 |
-
" 'Model_url', 'Vae_url', 'LoRA_url', 'Embedding_url',\n",
|
318 |
-
" 'Extensions_url', 'custom_file_urls'\n",
|
319 |
-
"]\n",
|
320 |
-
"\n",
|
321 |
-
"def save_settings():\n",
|
322 |
-
" settings = {key: globals()[f\"{key}_widget\"].value for key in SETTINGS_KEYS}\n",
|
323 |
-
" with open(SETTINGS_FILE, 'w') as f:\n",
|
324 |
-
" json.dump(settings, f, indent=2)\n",
|
325 |
-
"\n",
|
326 |
-
"def load_settings():\n",
|
327 |
-
" if os.path.exists(SETTINGS_FILE):\n",
|
328 |
-
" with open(SETTINGS_FILE, 'r') as f:\n",
|
329 |
-
" settings = json.load(f)\n",
|
330 |
-
" for key in SETTINGS_KEYS:\n",
|
331 |
-
" globals()[f\"{key}_widget\"].value = settings.get(key, \"\")\n",
|
332 |
-
"\n",
|
333 |
-
"def hide_widgets():\n",
|
334 |
-
" widgets_list = [all_model_box, all_vae_box, all_additional_box, all_custom_box, save_button]\n",
|
335 |
-
" for widget in widgets_list:\n",
|
336 |
-
" widget.add_class(\"hide\")\n",
|
337 |
-
" time.sleep(0.5)\n",
|
338 |
-
" widgets.Widget.close_all()\n",
|
339 |
-
"\n",
|
340 |
-
"def save_data(button):\n",
|
341 |
-
" save_settings()\n",
|
342 |
-
" hide_widgets()\n",
|
343 |
-
"\n",
|
344 |
-
"load_settings()\n",
|
345 |
-
"save_button.on_click(save_data)"
|
346 |
-
]
|
347 |
-
}
|
348 |
-
]
|
349 |
}
|
|
|
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 |
+
"##~ WIDGET CODE | BY: ANXETY ~##\n",
|
26 |
+
"\n",
|
27 |
+
"import os\n",
|
28 |
+
"import json\n",
|
29 |
+
"import time\n",
|
30 |
+
"import ipywidgets as widgets\n",
|
31 |
+
"from ipywidgets import widgets, Layout, Label, Button, VBox, HBox\n",
|
32 |
+
"from IPython.display import display, HTML, Javascript, 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 |
+
" for env_var, (environment, path) in environments.items():\n",
|
43 |
+
" if env_var in os.environ:\n",
|
44 |
+
" return environment, path, free_plan\n",
|
45 |
+
"\n",
|
46 |
+
"env, root_path, free_plan = detect_environment()\n",
|
47 |
+
"webui_path = f\"{root_path}/sdw\"\n",
|
48 |
+
"!mkdir -p {root_path}\n",
|
49 |
+
"\n",
|
50 |
+
"\n",
|
51 |
+
"# ==================== CSS JS ====================\n",
|
52 |
+
"##~ custom background images V1.5 ~##\n",
|
53 |
+
"import argparse\n",
|
54 |
+
"parser = argparse.ArgumentParser(description='This script processes an background image.')\n",
|
55 |
+
"parser.add_argument('-i', '--image', type=str, help='URL of the image to process', metavar='')\n",
|
56 |
+
"parser.add_argument('-o', '--opacity', type=float, help='Opacity level for the image, between 0 and 1', metavar='', default=0.3)\n",
|
57 |
+
"parser.add_argument('-b', '--blur', type=str, help='Blur level for the image', metavar='', default=0)\n",
|
58 |
+
"parser.add_argument('-y', type=int, help='Y coordinate for the image in px', metavar='', default=0)\n",
|
59 |
+
"parser.add_argument('-x', type=int, help='X coordinate for the image in px', metavar='', default=0)\n",
|
60 |
+
"parser.add_argument('-s', '--scale', type=int, help='Scale image in %%', metavar='', default=100)\n",
|
61 |
+
"parser.add_argument('-m', '--mode', action='store_true', help='Removes repetitive image tiles')\n",
|
62 |
+
"parser.add_argument('-t', '--transparent', action='store_true', help='Makes input/selection fields 35%% more transparent')\n",
|
63 |
+
"parser.add_argument('-bf', '--blur-fields', type=str, help='Background blur level for input/selection fields', metavar='', default=2)\n",
|
64 |
+
"\n",
|
65 |
+
"args = parser.parse_args()\n",
|
66 |
+
"\n",
|
67 |
+
"url_img = args.image\n",
|
68 |
+
"opacity_img = args.opacity\n",
|
69 |
+
"blur_img = args.blur\n",
|
70 |
+
"y_img = args.y\n",
|
71 |
+
"x_img = args.x\n",
|
72 |
+
"scale_img = args.scale\n",
|
73 |
+
"blur_fields = args.blur_fields\n",
|
74 |
+
"\n",
|
75 |
+
"## ---\n",
|
76 |
+
"\"\"\" WTF KAGGLE - WHAT THE FUCK IS THE DIFFERENCE OF 35 PIXELS!?!?!? \"\"\"\n",
|
77 |
+
"fix_heigh_img = \"-810px\" if env == \"Kaggle\" else \"-775px\"\n",
|
78 |
+
"\n",
|
79 |
+
"\"\"\" transperent fields \"\"\"\n",
|
80 |
+
"t_bg_alpha = \"1\" if not args.transparent else \"0.65\"\n",
|
81 |
+
"\n",
|
82 |
+
"\"\"\" mode img - repeats \"\"\"\n",
|
83 |
+
"mode_img = \"repeat\" if not args.mode else \"no-repeat\"\n",
|
84 |
+
"\n",
|
85 |
+
"container_background = f'''\n",
|
86 |
+
"<style>\n",
|
87 |
+
":root {{\n",
|
88 |
+
" /* for background container*/\n",
|
89 |
+
" --img_background: url({url_img});\n",
|
90 |
+
" --img_opacity: {opacity_img};\n",
|
91 |
+
" --img_blur: {blur_img}px;\n",
|
92 |
+
" --image_y: {y_img}px;\n",
|
93 |
+
" --image_x: {x_img}px;\n",
|
94 |
+
" --img_scale: {scale_img}%;\n",
|
95 |
+
" --img_mode: {mode_img};\n",
|
96 |
+
" --img_height_dif: {fix_heigh_img};\n",
|
97 |
+
"\n",
|
98 |
+
" /* for fields */\n",
|
99 |
+
" --bg-field-color: rgba(28, 28, 28, {t_bg_alpha}); /* -> #1c1c1c */\n",
|
100 |
+
" --bg-field-color-hover: rgba(38, 38, 38, {t_bg_alpha}); /* -> #262626; */\n",
|
101 |
+
" --bg-field-blur-level: {blur_fields}px;\n",
|
102 |
+
"}}\n",
|
103 |
+
"'''\n",
|
104 |
+
"\n",
|
105 |
+
"display(HTML(container_background))\n",
|
106 |
+
"\n",
|
107 |
+
"# Main CSS\n",
|
108 |
+
"css_file_path = f\"{root_path}/CSS/main_widgets.css\"\n",
|
109 |
+
"with open(css_file_path , \"r\") as f:\n",
|
110 |
+
" CSS = f.read()\n",
|
111 |
+
"display(HTML(f\"<style>{CSS}</style>\"))\n",
|
112 |
+
"\n",
|
113 |
+
"# Main JS\n",
|
114 |
+
"JS = '''\n",
|
115 |
+
"<!-- TOGGLE 'CustomDL' SCRIPT -->\n",
|
116 |
+
"<script>\n",
|
117 |
+
"function toggleContainer() {\n",
|
118 |
+
" let downloadContainer = document.querySelector('.container_custom_downlad');\n",
|
119 |
+
" let info = document.querySelector('.info');\n",
|
120 |
+
"\n",
|
121 |
+
" downloadContainer.classList.toggle('expanded');\n",
|
122 |
+
" info.classList.toggle('showed');\n",
|
123 |
+
"}\n",
|
124 |
+
"</script>\n",
|
125 |
+
"'''\n",
|
126 |
+
"display(HTML(JS))\n",
|
127 |
+
"\n",
|
128 |
+
"# ==================== WIDGETS V2 ====================\n",
|
129 |
+
"HR = widgets.HTML('<hr>')\n",
|
130 |
+
"\n",
|
131 |
+
"class WidgetFactory:\n",
|
132 |
+
" def __init__(self, style=None, layout=None):\n",
|
133 |
+
" self.style = style if style else {'description_width': 'initial'}\n",
|
134 |
+
" self.layout = layout if layout else widgets.Layout(max_width='1080px', width='100%')\n",
|
135 |
+
"\n",
|
136 |
+
" def create_html(self, content, class_name=None):\n",
|
137 |
+
" html_widget = widgets.HTML(content)\n",
|
138 |
+
" if class_name:\n",
|
139 |
+
" html_widget.add_class(class_name)\n",
|
140 |
+
" return html_widget\n",
|
141 |
+
"\n",
|
142 |
+
" def create_header(self, name):\n",
|
143 |
+
" return widgets.HTML(f'<div class=\"header\">{name}<div>')\n",
|
144 |
+
"\n",
|
145 |
+
" def create_dropdown(self, options, value, description):\n",
|
146 |
+
" return widgets.Dropdown(options=options, value=value, description=description, style=self.style, layout=self.layout)\n",
|
147 |
+
"\n",
|
148 |
+
" def create_text(self, description, placeholder='', value=''):\n",
|
149 |
+
" return widgets.Text(description=description, placeholder=placeholder, value=value, style=self.style, layout=self.layout)\n",
|
150 |
+
"\n",
|
151 |
+
" def create_checkbox(self, value, description):\n",
|
152 |
+
" return widgets.Checkbox(value=value, description=description, style=self.style, layout=self.layout)\n",
|
153 |
+
"\n",
|
154 |
+
" def create_button(self, description, class_name=None):\n",
|
155 |
+
" button = widgets.Button(description=description)\n",
|
156 |
+
" if class_name:\n",
|
157 |
+
" button.add_class(class_name)\n",
|
158 |
+
" return button\n",
|
159 |
+
"\n",
|
160 |
+
" def create_hbox(self, children):\n",
|
161 |
+
" return widgets.HBox(children)\n",
|
162 |
+
"\n",
|
163 |
+
" def create_vbox(self, children, class_names=None):\n",
|
164 |
+
" vbox = widgets.VBox(children)\n",
|
165 |
+
" if class_names:\n",
|
166 |
+
" for class_name in class_names:\n",
|
167 |
+
" vbox.add_class(class_name)\n",
|
168 |
+
" return vbox\n",
|
169 |
+
"\n",
|
170 |
+
" def display(self, widget):\n",
|
171 |
+
" display(widget)\n",
|
172 |
+
"\n",
|
173 |
+
"# Instantiate the factory\n",
|
174 |
+
"factory = WidgetFactory()\n",
|
175 |
+
"\n",
|
176 |
+
"# --- MODEL ---\n",
|
177 |
+
"model_header = factory.create_header('Model Selection')\n",
|
178 |
+
"model_options = ['none',\n",
|
179 |
+
" '1.Anime (by XpucT) + INP',\n",
|
180 |
+
" '2.BluMix [Anime] [V7] + INP',\n",
|
181 |
+
" '3.Cetus-Mix [Anime] [V4] + INP',\n",
|
182 |
+
" '4.Counterfeit [Anime] [V3] + INP',\n",
|
183 |
+
" '5.CuteColor [Anime] [V3]',\n",
|
184 |
+
" '6.Dark-Sushi-Mix [Anime]',\n",
|
185 |
+
" '7.Deliberate [Realism] [V6] + INP',\n",
|
186 |
+
" '8.Meina-Mix [Anime] [V11] + INP',\n",
|
187 |
+
" '9.Mix-Pro [Anime] [V4] + INP']\n",
|
188 |
+
"model_widget = factory.create_dropdown(model_options, '4.Counterfeit [Anime] [V3] + INP', 'Model:')\n",
|
189 |
+
"model_num_widget = factory.create_text('Model Number:', 'Enter the model numbers to be downloaded using comma/space.')\n",
|
190 |
+
"inpainting_model_widget = factory.create_checkbox(False, 'Inpainting Models')\n",
|
191 |
+
"\n",
|
192 |
+
"# Display Model\n",
|
193 |
+
"all_model_box = factory.create_vbox([model_header, model_widget, model_num_widget, inpainting_model_widget], class_names=[\"container\", \"image_1\"])\n",
|
194 |
+
"factory.display(all_model_box)\n",
|
195 |
+
"\n",
|
196 |
+
"# --- VAE ---\n",
|
197 |
+
"vae_header = factory.create_header('VAE Selection')\n",
|
198 |
+
"vae_options = ['none',\n",
|
199 |
+
" '1.Anime.vae',\n",
|
200 |
+
" '2.Anything.vae',\n",
|
201 |
+
" '3.Blessed2.vae',\n",
|
202 |
+
" '4.ClearVae.vae',\n",
|
203 |
+
" '5.WD.vae']\n",
|
204 |
+
"vae_widget = factory.create_dropdown(vae_options, '3.Blessed2.vae', 'Vae:')\n",
|
205 |
+
"vae_num_widget = factory.create_text('Vae Number:', 'Enter the vae numbers to be downloaded using comma/space.')\n",
|
206 |
+
"\n",
|
207 |
+
"# Display Vae\n",
|
208 |
+
"all_vae_box = factory.create_vbox([vae_header, vae_widget, vae_num_widget], class_names=[\"container\", \"image_2\"])\n",
|
209 |
+
"factory.display(all_vae_box)\n",
|
210 |
+
"\n",
|
211 |
+
"# --- ADDITIONAL ---\n",
|
212 |
+
"additional_header = factory.create_header('Additional')\n",
|
213 |
+
"latest_webui_widget = factory.create_checkbox(True, 'Update WebUI')\n",
|
214 |
+
"latest_exstensions_widget = factory.create_checkbox(True, 'Update Extensions')\n",
|
215 |
+
"change_webui_widget = factory.create_dropdown(['A1111', 'Forge'], 'A1111', 'Change WebUI:')\n",
|
216 |
+
"detailed_download_widget = factory.create_dropdown(['off', 'on'], 'off', 'Detailed Download:')\n",
|
217 |
+
"choose_changes_widget = factory.create_hbox([latest_webui_widget, latest_exstensions_widget, change_webui_widget, detailed_download_widget])\n",
|
218 |
+
"\n",
|
219 |
+
"controlnet_options = ['none', 'ALL', '1.canny',\n",
|
220 |
+
" '2.openpose', '3.depth',\n",
|
221 |
+
" '4.normal_map', '5.mlsd',\n",
|
222 |
+
" '6.lineart', '7.soft_edge',\n",
|
223 |
+
" '8.scribble', '9.segmentation',\n",
|
224 |
+
" '10.shuffle', '11.tile',\n",
|
225 |
+
" '12.inpaint', '13.instruct_p2p']\n",
|
226 |
+
"controlnet_widget = factory.create_dropdown(controlnet_options, 'none', 'ControlNet:')\n",
|
227 |
+
"controlnet_num_widget = factory.create_text('ControlNet Number:', 'Enter the ControlNet model numbers to be downloaded using comma/space.')\n",
|
228 |
+
"commit_hash_widget = factory.create_text('Commit Hash:')\n",
|
229 |
+
"huggingface_token_widget = factory.create_text('HuggingFace Token:')\n",
|
230 |
+
"\n",
|
231 |
+
"ngrok_token_widget = factory.create_text('Ngrok Token:')\n",
|
232 |
+
"ngrock_button = factory.create_html('<a href=\"https://dashboard.ngrok.com/get-started/your-authtoken\" target=\"_blank\">Получить Ngrok Токен</a>', class_name=\"button_ngrok\")\n",
|
233 |
+
"ngrok_widget = factory.create_hbox([ngrok_token_widget, ngrock_button])\n",
|
234 |
+
"\n",
|
235 |
+
"zrok_token_widget = factory.create_text('Zrok Token:')\n",
|
236 |
+
"zrok_button = factory.create_html('<a href=\"https://colab.research.google.com/drive/1d2sjWDJi_GYBUavrHSuQyHTDuLy36WpU\" target=\"_blank\">Зарегать Zrok Токен</a>', class_name=\"button_ngrok\")\n",
|
237 |
+
"zrok_widget = factory.create_hbox([zrok_token_widget, zrok_button])\n",
|
238 |
+
"\n",
|
239 |
+
"commandline_arguments_options = \"--listen --enable-insecure-extension-access --theme dark --no-half-vae --disable-console-progressbars --xformers\"\n",
|
240 |
+
"commandline_arguments_widget = factory.create_text('Arguments:', value=commandline_arguments_options)\n",
|
241 |
+
"\n",
|
242 |
+
"# Display Additional\n",
|
243 |
+
"additional_widget_list = [additional_header,\n",
|
244 |
+
" choose_changes_widget,\n",
|
245 |
+
" HR,\n",
|
246 |
+
" controlnet_widget,\n",
|
247 |
+
" controlnet_num_widget,\n",
|
248 |
+
" commit_hash_widget,\n",
|
249 |
+
" huggingface_token_widget,\n",
|
250 |
+
" ngrok_widget,\n",
|
251 |
+
" zrok_widget,\n",
|
252 |
+
" HR,\n",
|
253 |
+
" commandline_arguments_widget]\n",
|
254 |
+
"\n",
|
255 |
+
"if free_plan and env == \"Google Colab\": # remove ngrok from colab\n",
|
256 |
+
" additional_widget_list.remove(ngrok_widget)\n",
|
257 |
+
"if os.path.exists(webui_path): # remove selection after selection ;3\n",
|
258 |
+
" choose_changes_widget.children = [widget for widget in choose_changes_widget.children if widget != change_webui_widget]\n",
|
259 |
+
"\n",
|
260 |
+
"all_additional_box = factory.create_vbox(additional_widget_list, class_names=[\"container\", \"image_3\"])\n",
|
261 |
+
"factory.display(all_additional_box)\n",
|
262 |
+
"\n",
|
263 |
+
"# --- CUSTOM DOWNLOAD ---\n",
|
264 |
+
"custom_download_header_popup = factory.create_html('''\n",
|
265 |
+
"<style>\n",
|
266 |
+
"/* Term Colors */\n",
|
267 |
+
".sample_label {color: #dbafff;}\n",
|
268 |
+
".braces {color: #ffff00;}\n",
|
269 |
+
".extension {color: #eb934b;}\n",
|
270 |
+
".file_name {color: #ffffd8;}\n",
|
271 |
+
"</style>\n",
|
272 |
+
"\n",
|
273 |
+
"<div class=\"header\" style=\"cursor: pointer;\" onclick=\"toggleContainer()\">Custom Download</div>\n",
|
274 |
+
"<!-- PopUp Window -->\n",
|
275 |
+
"<div class=\"info\">INFO</div>\n",
|
276 |
+
"<div class=\"popup\">\n",
|
277 |
+
" 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",
|
278 |
+
" after the URL without spaces.\n",
|
279 |
+
" <span style=\"color: #ff9999\">For files, be sure to specify</span> - <span class=\"extension\">Filename Extension.</span>\n",
|
280 |
+
" <div class=\"sample\">\n",
|
281 |
+
" <span class=\"sample_label\">Example for File:</span>\n",
|
282 |
+
" 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",
|
283 |
+
" <br>\n",
|
284 |
+
" <span class=\"sample_label\">Example for Extension:</span>\n",
|
285 |
+
" 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",
|
286 |
+
" </div>\n",
|
287 |
+
"</div>\n",
|
288 |
+
"''')\n",
|
289 |
+
"\n",
|
290 |
+
"Model_url_widget = factory.create_text('Model:')\n",
|
291 |
+
"Vae_url_widget = factory.create_text('Vae:')\n",
|
292 |
+
"LoRA_url_widget = factory.create_text('LoRa:')\n",
|
293 |
+
"Embedding_url_widget = factory.create_text('Embedding:')\n",
|
294 |
+
"Extensions_url_widget = factory.create_text('Extensions:')\n",
|
295 |
+
"custom_file_urls_widget = factory.create_text('File (txt):')\n",
|
296 |
+
"\n",
|
297 |
+
"# Display CustomDl\n",
|
298 |
+
"all_custom_box = factory.create_vbox([\n",
|
299 |
+
" custom_download_header_popup, Model_url_widget, Vae_url_widget, LoRA_url_widget, Embedding_url_widget, Extensions_url_widget, custom_file_urls_widget\n",
|
300 |
+
"], class_names=[\"container\", \"image_4\", \"container_custom_downlad\"])\n",
|
301 |
+
"factory.display(all_custom_box)\n",
|
302 |
+
"\n",
|
303 |
+
"# --- Save Button ---\n",
|
304 |
+
"save_button = factory.create_button('Save', class_name=\"button_save\")\n",
|
305 |
+
"factory.display(save_button)\n",
|
306 |
+
"\n",
|
307 |
+
"\n",
|
308 |
+
"# ============ Load / Save - Settings V2 ============\n",
|
309 |
+
"SETTINGS_FILE = f'{root_path}/settings.json'\n",
|
310 |
+
"\n",
|
311 |
+
"SETTINGS_KEYS = [\n",
|
312 |
+
" 'model', 'model_num', 'inpainting_model',\n",
|
313 |
+
" 'vae', 'vae_num', 'latest_webui', 'latest_exstensions',\n",
|
314 |
+
" 'change_webui', 'detailed_download', 'controlnet',\n",
|
315 |
+
" 'controlnet_num', 'commit_hash', 'huggingface_token',\n",
|
316 |
+
" 'ngrok_token', 'zrok_token', 'commandline_arguments',\n",
|
317 |
+
" 'Model_url', 'Vae_url', 'LoRA_url', 'Embedding_url',\n",
|
318 |
+
" 'Extensions_url', 'custom_file_urls'\n",
|
319 |
+
"]\n",
|
320 |
+
"\n",
|
321 |
+
"def save_settings():\n",
|
322 |
+
" settings = {key: globals()[f\"{key}_widget\"].value for key in SETTINGS_KEYS}\n",
|
323 |
+
" with open(SETTINGS_FILE, 'w') as f:\n",
|
324 |
+
" json.dump(settings, f, indent=2)\n",
|
325 |
+
"\n",
|
326 |
+
"def load_settings():\n",
|
327 |
+
" if os.path.exists(SETTINGS_FILE):\n",
|
328 |
+
" with open(SETTINGS_FILE, 'r') as f:\n",
|
329 |
+
" settings = json.load(f)\n",
|
330 |
+
" for key in SETTINGS_KEYS:\n",
|
331 |
+
" globals()[f\"{key}_widget\"].value = settings.get(key, \"\")\n",
|
332 |
+
"\n",
|
333 |
+
"def hide_widgets():\n",
|
334 |
+
" widgets_list = [all_model_box, all_vae_box, all_additional_box, all_custom_box, save_button]\n",
|
335 |
+
" for widget in widgets_list:\n",
|
336 |
+
" widget.add_class(\"hide\")\n",
|
337 |
+
" time.sleep(0.5)\n",
|
338 |
+
" widgets.Widget.close_all()\n",
|
339 |
+
"\n",
|
340 |
+
"def save_data(button):\n",
|
341 |
+
" save_settings()\n",
|
342 |
+
" hide_widgets()\n",
|
343 |
+
"\n",
|
344 |
+
"load_settings()\n",
|
345 |
+
"save_button.on_click(save_data)"
|
346 |
+
]
|
347 |
+
}
|
348 |
+
]
|
349 |
}
|
files_cells/notebooks/ru/auto_cleaner_ru.ipynb
CHANGED
@@ -1,165 +1,165 @@
|
|
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 |
-
"##~ AutoCleaner V3.7 CODE | BY: ANXETY ~##\n",
|
26 |
-
"\n",
|
27 |
-
"import os\n",
|
28 |
-
"import time\n",
|
29 |
-
"import ipywidgets as widgets\n",
|
30 |
-
"from ipywidgets import Label, Button, VBox, HBox\n",
|
31 |
-
"from IPython.display import display, HTML\n",
|
32 |
-
"\n",
|
33 |
-
"\n",
|
34 |
-
"# ================= DETECT ENV =================\n",
|
35 |
-
"def detect_environment():\n",
|
36 |
-
" free_plan = (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024 ** 3) <= 20)\n",
|
37 |
-
" environments = {\n",
|
38 |
-
" 'COLAB_GPU': ('Google Colab', \"/root\" if free_plan else \"/content\"),\n",
|
39 |
-
" 'KAGGLE_URL_BASE': ('Kaggle', \"/kaggle/working/content\")\n",
|
40 |
-
" }\n",
|
41 |
-
" for env_var, (environment, path) in environments.items():\n",
|
42 |
-
" if env_var in os.environ:\n",
|
43 |
-
" return environment, path, free_plan\n",
|
44 |
-
"\n",
|
45 |
-
"env, root_path, free_plan = detect_environment()\n",
|
46 |
-
"webui_path = f\"{root_path}/sdw\"\n",
|
47 |
-
"\n",
|
48 |
-
"\n",
|
49 |
-
"# ==================== CSS ====================\n",
|
50 |
-
"# Main CSS\n",
|
51 |
-
"css_file_path = f\"{root_path}/CSS/auto_cleaner.css\"\n",
|
52 |
-
"with open(css_file_path , \"r\") as f:\n",
|
53 |
-
" CSS_AC = f.read()\n",
|
54 |
-
"display(HTML(f\"<style>{CSS_AC}</style>\"))\n",
|
55 |
-
"\n",
|
56 |
-
"\n",
|
57 |
-
"# ================ AutoCleaner function ================\n",
|
58 |
-
"directories = {\n",
|
59 |
-
" \"Изображения\": f\"{webui_path}/output\",\n",
|
60 |
-
" \"Модели\": f\"{webui_path}/models/Stable-diffusion/\",\n",
|
61 |
-
" \"Vae\": f\"{webui_path}/models/VAE/\",\n",
|
62 |
-
" \"LoRa\": f\"{webui_path}/models/Lora/\",\n",
|
63 |
-
" \"ControlNet Модели\": f\"{webui_path}/models/ControlNet/\"\n",
|
64 |
-
"}\n",
|
65 |
-
"\n",
|
66 |
-
"\"\"\" functions \"\"\"\n",
|
67 |
-
"def clean_directory(directory):\n",
|
68 |
-
" deleted_files = 0\n",
|
69 |
-
" image_dir = directories['Изображения']\n",
|
70 |
-
"\n",
|
71 |
-
" for root, dirs, files in os.walk(directory):\n",
|
72 |
-
" for file in files:\n",
|
73 |
-
" file_path = os.path.join(root, file)\n",
|
74 |
-
"\n",
|
75 |
-
" if file.endswith(\".txt\"):\n",
|
76 |
-
" continue\n",
|
77 |
-
" if file.endswith((\".safetensors\", \".pt\")) or root == image_dir: # fix for image counter\n",
|
78 |
-
" deleted_files += 1\n",
|
79 |
-
"\n",
|
80 |
-
" os.remove(file_path)\n",
|
81 |
-
" return deleted_files\n",
|
82 |
-
"\n",
|
83 |
-
"def update_memory_info():\n",
|
84 |
-
" disk_space = psutil.disk_usage(os.getcwd())\n",
|
85 |
-
" total = disk_space.total / (1024 ** 3)\n",
|
86 |
-
" used = disk_space.used / (1024 ** 3)\n",
|
87 |
-
" free = disk_space.free / (1024 ** 3)\n",
|
88 |
-
"\n",
|
89 |
-
" storage_info.value = f'''\n",
|
90 |
-
" <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",
|
91 |
-
" '''\n",
|
92 |
-
"\n",
|
93 |
-
"def on_execute_button_press(button):\n",
|
94 |
-
" selected_cleaners = auto_cleaner_widget.value\n",
|
95 |
-
" deleted_files_dict = {}\n",
|
96 |
-
"\n",
|
97 |
-
" for option in selected_cleaners:\n",
|
98 |
-
" if option in directories:\n",
|
99 |
-
" deleted_files_dict[option] = clean_directory(directories[option])\n",
|
100 |
-
"\n",
|
101 |
-
" output.clear_output()\n",
|
102 |
-
"\n",
|
103 |
-
" with output:\n",
|
104 |
-
" for message in generate_messages(deleted_files_dict):\n",
|
105 |
-
" message_widget = HTML(f'<p class=\"output_message_AC\">{message}</p>')\n",
|
106 |
-
" display(message_widget)\n",
|
107 |
-
"\n",
|
108 |
-
" update_memory_info()\n",
|
109 |
-
"\n",
|
110 |
-
"def on_clear_button_press(button):\n",
|
111 |
-
" container.add_class(\"hide\")\n",
|
112 |
-
" time.sleep(0.5)\n",
|
113 |
-
" widgets.Widget.close_all()\n",
|
114 |
-
"\n",
|
115 |
-
"def generate_messages(deleted_files_dict):\n",
|
116 |
-
" messages = []\n",
|
117 |
-
" word_variants = {\n",
|
118 |
-
" \"Изображения\": \"Изображений\",\n",
|
119 |
-
" \"Модели\": \"Моделей\",\n",
|
120 |
-
" \"Vae\": \"Vae\",\n",
|
121 |
-
" \"LoRa\": \"LoRa\",\n",
|
122 |
-
" \"ControlNet Модели\": \"ControlNet Моделей\"\n",
|
123 |
-
" }\n",
|
124 |
-
" for key, value in deleted_files_dict.items():\n",
|
125 |
-
" object_word = word_variants.get(key)\n",
|
126 |
-
" messages.append(f\"Удалено {value} {object_word}\")\n",
|
127 |
-
" return messages\n",
|
128 |
-
"\n",
|
129 |
-
"\n",
|
130 |
-
"# --- storage memory ---\n",
|
131 |
-
"import psutil\n",
|
132 |
-
"disk_space = psutil.disk_usage(os.getcwd())\n",
|
133 |
-
"total = disk_space.total / (1024 ** 3)\n",
|
134 |
-
"used = disk_space.used / (1024 ** 3)\n",
|
135 |
-
"free = disk_space.free / (1024 ** 3)\n",
|
136 |
-
"\n",
|
137 |
-
"\n",
|
138 |
-
"# ================ Widgets ================\n",
|
139 |
-
"# UI Code\n",
|
140 |
-
"AutoCleaner_options = AutoCleaner_options = list(directories.keys())\n",
|
141 |
-
"instruction_label = widgets.HTML('''\n",
|
142 |
-
"<span class=\"instruction_AC\">Используйте <span style=\"color: #B2B2B2;\">ctrl</span> или <span style=\"color: #B2B2B2;\">shift</span> для множественного выбора.</span>\n",
|
143 |
-
"''')\n",
|
144 |
-
"auto_cleaner_widget = widgets.SelectMultiple(options=AutoCleaner_options, layout=widgets.Layout(width=\"auto\")).add_class(\"custom-select-multiple_AC\")\n",
|
145 |
-
"output = widgets.Output().add_class(\"output_AC\")\n",
|
146 |
-
"\n",
|
147 |
-
"execute_button = Button(description='Выполнить Очистку').add_class(\"button_execute_AC\").add_class(\"button_AC\")\n",
|
148 |
-
"execute_button.on_click(on_execute_button_press)\n",
|
149 |
-
"clear_button = Button(description='Скрыть Виджет').add_class(\"button_clear_AC\").add_class(\"button_AC\")\n",
|
150 |
-
"clear_button.on_click(on_clear_button_press)\n",
|
151 |
-
"\n",
|
152 |
-
"storage_info = widgets.HTML(f'''\n",
|
153 |
-
"<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",
|
154 |
-
"''')\n",
|
155 |
-
"\n",
|
156 |
-
"buttons = widgets.HBox([execute_button, clear_button])\n",
|
157 |
-
"lower_information_panel = widgets.HBox([buttons, storage_info]).add_class(\"lower_information_panel_AC\")\n",
|
158 |
-
"\n",
|
159 |
-
"container = VBox([instruction_label, widgets.HTML('<hr>'), auto_cleaner_widget, output, widgets.HTML('<hr>'), lower_information_panel]).add_class(\"container_AC\")\n",
|
160 |
-
"\n",
|
161 |
-
"display(container)"
|
162 |
-
]
|
163 |
-
}
|
164 |
-
]
|
165 |
}
|
|
|
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 |
+
"##~ AutoCleaner V3.7 CODE | BY: ANXETY ~##\n",
|
26 |
+
"\n",
|
27 |
+
"import os\n",
|
28 |
+
"import time\n",
|
29 |
+
"import ipywidgets as widgets\n",
|
30 |
+
"from ipywidgets import Label, Button, VBox, HBox\n",
|
31 |
+
"from IPython.display import display, HTML\n",
|
32 |
+
"\n",
|
33 |
+
"\n",
|
34 |
+
"# ================= DETECT ENV =================\n",
|
35 |
+
"def detect_environment():\n",
|
36 |
+
" free_plan = (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024 ** 3) <= 20)\n",
|
37 |
+
" environments = {\n",
|
38 |
+
" 'COLAB_GPU': ('Google Colab', \"/root\" if free_plan else \"/content\"),\n",
|
39 |
+
" 'KAGGLE_URL_BASE': ('Kaggle', \"/kaggle/working/content\")\n",
|
40 |
+
" }\n",
|
41 |
+
" for env_var, (environment, path) in environments.items():\n",
|
42 |
+
" if env_var in os.environ:\n",
|
43 |
+
" return environment, path, free_plan\n",
|
44 |
+
"\n",
|
45 |
+
"env, root_path, free_plan = detect_environment()\n",
|
46 |
+
"webui_path = f\"{root_path}/sdw\"\n",
|
47 |
+
"\n",
|
48 |
+
"\n",
|
49 |
+
"# ==================== CSS ====================\n",
|
50 |
+
"# Main CSS\n",
|
51 |
+
"css_file_path = f\"{root_path}/CSS/auto_cleaner.css\"\n",
|
52 |
+
"with open(css_file_path , \"r\") as f:\n",
|
53 |
+
" CSS_AC = f.read()\n",
|
54 |
+
"display(HTML(f\"<style>{CSS_AC}</style>\"))\n",
|
55 |
+
"\n",
|
56 |
+
"\n",
|
57 |
+
"# ================ AutoCleaner function ================\n",
|
58 |
+
"directories = {\n",
|
59 |
+
" \"Изображения\": f\"{webui_path}/output\",\n",
|
60 |
+
" \"Модели\": f\"{webui_path}/models/Stable-diffusion/\",\n",
|
61 |
+
" \"Vae\": f\"{webui_path}/models/VAE/\",\n",
|
62 |
+
" \"LoRa\": f\"{webui_path}/models/Lora/\",\n",
|
63 |
+
" \"ControlNet Модели\": f\"{webui_path}/models/ControlNet/\"\n",
|
64 |
+
"}\n",
|
65 |
+
"\n",
|
66 |
+
"\"\"\" functions \"\"\"\n",
|
67 |
+
"def clean_directory(directory):\n",
|
68 |
+
" deleted_files = 0\n",
|
69 |
+
" image_dir = directories['Изображения']\n",
|
70 |
+
"\n",
|
71 |
+
" for root, dirs, files in os.walk(directory):\n",
|
72 |
+
" for file in files:\n",
|
73 |
+
" file_path = os.path.join(root, file)\n",
|
74 |
+
"\n",
|
75 |
+
" if file.endswith(\".txt\"):\n",
|
76 |
+
" continue\n",
|
77 |
+
" if file.endswith((\".safetensors\", \".pt\")) or root == image_dir: # fix for image counter\n",
|
78 |
+
" deleted_files += 1\n",
|
79 |
+
"\n",
|
80 |
+
" os.remove(file_path)\n",
|
81 |
+
" return deleted_files\n",
|
82 |
+
"\n",
|
83 |
+
"def update_memory_info():\n",
|
84 |
+
" disk_space = psutil.disk_usage(os.getcwd())\n",
|
85 |
+
" total = disk_space.total / (1024 ** 3)\n",
|
86 |
+
" used = disk_space.used / (1024 ** 3)\n",
|
87 |
+
" free = disk_space.free / (1024 ** 3)\n",
|
88 |
+
"\n",
|
89 |
+
" storage_info.value = f'''\n",
|
90 |
+
" <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",
|
91 |
+
" '''\n",
|
92 |
+
"\n",
|
93 |
+
"def on_execute_button_press(button):\n",
|
94 |
+
" selected_cleaners = auto_cleaner_widget.value\n",
|
95 |
+
" deleted_files_dict = {}\n",
|
96 |
+
"\n",
|
97 |
+
" for option in selected_cleaners:\n",
|
98 |
+
" if option in directories:\n",
|
99 |
+
" deleted_files_dict[option] = clean_directory(directories[option])\n",
|
100 |
+
"\n",
|
101 |
+
" output.clear_output()\n",
|
102 |
+
"\n",
|
103 |
+
" with output:\n",
|
104 |
+
" for message in generate_messages(deleted_files_dict):\n",
|
105 |
+
" message_widget = HTML(f'<p class=\"output_message_AC\">{message}</p>')\n",
|
106 |
+
" display(message_widget)\n",
|
107 |
+
"\n",
|
108 |
+
" update_memory_info()\n",
|
109 |
+
"\n",
|
110 |
+
"def on_clear_button_press(button):\n",
|
111 |
+
" container.add_class(\"hide\")\n",
|
112 |
+
" time.sleep(0.5)\n",
|
113 |
+
" widgets.Widget.close_all()\n",
|
114 |
+
"\n",
|
115 |
+
"def generate_messages(deleted_files_dict):\n",
|
116 |
+
" messages = []\n",
|
117 |
+
" word_variants = {\n",
|
118 |
+
" \"Изображения\": \"Изображений\",\n",
|
119 |
+
" \"Модели\": \"Моделей\",\n",
|
120 |
+
" \"Vae\": \"Vae\",\n",
|
121 |
+
" \"LoRa\": \"LoRa\",\n",
|
122 |
+
" \"ControlNet Модели\": \"ControlNet Моделей\"\n",
|
123 |
+
" }\n",
|
124 |
+
" for key, value in deleted_files_dict.items():\n",
|
125 |
+
" object_word = word_variants.get(key)\n",
|
126 |
+
" messages.append(f\"Удалено {value} {object_word}\")\n",
|
127 |
+
" return messages\n",
|
128 |
+
"\n",
|
129 |
+
"\n",
|
130 |
+
"# --- storage memory ---\n",
|
131 |
+
"import psutil\n",
|
132 |
+
"disk_space = psutil.disk_usage(os.getcwd())\n",
|
133 |
+
"total = disk_space.total / (1024 ** 3)\n",
|
134 |
+
"used = disk_space.used / (1024 ** 3)\n",
|
135 |
+
"free = disk_space.free / (1024 ** 3)\n",
|
136 |
+
"\n",
|
137 |
+
"\n",
|
138 |
+
"# ================ Widgets ================\n",
|
139 |
+
"# UI Code\n",
|
140 |
+
"AutoCleaner_options = AutoCleaner_options = list(directories.keys())\n",
|
141 |
+
"instruction_label = widgets.HTML('''\n",
|
142 |
+
"<span class=\"instruction_AC\">Используйте <span style=\"color: #B2B2B2;\">ctrl</span> или <span style=\"color: #B2B2B2;\">shift</span> для множественного выбора.</span>\n",
|
143 |
+
"''')\n",
|
144 |
+
"auto_cleaner_widget = widgets.SelectMultiple(options=AutoCleaner_options, layout=widgets.Layout(width=\"auto\")).add_class(\"custom-select-multiple_AC\")\n",
|
145 |
+
"output = widgets.Output().add_class(\"output_AC\")\n",
|
146 |
+
"\n",
|
147 |
+
"execute_button = Button(description='Выполнить Очистку').add_class(\"button_execute_AC\").add_class(\"button_AC\")\n",
|
148 |
+
"execute_button.on_click(on_execute_button_press)\n",
|
149 |
+
"clear_button = Button(description='Скрыть Виджет').add_class(\"button_clear_AC\").add_class(\"button_AC\")\n",
|
150 |
+
"clear_button.on_click(on_clear_button_press)\n",
|
151 |
+
"\n",
|
152 |
+
"storage_info = widgets.HTML(f'''\n",
|
153 |
+
"<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",
|
154 |
+
"''')\n",
|
155 |
+
"\n",
|
156 |
+
"buttons = widgets.HBox([execute_button, clear_button])\n",
|
157 |
+
"lower_information_panel = widgets.HBox([buttons, storage_info]).add_class(\"lower_information_panel_AC\")\n",
|
158 |
+
"\n",
|
159 |
+
"container = VBox([instruction_label, widgets.HTML('<hr>'), auto_cleaner_widget, output, widgets.HTML('<hr>'), lower_information_panel]).add_class(\"container_AC\")\n",
|
160 |
+
"\n",
|
161 |
+
"display(container)"
|
162 |
+
]
|
163 |
+
}
|
164 |
+
]
|
165 |
}
|
files_cells/notebooks/ru/downloading_ru.ipynb
CHANGED
@@ -1,641 +1,696 @@
|
|
1 |
-
{
|
2 |
-
"cells": [
|
3 |
-
{
|
4 |
-
"cell_type": "code",
|
5 |
-
"execution_count": null,
|
6 |
-
"metadata": {
|
7 |
-
"id": "2lJmbqrs3Mu8"
|
8 |
-
},
|
9 |
-
"outputs": [],
|
10 |
-
"source": [
|
11 |
-
"##~ DOWNLOADING CODE | BY: ANXETY ~##\n",
|
12 |
-
"\n",
|
13 |
-
"import os\n",
|
14 |
-
"import re\n",
|
15 |
-
"import time\n",
|
16 |
-
"import json\n",
|
17 |
-
"import shutil\n",
|
18 |
-
"import zipfile\n",
|
19 |
-
"import requests\n",
|
20 |
-
"import subprocess\n",
|
21 |
-
"from datetime import timedelta\n",
|
22 |
-
"from subprocess import getoutput\n",
|
23 |
-
"from IPython.utils import capture\n",
|
24 |
-
"from IPython.display import clear_output\n",
|
25 |
-
"from urllib.parse import urlparse, parse_qs\n",
|
26 |
-
"\n",
|
27 |
-
"\n",
|
28 |
-
"# ================= DETECT ENV =================\n",
|
29 |
-
"def detect_environment():\n",
|
30 |
-
" free_plan = (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024 ** 3) <= 20)\n",
|
31 |
-
" environments = {\n",
|
32 |
-
" 'COLAB_GPU': ('Google Colab', \"/root\" if free_plan else \"/content\"),\n",
|
33 |
-
" 'KAGGLE_URL_BASE': ('Kaggle', \"/kaggle/working/content\")\n",
|
34 |
-
" }\n",
|
35 |
-
" for env_var, (environment, path) in environments.items():\n",
|
36 |
-
" if env_var in os.environ:\n",
|
37 |
-
" return environment, path, free_plan\n",
|
38 |
-
"\n",
|
39 |
-
"env, root_path, free_plan = detect_environment()\n",
|
40 |
-
"webui_path = f\"{root_path}/sdw\"\n",
|
41 |
-
"\n",
|
42 |
-
"\n",
|
43 |
-
"# ================ LIBRARIES V2 ================\n",
|
44 |
-
"flag_file = f\"{root_path}/libraries_installed.txt\"\n",
|
45 |
-
"\n",
|
46 |
-
"if not os.path.exists(flag_file):\n",
|
47 |
-
" print(\"💿 Установка библиотек, это займет какое-то время:\\n\")\n",
|
48 |
-
"\n",
|
49 |
-
" install_lib = {\n",
|
50 |
-
" \"aria2\": \"apt -y install aria2\",\n",
|
51 |
-
" \"localtunnel\": \"npm install -g localtunnel\",\n",
|
52 |
-
" \"insightface\": \"pip install insightface\"\n",
|
53 |
-
" }\n",
|
54 |
-
"\n",
|
55 |
-
" additional_libs = {\n",
|
56 |
-
" \"Google Colab\": {\n",
|
57 |
-
" \"xformers\": \"pip install xformers==0.0.26.post1 --no-deps\"\n",
|
58 |
-
" },\n",
|
59 |
-
" \"Kaggle\": {\n",
|
60 |
-
" \"xformers\": \"pip install xformers==0.0.26.post1\",\n",
|
61 |
-
" # \"torch\": \"pip install torch==2.1.2+cu121 torchvision==0.16.2+cu121 torchaudio==2.1.2 --extra-index-url https://download.pytorch.org/whl/cu121\",\n",
|
62 |
-
" \"aiohttp\": \"pip install trash-cli && trash-put /opt/conda/lib/python3.10/site-packages/aiohttp*\" # fix install req\n",
|
63 |
-
" }\n",
|
64 |
-
" }\n",
|
65 |
-
"\n",
|
66 |
-
" if env in additional_libs:\n",
|
67 |
-
" install_lib.update(additional_libs[env])\n",
|
68 |
-
"\n",
|
69 |
-
" # Loop through libraries\n",
|
70 |
-
" for index, (package, install_cmd) in enumerate(install_lib.items(), start=1):\n",
|
71 |
-
" print(f\"\\r[{index}/{len(install_lib)}] \\033[32m>>\\033[0m Installing \\033[33m{package}\\033[0m...\" + \" \"*35, end='')\n",
|
72 |
-
" subprocess.run(install_cmd, shell=True, capture_output=True)\n",
|
73 |
-
"\n",
|
74 |
-
" # Additional specific packages\n",
|
75 |
-
" with capture.capture_output() as cap:\n",
|
76 |
-
" !curl -s -OL https://github.com/DEX-1101/sd-webui-notebook/raw/main/res/new_tunnel --output-dir {root_path}\n",
|
77 |
-
" !curl -s -Lo /usr/bin/cl https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 && chmod +x /usr/bin/cl\n",
|
78 |
-
" !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",
|
79 |
-
" del cap\n",
|
80 |
-
"\n",
|
81 |
-
" clear_output()\n",
|
82 |
-
"\n",
|
83 |
-
" # Save file install lib\n",
|
84 |
-
" with open(flag_file, \"w\") as f:\n",
|
85 |
-
" f.write(\">W<'\")\n",
|
86 |
-
"\n",
|
87 |
-
" print(\"🍪 Библиотеки установлены!\" + \" \"*35)\n",
|
88 |
-
" time.sleep(2)\n",
|
89 |
-
" clear_output()\n",
|
90 |
-
"\n",
|
91 |
-
"\n",
|
92 |
-
"# ================= loading settings V4 =================\n",
|
93 |
-
"def load_settings(path):\n",
|
94 |
-
" if os.path.exists(path):\n",
|
95 |
-
" with open(path, 'r') as file:\n",
|
96 |
-
" return json.load(file)\n",
|
97 |
-
" return {}\n",
|
98 |
-
"\n",
|
99 |
-
"settings = load_settings(f'{root_path}/settings.json')\n",
|
100 |
-
"\n",
|
101 |
-
"VARIABLES = [\n",
|
102 |
-
" 'model', 'model_num', 'inpainting_model',\n",
|
103 |
-
" 'vae', 'vae_num', 'latest_webui', 'latest_exstensions',\n",
|
104 |
-
" 'change_webui', 'detailed_download', 'controlnet',\n",
|
105 |
-
" 'controlnet_num', 'commit_hash', 'huggingface_token',\n",
|
106 |
-
" 'ngrok_token', 'zrok_token', 'commandline_arguments',\n",
|
107 |
-
" 'Model_url', 'Vae_url', 'LoRA_url', 'Embedding_url',\n",
|
108 |
-
" 'Extensions_url', 'custom_file_urls'\n",
|
109 |
-
"]\n",
|
110 |
-
"\n",
|
111 |
-
"locals().update({key: settings.get(key) for key in VARIABLES})\n",
|
112 |
-
"\n",
|
113 |
-
"\n",
|
114 |
-
"# ================= OTHER =================\n",
|
115 |
-
"try:\n",
|
116 |
-
" start_colab\n",
|
117 |
-
"except:\n",
|
118 |
-
" start_colab = int(time.time())-5\n",
|
119 |
-
"\n",
|
120 |
-
"# CONFIG DIR\n",
|
121 |
-
"models_dir = f\"{webui_path}/models/Stable-diffusion\"\n",
|
122 |
-
"vaes_dir = f\"{webui_path}/models/VAE\"\n",
|
123 |
-
"embeddings_dir = f\"{webui_path}/embeddings\"\n",
|
124 |
-
"loras_dir = f\"{webui_path}/models/Lora\"\n",
|
125 |
-
"extensions_dir = f\"{webui_path}/extensions\"\n",
|
126 |
-
"control_dir = f\"{webui_path}/models/ControlNet\"\n",
|
127 |
-
"adetailer_dir = f\"{webui_path}/models/adetailer\"\n",
|
128 |
-
"\n",
|
129 |
-
"\n",
|
130 |
-
"# ================= MAIN CODE =================\n",
|
131 |
-
"if not os.path.exists(webui_path):\n",
|
132 |
-
" start_install = int(time.time())\n",
|
133 |
-
" print(\"⌚ Распаковка Stable Diffusion...\" if change_webui != 'Forge' else \"⌚ Распаковка Stable Diffusion (Forge)...\", end='')\n",
|
134 |
-
" with capture.capture_output() as cap:\n",
|
135 |
-
" aria2_command = \"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M\"\n",
|
136 |
-
" url = \"https://huggingface.co/NagisaNao/fast_repo/resolve/main/FULL_REPO.zip\" if change_webui != 'Forge' else \"https://huggingface.co/NagisaNao/fast_repo/resolve/main/FULL_REPO_forge.zip\"\n",
|
137 |
-
" !{aria2_command} {url} -o repo.zip\n",
|
138 |
-
"\n",
|
139 |
-
" !unzip -q -o repo.zip -d {webui_path}\n",
|
140 |
-
" !rm -rf repo.zip\n",
|
141 |
-
"\n",
|
142 |
-
" %cd {root_path}\n",
|
143 |
-
" os.environ[\"SAFETENSORS_FAST_GPU\"]='1'\n",
|
144 |
-
" os.environ[\"CUDA_MODULE_LOADING\"]=\"LAZY\"\n",
|
145 |
-
" os.environ[\"TF_CPP_MIN_LOG_LEVEL\"] = \"3\"\n",
|
146 |
-
" os.environ[\"PYTHONWARNINGS\"] = \"ignore\"\n",
|
147 |
-
"\n",
|
148 |
-
" !echo -n {start_colab} > {webui_path}/static/colabTimer.txt\n",
|
149 |
-
" del cap\n",
|
150 |
-
" install_time = timedelta(seconds=time.time()-start_install)\n",
|
151 |
-
" print(\"\\r🚀 Распаковка Завершена! За\",\"%02d:%02d:%02d ⚡\\n\" % (install_time.seconds / 3600, (install_time.seconds / 60) % 60, install_time.seconds % 60), end='', flush=True)\n",
|
152 |
-
"else:\n",
|
153 |
-
" print(\"🚀 Все распакованно... Пропуск. ⚡\")\n",
|
154 |
-
" start_colab = float(open(f'{webui_path}/static/colabTimer.txt', 'r').read())\n",
|
155 |
-
" time_since_start = str(timedelta(seconds=time.time()-start_colab)).split('.')[0]\n",
|
156 |
-
" print(f\"⌚️ Вы проводите эту сессию в течение - \\033[33m{time_since_start}\\033[0m\")\n",
|
157 |
-
"\n",
|
158 |
-
"\n",
|
159 |
-
"## Changes extensions and WebUi\n",
|
160 |
-
"if latest_webui or latest_exstensions:\n",
|
161 |
-
" action = \"Обновление WebUI и
|
162 |
-
" print(f\"⌚️ {action}...\", end='', flush=True)\n",
|
163 |
-
" with capture.capture_output() as cap:\n",
|
164 |
-
" !git config --global user.email \"[email protected]\"\n",
|
165 |
-
" !git config --global user.name \"Your Name\"\n",
|
166 |
-
"\n",
|
167 |
-
" ## Update Webui\n",
|
168 |
-
" if latest_webui:\n",
|
169 |
-
" %cd {webui_path}\n",
|
170 |
-
" !git restore .\n",
|
171 |
-
" !git pull -X theirs --rebase --autostash\n",
|
172 |
-
"\n",
|
173 |
-
" ## Update extensions\n",
|
174 |
-
" if latest_exstensions:\n",
|
175 |
-
" !{'for dir in ' + webui_path + '/extensions/*/; do cd \\\"$dir\\\" && git reset --hard && git pull; done'}\n",
|
176 |
-
" del cap\n",
|
177 |
-
" print(f\"\\r✨ {action} Завершено!\")\n",
|
178 |
-
"\n",
|
179 |
-
"\n",
|
180 |
-
"# === FIXING EXTENSIONS ===\n",
|
181 |
-
"anxety_repos = \"https://huggingface.co/NagisaNao/fast_repo/resolve/main\"\n",
|
182 |
-
"\n",
|
183 |
-
"with capture.capture_output() as cap:\n",
|
184 |
-
" # --- Umi-Wildcard ---\n",
|
185 |
-
" !sed -i '521s/open=\\(False\\|True\\)/open=False/' {webui_path}/extensions/Umi-AI-Wildcards/scripts/wildcard_recursive.py # Closed accordion by default\n",
|
186 |
-
"\n",
|
187 |
-
" # --- Encrypt-Image ---\n",
|
188 |
-
" !sed -i '9,37d' {webui_path}/extensions/Encrypt-Image/javascript/encrypt_images_info.js # Removes the weird text in webui\n",
|
189 |
-
"\n",
|
190 |
-
" # --- Additional-Networks ---\n",
|
191 |
-
" !wget -O {webui_path}/extensions/additional-networks/scripts/metadata_editor.py {anxety_repos}/extensions/Additional-Networks/fix/metadata_editor.py # Fixing an error due to old style\n",
|
192 |
-
"del cap\n",
|
193 |
-
"\n",
|
194 |
-
"\n",
|
195 |
-
"## Version switching\n",
|
196 |
-
"if commit_hash:\n",
|
197 |
-
" print('⏳ Активация машины времени...', end=\"\", flush=True)\n",
|
198 |
-
" with capture.capture_output() as cap:\n",
|
199 |
-
" %cd {webui_path}\n",
|
200 |
-
" !git config --global user.email \"[email protected]\"\n",
|
201 |
-
" !git config --global user.name \"Your Name\"\n",
|
202 |
-
" !git reset --hard {commit_hash}\n",
|
203 |
-
" del cap\n",
|
204 |
-
" print(f\"\\r⌛️ Машина времени активированна! Текущий коммит: \\033[34m{commit_hash}\\033[0m\")\n",
|
205 |
-
"\n",
|
206 |
-
"\n",
|
207 |
-
"## Downloading model and stuff | oh~ Hey! If you're freaked out by that code too, don't worry, me too!\n",
|
208 |
-
"print(\"📦 Скачивание моделей и прочего...\", end='')\n",
|
209 |
-
"model_list = {\n",
|
210 |
-
" \"1.Anime (by XpucT) + INP\": [\n",
|
211 |
-
" {\"url\": \"https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2.safetensors\", \"name\": \"
|
212 |
-
" {\"url\": \"https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2-inpainting.safetensors\", \"name\": \"
|
213 |
-
" ],\n",
|
214 |
-
" \"2.BluMix [Anime] [V7] + INP\": [\n",
|
215 |
-
" {\"url\": \"https://civitai.com/api/download/models/361779\", \"name\": \"
|
216 |
-
" {\"url\": \"https://civitai.com/api/download/models/363850\", \"name\": \"
|
217 |
-
" ],\n",
|
218 |
-
" \"3.Cetus-Mix [Anime] [V4] + INP\": [\n",
|
219 |
-
" {\"url\": \"https://civitai.com/api/download/models/130298\", \"name\": \"CetusMix_V4.safetensors\"},\n",
|
220 |
-
" {\"url\": \"https://civitai.com/api/download/models/139882\", \"name\": \"CetusMix_V4-inpainting.safetensors\"}\n",
|
221 |
-
" ],\n",
|
222 |
-
" \"4.Counterfeit [Anime] [V3] + INP\": [\n",
|
223 |
-
" {\"url\": \"https://
|
224 |
-
" {\"url\": \"https://civitai.com/api/download/models/137911\", \"name\": \"Counterfeit_V3-inpainting.safetensors\"}\n",
|
225 |
-
" ],\n",
|
226 |
-
" \"5.CuteColor [Anime] [V3]\": [\n",
|
227 |
-
" {\"url\": \"https://civitai.com/api/download/models/138754\", \"name\": \"CuteColor_V3.safetensors\"}\n",
|
228 |
-
" ],\n",
|
229 |
-
" \"6.Dark-Sushi-Mix [Anime]\": [\n",
|
230 |
-
" {\"url\": \"https://civitai.com/api/download/models/101640\", \"name\": \"DarkSushiMix_2_5D.safetensors\"},\n",
|
231 |
-
" {\"url\": \"https://civitai.com/api/download/models/56071\", \"name\": \"DarkSushiMix_colorful.safetensors\"}\n",
|
232 |
-
" ],\n",
|
233 |
-
" \"7.Deliberate [Realism] [V6] + INP\": [\n",
|
234 |
-
" {\"url\": \"https://huggingface.co/XpucT/Deliberate/resolve/main/Deliberate_v6.safetensors\", \"name\": \"
|
235 |
-
" {\"url\": \"https://huggingface.co/XpucT/Deliberate/resolve/main/Deliberate_v6-inpainting.safetensors\", \"name\": \"
|
236 |
-
" ],\n",
|
237 |
-
" \"8.Meina-Mix [Anime] [V11] + INP\": [\n",
|
238 |
-
" {\"url\": \"https://civitai.com/api/download/models/119057\", \"name\": \"MeinaMix_V11.safetensors\"},\n",
|
239 |
-
" {\"url\": \"https://civitai.com/api/download/models/120702\", \"name\": \"MeinaMix_V11-inpainting.safetensors\"}\n",
|
240 |
-
" ],\n",
|
241 |
-
" \"9.Mix-Pro [Anime] [V4] + INP\": [\n",
|
242 |
-
" {\"url\": \"https://civitai.com/api/download/models/125668\", \"name\": \"MixPro_V4.safetensors\"},\n",
|
243 |
-
" {\"url\": \"https://civitai.com/api/download/models/139878\", \"name\": \"MixPro_V4-inpainting.safetensors\"}\n",
|
244 |
-
" ]\n",
|
245 |
-
"}\n",
|
246 |
-
"\n",
|
247 |
-
"vae_list = {\n",
|
248 |
-
" \"1.Anime.vae\": [{\"url\": \"https://civitai.com/api/download/models/311162\", \"name\": \"vae-ft-mse-840000-ema-pruned.vae.safetensors\"}],\n",
|
249 |
-
" \"2.Anything.vae\": [{\"url\": \"https://
|
250 |
-
" \"3.Blessed2.vae\": [{\"url\": \"https://huggingface.co/NoCrypt/
|
251 |
-
" \"4.ClearVae.vae\": [{\"url\": \"https://civitai.com/api/download/models/88156\", \"name\": \"ClearVae_23.vae.safetensors\"}],\n",
|
252 |
-
" \"5.WD.vae\": [{\"url\": \"https://huggingface.co/NoCrypt/resources/resolve/main/VAE/wd.vae.safetensors\", \"name\": \"WD.vae.safetensors\"}]\n",
|
253 |
-
"}\n",
|
254 |
-
"\n",
|
255 |
-
"controlnet_list = {\n",
|
256 |
-
" \"1.canny\": [\n",
|
257 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny_fp16.safetensors\", \"name\": \"control_v11p_sd15_canny_fp16.safetensors\"},\n",
|
258 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_canny_fp16.yaml\", \"name\": \"control_v11p_sd15_canny_fp16.yaml\"}\n",
|
259 |
-
" ],\n",
|
260 |
-
" \"2.openpose\": [\n",
|
261 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose_fp16.safetensors\", \"name\": \"control_v11p_sd15_openpose_fp16.safetensors\"},\n",
|
262 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_openpose_fp16.yaml\", \"name\": \"control_v11p_sd15_openpose_fp16.yaml\"}\n",
|
263 |
-
" ],\n",
|
264 |
-
" \"3.depth\": [\n",
|
265 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth_fp16.safetensors\", \"name\": \"control_v11f1p_sd15_depth_fp16.safetensors\"},\n",
|
266 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1p_sd15_depth_fp16.yaml\", \"name\": \"control_v11f1p_sd15_depth_fp16.yaml\"},\n",
|
267 |
-
" {\"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",
|
268 |
-
" ],\n",
|
269 |
-
" \"4.normal_map\": [\n",
|
270 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_normalbae_fp16.safetensors\", \"name\": \"control_v11p_sd15_normalbae_fp16.safetensors\"},\n",
|
271 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_normalbae_fp16.yaml\", \"name\": \"control_v11p_sd15_normalbae_fp16.yaml\"}\n",
|
272 |
-
" ],\n",
|
273 |
-
" \"5.mlsd\": [\n",
|
274 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_mlsd_fp16.safetensors\", \"name\": \"control_v11p_sd15_mlsd_fp16.safetensors\"},\n",
|
275 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_mlsd_fp16.yaml\", \"name\": \"control_v11p_sd15_mlsd_fp16.yaml\"}\n",
|
276 |
-
" ],\n",
|
277 |
-
" \"6.lineart\": [\n",
|
278 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart_fp16.safetensors\", \"name\": \"control_v11p_sd15_lineart_fp16.safetensors\"},\n",
|
279 |
-
" {\"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",
|
280 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_lineart_fp16.yaml\", \"name\": \"control_v11p_sd15_lineart_fp16.yaml\"},\n",
|
281 |
-
" {\"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",
|
282 |
-
" ],\n",
|
283 |
-
" \"7.soft_edge\": [\n",
|
284 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge_fp16.safetensors\", \"name\": \"control_v11p_sd15_softedge_fp16.safetensors\"},\n",
|
285 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_softedge_fp16.yaml\", \"name\": \"control_v11p_sd15_softedge_fp16.yaml\"}\n",
|
286 |
-
" ],\n",
|
287 |
-
" \"8.scribble\": [\n",
|
288 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble_fp16.safetensors\", \"name\": \"control_v11p_sd15_scribble_fp16.safetensors\"},\n",
|
289 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_scribble_fp16.yaml\", \"name\": \"control_v11p_sd15_scribble_fp16.yaml\"}\n",
|
290 |
-
" ],\n",
|
291 |
-
" \"9.segmentation\": [\n",
|
292 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg_fp16.safetensors\", \"name\": \"control_v11p_sd15_seg_fp16.safetensors\"},\n",
|
293 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_seg_fp16.yaml\", \"name\": \"control_v11p_sd15_seg_fp16.yaml\"}\n",
|
294 |
-
" ],\n",
|
295 |
-
" \"10.shuffle\": [\n",
|
296 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle_fp16.safetensors\", \"name\": \"control_v11e_sd15_shuffle_fp16.safetensors\"},\n",
|
297 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_shuffle_fp16.yaml\", \"name\": \"control_v11e_sd15_shuffle_fp16.yaml\"}\n",
|
298 |
-
" ],\n",
|
299 |
-
" \"11.tile\": [\n",
|
300 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile_fp16.safetensors\", \"name\": \"control_v11f1e_sd15_tile_fp16.safetensors\"},\n",
|
301 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1e_sd15_tile_fp16.yaml\", \"name\": \"control_v11f1e_sd15_tile_fp16.yaml\"}\n",
|
302 |
-
" ],\n",
|
303 |
-
" \"12.inpaint\": [\n",
|
304 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_inpaint_fp16.safetensors\", \"name\": \"control_v11p_sd15_inpaint_fp16.safetensors\"},\n",
|
305 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_inpaint_fp16.yaml\", \"name\": \"control_v11p_sd15_inpaint_fp16.yaml\"}\n",
|
306 |
-
" ],\n",
|
307 |
-
" \"13.instruct_p2p\": [\n",
|
308 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p_fp16.safetensors\", \"name\": \"control_v11e_sd15_ip2p_fp16.safetensors\"},\n",
|
309 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_ip2p_fp16.yaml\", \"name\": \"control_v11e_sd15_ip2p_fp16.yaml\"}\n",
|
310 |
-
" ]\n",
|
311 |
-
"}\n",
|
312 |
-
"\n",
|
313 |
-
"url = \"\"\n",
|
314 |
-
"prefixes = {\n",
|
315 |
-
" \"model\": models_dir,\n",
|
316 |
-
" \"vae\": vaes_dir,\n",
|
317 |
-
" \"lora\": loras_dir,\n",
|
318 |
-
" \"embed\": embeddings_dir,\n",
|
319 |
-
" \"extension\": extensions_dir,\n",
|
320 |
-
" \"control\": control_dir,\n",
|
321 |
-
" \"adetailer\": adetailer_dir
|
322 |
-
"
|
323 |
-
"\n",
|
324 |
-
"
|
325 |
-
"
|
326 |
-
"
|
327 |
-
"\n",
|
328 |
-
"
|
329 |
-
"
|
330 |
-
"\n",
|
331 |
-
"
|
332 |
-
"\n",
|
333 |
-
"
|
334 |
-
"\n",
|
335 |
-
"
|
336 |
-
"
|
337 |
-
"
|
338 |
-
"
|
339 |
-
"
|
340 |
-
"\n",
|
341 |
-
"
|
342 |
-
"
|
343 |
-
" info =
|
344 |
-
"\n",
|
345 |
-
"
|
346 |
-
" print(f\"\\
|
347 |
-
" print(f\"\\033[
|
348 |
-
" print(f\"\\033[
|
349 |
-
"\n",
|
350 |
-
"
|
351 |
-
"\n",
|
352 |
-
"
|
353 |
-
"
|
354 |
-
"
|
355 |
-
"
|
356 |
-
"
|
357 |
-
"
|
358 |
-
"
|
359 |
-
" return
|
360 |
-
"
|
361 |
-
"
|
362 |
-
"
|
363 |
-
"\n",
|
364 |
-
"
|
365 |
-
"
|
366 |
-
"
|
367 |
-
"
|
368 |
-
"
|
369 |
-
"
|
370 |
-
"
|
371 |
-
"
|
372 |
-
"\n",
|
373 |
-
"
|
374 |
-
"
|
375 |
-
" if
|
376 |
-
"
|
377 |
-
"
|
378 |
-
"
|
379 |
-
"\n",
|
380 |
-
"
|
381 |
-
"\n",
|
382 |
-
"
|
383 |
-
"
|
384 |
-
"
|
385 |
-
"
|
386 |
-
"
|
387 |
-
"\n",
|
388 |
-
"
|
389 |
-
"\n",
|
390 |
-
"
|
391 |
-
"
|
392 |
-
"
|
393 |
-
"
|
394 |
-
"\n",
|
395 |
-
"
|
396 |
-
"
|
397 |
-
" if
|
398 |
-
"
|
399 |
-
"\n",
|
400 |
-
"
|
401 |
-
"
|
402 |
-
" if
|
403 |
-
"
|
404 |
-
"
|
405 |
-
"
|
406 |
-
"
|
407 |
-
"
|
408 |
-
"
|
409 |
-
"\n",
|
410 |
-
"
|
411 |
-
"
|
412 |
-
"
|
413 |
-
"
|
414 |
-
"
|
415 |
-
"
|
416 |
-
"
|
417 |
-
"
|
418 |
-
"\n",
|
419 |
-
"
|
420 |
-
"
|
421 |
-
"
|
422 |
-
"
|
423 |
-
"\n",
|
424 |
-
"
|
425 |
-
"
|
426 |
-
"
|
427 |
-
"
|
428 |
-
"
|
429 |
-
"
|
430 |
-
"
|
431 |
-
"
|
432 |
-
"
|
433 |
-
"
|
434 |
-
"
|
435 |
-
"
|
436 |
-
"
|
437 |
-
"\n",
|
438 |
-
"
|
439 |
-
"
|
440 |
-
"
|
441 |
-
"
|
442 |
-
"
|
443 |
-
"
|
444 |
-
"
|
445 |
-
"
|
446 |
-
"\n",
|
447 |
-
"
|
448 |
-
"
|
449 |
-
"
|
450 |
-
"
|
451 |
-
"
|
452 |
-
"
|
453 |
-
"
|
454 |
-
"\n",
|
455 |
-
"
|
456 |
-
"
|
457 |
-
"
|
458 |
-
"
|
459 |
-
"
|
460 |
-
"
|
461 |
-
"
|
462 |
-
"\n",
|
463 |
-
"
|
464 |
-
"
|
465 |
-
"
|
466 |
-
"
|
467 |
-
"
|
468 |
-
"
|
469 |
-
"
|
470 |
-
"
|
471 |
-
"
|
472 |
-
"\n",
|
473 |
-
"
|
474 |
-
"
|
475 |
-
"\n",
|
476 |
-
"
|
477 |
-
"
|
478 |
-
"
|
479 |
-
"
|
480 |
-
"
|
481 |
-
"
|
482 |
-
"
|
483 |
-
"\n",
|
484 |
-
"
|
485 |
-
"
|
486 |
-
"\n",
|
487 |
-
"
|
488 |
-
"\n",
|
489 |
-
"
|
490 |
-
"
|
491 |
-
"
|
492 |
-
"
|
493 |
-
"
|
494 |
-
"
|
495 |
-
"
|
496 |
-
"
|
497 |
-
"
|
498 |
-
"
|
499 |
-
"
|
500 |
-
"\n",
|
501 |
-
"
|
502 |
-
"
|
503 |
-
"
|
504 |
-
"
|
505 |
-
"
|
506 |
-
"
|
507 |
-
"
|
508 |
-
"
|
509 |
-
"
|
510 |
-
"
|
511 |
-
"
|
512 |
-
"
|
513 |
-
"
|
514 |
-
"
|
515 |
-
"
|
516 |
-
"
|
517 |
-
"
|
518 |
-
"\n",
|
519 |
-
"
|
520 |
-
"
|
521 |
-
"
|
522 |
-
"\n",
|
523 |
-
"
|
524 |
-
"
|
525 |
-
"
|
526 |
-
"
|
527 |
-
"
|
528 |
-
"
|
529 |
-
"
|
530 |
-
"
|
531 |
-
"
|
532 |
-
"
|
533 |
-
"
|
534 |
-
"
|
535 |
-
"
|
536 |
-
"
|
537 |
-
"
|
538 |
-
"\n",
|
539 |
-
"
|
540 |
-
"
|
541 |
-
"\n",
|
542 |
-
"
|
543 |
-
"
|
544 |
-
"
|
545 |
-
"
|
546 |
-
"
|
547 |
-
"
|
548 |
-
"
|
549 |
-
"
|
550 |
-
"\n",
|
551 |
-
"
|
552 |
-
"
|
553 |
-
"
|
554 |
-
"
|
555 |
-
"
|
556 |
-
"\n",
|
557 |
-
"
|
558 |
-
"
|
559 |
-
"
|
560 |
-
"\n",
|
561 |
-
"
|
562 |
-
"
|
563 |
-
"
|
564 |
-
"\n",
|
565 |
-
"
|
566 |
-
"
|
567 |
-
"
|
568 |
-
"
|
569 |
-
"
|
570 |
-
"if
|
571 |
-
"
|
572 |
-
"
|
573 |
-
"
|
574 |
-
"
|
575 |
-
"
|
576 |
-
"
|
577 |
-
"\n",
|
578 |
-
"
|
579 |
-
"
|
580 |
-
"
|
581 |
-
"
|
582 |
-
"
|
583 |
-
"
|
584 |
-
"
|
585 |
-
"
|
586 |
-
"url
|
587 |
-
"\n",
|
588 |
-
"
|
589 |
-
"
|
590 |
-
"
|
591 |
-
"
|
592 |
-
"
|
593 |
-
"
|
594 |
-
"
|
595 |
-
"
|
596 |
-
"\n",
|
597 |
-
"
|
598 |
-
"\n",
|
599 |
-
"\n",
|
600 |
-
"
|
601 |
-
"
|
602 |
-
"
|
603 |
-
"
|
604 |
-
"
|
605 |
-
"
|
606 |
-
"
|
607 |
-
"
|
608 |
-
"
|
609 |
-
"
|
610 |
-
"
|
611 |
-
"
|
612 |
-
"
|
613 |
-
"
|
614 |
-
"
|
615 |
-
"
|
616 |
-
"
|
617 |
-
"\n",
|
618 |
-
"\n",
|
619 |
-
"
|
620 |
-
"
|
621 |
-
"
|
622 |
-
"\n",
|
623 |
-
"
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
641 |
}
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": null,
|
6 |
+
"metadata": {
|
7 |
+
"id": "2lJmbqrs3Mu8"
|
8 |
+
},
|
9 |
+
"outputs": [],
|
10 |
+
"source": [
|
11 |
+
"##~ DOWNLOADING CODE | BY: ANXETY ~##\n",
|
12 |
+
"\n",
|
13 |
+
"import os\n",
|
14 |
+
"import re\n",
|
15 |
+
"import time\n",
|
16 |
+
"import json\n",
|
17 |
+
"import shutil\n",
|
18 |
+
"import zipfile\n",
|
19 |
+
"import requests\n",
|
20 |
+
"import subprocess\n",
|
21 |
+
"from datetime import timedelta\n",
|
22 |
+
"from subprocess import getoutput\n",
|
23 |
+
"from IPython.utils import capture\n",
|
24 |
+
"from IPython.display import clear_output\n",
|
25 |
+
"from urllib.parse import urlparse, parse_qs\n",
|
26 |
+
"\n",
|
27 |
+
"\n",
|
28 |
+
"# ================= DETECT ENV =================\n",
|
29 |
+
"def detect_environment():\n",
|
30 |
+
" free_plan = (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024 ** 3) <= 20)\n",
|
31 |
+
" environments = {\n",
|
32 |
+
" 'COLAB_GPU': ('Google Colab', \"/root\" if free_plan else \"/content\"),\n",
|
33 |
+
" 'KAGGLE_URL_BASE': ('Kaggle', \"/kaggle/working/content\")\n",
|
34 |
+
" }\n",
|
35 |
+
" for env_var, (environment, path) in environments.items():\n",
|
36 |
+
" if env_var in os.environ:\n",
|
37 |
+
" return environment, path, free_plan\n",
|
38 |
+
"\n",
|
39 |
+
"env, root_path, free_plan = detect_environment()\n",
|
40 |
+
"webui_path = f\"{root_path}/sdw\"\n",
|
41 |
+
"\n",
|
42 |
+
"\n",
|
43 |
+
"# ================ LIBRARIES V2 ================\n",
|
44 |
+
"flag_file = f\"{root_path}/libraries_installed.txt\"\n",
|
45 |
+
"\n",
|
46 |
+
"if not os.path.exists(flag_file):\n",
|
47 |
+
" print(\"💿 Установка библиотек, это займет какое-то время:\\n\")\n",
|
48 |
+
"\n",
|
49 |
+
" install_lib = {\n",
|
50 |
+
" \"aria2\": \"apt -y install aria2\",\n",
|
51 |
+
" \"localtunnel\": \"npm install -g localtunnel\",\n",
|
52 |
+
" \"insightface\": \"pip install insightface\"\n",
|
53 |
+
" }\n",
|
54 |
+
"\n",
|
55 |
+
" additional_libs = {\n",
|
56 |
+
" \"Google Colab\": {\n",
|
57 |
+
" \"xformers\": \"pip install xformers==0.0.26.post1 --no-deps\"\n",
|
58 |
+
" },\n",
|
59 |
+
" \"Kaggle\": {\n",
|
60 |
+
" \"xformers\": \"pip install xformers==0.0.26.post1\",\n",
|
61 |
+
" # \"torch\": \"pip install torch==2.1.2+cu121 torchvision==0.16.2+cu121 torchaudio==2.1.2 --extra-index-url https://download.pytorch.org/whl/cu121\",\n",
|
62 |
+
" \"aiohttp\": \"pip install trash-cli && trash-put /opt/conda/lib/python3.10/site-packages/aiohttp*\" # fix install req\n",
|
63 |
+
" }\n",
|
64 |
+
" }\n",
|
65 |
+
"\n",
|
66 |
+
" if env in additional_libs:\n",
|
67 |
+
" install_lib.update(additional_libs[env])\n",
|
68 |
+
"\n",
|
69 |
+
" # Loop through libraries\n",
|
70 |
+
" for index, (package, install_cmd) in enumerate(install_lib.items(), start=1):\n",
|
71 |
+
" print(f\"\\r[{index}/{len(install_lib)}] \\033[32m>>\\033[0m Installing \\033[33m{package}\\033[0m...\" + \" \"*35, end='')\n",
|
72 |
+
" subprocess.run(install_cmd, shell=True, capture_output=True)\n",
|
73 |
+
"\n",
|
74 |
+
" # Additional specific packages\n",
|
75 |
+
" with capture.capture_output() as cap:\n",
|
76 |
+
" !curl -s -OL https://github.com/DEX-1101/sd-webui-notebook/raw/main/res/new_tunnel --output-dir {root_path}\n",
|
77 |
+
" !curl -s -Lo /usr/bin/cl https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 && chmod +x /usr/bin/cl\n",
|
78 |
+
" !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",
|
79 |
+
" del cap\n",
|
80 |
+
"\n",
|
81 |
+
" clear_output()\n",
|
82 |
+
"\n",
|
83 |
+
" # Save file install lib\n",
|
84 |
+
" with open(flag_file, \"w\") as f:\n",
|
85 |
+
" f.write(\">W<'\")\n",
|
86 |
+
"\n",
|
87 |
+
" print(\"🍪 Библиотеки установлены!\" + \" \"*35)\n",
|
88 |
+
" time.sleep(2)\n",
|
89 |
+
" clear_output()\n",
|
90 |
+
"\n",
|
91 |
+
"\n",
|
92 |
+
"# ================= loading settings V4 =================\n",
|
93 |
+
"def load_settings(path):\n",
|
94 |
+
" if os.path.exists(path):\n",
|
95 |
+
" with open(path, 'r') as file:\n",
|
96 |
+
" return json.load(file)\n",
|
97 |
+
" return {}\n",
|
98 |
+
"\n",
|
99 |
+
"settings = load_settings(f'{root_path}/settings.json')\n",
|
100 |
+
"\n",
|
101 |
+
"VARIABLES = [\n",
|
102 |
+
" 'model', 'model_num', 'inpainting_model',\n",
|
103 |
+
" 'vae', 'vae_num', 'latest_webui', 'latest_exstensions',\n",
|
104 |
+
" 'change_webui', 'detailed_download', 'controlnet',\n",
|
105 |
+
" 'controlnet_num', 'commit_hash', 'huggingface_token',\n",
|
106 |
+
" 'ngrok_token', 'zrok_token', 'commandline_arguments',\n",
|
107 |
+
" 'Model_url', 'Vae_url', 'LoRA_url', 'Embedding_url',\n",
|
108 |
+
" 'Extensions_url', 'custom_file_urls'\n",
|
109 |
+
"]\n",
|
110 |
+
"\n",
|
111 |
+
"locals().update({key: settings.get(key) for key in VARIABLES})\n",
|
112 |
+
"\n",
|
113 |
+
"\n",
|
114 |
+
"# ================= OTHER =================\n",
|
115 |
+
"try:\n",
|
116 |
+
" start_colab\n",
|
117 |
+
"except:\n",
|
118 |
+
" start_colab = int(time.time())-5\n",
|
119 |
+
"\n",
|
120 |
+
"# CONFIG DIR\n",
|
121 |
+
"models_dir = f\"{webui_path}/models/Stable-diffusion\"\n",
|
122 |
+
"vaes_dir = f\"{webui_path}/models/VAE\"\n",
|
123 |
+
"embeddings_dir = f\"{webui_path}/embeddings\"\n",
|
124 |
+
"loras_dir = f\"{webui_path}/models/Lora\"\n",
|
125 |
+
"extensions_dir = f\"{webui_path}/extensions\"\n",
|
126 |
+
"control_dir = f\"{webui_path}/models/ControlNet\"\n",
|
127 |
+
"adetailer_dir = f\"{webui_path}/models/adetailer\"\n",
|
128 |
+
"\n",
|
129 |
+
"\n",
|
130 |
+
"# ================= MAIN CODE =================\n",
|
131 |
+
"if not os.path.exists(webui_path):\n",
|
132 |
+
" start_install = int(time.time())\n",
|
133 |
+
" print(\"⌚ Распаковка Stable Diffusion...\" if change_webui != 'Forge' else \"⌚ Распаковка Stable Diffusion (Forge)...\", end='')\n",
|
134 |
+
" with capture.capture_output() as cap:\n",
|
135 |
+
" aria2_command = \"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M\"\n",
|
136 |
+
" url = \"https://huggingface.co/NagisaNao/fast_repo/resolve/main/FULL_REPO.zip\" if change_webui != 'Forge' else \"https://huggingface.co/NagisaNao/fast_repo/resolve/main/FULL_REPO_forge.zip\"\n",
|
137 |
+
" !{aria2_command} {url} -o repo.zip\n",
|
138 |
+
"\n",
|
139 |
+
" !unzip -q -o repo.zip -d {webui_path}\n",
|
140 |
+
" !rm -rf repo.zip\n",
|
141 |
+
"\n",
|
142 |
+
" %cd {root_path}\n",
|
143 |
+
" os.environ[\"SAFETENSORS_FAST_GPU\"]='1'\n",
|
144 |
+
" os.environ[\"CUDA_MODULE_LOADING\"]=\"LAZY\"\n",
|
145 |
+
" os.environ[\"TF_CPP_MIN_LOG_LEVEL\"] = \"3\"\n",
|
146 |
+
" os.environ[\"PYTHONWARNINGS\"] = \"ignore\"\n",
|
147 |
+
"\n",
|
148 |
+
" !echo -n {start_colab} > {webui_path}/static/colabTimer.txt\n",
|
149 |
+
" del cap\n",
|
150 |
+
" install_time = timedelta(seconds=time.time()-start_install)\n",
|
151 |
+
" print(\"\\r🚀 Распаковка Завершена! За\",\"%02d:%02d:%02d ⚡\\n\" % (install_time.seconds / 3600, (install_time.seconds / 60) % 60, install_time.seconds % 60), end='', flush=True)\n",
|
152 |
+
"else:\n",
|
153 |
+
" print(\"🚀 Все распакованно... Пропуск. ⚡\")\n",
|
154 |
+
" start_colab = float(open(f'{webui_path}/static/colabTimer.txt', 'r').read())\n",
|
155 |
+
" time_since_start = str(timedelta(seconds=time.time()-start_colab)).split('.')[0]\n",
|
156 |
+
" print(f\"⌚️ Вы проводите эту сессию в течение - \\033[33m{time_since_start}\\033[0m\")\n",
|
157 |
+
"\n",
|
158 |
+
"\n",
|
159 |
+
"## Changes extensions and WebUi\n",
|
160 |
+
"if latest_webui or latest_exstensions:\n",
|
161 |
+
" action = \"Обновление WebUI и Рас��ирений\" if latest_webui and latest_exstensions else (\"Обновление WebUI\" if latest_webui else \"Обновление Расширений\")\n",
|
162 |
+
" print(f\"⌚️ {action}...\", end='', flush=True)\n",
|
163 |
+
" with capture.capture_output() as cap:\n",
|
164 |
+
" !git config --global user.email \"[email protected]\"\n",
|
165 |
+
" !git config --global user.name \"Your Name\"\n",
|
166 |
+
"\n",
|
167 |
+
" ## Update Webui\n",
|
168 |
+
" if latest_webui:\n",
|
169 |
+
" %cd {webui_path}\n",
|
170 |
+
" !git restore .\n",
|
171 |
+
" !git pull -X theirs --rebase --autostash\n",
|
172 |
+
"\n",
|
173 |
+
" ## Update extensions\n",
|
174 |
+
" if latest_exstensions:\n",
|
175 |
+
" !{'for dir in ' + webui_path + '/extensions/*/; do cd \\\"$dir\\\" && git reset --hard && git pull; done'}\n",
|
176 |
+
" del cap\n",
|
177 |
+
" print(f\"\\r✨ {action} Завершено!\")\n",
|
178 |
+
"\n",
|
179 |
+
"\n",
|
180 |
+
"# === FIXING EXTENSIONS ===\n",
|
181 |
+
"anxety_repos = \"https://huggingface.co/NagisaNao/fast_repo/resolve/main\"\n",
|
182 |
+
"\n",
|
183 |
+
"with capture.capture_output() as cap:\n",
|
184 |
+
" # --- Umi-Wildcard ---\n",
|
185 |
+
" !sed -i '521s/open=\\(False\\|True\\)/open=False/' {webui_path}/extensions/Umi-AI-Wildcards/scripts/wildcard_recursive.py # Closed accordion by default\n",
|
186 |
+
"\n",
|
187 |
+
" # --- Encrypt-Image ---\n",
|
188 |
+
" !sed -i '9,37d' {webui_path}/extensions/Encrypt-Image/javascript/encrypt_images_info.js # Removes the weird text in webui\n",
|
189 |
+
"\n",
|
190 |
+
" # --- Additional-Networks ---\n",
|
191 |
+
" !wget -O {webui_path}/extensions/additional-networks/scripts/metadata_editor.py {anxety_repos}/extensions/Additional-Networks/fix/metadata_editor.py # Fixing an error due to old style\n",
|
192 |
+
"del cap\n",
|
193 |
+
"\n",
|
194 |
+
"\n",
|
195 |
+
"## Version switching\n",
|
196 |
+
"if commit_hash:\n",
|
197 |
+
" print('⏳ Активация машины времени...', end=\"\", flush=True)\n",
|
198 |
+
" with capture.capture_output() as cap:\n",
|
199 |
+
" %cd {webui_path}\n",
|
200 |
+
" !git config --global user.email \"[email protected]\"\n",
|
201 |
+
" !git config --global user.name \"Your Name\"\n",
|
202 |
+
" !git reset --hard {commit_hash}\n",
|
203 |
+
" del cap\n",
|
204 |
+
" print(f\"\\r⌛️ Машина времени активированна! Текущий коммит: \\033[34m{commit_hash}\\033[0m\")\n",
|
205 |
+
"\n",
|
206 |
+
"\n",
|
207 |
+
"## Downloading model and stuff | oh~ Hey! If you're freaked out by that code too, don't worry, me too!\n",
|
208 |
+
"print(\"📦 Скачивание моделей и прочего...\", end='')\n",
|
209 |
+
"model_list = {\n",
|
210 |
+
" \"1.Anime (by XpucT) + INP\": [\n",
|
211 |
+
" {\"url\": \"https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2.safetensors\", \"name\": \"Anime_V2.safetensors\"},\n",
|
212 |
+
" {\"url\": \"https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2-inpainting.safetensors\", \"name\": \"Anime_V2-inpainting.safetensors\"}\n",
|
213 |
+
" ],\n",
|
214 |
+
" \"2.BluMix [Anime] [V7] + INP\": [\n",
|
215 |
+
" {\"url\": \"https://civitai.com/api/download/models/361779\", \"name\": \"BluMix_V7.safetensors\"},\n",
|
216 |
+
" {\"url\": \"https://civitai.com/api/download/models/363850\", \"name\": \"BluMix_V7-inpainting.safetensors\"}\n",
|
217 |
+
" ],\n",
|
218 |
+
" \"3.Cetus-Mix [Anime] [V4] + INP\": [\n",
|
219 |
+
" {\"url\": \"https://civitai.com/api/download/models/130298\", \"name\": \"CetusMix_V4.safetensors\"},\n",
|
220 |
+
" {\"url\": \"https://civitai.com/api/download/models/139882\", \"name\": \"CetusMix_V4-inpainting.safetensors\"}\n",
|
221 |
+
" ],\n",
|
222 |
+
" \"4.Counterfeit [Anime] [V3] + INP\": [\n",
|
223 |
+
" {\"url\": \"https://huggingface.co/gsdf/Counterfeit-V3.0/resolve/main/Counterfeit-V3.0_fix_fp16.safetensors\", \"name\": \"Counterfeit_V3.safetensors\"},\n",
|
224 |
+
" {\"url\": \"https://civitai.com/api/download/models/137911\", \"name\": \"Counterfeit_V3-inpainting.safetensors\"}\n",
|
225 |
+
" ],\n",
|
226 |
+
" \"5.CuteColor [Anime] [V3]\": [\n",
|
227 |
+
" {\"url\": \"https://civitai.com/api/download/models/138754\", \"name\": \"CuteColor_V3.safetensors\"}\n",
|
228 |
+
" ],\n",
|
229 |
+
" \"6.Dark-Sushi-Mix [Anime]\": [\n",
|
230 |
+
" {\"url\": \"https://civitai.com/api/download/models/101640\", \"name\": \"DarkSushiMix_2_5D.safetensors\"},\n",
|
231 |
+
" {\"url\": \"https://civitai.com/api/download/models/56071\", \"name\": \"DarkSushiMix_colorful.safetensors\"}\n",
|
232 |
+
" ],\n",
|
233 |
+
" \"7.Deliberate [Realism] [V6] + INP\": [\n",
|
234 |
+
" {\"url\": \"https://huggingface.co/XpucT/Deliberate/resolve/main/Deliberate_v6.safetensors\", \"name\": \"Deliberate_V6.safetensors\"},\n",
|
235 |
+
" {\"url\": \"https://huggingface.co/XpucT/Deliberate/resolve/main/Deliberate_v6-inpainting.safetensors\", \"name\": \"Deliberate_V6-inpainting.safetensors\"}\n",
|
236 |
+
" ],\n",
|
237 |
+
" \"8.Meina-Mix [Anime] [V11] + INP\": [\n",
|
238 |
+
" {\"url\": \"https://civitai.com/api/download/models/119057\", \"name\": \"MeinaMix_V11.safetensors\"},\n",
|
239 |
+
" {\"url\": \"https://civitai.com/api/download/models/120702\", \"name\": \"MeinaMix_V11-inpainting.safetensors\"}\n",
|
240 |
+
" ],\n",
|
241 |
+
" \"9.Mix-Pro [Anime] [V4] + INP\": [\n",
|
242 |
+
" {\"url\": \"https://civitai.com/api/download/models/125668\", \"name\": \"MixPro_V4.safetensors\"},\n",
|
243 |
+
" {\"url\": \"https://civitai.com/api/download/models/139878\", \"name\": \"MixPro_V4-inpainting.safetensors\"}\n",
|
244 |
+
" ]\n",
|
245 |
+
"}\n",
|
246 |
+
"\n",
|
247 |
+
"vae_list = {\n",
|
248 |
+
" \"1.Anime.vae\": [{\"url\": \"https://civitai.com/api/download/models/311162\", \"name\": \"vae-ft-mse-840000-ema-pruned.vae.safetensors\"}],\n",
|
249 |
+
" \"2.Anything.vae\": [{\"url\": \"https://huggingface.co/NoCrypt/resources/resolve/main/VAE/any.vae.safetensors\", \"name\": \"Anything.vae.safetensors\"}],\n",
|
250 |
+
" \"3.Blessed2.vae\": [{\"url\": \"https://huggingface.co/NoCrypt/resources/resolve/main/VAE/blessed2.vae.safetensors\", \"name\": \"Blessed2.vae.safetensors\"}],\n",
|
251 |
+
" \"4.ClearVae.vae\": [{\"url\": \"https://civitai.com/api/download/models/88156\", \"name\": \"ClearVae_23.vae.safetensors\"}],\n",
|
252 |
+
" \"5.WD.vae\": [{\"url\": \"https://huggingface.co/NoCrypt/resources/resolve/main/VAE/wd.vae.safetensors\", \"name\": \"WD.vae.safetensors\"}]\n",
|
253 |
+
"}\n",
|
254 |
+
"\n",
|
255 |
+
"controlnet_list = {\n",
|
256 |
+
" \"1.canny\": [\n",
|
257 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny_fp16.safetensors\", \"name\": \"control_v11p_sd15_canny_fp16.safetensors\"},\n",
|
258 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_canny_fp16.yaml\", \"name\": \"control_v11p_sd15_canny_fp16.yaml\"}\n",
|
259 |
+
" ],\n",
|
260 |
+
" \"2.openpose\": [\n",
|
261 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose_fp16.safetensors\", \"name\": \"control_v11p_sd15_openpose_fp16.safetensors\"},\n",
|
262 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_openpose_fp16.yaml\", \"name\": \"control_v11p_sd15_openpose_fp16.yaml\"}\n",
|
263 |
+
" ],\n",
|
264 |
+
" \"3.depth\": [\n",
|
265 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth_fp16.safetensors\", \"name\": \"control_v11f1p_sd15_depth_fp16.safetensors\"},\n",
|
266 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1p_sd15_depth_fp16.yaml\", \"name\": \"control_v11f1p_sd15_depth_fp16.yaml\"},\n",
|
267 |
+
" {\"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",
|
268 |
+
" ],\n",
|
269 |
+
" \"4.normal_map\": [\n",
|
270 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_normalbae_fp16.safetensors\", \"name\": \"control_v11p_sd15_normalbae_fp16.safetensors\"},\n",
|
271 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_normalbae_fp16.yaml\", \"name\": \"control_v11p_sd15_normalbae_fp16.yaml\"}\n",
|
272 |
+
" ],\n",
|
273 |
+
" \"5.mlsd\": [\n",
|
274 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_mlsd_fp16.safetensors\", \"name\": \"control_v11p_sd15_mlsd_fp16.safetensors\"},\n",
|
275 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_mlsd_fp16.yaml\", \"name\": \"control_v11p_sd15_mlsd_fp16.yaml\"}\n",
|
276 |
+
" ],\n",
|
277 |
+
" \"6.lineart\": [\n",
|
278 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart_fp16.safetensors\", \"name\": \"control_v11p_sd15_lineart_fp16.safetensors\"},\n",
|
279 |
+
" {\"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",
|
280 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_lineart_fp16.yaml\", \"name\": \"control_v11p_sd15_lineart_fp16.yaml\"},\n",
|
281 |
+
" {\"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",
|
282 |
+
" ],\n",
|
283 |
+
" \"7.soft_edge\": [\n",
|
284 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge_fp16.safetensors\", \"name\": \"control_v11p_sd15_softedge_fp16.safetensors\"},\n",
|
285 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_softedge_fp16.yaml\", \"name\": \"control_v11p_sd15_softedge_fp16.yaml\"}\n",
|
286 |
+
" ],\n",
|
287 |
+
" \"8.scribble\": [\n",
|
288 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble_fp16.safetensors\", \"name\": \"control_v11p_sd15_scribble_fp16.safetensors\"},\n",
|
289 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_scribble_fp16.yaml\", \"name\": \"control_v11p_sd15_scribble_fp16.yaml\"}\n",
|
290 |
+
" ],\n",
|
291 |
+
" \"9.segmentation\": [\n",
|
292 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg_fp16.safetensors\", \"name\": \"control_v11p_sd15_seg_fp16.safetensors\"},\n",
|
293 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_seg_fp16.yaml\", \"name\": \"control_v11p_sd15_seg_fp16.yaml\"}\n",
|
294 |
+
" ],\n",
|
295 |
+
" \"10.shuffle\": [\n",
|
296 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle_fp16.safetensors\", \"name\": \"control_v11e_sd15_shuffle_fp16.safetensors\"},\n",
|
297 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_shuffle_fp16.yaml\", \"name\": \"control_v11e_sd15_shuffle_fp16.yaml\"}\n",
|
298 |
+
" ],\n",
|
299 |
+
" \"11.tile\": [\n",
|
300 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile_fp16.safetensors\", \"name\": \"control_v11f1e_sd15_tile_fp16.safetensors\"},\n",
|
301 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1e_sd15_tile_fp16.yaml\", \"name\": \"control_v11f1e_sd15_tile_fp16.yaml\"}\n",
|
302 |
+
" ],\n",
|
303 |
+
" \"12.inpaint\": [\n",
|
304 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_inpaint_fp16.safetensors\", \"name\": \"control_v11p_sd15_inpaint_fp16.safetensors\"},\n",
|
305 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_inpaint_fp16.yaml\", \"name\": \"control_v11p_sd15_inpaint_fp16.yaml\"}\n",
|
306 |
+
" ],\n",
|
307 |
+
" \"13.instruct_p2p\": [\n",
|
308 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p_fp16.safetensors\", \"name\": \"control_v11e_sd15_ip2p_fp16.safetensors\"},\n",
|
309 |
+
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_ip2p_fp16.yaml\", \"name\": \"control_v11e_sd15_ip2p_fp16.yaml\"}\n",
|
310 |
+
" ]\n",
|
311 |
+
"}\n",
|
312 |
+
"\n",
|
313 |
+
"url = \"\"\n",
|
314 |
+
"prefixes = {\n",
|
315 |
+
" \"model\": models_dir,\n",
|
316 |
+
" \"vae\": vaes_dir,\n",
|
317 |
+
" \"lora\": loras_dir,\n",
|
318 |
+
" \"embed\": embeddings_dir,\n",
|
319 |
+
" \"extension\": extensions_dir,\n",
|
320 |
+
" \"control\": control_dir,\n",
|
321 |
+
" \"adetailer\": adetailer_dir,\n",
|
322 |
+
" \"config\": webui_path\n",
|
323 |
+
"}\n",
|
324 |
+
"\n",
|
325 |
+
"extension_repo = []\n",
|
326 |
+
"directories = [value for key, value in prefixes.items()] # for unpucking zip files\n",
|
327 |
+
"!mkdir -p {\" \".join(directories)}\n",
|
328 |
+
"\n",
|
329 |
+
"hf_token = huggingface_token if huggingface_token else \"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\"\n",
|
330 |
+
"user_header = f\"\\\"Authorization: Bearer {hf_token}\\\"\"\n",
|
331 |
+
"\n",
|
332 |
+
"''' Formatted Info Output '''\n",
|
333 |
+
"\n",
|
334 |
+
"from math import floor\n",
|
335 |
+
"\n",
|
336 |
+
"def center_text(text, terminal_width=45):\n",
|
337 |
+
" text_length = len(text)\n",
|
338 |
+
" left_padding = floor((terminal_width - text_length) / 2)\n",
|
339 |
+
" right_padding = terminal_width - text_length - left_padding\n",
|
340 |
+
" return f\"\\033[1m\\033[36m{' ' * left_padding}{text}{' ' * right_padding}\\033[0m\\033[32m\"\n",
|
341 |
+
"\n",
|
342 |
+
"def format_output(url, dst_dir, file_name):\n",
|
343 |
+
" info = f\"[{file_name.split('.')[0]}]\"\n",
|
344 |
+
" info = center_text(info)\n",
|
345 |
+
"\n",
|
346 |
+
" print(f\"\\n\\033[32m{'---'*20}]{info}[{'---'*20}\")\n",
|
347 |
+
" print(f\"\\033[33mURL: \\033[34m{url}\")\n",
|
348 |
+
" print(f\"\\033[33mSAVE DIR: \\033[34m{dst_dir}\")\n",
|
349 |
+
" print(f\"\\033[33mFILE NAME: \\033[34m{file_name}\\033[0m\")\n",
|
350 |
+
"\n",
|
351 |
+
"''' GET CivitAi API - DATA '''\n",
|
352 |
+
"\n",
|
353 |
+
"def strip_(url, file_name=None):\n",
|
354 |
+
" if 'github.com' in url:\n",
|
355 |
+
" if '/blob/' in url:\n",
|
356 |
+
" url = url.replace('/blob/', '/raw/')\n",
|
357 |
+
"\n",
|
358 |
+
" elif \"civitai.com\" in url:\n",
|
359 |
+
" return CivitAi_API(url, file_name)\n",
|
360 |
+
"\n",
|
361 |
+
" elif \"huggingface.co\" in url:\n",
|
362 |
+
" if '/blob/' in url:\n",
|
363 |
+
" url = url.replace('/blob/', '/resolve/')\n",
|
364 |
+
" if '?' in url:\n",
|
365 |
+
" url = url.split('?')[0]\n",
|
366 |
+
"\n",
|
367 |
+
" return url\n",
|
368 |
+
"\n",
|
369 |
+
"def CivitAi_API(url, file_name=None):\n",
|
370 |
+
" support_types = ('Checkpoint', 'Model', 'TextualInversion', 'LORA')\n",
|
371 |
+
" civitai_token = \"62c0c5956b2f9defbd844d754000180b\"\n",
|
372 |
+
"\n",
|
373 |
+
" if '?token=' in url:\n",
|
374 |
+
" url = url.split('?token=')[0]\n",
|
375 |
+
" if '?type=' in url:\n",
|
376 |
+
" url = url.replace('?type=', f'?token={civitai_token}&type=')\n",
|
377 |
+
" else:\n",
|
378 |
+
" url = f\"{url}?token={civitai_token}\"\n",
|
379 |
+
"\n",
|
380 |
+
" # Determine model or version id\n",
|
381 |
+
" if \"civitai.com/models/\" in url:\n",
|
382 |
+
" if '?modelVersionId=' in url:\n",
|
383 |
+
" version_id = url.split('?modelVersionId=')[1]\n",
|
384 |
+
" response = requests.get(f\"https://civitai.com/api/v1/model-versions/{version_id}\")\n",
|
385 |
+
" # print(f\"end - https://civitai.com/api/v1/model-versions/{version_id}\")\n",
|
386 |
+
" else:\n",
|
387 |
+
" model_id = url.split('/models/')[1].split('/')[0]\n",
|
388 |
+
" response = requests.get(f\"https://civitai.com/api/v1/models/{model_id}\")\n",
|
389 |
+
" # print(f\"end - https://civitai.com/api/v1/models/{model_id}\")\n",
|
390 |
+
" else:\n",
|
391 |
+
" version_id = url.split('/models/')[1].split('/')[0]\n",
|
392 |
+
" response = requests.get(f\"https://civitai.com/api/v1/model-versions/{version_id}\")\n",
|
393 |
+
" # print(f\"end - https://civitai.com/api/v1/model-versions/{version_id}\")\n",
|
394 |
+
"\n",
|
395 |
+
" data = response.json()\n",
|
396 |
+
"\n",
|
397 |
+
" if response.status_code != 200:\n",
|
398 |
+
" return None, None, None, None, None, None, None\n",
|
399 |
+
"\n",
|
400 |
+
" # Define model type and name\n",
|
401 |
+
" if \"civitai.com/models/\" in url:\n",
|
402 |
+
" if '?modelVersionId=' in url:\n",
|
403 |
+
" model_type = data['model']['type']\n",
|
404 |
+
" model_name = data['files'][0]['name']\n",
|
405 |
+
" else:\n",
|
406 |
+
" model_type = data['type']\n",
|
407 |
+
" model_name = data['modelVersions'][0]['files'][0]['name']\n",
|
408 |
+
" elif 'type=' in url:\n",
|
409 |
+
" model_type = parse_qs(urlparse(url).query).get('type', [''])[0]\n",
|
410 |
+
" if 'model' in model_type.lower():\n",
|
411 |
+
" model_name = data['files'][0]['name']\n",
|
412 |
+
" else:\n",
|
413 |
+
" model_name = data['files'][1]['name']\n",
|
414 |
+
" else:\n",
|
415 |
+
" model_type = data['model']['type']\n",
|
416 |
+
" model_name = data['files'][0]['name']\n",
|
417 |
+
"\n",
|
418 |
+
" model_name = file_name or model_name\n",
|
419 |
+
"\n",
|
420 |
+
" # Determine DownloadUrl\n",
|
421 |
+
" if \"civitai.com/models/\" in url:\n",
|
422 |
+
" if '?modelVersionId=' in url:\n",
|
423 |
+
" download_url = data.get('downloadUrl')\n",
|
424 |
+
" else:\n",
|
425 |
+
" download_url = data[\"modelVersions\"][0].get(\"downloadUrl\", \"\")\n",
|
426 |
+
" elif 'type=' in url:\n",
|
427 |
+
" if any(t.lower() in model_type.lower() for t in support_types):\n",
|
428 |
+
" download_url = data['files'][0]['downloadUrl']\n",
|
429 |
+
" else:\n",
|
430 |
+
" download_url = data['files'][1]['downloadUrl']\n",
|
431 |
+
" else:\n",
|
432 |
+
" download_url = data.get('downloadUrl')\n",
|
433 |
+
"\n",
|
434 |
+
" clean_url = re.sub(r'[?&]token=[^&]*', '', download_url) # hide token\n",
|
435 |
+
"\n",
|
436 |
+
" # Find a safe image: level less than 4 | Kaggle\n",
|
437 |
+
" image_url, image_name = None, None\n",
|
438 |
+
" if any(t in model_type for t in support_types):\n",
|
439 |
+
" try:\n",
|
440 |
+
" images = data.get('images') or data['modelVersions'][0].get('images', [])\n",
|
441 |
+
" if env == 'Kaggle':\n",
|
442 |
+
" image_url = next((image['url'] for image in images if image['nsfwLevel'] < 4), None)\n",
|
443 |
+
" else:\n",
|
444 |
+
" image_url = images[0]['url'] if images else None\n",
|
445 |
+
" except KeyError:\n",
|
446 |
+
" pass\n",
|
447 |
+
"\n",
|
448 |
+
" # Generate a name to save the image\n",
|
449 |
+
" image_name = f\"{model_name.split('.')[0]}.preview.{image_url.split('.')[-1]}\" if image_url else None\n",
|
450 |
+
"\n",
|
451 |
+
" return f\"{download_url}{'&' if '?' in download_url else '?'}token={civitai_token}\", clean_url, model_type, model_name, image_url, image_name, data\n",
|
452 |
+
"\n",
|
453 |
+
"''' Main Download Code '''\n",
|
454 |
+
"\n",
|
455 |
+
"def download(url):\n",
|
456 |
+
" links_and_paths = [link_or_path.strip() for link_or_path in url.split(',') if link_or_path.strip()]\n",
|
457 |
+
"\n",
|
458 |
+
" for link_or_path in links_and_paths:\n",
|
459 |
+
" if any(link_or_path.lower().startswith(prefix) for prefix in prefixes):\n",
|
460 |
+
" handle_manual(link_or_path)\n",
|
461 |
+
" else:\n",
|
462 |
+
" url, dst_dir, file_name = link_or_path.split()\n",
|
463 |
+
" manual_download(url, dst_dir, file_name)\n",
|
464 |
+
"\n",
|
465 |
+
" unpack_zip_files()\n",
|
466 |
+
"\n",
|
467 |
+
"def unpack_zip_files():\n",
|
468 |
+
" for directory in directories:\n",
|
469 |
+
" for root, _, files in os.walk(directory):\n",
|
470 |
+
" for file in files:\n",
|
471 |
+
" if file.endswith(\".zip\"):\n",
|
472 |
+
" zip_path = os.path.join(root, file)\n",
|
473 |
+
" extract_path = os.path.splitext(zip_path)[0]\n",
|
474 |
+
" with zipfile.ZipFile(zip_path, 'r') as zip_ref:\n",
|
475 |
+
" zip_ref.extractall(extract_path)\n",
|
476 |
+
" os.remove(zip_path)\n",
|
477 |
+
"\n",
|
478 |
+
"def handle_manual(url):\n",
|
479 |
+
" url_parts = url.split(':', 1)\n",
|
480 |
+
" prefix, path = url_parts[0], url_parts[1]\n",
|
481 |
+
"\n",
|
482 |
+
" file_name_match = re.search(r'\\[(.*?)\\]', path)\n",
|
483 |
+
" file_name = file_name_match.group(1) if file_name_match else None\n",
|
484 |
+
" if file_name:\n",
|
485 |
+
" path = re.sub(r'\\[.*?\\]', '', path)\n",
|
486 |
+
"\n",
|
487 |
+
" if prefix in prefixes:\n",
|
488 |
+
" dir = prefixes[prefix]\n",
|
489 |
+
" if prefix != \"extension\":\n",
|
490 |
+
" try:\n",
|
491 |
+
" manual_download(path, dir, file_name=file_name)\n",
|
492 |
+
" except Exception as e:\n",
|
493 |
+
" print(f\"Error downloading file: {e}\")\n",
|
494 |
+
" else:\n",
|
495 |
+
" extension_repo.append((path, file_name))\n",
|
496 |
+
"\n",
|
497 |
+
"def manual_download(url, dst_dir, file_name):\n",
|
498 |
+
" aria2_args = '--optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c'\n",
|
499 |
+
" basename = url.split(\"/\")[-1] if file_name is None else file_name\n",
|
500 |
+
" header_option = f\"--header={user_header}\"\n",
|
501 |
+
"\n",
|
502 |
+
" if 'github.com' in url:\n",
|
503 |
+
" url = strip_(url)\n",
|
504 |
+
"\n",
|
505 |
+
" # -- CivitAi APi+ V2 --\n",
|
506 |
+
" elif 'civitai' in url:\n",
|
507 |
+
" url, clean_url, model_type, file_name, image_url, image_name, data = strip_(url, file_name)\n",
|
508 |
+
"\n",
|
509 |
+
" if image_url and image_name:\n",
|
510 |
+
" with capture.capture_output() as cap:\n",
|
511 |
+
" !aria2c {aria2_args} -d {dst_dir} -o '{image_name}' '{image_url}'\n",
|
512 |
+
" del cap\n",
|
513 |
+
"\n",
|
514 |
+
" elif \"huggingface.co\" in url:\n",
|
515 |
+
" clean_url = strip_(url)\n",
|
516 |
+
"\n",
|
517 |
+
" \"\"\" Formatted info output \"\"\"\n",
|
518 |
+
" model_name_or_basename = file_name if not 'huggingface' in url else basename\n",
|
519 |
+
" format_output(clean_url or url, dst_dir, model_name_or_basename)\n",
|
520 |
+
"\n",
|
521 |
+
" # ## -- for my tests --\n",
|
522 |
+
" # print(url, dst_dir, model_name_or_basename)\n",
|
523 |
+
" print(f\"\\033[31m[Data Info]:\\033[0m Failed to retrieve data from the API.\\n\") if 'civitai' in url and not data else None\n",
|
524 |
+
" if 'civitai' in url and data and image_name:\n",
|
525 |
+
" print(f\"\\033[32m[Preview DL]:\\033[0m {image_name} - {image_url}\\n\")\n",
|
526 |
+
" # =====================\n",
|
527 |
+
"\n",
|
528 |
+
" # # -- Git Hub --\n",
|
529 |
+
" if 'github.com' in url or 'githubusercontent.com' in url:\n",
|
530 |
+
" !aria2c {aria2_args} -d {dst_dir} -o '{basename}' '{url}'\n",
|
531 |
+
"\n",
|
532 |
+
" # -- GDrive --\n",
|
533 |
+
" elif 'drive.google' in url:\n",
|
534 |
+
" try:\n",
|
535 |
+
" have_drive_link\n",
|
536 |
+
" except:\n",
|
537 |
+
" !pip install -U gdown > /dev/null\n",
|
538 |
+
" have_drive_link = True\n",
|
539 |
+
"\n",
|
540 |
+
" if 'folders' in url:\n",
|
541 |
+
" !gdown --folder \"{url}\" -O {dst_dir} --fuzzy -c\n",
|
542 |
+
" else:\n",
|
543 |
+
" if file_name:\n",
|
544 |
+
" !gdown \"{url}\" -O {dst_dir}/{file_name} --fuzzy -c\n",
|
545 |
+
" else:\n",
|
546 |
+
" !gdown \"{url}\" -O {dst_dir} --fuzzy -c\n",
|
547 |
+
"\n",
|
548 |
+
" # -- Hugging Face --\n",
|
549 |
+
" elif 'huggingface' in url:\n",
|
550 |
+
" !aria2c {header_option} {aria2_args} -d {dst_dir} -o '{basename}' '{url}'\n",
|
551 |
+
"\n",
|
552 |
+
" # -- Other --\n",
|
553 |
+
" elif 'http' in url:\n",
|
554 |
+
" !aria2c {aria2_args} -d {dst_dir} '{'-o' + file_name if file_name else ''}' '{url}'\n",
|
555 |
+
"\n",
|
556 |
+
"''' SubModels - Added URLs '''\n",
|
557 |
+
"\n",
|
558 |
+
"def add_submodels(selection, num_selection, model_dict, dst_dir):\n",
|
559 |
+
" if selection == \"none\":\n",
|
560 |
+
" return []\n",
|
561 |
+
" if selection == \"ALL\":\n",
|
562 |
+
" all_models = []\n",
|
563 |
+
" for models in model_dict.values():\n",
|
564 |
+
" all_models.extend(models)\n",
|
565 |
+
" selected_models = all_models\n",
|
566 |
+
" else:\n",
|
567 |
+
" selected_models = model_dict[selection]\n",
|
568 |
+
" selected_nums = map(int, num_selection.replace(',', '').split())\n",
|
569 |
+
" for num in selected_nums:\n",
|
570 |
+
" if 1 <= num <= len(model_dict):\n",
|
571 |
+
" name = list(model_dict)[num - 1]\n",
|
572 |
+
" selected_models.extend(model_dict[name])\n",
|
573 |
+
"\n",
|
574 |
+
" unique_models = list({model['name']: model for model in selected_models}.values())\n",
|
575 |
+
" for model in unique_models:\n",
|
576 |
+
" model['dst_dir'] = dst_dir\n",
|
577 |
+
"\n",
|
578 |
+
" return unique_models\n",
|
579 |
+
"\n",
|
580 |
+
"def handle_submodels(selection, num_selection, model_dict, dst_dir, url):\n",
|
581 |
+
" submodels = add_submodels(selection, num_selection, model_dict, dst_dir)\n",
|
582 |
+
" for submodel in submodels:\n",
|
583 |
+
" if not inpainting_model and \"inpainting\" in submodel['name']:\n",
|
584 |
+
" continue\n",
|
585 |
+
" url += f\"{submodel['url']} {submodel['dst_dir']} {submodel['name']}, \"\n",
|
586 |
+
" return url\n",
|
587 |
+
"\n",
|
588 |
+
"url = handle_submodels(model, model_num, model_list, models_dir, url)\n",
|
589 |
+
"url = handle_submodels(vae, vae_num, vae_list, vaes_dir, url)\n",
|
590 |
+
"url = handle_submodels(controlnet, controlnet_num, controlnet_list, control_dir, url)\n",
|
591 |
+
"\n",
|
592 |
+
"''' file.txt - added urls '''\n",
|
593 |
+
"\n",
|
594 |
+
"def process_file_download(file_url, prefixes, unique_urls):\n",
|
595 |
+
" files_urls = \"\"\n",
|
596 |
+
"\n",
|
597 |
+
" if file_url.startswith(\"http\"):\n",
|
598 |
+
" if \"blob\" in file_url:\n",
|
599 |
+
" file_url = file_url.replace(\"blob\", \"raw\")\n",
|
600 |
+
" response = requests.get(file_url)\n",
|
601 |
+
" lines = response.text.split('\\n')\n",
|
602 |
+
" else:\n",
|
603 |
+
" with open(file_url, 'r') as file:\n",
|
604 |
+
" lines = file.readlines()\n",
|
605 |
+
"\n",
|
606 |
+
" current_tag = None\n",
|
607 |
+
" for line in lines:\n",
|
608 |
+
" line = line.strip()\n",
|
609 |
+
" if any(f'# {tag}' in line.lower() for tag in prefixes):\n",
|
610 |
+
" current_tag = next((tag for tag in prefixes if tag in line.lower()))\n",
|
611 |
+
"\n",
|
612 |
+
" urls = [url.split('#')[0].strip() for url in line.split(',')] # filter urls\n",
|
613 |
+
" for url in urls:\n",
|
614 |
+
" filter_url = url.split('[')[0] # same url filter\n",
|
615 |
+
"\n",
|
616 |
+
" if url.startswith(\"http\") and filter_url not in unique_urls:\n",
|
617 |
+
" files_urls += f\"{current_tag}:{url}, \"\n",
|
618 |
+
" unique_urls.add(filter_url)\n",
|
619 |
+
"\n",
|
620 |
+
" return files_urls\n",
|
621 |
+
"\n",
|
622 |
+
"file_urls = \"\"\n",
|
623 |
+
"unique_urls = set()\n",
|
624 |
+
"\n",
|
625 |
+
"if custom_file_urls:\n",
|
626 |
+
" for custom_file_url in custom_file_urls.replace(',', '').split():\n",
|
627 |
+
" if not custom_file_url.endswith('.txt'):\n",
|
628 |
+
" custom_file_url += '.txt'\n",
|
629 |
+
" if not custom_file_url.startswith('http'):\n",
|
630 |
+
" if not custom_file_url.startswith(root_path):\n",
|
631 |
+
" custom_file_url = f'{root_path}/{custom_file_url}'\n",
|
632 |
+
"\n",
|
633 |
+
" try:\n",
|
634 |
+
" file_urls += process_file_download(custom_file_url, prefixes, unique_urls)\n",
|
635 |
+
" except FileNotFoundError:\n",
|
636 |
+
" pass\n",
|
637 |
+
"\n",
|
638 |
+
"# url prefixing\n",
|
639 |
+
"urls = (Model_url, Vae_url, LoRA_url, Embedding_url, Extensions_url)\n",
|
640 |
+
"prefixed_urls = (f\"{prefix}:{url}\" for prefix, url in zip(prefixes.keys(), urls) if url for url in url.replace(',', '').split())\n",
|
641 |
+
"url += \", \".join(prefixed_urls) + \", \" + file_urls\n",
|
642 |
+
"\n",
|
643 |
+
"if detailed_download == \"on\":\n",
|
644 |
+
" print(\"\\n\\n\\033[33m# ====== Подробная Загрузка ====== #\\n\\033[0m\")\n",
|
645 |
+
" download(url)\n",
|
646 |
+
" print(\"\\n\\033[33m# =============================== #\\n\\033[0m\")\n",
|
647 |
+
"else:\n",
|
648 |
+
" with capture.capture_output() as cap:\n",
|
649 |
+
" download(url)\n",
|
650 |
+
" del cap\n",
|
651 |
+
"\n",
|
652 |
+
"print(\"\\r🏁 Скачивание Завершено!\" + \" \"*15)\n",
|
653 |
+
"\n",
|
654 |
+
"\n",
|
655 |
+
"# Cleaning shit after downloading...\n",
|
656 |
+
"!find {webui_path} \\( -type d \\( -name \".ipynb_checkpoints\" -o -name \".aria2\" \\) -o -type f -name \"*.aria2\" \\) -exec rm -r {{}} \\; >/dev/null 2>&1\n",
|
657 |
+
"\n",
|
658 |
+
"\n",
|
659 |
+
"## Install of Custom extensions\n",
|
660 |
+
"if len(extension_repo) > 0:\n",
|
661 |
+
" print(\"✨ Установка кастомных расширений...\", end='', flush=True)\n",
|
662 |
+
" with capture.capture_output() as cap:\n",
|
663 |
+
" for repo, repo_name in extension_repo:\n",
|
664 |
+
" if not repo_name:\n",
|
665 |
+
" repo_name = repo.split('/')[-1]\n",
|
666 |
+
" !cd {extensions_dir} \\\n",
|
667 |
+
" && git clone {repo} {repo_name} \\\n",
|
668 |
+
" && cd {repo_name} \\\n",
|
669 |
+
" && git fetch\n",
|
670 |
+
" del cap\n",
|
671 |
+
" print(f\"\\r📦 Установлено '{len(extension_repo)}', Кастомных расширений!\")\n",
|
672 |
+
"\n",
|
673 |
+
"\n",
|
674 |
+
"## List Models and stuff V2\n",
|
675 |
+
"if detailed_download == \"off\":\n",
|
676 |
+
" print(\"\\n\\n\\033[33mЕсли вы не видете каких-то скаченных файлов, включите в виджетах функцию 'Подробная Загрузка'.\")\n",
|
677 |
+
"\n",
|
678 |
+
"%run {root_path}/file_cell/special/dl_display_results.py # display widgets result"
|
679 |
+
]
|
680 |
+
}
|
681 |
+
],
|
682 |
+
"metadata": {
|
683 |
+
"colab": {
|
684 |
+
"provenance": []
|
685 |
+
},
|
686 |
+
"kernelspec": {
|
687 |
+
"display_name": "Python 3",
|
688 |
+
"name": "python3"
|
689 |
+
},
|
690 |
+
"language_info": {
|
691 |
+
"name": "python"
|
692 |
+
}
|
693 |
+
},
|
694 |
+
"nbformat": 4,
|
695 |
+
"nbformat_minor": 0
|
696 |
}
|
files_cells/notebooks/ru/launch_ru.ipynb
CHANGED
@@ -1,156 +1,145 @@
|
|
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 |
-
"import cloudpickle as pickle\n",
|
33 |
-
"from datetime import timedelta\n",
|
34 |
-
"from IPython.display import clear_output\n",
|
35 |
-
"\n",
|
36 |
-
"
|
37 |
-
"
|
38 |
-
"
|
39 |
-
"
|
40 |
-
"
|
41 |
-
" '
|
42 |
-
"
|
43 |
-
"
|
44 |
-
"
|
45 |
-
"
|
46 |
-
"
|
47 |
-
"
|
48 |
-
"\n",
|
49 |
-
"env, root_path, free_plan = detect_environment()\n",
|
50 |
-
"webui_path = f\"{root_path}/sdw\"\n",
|
51 |
-
"
|
52 |
-
"
|
53 |
-
"
|
54 |
-
"
|
55 |
-
"
|
56 |
-
"
|
57 |
-
"
|
58 |
-
"
|
59 |
-
"\n",
|
60 |
-
"
|
61 |
-
"
|
62 |
-
"
|
63 |
-
"
|
64 |
-
"
|
65 |
-
"
|
66 |
-
"\n",
|
67 |
-
"
|
68 |
-
"
|
69 |
-
"
|
70 |
-
"
|
71 |
-
"
|
72 |
-
"
|
73 |
-
"
|
74 |
-
"
|
75 |
-
"
|
76 |
-
"
|
77 |
-
"
|
78 |
-
"
|
79 |
-
"
|
80 |
-
"
|
81 |
-
"
|
82 |
-
"
|
83 |
-
"
|
84 |
-
"
|
85 |
-
"
|
86 |
-
"
|
87 |
-
"
|
88 |
-
"\n",
|
89 |
-
"
|
90 |
-
"
|
91 |
-
"
|
92 |
-
"
|
93 |
-
"
|
94 |
-
"\n",
|
95 |
-
"
|
96 |
-
"
|
97 |
-
"
|
98 |
-
"
|
99 |
-
"\n",
|
100 |
-
"
|
101 |
-
"\n",
|
102 |
-
"\n",
|
103 |
-
"
|
104 |
-
"
|
105 |
-
"
|
106 |
-
"
|
107 |
-
"
|
108 |
-
"
|
109 |
-
"
|
110 |
-
"
|
111 |
-
"
|
112 |
-
"\n",
|
113 |
-
"
|
114 |
-
"
|
115 |
-
"
|
116 |
-
"
|
117 |
-
"\n",
|
118 |
-
"
|
119 |
-
" if
|
120 |
-
"
|
121 |
-
"
|
122 |
-
"
|
123 |
-
"
|
124 |
-
"
|
125 |
-
"
|
126 |
-
"
|
127 |
-
"\n",
|
128 |
-
"\n",
|
129 |
-
"
|
130 |
-
"
|
131 |
-
"
|
132 |
-
"
|
133 |
-
"
|
134 |
-
"
|
135 |
-
"
|
136 |
-
"
|
137 |
-
"\n",
|
138 |
-
"
|
139 |
-
"
|
140 |
-
"
|
141 |
-
"
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
"# after runnig\n",
|
146 |
-
"start_colab = float(open(f'{webui_path}/static/colabTimer.txt', 'r').read())\n",
|
147 |
-
"time_since_start = str(timedelta(seconds=time.time()-start_colab)).split('.')[0]\n",
|
148 |
-
"print(f\"\\n⌚️ \\033[0mВы проводите эту сессию в течение - \\033[33m{time_since_start}\\033[0m\\n\\n\")\n",
|
149 |
-
"\n",
|
150 |
-
"''' del zrok tunnel '''\n",
|
151 |
-
"if zrok_token:\n",
|
152 |
-
" !zrok disable &> /dev/null"
|
153 |
-
]
|
154 |
-
}
|
155 |
-
]
|
156 |
}
|
|
|
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 |
+
"import cloudpickle as pickle\n",
|
33 |
+
"from datetime import timedelta\n",
|
34 |
+
"from IPython.display import clear_output\n",
|
35 |
+
"\n",
|
36 |
+
"# ================= DETECT ENV =================\n",
|
37 |
+
"def detect_environment():\n",
|
38 |
+
" free_plan = (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024 ** 3) <= 20)\n",
|
39 |
+
" environments = {\n",
|
40 |
+
" 'COLAB_GPU': ('Google Colab', \"/root\" if free_plan else \"/content\"),\n",
|
41 |
+
" 'KAGGLE_URL_BASE': ('Kaggle', \"/kaggle/working/content\")\n",
|
42 |
+
" }\n",
|
43 |
+
"\n",
|
44 |
+
" for env_var, (environment, path) in environments.items():\n",
|
45 |
+
" if env_var in os.environ:\n",
|
46 |
+
" return environment, path, free_plan\n",
|
47 |
+
" return 'Unknown', '/unknown/path', free_plan\n",
|
48 |
+
"\n",
|
49 |
+
"env, root_path, free_plan = detect_environment()\n",
|
50 |
+
"webui_path = f\"{root_path}/sdw\"\n",
|
51 |
+
"\n",
|
52 |
+
"def load_settings():\n",
|
53 |
+
" SETTINGS_FILE = f'{root_path}/settings.json'\n",
|
54 |
+
" if os.path.exists(SETTINGS_FILE):\n",
|
55 |
+
" with open(SETTINGS_FILE, 'r') as f:\n",
|
56 |
+
" return json.load(f)\n",
|
57 |
+
" return {}\n",
|
58 |
+
"\n",
|
59 |
+
"settings = load_settings()\n",
|
60 |
+
"ngrok_token = settings.get('ngrok_token', \"\")\n",
|
61 |
+
"zrok_token = settings.get('zrok_token', \"\")\n",
|
62 |
+
"commandline_arguments = settings.get('commandline_arguments', \"\")\n",
|
63 |
+
"change_webui = settings.get('change_webui', \"\")\n",
|
64 |
+
"\n",
|
65 |
+
"# ======================== TUNNEL V2 ========================\n",
|
66 |
+
"print('Please Wait...')\n",
|
67 |
+
"\n",
|
68 |
+
"def get_public_ip(version='ipv4'):\n",
|
69 |
+
" try:\n",
|
70 |
+
" url = f'https://api64.ipify.org?format=json&{version}=true'\n",
|
71 |
+
" response = requests.get(url)\n",
|
72 |
+
" return response.json().get('ip', 'N/A')\n",
|
73 |
+
" except Exception as e:\n",
|
74 |
+
" print(f\"Error getting public {version} address:\", e)\n",
|
75 |
+
"\n",
|
76 |
+
"# Check if public IP is already saved, if not then get it\n",
|
77 |
+
"public_ip_file = f\"{root_path}/public_ip.txt\"\n",
|
78 |
+
"if os.path.exists(public_ip_file):\n",
|
79 |
+
" with open(public_ip_file, 'r') as file:\n",
|
80 |
+
" public_ipv4 = file.read().strip()\n",
|
81 |
+
"else:\n",
|
82 |
+
" public_ipv4 = get_public_ip(version='ipv4')\n",
|
83 |
+
" with open(public_ip_file, 'w') as file:\n",
|
84 |
+
" file.write(public_ipv4)\n",
|
85 |
+
"\n",
|
86 |
+
"tunnel_class = pickle.load(open(f\"{root_path}/new_tunnel\", \"rb\"), encoding=\"utf-8\")\n",
|
87 |
+
"tunnel_port = 1834\n",
|
88 |
+
"tunnel = tunnel_class(tunnel_port)\n",
|
89 |
+
"tunnel.add_tunnel(command=\"cl tunnel --url localhost:{port}\", name=\"cl\", pattern=re.compile(r\"[\\w-]+\\.trycloudflare\\.com\"))\n",
|
90 |
+
"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",
|
91 |
+
"\n",
|
92 |
+
"if zrok_token:\n",
|
93 |
+
" !zrok enable {zrok_token} &> /dev/null\n",
|
94 |
+
" tunnel.add_tunnel(command=\"zrok share public http://localhost:{port}/ --headless\", name=\"zrok\", pattern=re.compile(r\"[\\w-]+\\.share\\.zrok\\.io\"))\n",
|
95 |
+
"\n",
|
96 |
+
"clear_output()\n",
|
97 |
+
"\n",
|
98 |
+
"# =============== Automatic Fixing Path V3 ===============\n",
|
99 |
+
"paths_to_check = {\n",
|
100 |
+
" \"tagger_hf_cache_dir\": f\"{webui_path}/models/interrogators/\",\n",
|
101 |
+
" \"additional_networks_extra_lora_path\": f\"{webui_path}/models/Lora/\",\n",
|
102 |
+
" \"ad_extra_models_dir\": f\"{webui_path}/models/adetailer/\",\n",
|
103 |
+
" \"sd_checkpoint_hash\": \"\",\n",
|
104 |
+
" \"sd_model_checkpoint\": \"\",\n",
|
105 |
+
" \"sd_vae\": \"None\"\n",
|
106 |
+
"}\n",
|
107 |
+
"\n",
|
108 |
+
"config_path = f'{webui_path}/ui-config.json'\n",
|
109 |
+
"\n",
|
110 |
+
"if os.path.exists(config_path):\n",
|
111 |
+
" with open(config_path, 'r') as file:\n",
|
112 |
+
" config_data = json.load(file)\n",
|
113 |
+
"\n",
|
114 |
+
" for key, value in paths_to_check.items():\n",
|
115 |
+
" if key in config_data and config_data[key] != value:\n",
|
116 |
+
" sed_command = f\"sed -i 's|\\\"{key}\\\": \\\".*\\\"|\\\"{key}\\\": \\\"{value}\\\"|' {config_path}\"\n",
|
117 |
+
" os.system(sed_command)\n",
|
118 |
+
"\n",
|
119 |
+
" if env == 'Kaggle':\n",
|
120 |
+
" get_ipython().system('sed -i \\'s/\"civitai_interface\\\\/NSFW content\\\\/value\":.*/\"civitai_interface\\\\/NSFW content\\\\/value\": false/g\\' {webui_path}/ui-config.json')\n",
|
121 |
+
"\n",
|
122 |
+
"with tunnel:\n",
|
123 |
+
" %cd {webui_path}\n",
|
124 |
+
"\n",
|
125 |
+
" commandline_arguments += f' --port={tunnel_port}'\n",
|
126 |
+
" if ngrok_token:\n",
|
127 |
+
" commandline_arguments += f' --ngrok {ngrok_token}'\n",
|
128 |
+
" if env != \"Google Colab\":\n",
|
129 |
+
" commandline_arguments += f' --encrypt-pass={tunnel_port} --api'\n",
|
130 |
+
"\n",
|
131 |
+
" if change_webui == 'Forge':\n",
|
132 |
+
" commandline_arguments += ' --cuda-stream --pin-shared-memory'\n",
|
133 |
+
"\n",
|
134 |
+
" !COMMANDLINE_ARGS=\"{commandline_arguments}\" python launch.py\n",
|
135 |
+
"\n",
|
136 |
+
"start_colab = float(open(f'{webui_path}/static/colabTimer.txt', 'r').read())\n",
|
137 |
+
"time_since_start = str(timedelta(seconds=time.time()-start_colab)).split('.')[0]\n",
|
138 |
+
"print(f\"\\n⌚️ \\033[0mВы проводите эту сессию в течение - \\033[33m{time_since_start}\\033[0m\\n\\n\")\n",
|
139 |
+
"\n",
|
140 |
+
"if zrok_token:\n",
|
141 |
+
" !zrok disable &> /dev/null"
|
142 |
+
]
|
143 |
+
}
|
144 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
}
|
files_cells/notebooks/ru/widgets_ru.ipynb
CHANGED
@@ -1,349 +1,349 @@
|
|
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 |
-
"##~ WIDGET CODE | BY: ANXETY ~##\n",
|
26 |
-
"\n",
|
27 |
-
"import os\n",
|
28 |
-
"import json\n",
|
29 |
-
"import time\n",
|
30 |
-
"import ipywidgets as widgets\n",
|
31 |
-
"from ipywidgets import widgets, Layout, Label, Button, VBox, HBox\n",
|
32 |
-
"from IPython.display import display, HTML, Javascript, 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 |
-
" for env_var, (environment, path) in environments.items():\n",
|
43 |
-
" if env_var in os.environ:\n",
|
44 |
-
" return environment, path, free_plan\n",
|
45 |
-
"\n",
|
46 |
-
"env, root_path, free_plan = detect_environment()\n",
|
47 |
-
"webui_path = f\"{root_path}/sdw\"\n",
|
48 |
-
"!mkdir -p {root_path}\n",
|
49 |
-
"\n",
|
50 |
-
"\n",
|
51 |
-
"# ==================== CSS JS ====================\n",
|
52 |
-
"##~ custom background images V1.5 ~##\n",
|
53 |
-
"import argparse\n",
|
54 |
-
"parser = argparse.ArgumentParser(description='This script processes an background image.')\n",
|
55 |
-
"parser.add_argument('-i', '--image', type=str, help='URL of the image to process', metavar='')\n",
|
56 |
-
"parser.add_argument('-o', '--opacity', type=float, help='Opacity level for the image, between 0 and 1', metavar='', default=0.3)\n",
|
57 |
-
"parser.add_argument('-b', '--blur', type=str, help='Blur level for the image', metavar='', default=0)\n",
|
58 |
-
"parser.add_argument('-y', type=int, help='Y coordinate for the image in px', metavar='', default=0)\n",
|
59 |
-
"parser.add_argument('-x', type=int, help='X coordinate for the image in px', metavar='', default=0)\n",
|
60 |
-
"parser.add_argument('-s', '--scale', type=int, help='Scale image in %%', metavar='', default=100)\n",
|
61 |
-
"parser.add_argument('-m', '--mode', action='store_true', help='Removes repetitive image tiles')\n",
|
62 |
-
"parser.add_argument('-t', '--transparent', action='store_true', help='Makes input/selection fields 35%% more transparent')\n",
|
63 |
-
"parser.add_argument('-bf', '--blur-fields', type=str, help='Background blur level for input/selection fields', metavar='', default=2)\n",
|
64 |
-
"\n",
|
65 |
-
"args = parser.parse_args()\n",
|
66 |
-
"\n",
|
67 |
-
"url_img = args.image\n",
|
68 |
-
"opacity_img = args.opacity\n",
|
69 |
-
"blur_img = args.blur\n",
|
70 |
-
"y_img = args.y\n",
|
71 |
-
"x_img = args.x\n",
|
72 |
-
"scale_img = args.scale\n",
|
73 |
-
"blur_fields = args.blur_fields\n",
|
74 |
-
"\n",
|
75 |
-
"## ---\n",
|
76 |
-
"\"\"\" WTF KAGGLE - WHAT THE FUCK IS THE DIFFERENCE OF 35 PIXELS!?!?!? \"\"\"\n",
|
77 |
-
"fix_heigh_img = \"-810px\" if env == \"Kaggle\" else \"-775px\"\n",
|
78 |
-
"\n",
|
79 |
-
"\"\"\" transperent fields \"\"\"\n",
|
80 |
-
"t_bg_alpha = \"1\" if not args.transparent else \"0.65\"\n",
|
81 |
-
"\n",
|
82 |
-
"\"\"\" mode img - repeats \"\"\"\n",
|
83 |
-
"mode_img = \"repeat\" if not args.mode else \"no-repeat\"\n",
|
84 |
-
"\n",
|
85 |
-
"container_background = f'''\n",
|
86 |
-
"<style>\n",
|
87 |
-
":root {{\n",
|
88 |
-
" /* for background container*/\n",
|
89 |
-
" --img_background: url({url_img});\n",
|
90 |
-
" --img_opacity: {opacity_img};\n",
|
91 |
-
" --img_blur: {blur_img}px;\n",
|
92 |
-
" --image_y: {y_img}px;\n",
|
93 |
-
" --image_x: {x_img}px;\n",
|
94 |
-
" --img_scale: {scale_img}%;\n",
|
95 |
-
" --img_mode: {mode_img};\n",
|
96 |
-
" --img_height_dif: {fix_heigh_img};\n",
|
97 |
-
"\n",
|
98 |
-
" /* for fields */\n",
|
99 |
-
" --bg-field-color: rgba(28, 28, 28, {t_bg_alpha}); /* -> #1c1c1c */\n",
|
100 |
-
" --bg-field-color-hover: rgba(38, 38, 38, {t_bg_alpha}); /* -> #262626; */\n",
|
101 |
-
" --bg-field-blur-level: {blur_fields}px;\n",
|
102 |
-
"}}\n",
|
103 |
-
"'''\n",
|
104 |
-
"\n",
|
105 |
-
"display(HTML(container_background))\n",
|
106 |
-
"\n",
|
107 |
-
"# Main CSS\n",
|
108 |
-
"css_file_path = f\"{root_path}/CSS/main_widgets.css\"\n",
|
109 |
-
"with open(css_file_path , \"r\") as f:\n",
|
110 |
-
" CSS = f.read()\n",
|
111 |
-
"display(HTML(f\"<style>{CSS}</style>\"))\n",
|
112 |
-
"\n",
|
113 |
-
"# Main JS\n",
|
114 |
-
"JS = '''\n",
|
115 |
-
"<!-- TOGGLE 'CustomDL' SCRIPT -->\n",
|
116 |
-
"<script>\n",
|
117 |
-
"function toggleContainer() {\n",
|
118 |
-
" let downloadContainer = document.querySelector('.container_custom_downlad');\n",
|
119 |
-
" let info = document.querySelector('.info');\n",
|
120 |
-
"\n",
|
121 |
-
" downloadContainer.classList.toggle('expanded');\n",
|
122 |
-
" info.classList.toggle('showed');\n",
|
123 |
-
"}\n",
|
124 |
-
"</script>\n",
|
125 |
-
"'''\n",
|
126 |
-
"display(HTML(JS))\n",
|
127 |
-
"\n",
|
128 |
-
"# ==================== WIDGETS V2 ====================\n",
|
129 |
-
"HR = widgets.HTML('<hr>')\n",
|
130 |
-
"\n",
|
131 |
-
"class WidgetFactory:\n",
|
132 |
-
" def __init__(self, style=None, layout=None):\n",
|
133 |
-
" self.style = style if style else {'description_width': 'initial'}\n",
|
134 |
-
" self.layout = layout if layout else widgets.Layout(max_width='1080px', width='100%')\n",
|
135 |
-
"\n",
|
136 |
-
" def create_html(self, content, class_name=None):\n",
|
137 |
-
" html_widget = widgets.HTML(content)\n",
|
138 |
-
" if class_name:\n",
|
139 |
-
" html_widget.add_class(class_name)\n",
|
140 |
-
" return html_widget\n",
|
141 |
-
"\n",
|
142 |
-
" def create_header(self, name):\n",
|
143 |
-
" return widgets.HTML(f'<div class=\"header\">{name}<div>')\n",
|
144 |
-
"\n",
|
145 |
-
" def create_dropdown(self, options, value, description):\n",
|
146 |
-
" return widgets.Dropdown(options=options, value=value, description=description, style=self.style, layout=self.layout)\n",
|
147 |
-
"\n",
|
148 |
-
" def create_text(self, description, placeholder='', value=''):\n",
|
149 |
-
" return widgets.Text(description=description, placeholder=placeholder, value=value, style=self.style, layout=self.layout)\n",
|
150 |
-
"\n",
|
151 |
-
" def create_checkbox(self, value, description):\n",
|
152 |
-
" return widgets.Checkbox(value=value, description=description, style=self.style, layout=self.layout)\n",
|
153 |
-
"\n",
|
154 |
-
" def create_button(self, description, class_name=None):\n",
|
155 |
-
" button = widgets.Button(description=description)\n",
|
156 |
-
" if class_name:\n",
|
157 |
-
" button.add_class(class_name)\n",
|
158 |
-
" return button\n",
|
159 |
-
"\n",
|
160 |
-
" def create_hbox(self, children):\n",
|
161 |
-
" return widgets.HBox(children)\n",
|
162 |
-
"\n",
|
163 |
-
" def create_vbox(self, children, class_names=None):\n",
|
164 |
-
" vbox = widgets.VBox(children)\n",
|
165 |
-
" if class_names:\n",
|
166 |
-
" for class_name in class_names:\n",
|
167 |
-
" vbox.add_class(class_name)\n",
|
168 |
-
" return vbox\n",
|
169 |
-
"\n",
|
170 |
-
" def display(self, widget):\n",
|
171 |
-
" display(widget)\n",
|
172 |
-
"\n",
|
173 |
-
"# Instantiate the factory\n",
|
174 |
-
"factory = WidgetFactory()\n",
|
175 |
-
"\n",
|
176 |
-
"# --- MODEL ---\n",
|
177 |
-
"model_header = factory.create_header('Выбор Модели')\n",
|
178 |
-
"model_options = ['none',\n",
|
179 |
-
" '1.Anime (by XpucT) + INP',\n",
|
180 |
-
" '2.BluMix [Anime] [V7] + INP',\n",
|
181 |
-
" '3.Cetus-Mix [Anime] [V4] + INP',\n",
|
182 |
-
" '4.Counterfeit [Anime] [V3] + INP',\n",
|
183 |
-
" '5.CuteColor [Anime] [V3]',\n",
|
184 |
-
" '6.Dark-Sushi-Mix [Anime]',\n",
|
185 |
-
" '7.Deliberate [Realism] [V6] + INP',\n",
|
186 |
-
" '8.Meina-Mix [Anime] [V11] + INP',\n",
|
187 |
-
" '9.Mix-Pro [Anime] [V4] + INP']\n",
|
188 |
-
"model_widget = factory.create_dropdown(model_options, '4.Counterfeit [Anime] [V3] + INP', 'Модель:')\n",
|
189 |
-
"model_num_widget = factory.create_text('Номер Модели:', 'Введите номера моделей для скачивания через запятую/пробел.')\n",
|
190 |
-
"inpainting_model_widget = factory.create_checkbox(False, 'Inpainting Модели')\n",
|
191 |
-
"\n",
|
192 |
-
"# Display Model\n",
|
193 |
-
"all_model_box = factory.create_vbox([model_header, model_widget, model_num_widget, inpainting_model_widget], class_names=[\"container\", \"image_1\"])\n",
|
194 |
-
"factory.display(all_model_box)\n",
|
195 |
-
"\n",
|
196 |
-
"# --- VAE ---\n",
|
197 |
-
"vae_header = factory.create_header('Выбор VAE')\n",
|
198 |
-
"vae_options = ['none',\n",
|
199 |
-
" '1.Anime.vae',\n",
|
200 |
-
" '2.Anything.vae',\n",
|
201 |
-
" '3.Blessed2.vae',\n",
|
202 |
-
" '4.ClearVae.vae',\n",
|
203 |
-
" '5.WD.vae']\n",
|
204 |
-
"vae_widget = factory.create_dropdown(vae_options, '3.Blessed2.vae', 'Vae:')\n",
|
205 |
-
"vae_num_widget = factory.create_text('Номер Vae:', 'Введите номера vae для скачивания через запятую/пробел.')\n",
|
206 |
-
"\n",
|
207 |
-
"# Display Vae\n",
|
208 |
-
"all_vae_box = factory.create_vbox([vae_header, vae_widget, vae_num_widget], class_names=[\"container\", \"image_2\"])\n",
|
209 |
-
"factory.display(all_vae_box)\n",
|
210 |
-
"\n",
|
211 |
-
"# --- ADDITIONAL ---\n",
|
212 |
-
"additional_header = factory.create_header('Дополнительно')\n",
|
213 |
-
"latest_webui_widget = factory.create_checkbox(True, 'Обновить WebUI')\n",
|
214 |
-
"latest_exstensions_widget = factory.create_checkbox(True, 'Обновить Расширения')\n",
|
215 |
-
"change_webui_widget = factory.create_dropdown(['A1111', 'Forge'], 'A1111', 'Изменить WebUI:')\n",
|
216 |
-
"detailed_download_widget = factory.create_dropdown(['off', 'on'], 'off', 'Подробная Загрузка:')\n",
|
217 |
-
"choose_changes_widget = factory.create_hbox([latest_webui_widget, latest_exstensions_widget, change_webui_widget, detailed_download_widget])\n",
|
218 |
-
"\n",
|
219 |
-
"controlnet_options = ['none', 'ALL', '1.canny',\n",
|
220 |
-
" '2.openpose', '3.depth',\n",
|
221 |
-
" '4.normal_map', '5.mlsd',\n",
|
222 |
-
" '6.lineart', '7.soft_edge',\n",
|
223 |
-
" '8.scribble', '9.segmentation',\n",
|
224 |
-
" '10.shuffle', '11.tile',\n",
|
225 |
-
" '12.inpaint', '13.instruct_p2p']\n",
|
226 |
-
"controlnet_widget = factory.create_dropdown(controlnet_options, 'none', 'ControlNet:')\n",
|
227 |
-
"controlnet_num_widget = factory.create_text('Номер ControlNet:', 'Введите номера моделей ControlNet для скачивания через запятую/пробел.')\n",
|
228 |
-
"commit_hash_widget = factory.create_text('Commit Hash:')\n",
|
229 |
-
"huggingface_token_widget = factory.create_text('Токен HuggingFace:')\n",
|
230 |
-
"\n",
|
231 |
-
"ngrok_token_widget = factory.create_text('Токен Ngrok:')\n",
|
232 |
-
"ngrock_button = factory.create_html('<a href=\"https://dashboard.ngrok.com/get-started/your-authtoken\" target=\"_blank\">Получить Ngrok Токен</a>', class_name=\"button_ngrok\")\n",
|
233 |
-
"ngrok_widget = factory.create_hbox([ngrok_token_widget, ngrock_button])\n",
|
234 |
-
"\n",
|
235 |
-
"zrok_token_widget = factory.create_text('Токен Zrok:')\n",
|
236 |
-
"zrok_button = factory.create_html('<a href=\"https://colab.research.google.com/drive/1d2sjWDJi_GYBUavrHSuQyHTDuLy36WpU\" target=\"_blank\">Зарегать Zrok Токен</a>', class_name=\"button_ngrok\")\n",
|
237 |
-
"zrok_widget = factory.create_hbox([zrok_token_widget, zrok_button])\n",
|
238 |
-
"\n",
|
239 |
-
"commandline_arguments_options = \"--listen --enable-insecure-extension-access --theme dark --no-half-vae --disable-console-progressbars --xformers\"\n",
|
240 |
-
"commandline_arguments_widget = factory.create_text('Аргументы:', value=commandline_arguments_options)\n",
|
241 |
-
"\n",
|
242 |
-
"# Display Additional\n",
|
243 |
-
"additional_widget_list = [additional_header,\n",
|
244 |
-
" choose_changes_widget,\n",
|
245 |
-
" HR,\n",
|
246 |
-
" controlnet_widget,\n",
|
247 |
-
" controlnet_num_widget,\n",
|
248 |
-
" commit_hash_widget,\n",
|
249 |
-
" huggingface_token_widget,\n",
|
250 |
-
" ngrok_widget,\n",
|
251 |
-
" zrok_widget,\n",
|
252 |
-
" HR,\n",
|
253 |
-
" commandline_arguments_widget]\n",
|
254 |
-
"\n",
|
255 |
-
"if free_plan and env == \"Google Colab\": # remove ngrok from colab\n",
|
256 |
-
" additional_widget_list.remove(ngrok_widget)\n",
|
257 |
-
"if os.path.exists(webui_path): # remove selection after selection ;3\n",
|
258 |
-
" choose_changes_widget.children = [widget for widget in choose_changes_widget.children if widget != change_webui_widget]\n",
|
259 |
-
"\n",
|
260 |
-
"all_additional_box = factory.create_vbox(additional_widget_list, class_names=[\"container\", \"image_3\"])\n",
|
261 |
-
"factory.display(all_additional_box)\n",
|
262 |
-
"\n",
|
263 |
-
"# --- CUSTOM DOWNLOAD ---\n",
|
264 |
-
"custom_download_header_popup = factory.create_html('''\n",
|
265 |
-
"<style>\n",
|
266 |
-
"/* Term Colors */\n",
|
267 |
-
".sample_label {color: #dbafff;}\n",
|
268 |
-
".braces {color: #ffff00;}\n",
|
269 |
-
".extension {color: #eb934b;}\n",
|
270 |
-
".file_name {color: #ffffd8;}\n",
|
271 |
-
"</style>\n",
|
272 |
-
"\n",
|
273 |
-
"<div class=\"header\" style=\"cursor: pointer;\" onclick=\"toggleContainer()\">Кастомная Загрузка</div>\n",
|
274 |
-
"<!-- PopUp Window -->\n",
|
275 |
-
"<div class=\"info\" id=\"info_dl\">INFO</div>\n",
|
276 |
-
"<div class=\"popup\">\n",
|
277 |
-
" Разделите несколько URL-адресов запятой/пробелом. Для <span class=\"file_name\">пользовательского имени</span> файла/расширения укажите его через <span class=\"braces\">[]</span>\n",
|
278 |
-
" после URL без пробелов.\n",
|
279 |
-
" <span style=\"color: #ff9999\">Для файлов обязательно укажите</span> - <span class=\"extension\">Расширение Файла.</span>\n",
|
280 |
-
" <div class=\"sample\">\n",
|
281 |
-
" <span class=\"sample_label\">Пример для Файла:</span>\n",
|
282 |
-
" 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",
|
283 |
-
" <br>\n",
|
284 |
-
" <span class=\"sample_label\">Пример для Расширения:</span>\n",
|
285 |
-
" 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",
|
286 |
-
" </div>\n",
|
287 |
-
"</div>\n",
|
288 |
-
"''')\n",
|
289 |
-
"\n",
|
290 |
-
"Model_url_widget = factory.create_text('Model:')\n",
|
291 |
-
"Vae_url_widget = factory.create_text('Vae:')\n",
|
292 |
-
"LoRA_url_widget = factory.create_text('LoRa:')\n",
|
293 |
-
"Embedding_url_widget = factory.create_text('Embedding:')\n",
|
294 |
-
"Extensions_url_widget = factory.create_text('Extensions:')\n",
|
295 |
-
"custom_file_urls_widget = factory.create_text('Файл (txt):')\n",
|
296 |
-
"\n",
|
297 |
-
"# Display CustomDl\n",
|
298 |
-
"all_custom_box = factory.create_vbox([\n",
|
299 |
-
" custom_download_header_popup, Model_url_widget, Vae_url_widget, LoRA_url_widget, Embedding_url_widget, Extensions_url_widget, custom_file_urls_widget\n",
|
300 |
-
"], class_names=[\"container\", \"image_4\", \"container_custom_downlad\"])\n",
|
301 |
-
"factory.display(all_custom_box)\n",
|
302 |
-
"\n",
|
303 |
-
"# --- Save Button ---\n",
|
304 |
-
"save_button = factory.create_button('Сохранить', class_name=\"button_save\")\n",
|
305 |
-
"factory.display(save_button)\n",
|
306 |
-
"\n",
|
307 |
-
"\n",
|
308 |
-
"# ============ Load / Save - Settings V2 ============\n",
|
309 |
-
"SETTINGS_FILE = f'{root_path}/settings.json'\n",
|
310 |
-
"\n",
|
311 |
-
"SETTINGS_KEYS = [\n",
|
312 |
-
" 'model', 'model_num', 'inpainting_model',\n",
|
313 |
-
" 'vae', 'vae_num', 'latest_webui', 'latest_exstensions',\n",
|
314 |
-
" 'change_webui', 'detailed_download', 'controlnet',\n",
|
315 |
-
" 'controlnet_num', 'commit_hash', 'huggingface_token',\n",
|
316 |
-
" 'ngrok_token', 'zrok_token', 'commandline_arguments',\n",
|
317 |
-
" 'Model_url', 'Vae_url', 'LoRA_url', 'Embedding_url',\n",
|
318 |
-
" 'Extensions_url', 'custom_file_urls'\n",
|
319 |
-
"]\n",
|
320 |
-
"\n",
|
321 |
-
"def save_settings():\n",
|
322 |
-
" settings = {key: globals()[f\"{key}_widget\"].value for key in SETTINGS_KEYS}\n",
|
323 |
-
" with open(SETTINGS_FILE, 'w') as f:\n",
|
324 |
-
" json.dump(settings, f, indent=2)\n",
|
325 |
-
"\n",
|
326 |
-
"def load_settings():\n",
|
327 |
-
" if os.path.exists(SETTINGS_FILE):\n",
|
328 |
-
" with open(SETTINGS_FILE, 'r') as f:\n",
|
329 |
-
" settings = json.load(f)\n",
|
330 |
-
" for key in SETTINGS_KEYS:\n",
|
331 |
-
" globals()[f\"{key}_widget\"].value = settings.get(key, \"\")\n",
|
332 |
-
"\n",
|
333 |
-
"def hide_widgets():\n",
|
334 |
-
" widgets_list = [all_model_box, all_vae_box, all_additional_box, all_custom_box, save_button]\n",
|
335 |
-
" for widget in widgets_list:\n",
|
336 |
-
" widget.add_class(\"hide\")\n",
|
337 |
-
" time.sleep(0.5)\n",
|
338 |
-
" widgets.Widget.close_all()\n",
|
339 |
-
"\n",
|
340 |
-
"def save_data(button):\n",
|
341 |
-
" save_settings()\n",
|
342 |
-
" hide_widgets()\n",
|
343 |
-
"\n",
|
344 |
-
"load_settings()\n",
|
345 |
-
"save_button.on_click(save_data)"
|
346 |
-
]
|
347 |
-
}
|
348 |
-
]
|
349 |
}
|
|
|
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 |
+
"##~ WIDGET CODE | BY: ANXETY ~##\n",
|
26 |
+
"\n",
|
27 |
+
"import os\n",
|
28 |
+
"import json\n",
|
29 |
+
"import time\n",
|
30 |
+
"import ipywidgets as widgets\n",
|
31 |
+
"from ipywidgets import widgets, Layout, Label, Button, VBox, HBox\n",
|
32 |
+
"from IPython.display import display, HTML, Javascript, 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 |
+
" for env_var, (environment, path) in environments.items():\n",
|
43 |
+
" if env_var in os.environ:\n",
|
44 |
+
" return environment, path, free_plan\n",
|
45 |
+
"\n",
|
46 |
+
"env, root_path, free_plan = detect_environment()\n",
|
47 |
+
"webui_path = f\"{root_path}/sdw\"\n",
|
48 |
+
"!mkdir -p {root_path}\n",
|
49 |
+
"\n",
|
50 |
+
"\n",
|
51 |
+
"# ==================== CSS JS ====================\n",
|
52 |
+
"##~ custom background images V1.5 ~##\n",
|
53 |
+
"import argparse\n",
|
54 |
+
"parser = argparse.ArgumentParser(description='This script processes an background image.')\n",
|
55 |
+
"parser.add_argument('-i', '--image', type=str, help='URL of the image to process', metavar='')\n",
|
56 |
+
"parser.add_argument('-o', '--opacity', type=float, help='Opacity level for the image, between 0 and 1', metavar='', default=0.3)\n",
|
57 |
+
"parser.add_argument('-b', '--blur', type=str, help='Blur level for the image', metavar='', default=0)\n",
|
58 |
+
"parser.add_argument('-y', type=int, help='Y coordinate for the image in px', metavar='', default=0)\n",
|
59 |
+
"parser.add_argument('-x', type=int, help='X coordinate for the image in px', metavar='', default=0)\n",
|
60 |
+
"parser.add_argument('-s', '--scale', type=int, help='Scale image in %%', metavar='', default=100)\n",
|
61 |
+
"parser.add_argument('-m', '--mode', action='store_true', help='Removes repetitive image tiles')\n",
|
62 |
+
"parser.add_argument('-t', '--transparent', action='store_true', help='Makes input/selection fields 35%% more transparent')\n",
|
63 |
+
"parser.add_argument('-bf', '--blur-fields', type=str, help='Background blur level for input/selection fields', metavar='', default=2)\n",
|
64 |
+
"\n",
|
65 |
+
"args = parser.parse_args()\n",
|
66 |
+
"\n",
|
67 |
+
"url_img = args.image\n",
|
68 |
+
"opacity_img = args.opacity\n",
|
69 |
+
"blur_img = args.blur\n",
|
70 |
+
"y_img = args.y\n",
|
71 |
+
"x_img = args.x\n",
|
72 |
+
"scale_img = args.scale\n",
|
73 |
+
"blur_fields = args.blur_fields\n",
|
74 |
+
"\n",
|
75 |
+
"## ---\n",
|
76 |
+
"\"\"\" WTF KAGGLE - WHAT THE FUCK IS THE DIFFERENCE OF 35 PIXELS!?!?!? \"\"\"\n",
|
77 |
+
"fix_heigh_img = \"-810px\" if env == \"Kaggle\" else \"-775px\"\n",
|
78 |
+
"\n",
|
79 |
+
"\"\"\" transperent fields \"\"\"\n",
|
80 |
+
"t_bg_alpha = \"1\" if not args.transparent else \"0.65\"\n",
|
81 |
+
"\n",
|
82 |
+
"\"\"\" mode img - repeats \"\"\"\n",
|
83 |
+
"mode_img = \"repeat\" if not args.mode else \"no-repeat\"\n",
|
84 |
+
"\n",
|
85 |
+
"container_background = f'''\n",
|
86 |
+
"<style>\n",
|
87 |
+
":root {{\n",
|
88 |
+
" /* for background container*/\n",
|
89 |
+
" --img_background: url({url_img});\n",
|
90 |
+
" --img_opacity: {opacity_img};\n",
|
91 |
+
" --img_blur: {blur_img}px;\n",
|
92 |
+
" --image_y: {y_img}px;\n",
|
93 |
+
" --image_x: {x_img}px;\n",
|
94 |
+
" --img_scale: {scale_img}%;\n",
|
95 |
+
" --img_mode: {mode_img};\n",
|
96 |
+
" --img_height_dif: {fix_heigh_img};\n",
|
97 |
+
"\n",
|
98 |
+
" /* for fields */\n",
|
99 |
+
" --bg-field-color: rgba(28, 28, 28, {t_bg_alpha}); /* -> #1c1c1c */\n",
|
100 |
+
" --bg-field-color-hover: rgba(38, 38, 38, {t_bg_alpha}); /* -> #262626; */\n",
|
101 |
+
" --bg-field-blur-level: {blur_fields}px;\n",
|
102 |
+
"}}\n",
|
103 |
+
"'''\n",
|
104 |
+
"\n",
|
105 |
+
"display(HTML(container_background))\n",
|
106 |
+
"\n",
|
107 |
+
"# Main CSS\n",
|
108 |
+
"css_file_path = f\"{root_path}/CSS/main_widgets.css\"\n",
|
109 |
+
"with open(css_file_path , \"r\") as f:\n",
|
110 |
+
" CSS = f.read()\n",
|
111 |
+
"display(HTML(f\"<style>{CSS}</style>\"))\n",
|
112 |
+
"\n",
|
113 |
+
"# Main JS\n",
|
114 |
+
"JS = '''\n",
|
115 |
+
"<!-- TOGGLE 'CustomDL' SCRIPT -->\n",
|
116 |
+
"<script>\n",
|
117 |
+
"function toggleContainer() {\n",
|
118 |
+
" let downloadContainer = document.querySelector('.container_custom_downlad');\n",
|
119 |
+
" let info = document.querySelector('.info');\n",
|
120 |
+
"\n",
|
121 |
+
" downloadContainer.classList.toggle('expanded');\n",
|
122 |
+
" info.classList.toggle('showed');\n",
|
123 |
+
"}\n",
|
124 |
+
"</script>\n",
|
125 |
+
"'''\n",
|
126 |
+
"display(HTML(JS))\n",
|
127 |
+
"\n",
|
128 |
+
"# ==================== WIDGETS V2 ====================\n",
|
129 |
+
"HR = widgets.HTML('<hr>')\n",
|
130 |
+
"\n",
|
131 |
+
"class WidgetFactory:\n",
|
132 |
+
" def __init__(self, style=None, layout=None):\n",
|
133 |
+
" self.style = style if style else {'description_width': 'initial'}\n",
|
134 |
+
" self.layout = layout if layout else widgets.Layout(max_width='1080px', width='100%')\n",
|
135 |
+
"\n",
|
136 |
+
" def create_html(self, content, class_name=None):\n",
|
137 |
+
" html_widget = widgets.HTML(content)\n",
|
138 |
+
" if class_name:\n",
|
139 |
+
" html_widget.add_class(class_name)\n",
|
140 |
+
" return html_widget\n",
|
141 |
+
"\n",
|
142 |
+
" def create_header(self, name):\n",
|
143 |
+
" return widgets.HTML(f'<div class=\"header\">{name}<div>')\n",
|
144 |
+
"\n",
|
145 |
+
" def create_dropdown(self, options, value, description):\n",
|
146 |
+
" return widgets.Dropdown(options=options, value=value, description=description, style=self.style, layout=self.layout)\n",
|
147 |
+
"\n",
|
148 |
+
" def create_text(self, description, placeholder='', value=''):\n",
|
149 |
+
" return widgets.Text(description=description, placeholder=placeholder, value=value, style=self.style, layout=self.layout)\n",
|
150 |
+
"\n",
|
151 |
+
" def create_checkbox(self, value, description):\n",
|
152 |
+
" return widgets.Checkbox(value=value, description=description, style=self.style, layout=self.layout)\n",
|
153 |
+
"\n",
|
154 |
+
" def create_button(self, description, class_name=None):\n",
|
155 |
+
" button = widgets.Button(description=description)\n",
|
156 |
+
" if class_name:\n",
|
157 |
+
" button.add_class(class_name)\n",
|
158 |
+
" return button\n",
|
159 |
+
"\n",
|
160 |
+
" def create_hbox(self, children):\n",
|
161 |
+
" return widgets.HBox(children)\n",
|
162 |
+
"\n",
|
163 |
+
" def create_vbox(self, children, class_names=None):\n",
|
164 |
+
" vbox = widgets.VBox(children)\n",
|
165 |
+
" if class_names:\n",
|
166 |
+
" for class_name in class_names:\n",
|
167 |
+
" vbox.add_class(class_name)\n",
|
168 |
+
" return vbox\n",
|
169 |
+
"\n",
|
170 |
+
" def display(self, widget):\n",
|
171 |
+
" display(widget)\n",
|
172 |
+
"\n",
|
173 |
+
"# Instantiate the factory\n",
|
174 |
+
"factory = WidgetFactory()\n",
|
175 |
+
"\n",
|
176 |
+
"# --- MODEL ---\n",
|
177 |
+
"model_header = factory.create_header('Выбор Модели')\n",
|
178 |
+
"model_options = ['none',\n",
|
179 |
+
" '1.Anime (by XpucT) + INP',\n",
|
180 |
+
" '2.BluMix [Anime] [V7] + INP',\n",
|
181 |
+
" '3.Cetus-Mix [Anime] [V4] + INP',\n",
|
182 |
+
" '4.Counterfeit [Anime] [V3] + INP',\n",
|
183 |
+
" '5.CuteColor [Anime] [V3]',\n",
|
184 |
+
" '6.Dark-Sushi-Mix [Anime]',\n",
|
185 |
+
" '7.Deliberate [Realism] [V6] + INP',\n",
|
186 |
+
" '8.Meina-Mix [Anime] [V11] + INP',\n",
|
187 |
+
" '9.Mix-Pro [Anime] [V4] + INP']\n",
|
188 |
+
"model_widget = factory.create_dropdown(model_options, '4.Counterfeit [Anime] [V3] + INP', 'Модель:')\n",
|
189 |
+
"model_num_widget = factory.create_text('Номер Модели:', 'Введите номера моделей для скачивания через запятую/пробел.')\n",
|
190 |
+
"inpainting_model_widget = factory.create_checkbox(False, 'Inpainting Модели')\n",
|
191 |
+
"\n",
|
192 |
+
"# Display Model\n",
|
193 |
+
"all_model_box = factory.create_vbox([model_header, model_widget, model_num_widget, inpainting_model_widget], class_names=[\"container\", \"image_1\"])\n",
|
194 |
+
"factory.display(all_model_box)\n",
|
195 |
+
"\n",
|
196 |
+
"# --- VAE ---\n",
|
197 |
+
"vae_header = factory.create_header('Выбор VAE')\n",
|
198 |
+
"vae_options = ['none',\n",
|
199 |
+
" '1.Anime.vae',\n",
|
200 |
+
" '2.Anything.vae',\n",
|
201 |
+
" '3.Blessed2.vae',\n",
|
202 |
+
" '4.ClearVae.vae',\n",
|
203 |
+
" '5.WD.vae']\n",
|
204 |
+
"vae_widget = factory.create_dropdown(vae_options, '3.Blessed2.vae', 'Vae:')\n",
|
205 |
+
"vae_num_widget = factory.create_text('Номер Vae:', 'Введите номера vae для скачивания через запятую/пробел.')\n",
|
206 |
+
"\n",
|
207 |
+
"# Display Vae\n",
|
208 |
+
"all_vae_box = factory.create_vbox([vae_header, vae_widget, vae_num_widget], class_names=[\"container\", \"image_2\"])\n",
|
209 |
+
"factory.display(all_vae_box)\n",
|
210 |
+
"\n",
|
211 |
+
"# --- ADDITIONAL ---\n",
|
212 |
+
"additional_header = factory.create_header('Дополнительно')\n",
|
213 |
+
"latest_webui_widget = factory.create_checkbox(True, 'Обновить WebUI')\n",
|
214 |
+
"latest_exstensions_widget = factory.create_checkbox(True, 'Обновить Расширения')\n",
|
215 |
+
"change_webui_widget = factory.create_dropdown(['A1111', 'Forge'], 'A1111', 'Изменить WebUI:')\n",
|
216 |
+
"detailed_download_widget = factory.create_dropdown(['off', 'on'], 'off', 'Подробная Загрузка:')\n",
|
217 |
+
"choose_changes_widget = factory.create_hbox([latest_webui_widget, latest_exstensions_widget, change_webui_widget, detailed_download_widget])\n",
|
218 |
+
"\n",
|
219 |
+
"controlnet_options = ['none', 'ALL', '1.canny',\n",
|
220 |
+
" '2.openpose', '3.depth',\n",
|
221 |
+
" '4.normal_map', '5.mlsd',\n",
|
222 |
+
" '6.lineart', '7.soft_edge',\n",
|
223 |
+
" '8.scribble', '9.segmentation',\n",
|
224 |
+
" '10.shuffle', '11.tile',\n",
|
225 |
+
" '12.inpaint', '13.instruct_p2p']\n",
|
226 |
+
"controlnet_widget = factory.create_dropdown(controlnet_options, 'none', 'ControlNet:')\n",
|
227 |
+
"controlnet_num_widget = factory.create_text('Номер ControlNet:', 'Введите номера моделей ControlNet для скачивания через запятую/пробел.')\n",
|
228 |
+
"commit_hash_widget = factory.create_text('Commit Hash:')\n",
|
229 |
+
"huggingface_token_widget = factory.create_text('Токен HuggingFace:')\n",
|
230 |
+
"\n",
|
231 |
+
"ngrok_token_widget = factory.create_text('Токен Ngrok:')\n",
|
232 |
+
"ngrock_button = factory.create_html('<a href=\"https://dashboard.ngrok.com/get-started/your-authtoken\" target=\"_blank\">Получить Ngrok Токен</a>', class_name=\"button_ngrok\")\n",
|
233 |
+
"ngrok_widget = factory.create_hbox([ngrok_token_widget, ngrock_button])\n",
|
234 |
+
"\n",
|
235 |
+
"zrok_token_widget = factory.create_text('Токен Zrok:')\n",
|
236 |
+
"zrok_button = factory.create_html('<a href=\"https://colab.research.google.com/drive/1d2sjWDJi_GYBUavrHSuQyHTDuLy36WpU\" target=\"_blank\">Зарегать Zrok Токен</a>', class_name=\"button_ngrok\")\n",
|
237 |
+
"zrok_widget = factory.create_hbox([zrok_token_widget, zrok_button])\n",
|
238 |
+
"\n",
|
239 |
+
"commandline_arguments_options = \"--listen --enable-insecure-extension-access --theme dark --no-half-vae --disable-console-progressbars --xformers\"\n",
|
240 |
+
"commandline_arguments_widget = factory.create_text('Аргументы:', value=commandline_arguments_options)\n",
|
241 |
+
"\n",
|
242 |
+
"# Display Additional\n",
|
243 |
+
"additional_widget_list = [additional_header,\n",
|
244 |
+
" choose_changes_widget,\n",
|
245 |
+
" HR,\n",
|
246 |
+
" controlnet_widget,\n",
|
247 |
+
" controlnet_num_widget,\n",
|
248 |
+
" commit_hash_widget,\n",
|
249 |
+
" huggingface_token_widget,\n",
|
250 |
+
" ngrok_widget,\n",
|
251 |
+
" zrok_widget,\n",
|
252 |
+
" HR,\n",
|
253 |
+
" commandline_arguments_widget]\n",
|
254 |
+
"\n",
|
255 |
+
"if free_plan and env == \"Google Colab\": # remove ngrok from colab\n",
|
256 |
+
" additional_widget_list.remove(ngrok_widget)\n",
|
257 |
+
"if os.path.exists(webui_path): # remove selection after selection ;3\n",
|
258 |
+
" choose_changes_widget.children = [widget for widget in choose_changes_widget.children if widget != change_webui_widget]\n",
|
259 |
+
"\n",
|
260 |
+
"all_additional_box = factory.create_vbox(additional_widget_list, class_names=[\"container\", \"image_3\"])\n",
|
261 |
+
"factory.display(all_additional_box)\n",
|
262 |
+
"\n",
|
263 |
+
"# --- CUSTOM DOWNLOAD ---\n",
|
264 |
+
"custom_download_header_popup = factory.create_html('''\n",
|
265 |
+
"<style>\n",
|
266 |
+
"/* Term Colors */\n",
|
267 |
+
".sample_label {color: #dbafff;}\n",
|
268 |
+
".braces {color: #ffff00;}\n",
|
269 |
+
".extension {color: #eb934b;}\n",
|
270 |
+
".file_name {color: #ffffd8;}\n",
|
271 |
+
"</style>\n",
|
272 |
+
"\n",
|
273 |
+
"<div class=\"header\" style=\"cursor: pointer;\" onclick=\"toggleContainer()\">Кастомная Загрузка</div>\n",
|
274 |
+
"<!-- PopUp Window -->\n",
|
275 |
+
"<div class=\"info\" id=\"info_dl\">INFO</div>\n",
|
276 |
+
"<div class=\"popup\">\n",
|
277 |
+
" Разделите несколько URL-адресов запятой/пробелом. Для <span class=\"file_name\">пользовательского имени</span> файла/расширения укажите его через <span class=\"braces\">[]</span>\n",
|
278 |
+
" после URL без пробелов.\n",
|
279 |
+
" <span style=\"color: #ff9999\">Для файлов обязательно укажите</span> - <span class=\"extension\">Расширение Файла.</span>\n",
|
280 |
+
" <div class=\"sample\">\n",
|
281 |
+
" <span class=\"sample_label\">Пример для Файла:</span>\n",
|
282 |
+
" 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",
|
283 |
+
" <br>\n",
|
284 |
+
" <span class=\"sample_label\">Пример для Расширения:</span>\n",
|
285 |
+
" 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",
|
286 |
+
" </div>\n",
|
287 |
+
"</div>\n",
|
288 |
+
"''')\n",
|
289 |
+
"\n",
|
290 |
+
"Model_url_widget = factory.create_text('Model:')\n",
|
291 |
+
"Vae_url_widget = factory.create_text('Vae:')\n",
|
292 |
+
"LoRA_url_widget = factory.create_text('LoRa:')\n",
|
293 |
+
"Embedding_url_widget = factory.create_text('Embedding:')\n",
|
294 |
+
"Extensions_url_widget = factory.create_text('Extensions:')\n",
|
295 |
+
"custom_file_urls_widget = factory.create_text('Файл (txt):')\n",
|
296 |
+
"\n",
|
297 |
+
"# Display CustomDl\n",
|
298 |
+
"all_custom_box = factory.create_vbox([\n",
|
299 |
+
" custom_download_header_popup, Model_url_widget, Vae_url_widget, LoRA_url_widget, Embedding_url_widget, Extensions_url_widget, custom_file_urls_widget\n",
|
300 |
+
"], class_names=[\"container\", \"image_4\", \"container_custom_downlad\"])\n",
|
301 |
+
"factory.display(all_custom_box)\n",
|
302 |
+
"\n",
|
303 |
+
"# --- Save Button ---\n",
|
304 |
+
"save_button = factory.create_button('Сохранить', class_name=\"button_save\")\n",
|
305 |
+
"factory.display(save_button)\n",
|
306 |
+
"\n",
|
307 |
+
"\n",
|
308 |
+
"# ============ Load / Save - Settings V2 ============\n",
|
309 |
+
"SETTINGS_FILE = f'{root_path}/settings.json'\n",
|
310 |
+
"\n",
|
311 |
+
"SETTINGS_KEYS = [\n",
|
312 |
+
" 'model', 'model_num', 'inpainting_model',\n",
|
313 |
+
" 'vae', 'vae_num', 'latest_webui', 'latest_exstensions',\n",
|
314 |
+
" 'change_webui', 'detailed_download', 'controlnet',\n",
|
315 |
+
" 'controlnet_num', 'commit_hash', 'huggingface_token',\n",
|
316 |
+
" 'ngrok_token', 'zrok_token', 'commandline_arguments',\n",
|
317 |
+
" 'Model_url', 'Vae_url', 'LoRA_url', 'Embedding_url',\n",
|
318 |
+
" 'Extensions_url', 'custom_file_urls'\n",
|
319 |
+
"]\n",
|
320 |
+
"\n",
|
321 |
+
"def save_settings():\n",
|
322 |
+
" settings = {key: globals()[f\"{key}_widget\"].value for key in SETTINGS_KEYS}\n",
|
323 |
+
" with open(SETTINGS_FILE, 'w') as f:\n",
|
324 |
+
" json.dump(settings, f, indent=2)\n",
|
325 |
+
"\n",
|
326 |
+
"def load_settings():\n",
|
327 |
+
" if os.path.exists(SETTINGS_FILE):\n",
|
328 |
+
" with open(SETTINGS_FILE, 'r') as f:\n",
|
329 |
+
" settings = json.load(f)\n",
|
330 |
+
" for key in SETTINGS_KEYS:\n",
|
331 |
+
" globals()[f\"{key}_widget\"].value = settings.get(key, \"\")\n",
|
332 |
+
"\n",
|
333 |
+
"def hide_widgets():\n",
|
334 |
+
" widgets_list = [all_model_box, all_vae_box, all_additional_box, all_custom_box, save_button]\n",
|
335 |
+
" for widget in widgets_list:\n",
|
336 |
+
" widget.add_class(\"hide\")\n",
|
337 |
+
" time.sleep(0.5)\n",
|
338 |
+
" widgets.Widget.close_all()\n",
|
339 |
+
"\n",
|
340 |
+
"def save_data(button):\n",
|
341 |
+
" save_settings()\n",
|
342 |
+
" hide_widgets()\n",
|
343 |
+
"\n",
|
344 |
+
"load_settings()\n",
|
345 |
+
"save_button.on_click(save_data)"
|
346 |
+
]
|
347 |
+
}
|
348 |
+
]
|
349 |
}
|
files_cells/python/en/auto_cleaner_en.py
CHANGED
@@ -1,138 +1,138 @@
|
|
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 |
-
for env_var, (environment, path) in environments.items():
|
18 |
-
if env_var in os.environ:
|
19 |
-
return environment, path, free_plan
|
20 |
-
|
21 |
-
env, root_path, free_plan = detect_environment()
|
22 |
-
webui_path = f"{root_path}/sdw"
|
23 |
-
|
24 |
-
|
25 |
-
# ==================== CSS ====================
|
26 |
-
# Main CSS
|
27 |
-
css_file_path = f"{root_path}/CSS/auto_cleaner.css"
|
28 |
-
with open(css_file_path , "r") as f:
|
29 |
-
CSS_AC = f.read()
|
30 |
-
display(HTML(f"<style>{CSS_AC}</style>"))
|
31 |
-
|
32 |
-
|
33 |
-
# ================ AutoCleaner function ================
|
34 |
-
directories = {
|
35 |
-
"Images": f"{webui_path}/output",
|
36 |
-
"Models": f"{webui_path}/models/Stable-diffusion/",
|
37 |
-
"Vae": f"{webui_path}/models/VAE/",
|
38 |
-
"LoRa": f"{webui_path}/models/Lora/",
|
39 |
-
"ControlNet Models": f"{webui_path}/models/ControlNet/"
|
40 |
-
}
|
41 |
-
|
42 |
-
""" functions """
|
43 |
-
def clean_directory(directory):
|
44 |
-
deleted_files = 0
|
45 |
-
image_dir = directories['Images']
|
46 |
-
|
47 |
-
for root, dirs, files in os.walk(directory):
|
48 |
-
for file in files:
|
49 |
-
file_path = os.path.join(root, file)
|
50 |
-
|
51 |
-
if file.endswith(".txt"):
|
52 |
-
continue
|
53 |
-
if file.endswith((".safetensors", ".pt")) or root == image_dir: # fix for image counter
|
54 |
-
deleted_files += 1
|
55 |
-
|
56 |
-
os.remove(file_path)
|
57 |
-
return deleted_files
|
58 |
-
|
59 |
-
def update_memory_info():
|
60 |
-
disk_space = psutil.disk_usage(os.getcwd())
|
61 |
-
total = disk_space.total / (1024 ** 3)
|
62 |
-
used = disk_space.used / (1024 ** 3)
|
63 |
-
free = disk_space.free / (1024 ** 3)
|
64 |
-
|
65 |
-
storage_info.value = f'''
|
66 |
-
<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>
|
67 |
-
'''
|
68 |
-
|
69 |
-
def on_execute_button_press(button):
|
70 |
-
selected_cleaners = auto_cleaner_widget.value
|
71 |
-
deleted_files_dict = {}
|
72 |
-
|
73 |
-
for option in selected_cleaners:
|
74 |
-
if option in directories:
|
75 |
-
deleted_files_dict[option] = clean_directory(directories[option])
|
76 |
-
|
77 |
-
output.clear_output()
|
78 |
-
|
79 |
-
with output:
|
80 |
-
for message in generate_messages(deleted_files_dict):
|
81 |
-
message_widget = HTML(f'<p class="output_message_AC">{message}</p>')
|
82 |
-
display(message_widget)
|
83 |
-
|
84 |
-
update_memory_info()
|
85 |
-
|
86 |
-
def on_clear_button_press(button):
|
87 |
-
container.add_class("hide")
|
88 |
-
time.sleep(0.5)
|
89 |
-
widgets.Widget.close_all()
|
90 |
-
|
91 |
-
def generate_messages(deleted_files_dict):
|
92 |
-
messages = []
|
93 |
-
word_variants = {
|
94 |
-
"Images": "Images",
|
95 |
-
"Models": "Models",
|
96 |
-
"Vae": "Vae",
|
97 |
-
"LoRa": "LoRa",
|
98 |
-
"ControlNet Models": "ControlNet Models"
|
99 |
-
}
|
100 |
-
for key, value in deleted_files_dict.items():
|
101 |
-
object_word = word_variants.get(key)
|
102 |
-
messages.append(f"Deleted {value} {object_word}")
|
103 |
-
return messages
|
104 |
-
# ================ AutoCleaner function ================
|
105 |
-
|
106 |
-
|
107 |
-
# --- storage memory ---
|
108 |
-
import psutil
|
109 |
-
disk_space = psutil.disk_usage(os.getcwd())
|
110 |
-
total = disk_space.total / (1024 ** 3)
|
111 |
-
used = disk_space.used / (1024 ** 3)
|
112 |
-
free = disk_space.free / (1024 ** 3)
|
113 |
-
|
114 |
-
|
115 |
-
# UI Code
|
116 |
-
AutoCleaner_options = AutoCleaner_options = list(directories.keys())
|
117 |
-
instruction_label = widgets.HTML('''
|
118 |
-
<span class="instruction_AC">Use <span style="color: #B2B2B2;">ctrl</span> or <span style="color: #B2B2B2;">shift</span> for multiple selections.</span>
|
119 |
-
''')
|
120 |
-
auto_cleaner_widget = widgets.SelectMultiple(options=AutoCleaner_options, layout=widgets.Layout(width='auto')).add_class("custom-select-multiple_AC")
|
121 |
-
output = widgets.Output().add_class("output_AC")
|
122 |
-
# ---
|
123 |
-
execute_button = Button(description='Execute Cleaning').add_class("button_execute_AC").add_class("button_AC")
|
124 |
-
execute_button.on_click(on_execute_button_press)
|
125 |
-
clear_button = Button(description='Hide Widget').add_class("button_clear_AC").add_class("button_AC")
|
126 |
-
clear_button.on_click(on_clear_button_press)
|
127 |
-
# ---
|
128 |
-
storage_info = widgets.HTML(f'''
|
129 |
-
<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>
|
130 |
-
''')
|
131 |
-
# ---
|
132 |
-
buttons = widgets.HBox([execute_button, clear_button])
|
133 |
-
lower_information_panel = widgets.HBox([buttons, storage_info]).add_class("lower_information_panel_AC")
|
134 |
-
|
135 |
-
container = VBox([instruction_label, widgets.HTML('<hr>'), auto_cleaner_widget, output, widgets.HTML('<hr>'), lower_information_panel]).add_class("container_AC")
|
136 |
-
|
137 |
-
display(container)
|
138 |
-
|
|
|
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 |
+
for env_var, (environment, path) in environments.items():
|
18 |
+
if env_var in os.environ:
|
19 |
+
return environment, path, free_plan
|
20 |
+
|
21 |
+
env, root_path, free_plan = detect_environment()
|
22 |
+
webui_path = f"{root_path}/sdw"
|
23 |
+
|
24 |
+
|
25 |
+
# ==================== CSS ====================
|
26 |
+
# Main CSS
|
27 |
+
css_file_path = f"{root_path}/CSS/auto_cleaner.css"
|
28 |
+
with open(css_file_path , "r") as f:
|
29 |
+
CSS_AC = f.read()
|
30 |
+
display(HTML(f"<style>{CSS_AC}</style>"))
|
31 |
+
|
32 |
+
|
33 |
+
# ================ AutoCleaner function ================
|
34 |
+
directories = {
|
35 |
+
"Images": f"{webui_path}/output",
|
36 |
+
"Models": f"{webui_path}/models/Stable-diffusion/",
|
37 |
+
"Vae": f"{webui_path}/models/VAE/",
|
38 |
+
"LoRa": f"{webui_path}/models/Lora/",
|
39 |
+
"ControlNet Models": f"{webui_path}/models/ControlNet/"
|
40 |
+
}
|
41 |
+
|
42 |
+
""" functions """
|
43 |
+
def clean_directory(directory):
|
44 |
+
deleted_files = 0
|
45 |
+
image_dir = directories['Images']
|
46 |
+
|
47 |
+
for root, dirs, files in os.walk(directory):
|
48 |
+
for file in files:
|
49 |
+
file_path = os.path.join(root, file)
|
50 |
+
|
51 |
+
if file.endswith(".txt"):
|
52 |
+
continue
|
53 |
+
if file.endswith((".safetensors", ".pt")) or root == image_dir: # fix for image counter
|
54 |
+
deleted_files += 1
|
55 |
+
|
56 |
+
os.remove(file_path)
|
57 |
+
return deleted_files
|
58 |
+
|
59 |
+
def update_memory_info():
|
60 |
+
disk_space = psutil.disk_usage(os.getcwd())
|
61 |
+
total = disk_space.total / (1024 ** 3)
|
62 |
+
used = disk_space.used / (1024 ** 3)
|
63 |
+
free = disk_space.free / (1024 ** 3)
|
64 |
+
|
65 |
+
storage_info.value = f'''
|
66 |
+
<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>
|
67 |
+
'''
|
68 |
+
|
69 |
+
def on_execute_button_press(button):
|
70 |
+
selected_cleaners = auto_cleaner_widget.value
|
71 |
+
deleted_files_dict = {}
|
72 |
+
|
73 |
+
for option in selected_cleaners:
|
74 |
+
if option in directories:
|
75 |
+
deleted_files_dict[option] = clean_directory(directories[option])
|
76 |
+
|
77 |
+
output.clear_output()
|
78 |
+
|
79 |
+
with output:
|
80 |
+
for message in generate_messages(deleted_files_dict):
|
81 |
+
message_widget = HTML(f'<p class="output_message_AC">{message}</p>')
|
82 |
+
display(message_widget)
|
83 |
+
|
84 |
+
update_memory_info()
|
85 |
+
|
86 |
+
def on_clear_button_press(button):
|
87 |
+
container.add_class("hide")
|
88 |
+
time.sleep(0.5)
|
89 |
+
widgets.Widget.close_all()
|
90 |
+
|
91 |
+
def generate_messages(deleted_files_dict):
|
92 |
+
messages = []
|
93 |
+
word_variants = {
|
94 |
+
"Images": "Images",
|
95 |
+
"Models": "Models",
|
96 |
+
"Vae": "Vae",
|
97 |
+
"LoRa": "LoRa",
|
98 |
+
"ControlNet Models": "ControlNet Models"
|
99 |
+
}
|
100 |
+
for key, value in deleted_files_dict.items():
|
101 |
+
object_word = word_variants.get(key)
|
102 |
+
messages.append(f"Deleted {value} {object_word}")
|
103 |
+
return messages
|
104 |
+
# ================ AutoCleaner function ================
|
105 |
+
|
106 |
+
|
107 |
+
# --- storage memory ---
|
108 |
+
import psutil
|
109 |
+
disk_space = psutil.disk_usage(os.getcwd())
|
110 |
+
total = disk_space.total / (1024 ** 3)
|
111 |
+
used = disk_space.used / (1024 ** 3)
|
112 |
+
free = disk_space.free / (1024 ** 3)
|
113 |
+
|
114 |
+
|
115 |
+
# UI Code
|
116 |
+
AutoCleaner_options = AutoCleaner_options = list(directories.keys())
|
117 |
+
instruction_label = widgets.HTML('''
|
118 |
+
<span class="instruction_AC">Use <span style="color: #B2B2B2;">ctrl</span> or <span style="color: #B2B2B2;">shift</span> for multiple selections.</span>
|
119 |
+
''')
|
120 |
+
auto_cleaner_widget = widgets.SelectMultiple(options=AutoCleaner_options, layout=widgets.Layout(width='auto')).add_class("custom-select-multiple_AC")
|
121 |
+
output = widgets.Output().add_class("output_AC")
|
122 |
+
# ---
|
123 |
+
execute_button = Button(description='Execute Cleaning').add_class("button_execute_AC").add_class("button_AC")
|
124 |
+
execute_button.on_click(on_execute_button_press)
|
125 |
+
clear_button = Button(description='Hide Widget').add_class("button_clear_AC").add_class("button_AC")
|
126 |
+
clear_button.on_click(on_clear_button_press)
|
127 |
+
# ---
|
128 |
+
storage_info = widgets.HTML(f'''
|
129 |
+
<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>
|
130 |
+
''')
|
131 |
+
# ---
|
132 |
+
buttons = widgets.HBox([execute_button, clear_button])
|
133 |
+
lower_information_panel = widgets.HBox([buttons, storage_info]).add_class("lower_information_panel_AC")
|
134 |
+
|
135 |
+
container = VBox([instruction_label, widgets.HTML('<hr>'), auto_cleaner_widget, output, widgets.HTML('<hr>'), lower_information_panel]).add_class("container_AC")
|
136 |
+
|
137 |
+
display(container)
|
138 |
+
|
files_cells/python/en/downloading_en.py
CHANGED
@@ -1,611 +1,666 @@
|
|
1 |
-
##~ DOWNLOADING CODE | BY: ANXETY ~##
|
2 |
-
|
3 |
-
import os
|
4 |
-
import re
|
5 |
-
import time
|
6 |
-
import json
|
7 |
-
import shutil
|
8 |
-
import zipfile
|
9 |
-
import requests
|
10 |
-
import subprocess
|
11 |
-
from datetime import timedelta
|
12 |
-
from subprocess import getoutput
|
13 |
-
from IPython.utils import capture
|
14 |
-
from IPython.display import clear_output
|
15 |
-
from urllib.parse import urlparse, parse_qs
|
16 |
-
|
17 |
-
|
18 |
-
# ================= DETECT ENV =================
|
19 |
-
def detect_environment():
|
20 |
-
free_plan = (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024 ** 3) <= 20)
|
21 |
-
environments = {
|
22 |
-
'COLAB_GPU': ('Google Colab', "/root" if free_plan else "/content"),
|
23 |
-
'KAGGLE_URL_BASE': ('Kaggle', "/kaggle/working/content")
|
24 |
-
}
|
25 |
-
for env_var, (environment, path) in environments.items():
|
26 |
-
if env_var in os.environ:
|
27 |
-
return environment, path, free_plan
|
28 |
-
|
29 |
-
env, root_path, free_plan = detect_environment()
|
30 |
-
webui_path = f"{root_path}/sdw"
|
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 |
-
"aria2": "apt -y install aria2",
|
41 |
-
"localtunnel": "npm install -g localtunnel",
|
42 |
-
"insightface": "pip install insightface"
|
43 |
-
}
|
44 |
-
|
45 |
-
additional_libs = {
|
46 |
-
"Google Colab": {
|
47 |
-
"xformers": "pip install xformers==0.0.26.post1 --no-deps"
|
48 |
-
},
|
49 |
-
"Kaggle": {
|
50 |
-
"xformers": "pip install xformers==0.0.26.post1",
|
51 |
-
# "torch": "pip install torch==2.1.2+cu121 torchvision==0.16.2+cu121 torchaudio==2.1.2 --extra-index-url https://download.pytorch.org/whl/cu121",
|
52 |
-
"aiohttp": "pip install trash-cli && trash-put /opt/conda/lib/python3.10/site-packages/aiohttp*" # fix install req
|
53 |
-
}
|
54 |
-
}
|
55 |
-
|
56 |
-
if env in additional_libs:
|
57 |
-
install_lib.update(additional_libs[env])
|
58 |
-
|
59 |
-
# Loop through libraries
|
60 |
-
for index, (package, install_cmd) in enumerate(install_lib.items(), start=1):
|
61 |
-
print(f"\r[{index}/{len(install_lib)}] \033[32m>>\033[0m Installing \033[33m{package}\033[0m..." + " "*35, end='')
|
62 |
-
subprocess.run(install_cmd, shell=True, capture_output=True)
|
63 |
-
|
64 |
-
# Additional specific packages
|
65 |
-
with capture.capture_output() as cap:
|
66 |
-
get_ipython().system('curl -s -OL https://github.com/DEX-1101/sd-webui-notebook/raw/main/res/new_tunnel --output-dir {root_path}')
|
67 |
-
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')
|
68 |
-
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')
|
69 |
-
del cap
|
70 |
-
|
71 |
-
clear_output()
|
72 |
-
|
73 |
-
# Save file install lib
|
74 |
-
with open(flag_file, "w") as f:
|
75 |
-
f.write(">W<'")
|
76 |
-
|
77 |
-
print("🍪 Libraries are installed!" + " "*35)
|
78 |
-
time.sleep(2)
|
79 |
-
clear_output()
|
80 |
-
|
81 |
-
|
82 |
-
# ================= loading settings V4 =================
|
83 |
-
def load_settings(path):
|
84 |
-
if os.path.exists(path):
|
85 |
-
with open(path, 'r') as file:
|
86 |
-
return json.load(file)
|
87 |
-
return {}
|
88 |
-
|
89 |
-
settings = load_settings(f'{root_path}/settings.json')
|
90 |
-
|
91 |
-
VARIABLES = [
|
92 |
-
'model', 'model_num', 'inpainting_model',
|
93 |
-
'vae', 'vae_num', 'latest_webui', 'latest_exstensions',
|
94 |
-
'change_webui', 'detailed_download', 'controlnet',
|
95 |
-
'controlnet_num', 'commit_hash', 'huggingface_token',
|
96 |
-
'ngrok_token', 'zrok_token', 'commandline_arguments',
|
97 |
-
'Model_url', 'Vae_url', 'LoRA_url', 'Embedding_url',
|
98 |
-
'Extensions_url', 'custom_file_urls'
|
99 |
-
]
|
100 |
-
|
101 |
-
locals().update({key: settings.get(key) for key in VARIABLES})
|
102 |
-
|
103 |
-
|
104 |
-
# ================= OTHER =================
|
105 |
-
try:
|
106 |
-
start_colab
|
107 |
-
except:
|
108 |
-
start_colab = int(time.time())-5
|
109 |
-
|
110 |
-
# CONFIG DIR
|
111 |
-
models_dir = f"{webui_path}/models/Stable-diffusion"
|
112 |
-
vaes_dir = f"{webui_path}/models/VAE"
|
113 |
-
embeddings_dir = f"{webui_path}/embeddings"
|
114 |
-
loras_dir = f"{webui_path}/models/Lora"
|
115 |
-
extensions_dir = f"{webui_path}/extensions"
|
116 |
-
control_dir = f"{webui_path}/models/ControlNet"
|
117 |
-
adetailer_dir = f"{webui_path}/models/adetailer"
|
118 |
-
|
119 |
-
|
120 |
-
# ================= MAIN CODE =================
|
121 |
-
if not os.path.exists(webui_path):
|
122 |
-
start_install = int(time.time())
|
123 |
-
print("⌚ Unpacking Stable Diffusion..." if change_webui != 'Forge' else "⌚ Unpacking Stable Diffusion (Forge)...", end='')
|
124 |
-
with capture.capture_output() as cap:
|
125 |
-
aria2_command = "aria2c --console-log-level=error -c -x 16 -s 16 -k 1M"
|
126 |
-
url = "https://huggingface.co/NagisaNao/fast_repo/resolve/main/FULL_REPO.zip" if change_webui != 'Forge' else "https://huggingface.co/NagisaNao/fast_repo/resolve/main/FULL_REPO_forge.zip"
|
127 |
-
get_ipython().system('{aria2_command} {url} -o repo.zip')
|
128 |
-
|
129 |
-
get_ipython().system('unzip -q -o repo.zip -d {webui_path}')
|
130 |
-
get_ipython().system('rm -rf repo.zip')
|
131 |
-
|
132 |
-
get_ipython().run_line_magic('cd', '{root_path}')
|
133 |
-
os.environ["SAFETENSORS_FAST_GPU"]='1'
|
134 |
-
os.environ["CUDA_MODULE_LOADING"]="LAZY"
|
135 |
-
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
|
136 |
-
os.environ["PYTHONWARNINGS"] = "ignore"
|
137 |
-
|
138 |
-
get_ipython().system('echo -n {start_colab} > {webui_path}/static/colabTimer.txt')
|
139 |
-
del cap
|
140 |
-
install_time = timedelta(seconds=time.time()-start_install)
|
141 |
-
print("\r🚀 Unpacking is complete! For","%02d:%02d:%02d ⚡\n" % (install_time.seconds / 3600, (install_time.seconds / 60) % 60, install_time.seconds % 60), end='', flush=True)
|
142 |
-
else:
|
143 |
-
print("🚀 All unpacked... Skip. ⚡")
|
144 |
-
start_colab = float(open(f'{webui_path}/static/colabTimer.txt', 'r').read())
|
145 |
-
time_since_start = str(timedelta(seconds=time.time()-start_colab)).split('.')[0]
|
146 |
-
print(f"⌚️ You have been conducting this session for - \033[33m{time_since_start}\033[0m")
|
147 |
-
|
148 |
-
|
149 |
-
## Changes extensions and WebUi
|
150 |
-
if latest_webui or latest_exstensions:
|
151 |
-
action = "Updating WebUI and Extensions" if latest_webui and latest_exstensions else ("WebUI Update" if latest_webui else "Update Extensions")
|
152 |
-
print(f"⌚️ {action}...", end='', flush=True)
|
153 |
-
with capture.capture_output() as cap:
|
154 |
-
get_ipython().system('git config --global user.email "[email protected]"')
|
155 |
-
get_ipython().system('git config --global user.name "Your Name"')
|
156 |
-
|
157 |
-
## Update Webui
|
158 |
-
if latest_webui:
|
159 |
-
get_ipython().run_line_magic('cd', '{webui_path}')
|
160 |
-
get_ipython().system('git restore .')
|
161 |
-
get_ipython().system('git pull -X theirs --rebase --autostash')
|
162 |
-
|
163 |
-
## Update extensions
|
164 |
-
if latest_exstensions:
|
165 |
-
get_ipython().system('{\'for dir in \' + webui_path + \'/extensions/*/; do cd \\"$dir\\" && git reset --hard && git pull; done\'}')
|
166 |
-
del cap
|
167 |
-
print(f"\r✨ {action} Completed!")
|
168 |
-
|
169 |
-
|
170 |
-
# === FIXING EXTENSIONS ===
|
171 |
-
anxety_repos = "https://huggingface.co/NagisaNao/fast_repo/resolve/main"
|
172 |
-
|
173 |
-
with capture.capture_output() as cap:
|
174 |
-
# --- Umi-Wildcard ---
|
175 |
-
get_ipython().system("sed -i '521s/open=\\(False\\|True\\)/open=False/' {webui_path}/extensions/Umi-AI-Wildcards/scripts/wildcard_recursive.py # Closed accordion by default")
|
176 |
-
|
177 |
-
# --- Encrypt-Image ---
|
178 |
-
get_ipython().system("sed -i '9,37d' {webui_path}/extensions/Encrypt-Image/javascript/encrypt_images_info.js # Removes the weird text in webui")
|
179 |
-
|
180 |
-
# --- Additional-Networks ---
|
181 |
-
get_ipython().system('wget -O {webui_path}/extensions/additional-networks/scripts/metadata_editor.py {anxety_repos}/extensions/Additional-Networks/fix/metadata_editor.py # Fixing an error due to old style')
|
182 |
-
del cap
|
183 |
-
|
184 |
-
|
185 |
-
## Version switching
|
186 |
-
if commit_hash:
|
187 |
-
print('⏳ Time machine activation...', end="", flush=True)
|
188 |
-
with capture.capture_output() as cap:
|
189 |
-
get_ipython().run_line_magic('cd', '{webui_path}')
|
190 |
-
get_ipython().system('git config --global user.email "[email protected]"')
|
191 |
-
get_ipython().system('git config --global user.name "Your Name"')
|
192 |
-
get_ipython().system('git reset --hard {commit_hash}')
|
193 |
-
del cap
|
194 |
-
print(f"\r⌛️ The time machine has been activated! Current commit: \033[34m{commit_hash}\033[0m")
|
195 |
-
|
196 |
-
|
197 |
-
## Downloading model and stuff | oh~ Hey! If you're freaked out by that code too, don't worry, me too!
|
198 |
-
print("📦 Downloading models and stuff...", end='')
|
199 |
-
model_list = {
|
200 |
-
"1.Anime (by XpucT) + INP": [
|
201 |
-
{"url": "https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2.safetensors", "name": "
|
202 |
-
{"url": "https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2-inpainting.safetensors", "name": "
|
203 |
-
],
|
204 |
-
"2.BluMix [Anime] [V7] + INP": [
|
205 |
-
{"url": "https://civitai.com/api/download/models/361779", "name": "
|
206 |
-
{"url": "https://civitai.com/api/download/models/363850", "name": "
|
207 |
-
],
|
208 |
-
"3.Cetus-Mix [Anime] [V4] + INP": [
|
209 |
-
{"url": "https://civitai.com/api/download/models/130298", "name": "CetusMix_V4.safetensors"},
|
210 |
-
{"url": "https://civitai.com/api/download/models/139882", "name": "CetusMix_V4-inpainting.safetensors"}
|
211 |
-
],
|
212 |
-
"4.Counterfeit [Anime] [V3] + INP": [
|
213 |
-
{"url": "https://
|
214 |
-
{"url": "https://civitai.com/api/download/models/137911", "name": "Counterfeit_V3-inpainting.safetensors"}
|
215 |
-
],
|
216 |
-
"5.CuteColor [Anime] [V3]": [
|
217 |
-
{"url": "https://civitai.com/api/download/models/138754", "name": "CuteColor_V3.safetensors"}
|
218 |
-
],
|
219 |
-
"6.Dark-Sushi-Mix [Anime]": [
|
220 |
-
{"url": "https://civitai.com/api/download/models/101640", "name": "DarkSushiMix_2_5D.safetensors"},
|
221 |
-
{"url": "https://civitai.com/api/download/models/56071", "name": "DarkSushiMix_colorful.safetensors"}
|
222 |
-
],
|
223 |
-
"7.Deliberate [Realism] [V6] + INP": [
|
224 |
-
{"url": "https://huggingface.co/XpucT/Deliberate/resolve/main/Deliberate_v6.safetensors", "name": "
|
225 |
-
{"url": "https://huggingface.co/XpucT/Deliberate/resolve/main/Deliberate_v6-inpainting.safetensors", "name": "
|
226 |
-
],
|
227 |
-
"8.Meina-Mix [Anime] [V11] + INP": [
|
228 |
-
{"url": "https://civitai.com/api/download/models/119057", "name": "MeinaMix_V11.safetensors"},
|
229 |
-
{"url": "https://civitai.com/api/download/models/120702", "name": "MeinaMix_V11-inpainting.safetensors"}
|
230 |
-
],
|
231 |
-
"9.Mix-Pro [Anime] [V4] + INP": [
|
232 |
-
{"url": "https://civitai.com/api/download/models/125668", "name": "MixPro_V4.safetensors"},
|
233 |
-
{"url": "https://civitai.com/api/download/models/139878", "name": "MixPro_V4-inpainting.safetensors"}
|
234 |
-
]
|
235 |
-
}
|
236 |
-
|
237 |
-
vae_list = {
|
238 |
-
"1.Anime.vae": [{"url": "https://civitai.com/api/download/models/311162", "name": "vae-ft-mse-840000-ema-pruned.vae.safetensors"}],
|
239 |
-
"2.Anything.vae": [{"url": "https://
|
240 |
-
"3.Blessed2.vae": [{"url": "https://huggingface.co/NoCrypt/
|
241 |
-
"4.ClearVae.vae": [{"url": "https://civitai.com/api/download/models/88156", "name": "ClearVae_23.vae.safetensors"}],
|
242 |
-
"5.WD.vae": [{"url": "https://huggingface.co/NoCrypt/resources/resolve/main/VAE/wd.vae.safetensors", "name": "WD.vae.safetensors"}]
|
243 |
-
}
|
244 |
-
|
245 |
-
controlnet_list = {
|
246 |
-
"1.canny": [
|
247 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny_fp16.safetensors", "name": "control_v11p_sd15_canny_fp16.safetensors"},
|
248 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_canny_fp16.yaml", "name": "control_v11p_sd15_canny_fp16.yaml"}
|
249 |
-
],
|
250 |
-
"2.openpose": [
|
251 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose_fp16.safetensors", "name": "control_v11p_sd15_openpose_fp16.safetensors"},
|
252 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_openpose_fp16.yaml", "name": "control_v11p_sd15_openpose_fp16.yaml"}
|
253 |
-
],
|
254 |
-
"3.depth": [
|
255 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth_fp16.safetensors", "name": "control_v11f1p_sd15_depth_fp16.safetensors"},
|
256 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1p_sd15_depth_fp16.yaml", "name": "control_v11f1p_sd15_depth_fp16.yaml"},
|
257 |
-
{"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"}
|
258 |
-
],
|
259 |
-
"4.normal_map": [
|
260 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_normalbae_fp16.safetensors", "name": "control_v11p_sd15_normalbae_fp16.safetensors"},
|
261 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_normalbae_fp16.yaml", "name": "control_v11p_sd15_normalbae_fp16.yaml"}
|
262 |
-
],
|
263 |
-
"5.mlsd": [
|
264 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_mlsd_fp16.safetensors", "name": "control_v11p_sd15_mlsd_fp16.safetensors"},
|
265 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_mlsd_fp16.yaml", "name": "control_v11p_sd15_mlsd_fp16.yaml"}
|
266 |
-
],
|
267 |
-
"6.lineart": [
|
268 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart_fp16.safetensors", "name": "control_v11p_sd15_lineart_fp16.safetensors"},
|
269 |
-
{"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"},
|
270 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_lineart_fp16.yaml", "name": "control_v11p_sd15_lineart_fp16.yaml"},
|
271 |
-
{"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"}
|
272 |
-
],
|
273 |
-
"7.soft_edge": [
|
274 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge_fp16.safetensors", "name": "control_v11p_sd15_softedge_fp16.safetensors"},
|
275 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_softedge_fp16.yaml", "name": "control_v11p_sd15_softedge_fp16.yaml"}
|
276 |
-
],
|
277 |
-
"8.scribble": [
|
278 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble_fp16.safetensors", "name": "control_v11p_sd15_scribble_fp16.safetensors"},
|
279 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_scribble_fp16.yaml", "name": "control_v11p_sd15_scribble_fp16.yaml"}
|
280 |
-
],
|
281 |
-
"9.segmentation": [
|
282 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg_fp16.safetensors", "name": "control_v11p_sd15_seg_fp16.safetensors"},
|
283 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_seg_fp16.yaml", "name": "control_v11p_sd15_seg_fp16.yaml"}
|
284 |
-
],
|
285 |
-
"10.shuffle": [
|
286 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle_fp16.safetensors", "name": "control_v11e_sd15_shuffle_fp16.safetensors"},
|
287 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_shuffle_fp16.yaml", "name": "control_v11e_sd15_shuffle_fp16.yaml"}
|
288 |
-
],
|
289 |
-
"11.tile": [
|
290 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile_fp16.safetensors", "name": "control_v11f1e_sd15_tile_fp16.safetensors"},
|
291 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1e_sd15_tile_fp16.yaml", "name": "control_v11f1e_sd15_tile_fp16.yaml"}
|
292 |
-
],
|
293 |
-
"12.inpaint": [
|
294 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_inpaint_fp16.safetensors", "name": "control_v11p_sd15_inpaint_fp16.safetensors"},
|
295 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_inpaint_fp16.yaml", "name": "control_v11p_sd15_inpaint_fp16.yaml"}
|
296 |
-
],
|
297 |
-
"13.instruct_p2p": [
|
298 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p_fp16.safetensors", "name": "control_v11e_sd15_ip2p_fp16.safetensors"},
|
299 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_ip2p_fp16.yaml", "name": "control_v11e_sd15_ip2p_fp16.yaml"}
|
300 |
-
]
|
301 |
-
}
|
302 |
-
|
303 |
-
url = ""
|
304 |
-
prefixes = {
|
305 |
-
"model": models_dir,
|
306 |
-
"vae": vaes_dir,
|
307 |
-
"lora": loras_dir,
|
308 |
-
"embed": embeddings_dir,
|
309 |
-
"extension": extensions_dir,
|
310 |
-
"control": control_dir,
|
311 |
-
"adetailer": adetailer_dir
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
info =
|
334 |
-
|
335 |
-
|
336 |
-
print(f"\
|
337 |
-
print(f"\033[
|
338 |
-
print(f"\033[
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
return
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
if
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
if
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
if
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
'
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
if
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
url
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
##~ DOWNLOADING CODE | BY: ANXETY ~##
|
2 |
+
|
3 |
+
import os
|
4 |
+
import re
|
5 |
+
import time
|
6 |
+
import json
|
7 |
+
import shutil
|
8 |
+
import zipfile
|
9 |
+
import requests
|
10 |
+
import subprocess
|
11 |
+
from datetime import timedelta
|
12 |
+
from subprocess import getoutput
|
13 |
+
from IPython.utils import capture
|
14 |
+
from IPython.display import clear_output
|
15 |
+
from urllib.parse import urlparse, parse_qs
|
16 |
+
|
17 |
+
|
18 |
+
# ================= DETECT ENV =================
|
19 |
+
def detect_environment():
|
20 |
+
free_plan = (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024 ** 3) <= 20)
|
21 |
+
environments = {
|
22 |
+
'COLAB_GPU': ('Google Colab', "/root" if free_plan else "/content"),
|
23 |
+
'KAGGLE_URL_BASE': ('Kaggle', "/kaggle/working/content")
|
24 |
+
}
|
25 |
+
for env_var, (environment, path) in environments.items():
|
26 |
+
if env_var in os.environ:
|
27 |
+
return environment, path, free_plan
|
28 |
+
|
29 |
+
env, root_path, free_plan = detect_environment()
|
30 |
+
webui_path = f"{root_path}/sdw"
|
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 |
+
"aria2": "apt -y install aria2",
|
41 |
+
"localtunnel": "npm install -g localtunnel",
|
42 |
+
"insightface": "pip install insightface"
|
43 |
+
}
|
44 |
+
|
45 |
+
additional_libs = {
|
46 |
+
"Google Colab": {
|
47 |
+
"xformers": "pip install xformers==0.0.26.post1 --no-deps"
|
48 |
+
},
|
49 |
+
"Kaggle": {
|
50 |
+
"xformers": "pip install xformers==0.0.26.post1",
|
51 |
+
# "torch": "pip install torch==2.1.2+cu121 torchvision==0.16.2+cu121 torchaudio==2.1.2 --extra-index-url https://download.pytorch.org/whl/cu121",
|
52 |
+
"aiohttp": "pip install trash-cli && trash-put /opt/conda/lib/python3.10/site-packages/aiohttp*" # fix install req
|
53 |
+
}
|
54 |
+
}
|
55 |
+
|
56 |
+
if env in additional_libs:
|
57 |
+
install_lib.update(additional_libs[env])
|
58 |
+
|
59 |
+
# Loop through libraries
|
60 |
+
for index, (package, install_cmd) in enumerate(install_lib.items(), start=1):
|
61 |
+
print(f"\r[{index}/{len(install_lib)}] \033[32m>>\033[0m Installing \033[33m{package}\033[0m..." + " "*35, end='')
|
62 |
+
subprocess.run(install_cmd, shell=True, capture_output=True)
|
63 |
+
|
64 |
+
# Additional specific packages
|
65 |
+
with capture.capture_output() as cap:
|
66 |
+
get_ipython().system('curl -s -OL https://github.com/DEX-1101/sd-webui-notebook/raw/main/res/new_tunnel --output-dir {root_path}')
|
67 |
+
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')
|
68 |
+
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')
|
69 |
+
del cap
|
70 |
+
|
71 |
+
clear_output()
|
72 |
+
|
73 |
+
# Save file install lib
|
74 |
+
with open(flag_file, "w") as f:
|
75 |
+
f.write(">W<'")
|
76 |
+
|
77 |
+
print("🍪 Libraries are installed!" + " "*35)
|
78 |
+
time.sleep(2)
|
79 |
+
clear_output()
|
80 |
+
|
81 |
+
|
82 |
+
# ================= loading settings V4 =================
|
83 |
+
def load_settings(path):
|
84 |
+
if os.path.exists(path):
|
85 |
+
with open(path, 'r') as file:
|
86 |
+
return json.load(file)
|
87 |
+
return {}
|
88 |
+
|
89 |
+
settings = load_settings(f'{root_path}/settings.json')
|
90 |
+
|
91 |
+
VARIABLES = [
|
92 |
+
'model', 'model_num', 'inpainting_model',
|
93 |
+
'vae', 'vae_num', 'latest_webui', 'latest_exstensions',
|
94 |
+
'change_webui', 'detailed_download', 'controlnet',
|
95 |
+
'controlnet_num', 'commit_hash', 'huggingface_token',
|
96 |
+
'ngrok_token', 'zrok_token', 'commandline_arguments',
|
97 |
+
'Model_url', 'Vae_url', 'LoRA_url', 'Embedding_url',
|
98 |
+
'Extensions_url', 'custom_file_urls'
|
99 |
+
]
|
100 |
+
|
101 |
+
locals().update({key: settings.get(key) for key in VARIABLES})
|
102 |
+
|
103 |
+
|
104 |
+
# ================= OTHER =================
|
105 |
+
try:
|
106 |
+
start_colab
|
107 |
+
except:
|
108 |
+
start_colab = int(time.time())-5
|
109 |
+
|
110 |
+
# CONFIG DIR
|
111 |
+
models_dir = f"{webui_path}/models/Stable-diffusion"
|
112 |
+
vaes_dir = f"{webui_path}/models/VAE"
|
113 |
+
embeddings_dir = f"{webui_path}/embeddings"
|
114 |
+
loras_dir = f"{webui_path}/models/Lora"
|
115 |
+
extensions_dir = f"{webui_path}/extensions"
|
116 |
+
control_dir = f"{webui_path}/models/ControlNet"
|
117 |
+
adetailer_dir = f"{webui_path}/models/adetailer"
|
118 |
+
|
119 |
+
|
120 |
+
# ================= MAIN CODE =================
|
121 |
+
if not os.path.exists(webui_path):
|
122 |
+
start_install = int(time.time())
|
123 |
+
print("⌚ Unpacking Stable Diffusion..." if change_webui != 'Forge' else "⌚ Unpacking Stable Diffusion (Forge)...", end='')
|
124 |
+
with capture.capture_output() as cap:
|
125 |
+
aria2_command = "aria2c --console-log-level=error -c -x 16 -s 16 -k 1M"
|
126 |
+
url = "https://huggingface.co/NagisaNao/fast_repo/resolve/main/FULL_REPO.zip" if change_webui != 'Forge' else "https://huggingface.co/NagisaNao/fast_repo/resolve/main/FULL_REPO_forge.zip"
|
127 |
+
get_ipython().system('{aria2_command} {url} -o repo.zip')
|
128 |
+
|
129 |
+
get_ipython().system('unzip -q -o repo.zip -d {webui_path}')
|
130 |
+
get_ipython().system('rm -rf repo.zip')
|
131 |
+
|
132 |
+
get_ipython().run_line_magic('cd', '{root_path}')
|
133 |
+
os.environ["SAFETENSORS_FAST_GPU"]='1'
|
134 |
+
os.environ["CUDA_MODULE_LOADING"]="LAZY"
|
135 |
+
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
|
136 |
+
os.environ["PYTHONWARNINGS"] = "ignore"
|
137 |
+
|
138 |
+
get_ipython().system('echo -n {start_colab} > {webui_path}/static/colabTimer.txt')
|
139 |
+
del cap
|
140 |
+
install_time = timedelta(seconds=time.time()-start_install)
|
141 |
+
print("\r🚀 Unpacking is complete! For","%02d:%02d:%02d ⚡\n" % (install_time.seconds / 3600, (install_time.seconds / 60) % 60, install_time.seconds % 60), end='', flush=True)
|
142 |
+
else:
|
143 |
+
print("🚀 All unpacked... Skip. ⚡")
|
144 |
+
start_colab = float(open(f'{webui_path}/static/colabTimer.txt', 'r').read())
|
145 |
+
time_since_start = str(timedelta(seconds=time.time()-start_colab)).split('.')[0]
|
146 |
+
print(f"⌚️ You have been conducting this session for - \033[33m{time_since_start}\033[0m")
|
147 |
+
|
148 |
+
|
149 |
+
## Changes extensions and WebUi
|
150 |
+
if latest_webui or latest_exstensions:
|
151 |
+
action = "Updating WebUI and Extensions" if latest_webui and latest_exstensions else ("WebUI Update" if latest_webui else "Update Extensions")
|
152 |
+
print(f"⌚️ {action}...", end='', flush=True)
|
153 |
+
with capture.capture_output() as cap:
|
154 |
+
get_ipython().system('git config --global user.email "[email protected]"')
|
155 |
+
get_ipython().system('git config --global user.name "Your Name"')
|
156 |
+
|
157 |
+
## Update Webui
|
158 |
+
if latest_webui:
|
159 |
+
get_ipython().run_line_magic('cd', '{webui_path}')
|
160 |
+
get_ipython().system('git restore .')
|
161 |
+
get_ipython().system('git pull -X theirs --rebase --autostash')
|
162 |
+
|
163 |
+
## Update extensions
|
164 |
+
if latest_exstensions:
|
165 |
+
get_ipython().system('{\'for dir in \' + webui_path + \'/extensions/*/; do cd \\"$dir\\" && git reset --hard && git pull; done\'}')
|
166 |
+
del cap
|
167 |
+
print(f"\r✨ {action} Completed!")
|
168 |
+
|
169 |
+
|
170 |
+
# === FIXING EXTENSIONS ===
|
171 |
+
anxety_repos = "https://huggingface.co/NagisaNao/fast_repo/resolve/main"
|
172 |
+
|
173 |
+
with capture.capture_output() as cap:
|
174 |
+
# --- Umi-Wildcard ---
|
175 |
+
get_ipython().system("sed -i '521s/open=\\(False\\|True\\)/open=False/' {webui_path}/extensions/Umi-AI-Wildcards/scripts/wildcard_recursive.py # Closed accordion by default")
|
176 |
+
|
177 |
+
# --- Encrypt-Image ---
|
178 |
+
get_ipython().system("sed -i '9,37d' {webui_path}/extensions/Encrypt-Image/javascript/encrypt_images_info.js # Removes the weird text in webui")
|
179 |
+
|
180 |
+
# --- Additional-Networks ---
|
181 |
+
get_ipython().system('wget -O {webui_path}/extensions/additional-networks/scripts/metadata_editor.py {anxety_repos}/extensions/Additional-Networks/fix/metadata_editor.py # Fixing an error due to old style')
|
182 |
+
del cap
|
183 |
+
|
184 |
+
|
185 |
+
## Version switching
|
186 |
+
if commit_hash:
|
187 |
+
print('⏳ Time machine activation...', end="", flush=True)
|
188 |
+
with capture.capture_output() as cap:
|
189 |
+
get_ipython().run_line_magic('cd', '{webui_path}')
|
190 |
+
get_ipython().system('git config --global user.email "[email protected]"')
|
191 |
+
get_ipython().system('git config --global user.name "Your Name"')
|
192 |
+
get_ipython().system('git reset --hard {commit_hash}')
|
193 |
+
del cap
|
194 |
+
print(f"\r⌛️ The time machine has been activated! Current commit: \033[34m{commit_hash}\033[0m")
|
195 |
+
|
196 |
+
|
197 |
+
## Downloading model and stuff | oh~ Hey! If you're freaked out by that code too, don't worry, me too!
|
198 |
+
print("📦 Downloading models and stuff...", end='')
|
199 |
+
model_list = {
|
200 |
+
"1.Anime (by XpucT) + INP": [
|
201 |
+
{"url": "https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2.safetensors", "name": "Anime_V2.safetensors"},
|
202 |
+
{"url": "https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2-inpainting.safetensors", "name": "Anime_V2-inpainting.safetensors"}
|
203 |
+
],
|
204 |
+
"2.BluMix [Anime] [V7] + INP": [
|
205 |
+
{"url": "https://civitai.com/api/download/models/361779", "name": "BluMix_V7.safetensors"},
|
206 |
+
{"url": "https://civitai.com/api/download/models/363850", "name": "BluMix_V7-inpainting.safetensors"}
|
207 |
+
],
|
208 |
+
"3.Cetus-Mix [Anime] [V4] + INP": [
|
209 |
+
{"url": "https://civitai.com/api/download/models/130298", "name": "CetusMix_V4.safetensors"},
|
210 |
+
{"url": "https://civitai.com/api/download/models/139882", "name": "CetusMix_V4-inpainting.safetensors"}
|
211 |
+
],
|
212 |
+
"4.Counterfeit [Anime] [V3] + INP": [
|
213 |
+
{"url": "https://huggingface.co/gsdf/Counterfeit-V3.0/resolve/main/Counterfeit-V3.0_fix_fp16.safetensors", "name": "Counterfeit_V3.safetensors"},
|
214 |
+
{"url": "https://civitai.com/api/download/models/137911", "name": "Counterfeit_V3-inpainting.safetensors"}
|
215 |
+
],
|
216 |
+
"5.CuteColor [Anime] [V3]": [
|
217 |
+
{"url": "https://civitai.com/api/download/models/138754", "name": "CuteColor_V3.safetensors"}
|
218 |
+
],
|
219 |
+
"6.Dark-Sushi-Mix [Anime]": [
|
220 |
+
{"url": "https://civitai.com/api/download/models/101640", "name": "DarkSushiMix_2_5D.safetensors"},
|
221 |
+
{"url": "https://civitai.com/api/download/models/56071", "name": "DarkSushiMix_colorful.safetensors"}
|
222 |
+
],
|
223 |
+
"7.Deliberate [Realism] [V6] + INP": [
|
224 |
+
{"url": "https://huggingface.co/XpucT/Deliberate/resolve/main/Deliberate_v6.safetensors", "name": "Deliberate_V6.safetensors"},
|
225 |
+
{"url": "https://huggingface.co/XpucT/Deliberate/resolve/main/Deliberate_v6-inpainting.safetensors", "name": "Deliberate_V6-inpainting.safetensors"}
|
226 |
+
],
|
227 |
+
"8.Meina-Mix [Anime] [V11] + INP": [
|
228 |
+
{"url": "https://civitai.com/api/download/models/119057", "name": "MeinaMix_V11.safetensors"},
|
229 |
+
{"url": "https://civitai.com/api/download/models/120702", "name": "MeinaMix_V11-inpainting.safetensors"}
|
230 |
+
],
|
231 |
+
"9.Mix-Pro [Anime] [V4] + INP": [
|
232 |
+
{"url": "https://civitai.com/api/download/models/125668", "name": "MixPro_V4.safetensors"},
|
233 |
+
{"url": "https://civitai.com/api/download/models/139878", "name": "MixPro_V4-inpainting.safetensors"}
|
234 |
+
]
|
235 |
+
}
|
236 |
+
|
237 |
+
vae_list = {
|
238 |
+
"1.Anime.vae": [{"url": "https://civitai.com/api/download/models/311162", "name": "vae-ft-mse-840000-ema-pruned.vae.safetensors"}],
|
239 |
+
"2.Anything.vae": [{"url": "https://huggingface.co/NoCrypt/resources/resolve/main/VAE/any.vae.safetensors", "name": "Anything.vae.safetensors"}],
|
240 |
+
"3.Blessed2.vae": [{"url": "https://huggingface.co/NoCrypt/resources/resolve/main/VAE/blessed2.vae.safetensors", "name": "Blessed2.vae.safetensors"}],
|
241 |
+
"4.ClearVae.vae": [{"url": "https://civitai.com/api/download/models/88156", "name": "ClearVae_23.vae.safetensors"}],
|
242 |
+
"5.WD.vae": [{"url": "https://huggingface.co/NoCrypt/resources/resolve/main/VAE/wd.vae.safetensors", "name": "WD.vae.safetensors"}]
|
243 |
+
}
|
244 |
+
|
245 |
+
controlnet_list = {
|
246 |
+
"1.canny": [
|
247 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny_fp16.safetensors", "name": "control_v11p_sd15_canny_fp16.safetensors"},
|
248 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_canny_fp16.yaml", "name": "control_v11p_sd15_canny_fp16.yaml"}
|
249 |
+
],
|
250 |
+
"2.openpose": [
|
251 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose_fp16.safetensors", "name": "control_v11p_sd15_openpose_fp16.safetensors"},
|
252 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_openpose_fp16.yaml", "name": "control_v11p_sd15_openpose_fp16.yaml"}
|
253 |
+
],
|
254 |
+
"3.depth": [
|
255 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth_fp16.safetensors", "name": "control_v11f1p_sd15_depth_fp16.safetensors"},
|
256 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1p_sd15_depth_fp16.yaml", "name": "control_v11f1p_sd15_depth_fp16.yaml"},
|
257 |
+
{"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"}
|
258 |
+
],
|
259 |
+
"4.normal_map": [
|
260 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_normalbae_fp16.safetensors", "name": "control_v11p_sd15_normalbae_fp16.safetensors"},
|
261 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_normalbae_fp16.yaml", "name": "control_v11p_sd15_normalbae_fp16.yaml"}
|
262 |
+
],
|
263 |
+
"5.mlsd": [
|
264 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_mlsd_fp16.safetensors", "name": "control_v11p_sd15_mlsd_fp16.safetensors"},
|
265 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_mlsd_fp16.yaml", "name": "control_v11p_sd15_mlsd_fp16.yaml"}
|
266 |
+
],
|
267 |
+
"6.lineart": [
|
268 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart_fp16.safetensors", "name": "control_v11p_sd15_lineart_fp16.safetensors"},
|
269 |
+
{"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"},
|
270 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_lineart_fp16.yaml", "name": "control_v11p_sd15_lineart_fp16.yaml"},
|
271 |
+
{"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"}
|
272 |
+
],
|
273 |
+
"7.soft_edge": [
|
274 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge_fp16.safetensors", "name": "control_v11p_sd15_softedge_fp16.safetensors"},
|
275 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_softedge_fp16.yaml", "name": "control_v11p_sd15_softedge_fp16.yaml"}
|
276 |
+
],
|
277 |
+
"8.scribble": [
|
278 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble_fp16.safetensors", "name": "control_v11p_sd15_scribble_fp16.safetensors"},
|
279 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_scribble_fp16.yaml", "name": "control_v11p_sd15_scribble_fp16.yaml"}
|
280 |
+
],
|
281 |
+
"9.segmentation": [
|
282 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg_fp16.safetensors", "name": "control_v11p_sd15_seg_fp16.safetensors"},
|
283 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_seg_fp16.yaml", "name": "control_v11p_sd15_seg_fp16.yaml"}
|
284 |
+
],
|
285 |
+
"10.shuffle": [
|
286 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle_fp16.safetensors", "name": "control_v11e_sd15_shuffle_fp16.safetensors"},
|
287 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_shuffle_fp16.yaml", "name": "control_v11e_sd15_shuffle_fp16.yaml"}
|
288 |
+
],
|
289 |
+
"11.tile": [
|
290 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile_fp16.safetensors", "name": "control_v11f1e_sd15_tile_fp16.safetensors"},
|
291 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1e_sd15_tile_fp16.yaml", "name": "control_v11f1e_sd15_tile_fp16.yaml"}
|
292 |
+
],
|
293 |
+
"12.inpaint": [
|
294 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_inpaint_fp16.safetensors", "name": "control_v11p_sd15_inpaint_fp16.safetensors"},
|
295 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_inpaint_fp16.yaml", "name": "control_v11p_sd15_inpaint_fp16.yaml"}
|
296 |
+
],
|
297 |
+
"13.instruct_p2p": [
|
298 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p_fp16.safetensors", "name": "control_v11e_sd15_ip2p_fp16.safetensors"},
|
299 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_ip2p_fp16.yaml", "name": "control_v11e_sd15_ip2p_fp16.yaml"}
|
300 |
+
]
|
301 |
+
}
|
302 |
+
|
303 |
+
url = ""
|
304 |
+
prefixes = {
|
305 |
+
"model": models_dir,
|
306 |
+
"vae": vaes_dir,
|
307 |
+
"lora": loras_dir,
|
308 |
+
"embed": embeddings_dir,
|
309 |
+
"extension": extensions_dir,
|
310 |
+
"control": control_dir,
|
311 |
+
"adetailer": adetailer_dir,
|
312 |
+
"config": webui_path
|
313 |
+
}
|
314 |
+
|
315 |
+
extension_repo = []
|
316 |
+
directories = [value for key, value in prefixes.items()] # for unpucking zip files
|
317 |
+
get_ipython().system('mkdir -p {" ".join(directories)}')
|
318 |
+
|
319 |
+
hf_token = huggingface_token if huggingface_token else "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"
|
320 |
+
user_header = f"\"Authorization: Bearer {hf_token}\""
|
321 |
+
|
322 |
+
''' Formatted Info Output '''
|
323 |
+
|
324 |
+
from math import floor
|
325 |
+
|
326 |
+
def center_text(text, terminal_width=45):
|
327 |
+
text_length = len(text)
|
328 |
+
left_padding = floor((terminal_width - text_length) / 2)
|
329 |
+
right_padding = terminal_width - text_length - left_padding
|
330 |
+
return f"\033[1m\033[36m{' ' * left_padding}{text}{' ' * right_padding}\033[0m\033[32m"
|
331 |
+
|
332 |
+
def format_output(url, dst_dir, file_name):
|
333 |
+
info = f"[{file_name.split('.')[0]}]"
|
334 |
+
info = center_text(info)
|
335 |
+
|
336 |
+
print(f"\n\033[32m{'---'*20}]{info}[{'---'*20}")
|
337 |
+
print(f"\033[33mURL: \033[34m{url}")
|
338 |
+
print(f"\033[33mSAVE DIR: \033[34m{dst_dir}")
|
339 |
+
print(f"\033[33mFILE NAME: \033[34m{file_name}\033[0m")
|
340 |
+
|
341 |
+
''' GET CivitAi API - DATA '''
|
342 |
+
|
343 |
+
def strip_(url, file_name=None):
|
344 |
+
if 'github.com' in url:
|
345 |
+
if '/blob/' in url:
|
346 |
+
url = url.replace('/blob/', '/raw/')
|
347 |
+
|
348 |
+
elif "civitai.com" in url:
|
349 |
+
return CivitAi_API(url, file_name)
|
350 |
+
|
351 |
+
elif "huggingface.co" in url:
|
352 |
+
if '/blob/' in url:
|
353 |
+
url = url.replace('/blob/', '/resolve/')
|
354 |
+
if '?' in url:
|
355 |
+
url = url.split('?')[0]
|
356 |
+
|
357 |
+
return url
|
358 |
+
|
359 |
+
def CivitAi_API(url, file_name=None):
|
360 |
+
support_types = ('Checkpoint', 'Model', 'TextualInversion', 'LORA')
|
361 |
+
civitai_token = "62c0c5956b2f9defbd844d754000180b"
|
362 |
+
|
363 |
+
if '?token=' in url:
|
364 |
+
url = url.split('?token=')[0]
|
365 |
+
if '?type=' in url:
|
366 |
+
url = url.replace('?type=', f'?token={civitai_token}&type=')
|
367 |
+
else:
|
368 |
+
url = f"{url}?token={civitai_token}"
|
369 |
+
|
370 |
+
# Determine model or version id
|
371 |
+
if "civitai.com/models/" in url:
|
372 |
+
if '?modelVersionId=' in url:
|
373 |
+
version_id = url.split('?modelVersionId=')[1]
|
374 |
+
response = requests.get(f"https://civitai.com/api/v1/model-versions/{version_id}")
|
375 |
+
# print(f"end - https://civitai.com/api/v1/model-versions/{version_id}")
|
376 |
+
else:
|
377 |
+
model_id = url.split('/models/')[1].split('/')[0]
|
378 |
+
response = requests.get(f"https://civitai.com/api/v1/models/{model_id}")
|
379 |
+
# print(f"end - https://civitai.com/api/v1/models/{model_id}")
|
380 |
+
else:
|
381 |
+
version_id = url.split('/models/')[1].split('/')[0]
|
382 |
+
response = requests.get(f"https://civitai.com/api/v1/model-versions/{version_id}")
|
383 |
+
# print(f"end - https://civitai.com/api/v1/model-versions/{version_id}")
|
384 |
+
|
385 |
+
data = response.json()
|
386 |
+
|
387 |
+
if response.status_code != 200:
|
388 |
+
return None, None, None, None, None, None, None
|
389 |
+
|
390 |
+
# Define model type and name
|
391 |
+
if "civitai.com/models/" in url:
|
392 |
+
if '?modelVersionId=' in url:
|
393 |
+
model_type = data['model']['type']
|
394 |
+
model_name = data['files'][0]['name']
|
395 |
+
else:
|
396 |
+
model_type = data['type']
|
397 |
+
model_name = data['modelVersions'][0]['files'][0]['name']
|
398 |
+
elif 'type=' in url:
|
399 |
+
model_type = parse_qs(urlparse(url).query).get('type', [''])[0]
|
400 |
+
if 'model' in model_type.lower():
|
401 |
+
model_name = data['files'][0]['name']
|
402 |
+
else:
|
403 |
+
model_name = data['files'][1]['name']
|
404 |
+
else:
|
405 |
+
model_type = data['model']['type']
|
406 |
+
model_name = data['files'][0]['name']
|
407 |
+
|
408 |
+
model_name = file_name or model_name
|
409 |
+
|
410 |
+
# Determine DownloadUrl
|
411 |
+
if "civitai.com/models/" in url:
|
412 |
+
if '?modelVersionId=' in url:
|
413 |
+
download_url = data.get('downloadUrl')
|
414 |
+
else:
|
415 |
+
download_url = data["modelVersions"][0].get("downloadUrl", "")
|
416 |
+
elif 'type=' in url:
|
417 |
+
if any(t.lower() in model_type.lower() for t in support_types):
|
418 |
+
download_url = data['files'][0]['downloadUrl']
|
419 |
+
else:
|
420 |
+
download_url = data['files'][1]['downloadUrl']
|
421 |
+
else:
|
422 |
+
download_url = data.get('downloadUrl')
|
423 |
+
|
424 |
+
clean_url = re.sub(r'[?&]token=[^&]*', '', download_url) # hide token
|
425 |
+
|
426 |
+
# Find a safe image: level less than 4 | Kaggle
|
427 |
+
image_url, image_name = None, None
|
428 |
+
if any(t in model_type for t in support_types):
|
429 |
+
try:
|
430 |
+
images = data.get('images') or data['modelVersions'][0].get('images', [])
|
431 |
+
if env == 'Kaggle':
|
432 |
+
image_url = next((image['url'] for image in images if image['nsfwLevel'] < 4), None)
|
433 |
+
else:
|
434 |
+
image_url = images[0]['url'] if images else None
|
435 |
+
except KeyError:
|
436 |
+
pass
|
437 |
+
|
438 |
+
# Generate a name to save the image
|
439 |
+
image_name = f"{model_name.split('.')[0]}.preview.{image_url.split('.')[-1]}" if image_url else None
|
440 |
+
|
441 |
+
return f"{download_url}{'&' if '?' in download_url else '?'}token={civitai_token}", clean_url, model_type, model_name, image_url, image_name, data
|
442 |
+
|
443 |
+
''' Main Download Code '''
|
444 |
+
|
445 |
+
def download(url):
|
446 |
+
links_and_paths = [link_or_path.strip() for link_or_path in url.split(',') if link_or_path.strip()]
|
447 |
+
|
448 |
+
for link_or_path in links_and_paths:
|
449 |
+
if any(link_or_path.lower().startswith(prefix) for prefix in prefixes):
|
450 |
+
handle_manual(link_or_path)
|
451 |
+
else:
|
452 |
+
url, dst_dir, file_name = link_or_path.split()
|
453 |
+
manual_download(url, dst_dir, file_name)
|
454 |
+
|
455 |
+
unpack_zip_files()
|
456 |
+
|
457 |
+
def unpack_zip_files():
|
458 |
+
for directory in directories:
|
459 |
+
for root, _, files in os.walk(directory):
|
460 |
+
for file in files:
|
461 |
+
if file.endswith(".zip"):
|
462 |
+
zip_path = os.path.join(root, file)
|
463 |
+
extract_path = os.path.splitext(zip_path)[0]
|
464 |
+
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
465 |
+
zip_ref.extractall(extract_path)
|
466 |
+
os.remove(zip_path)
|
467 |
+
|
468 |
+
def handle_manual(url):
|
469 |
+
url_parts = url.split(':', 1)
|
470 |
+
prefix, path = url_parts[0], url_parts[1]
|
471 |
+
|
472 |
+
file_name_match = re.search(r'\[(.*?)\]', path)
|
473 |
+
file_name = file_name_match.group(1) if file_name_match else None
|
474 |
+
if file_name:
|
475 |
+
path = re.sub(r'\[.*?\]', '', path)
|
476 |
+
|
477 |
+
if prefix in prefixes:
|
478 |
+
dir = prefixes[prefix]
|
479 |
+
if prefix != "extension":
|
480 |
+
try:
|
481 |
+
manual_download(path, dir, file_name=file_name)
|
482 |
+
except Exception as e:
|
483 |
+
print(f"Error downloading file: {e}")
|
484 |
+
else:
|
485 |
+
extension_repo.append((path, file_name))
|
486 |
+
|
487 |
+
def manual_download(url, dst_dir, file_name):
|
488 |
+
aria2_args = '--optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c'
|
489 |
+
basename = url.split("/")[-1] if file_name is None else file_name
|
490 |
+
header_option = f"--header={user_header}"
|
491 |
+
|
492 |
+
if 'github.com' in url:
|
493 |
+
url = strip_(url)
|
494 |
+
|
495 |
+
# -- CivitAi APi+ V2 --
|
496 |
+
elif 'civitai' in url:
|
497 |
+
url, clean_url, model_type, file_name, image_url, image_name, data = strip_(url, file_name)
|
498 |
+
|
499 |
+
if image_url and image_name:
|
500 |
+
with capture.capture_output() as cap:
|
501 |
+
get_ipython().system("aria2c {aria2_args} -d {dst_dir} -o '{image_name}' '{image_url}'")
|
502 |
+
del cap
|
503 |
+
|
504 |
+
elif "huggingface.co" in url:
|
505 |
+
clean_url = strip_(url)
|
506 |
+
|
507 |
+
""" Formatted info output """
|
508 |
+
model_name_or_basename = file_name if not 'huggingface' in url else basename
|
509 |
+
format_output(clean_url or url, dst_dir, model_name_or_basename)
|
510 |
+
|
511 |
+
# ## -- for my tests --
|
512 |
+
# print(url, dst_dir, model_name_or_basename)
|
513 |
+
print(f"\033[31m[Data Info]:\033[0m Failed to retrieve data from the API.\n") if 'civitai' in url and not data else None
|
514 |
+
if 'civitai' in url and data and image_name:
|
515 |
+
print(f"\033[32m[Preview DL]:\033[0m {image_name} - {image_url}\n")
|
516 |
+
# =====================
|
517 |
+
|
518 |
+
# # -- Git Hub --
|
519 |
+
if 'github.com' in url or 'githubusercontent.com' in url:
|
520 |
+
get_ipython().system("aria2c {aria2_args} -d {dst_dir} -o '{basename}' '{url}'")
|
521 |
+
|
522 |
+
# -- GDrive --
|
523 |
+
elif 'drive.google' in url:
|
524 |
+
try:
|
525 |
+
have_drive_link
|
526 |
+
except:
|
527 |
+
get_ipython().system('pip install -U gdown > /dev/null')
|
528 |
+
have_drive_link = True
|
529 |
+
|
530 |
+
if 'folders' in url:
|
531 |
+
get_ipython().system('gdown --folder "{url}" -O {dst_dir} --fuzzy -c')
|
532 |
+
else:
|
533 |
+
if file_name:
|
534 |
+
get_ipython().system('gdown "{url}" -O {dst_dir}/{file_name} --fuzzy -c')
|
535 |
+
else:
|
536 |
+
get_ipython().system('gdown "{url}" -O {dst_dir} --fuzzy -c')
|
537 |
+
|
538 |
+
# -- Hugging Face --
|
539 |
+
elif 'huggingface' in url:
|
540 |
+
get_ipython().system("aria2c {header_option} {aria2_args} -d {dst_dir} -o '{basename}' '{url}'")
|
541 |
+
|
542 |
+
# -- Other --
|
543 |
+
elif 'http' in url:
|
544 |
+
get_ipython().system("aria2c {aria2_args} -d {dst_dir} '{'-o' + file_name if file_name else ''}' '{url}'")
|
545 |
+
|
546 |
+
''' SubModels - Added URLs '''
|
547 |
+
|
548 |
+
def add_submodels(selection, num_selection, model_dict, dst_dir):
|
549 |
+
if selection == "none":
|
550 |
+
return []
|
551 |
+
if selection == "ALL":
|
552 |
+
all_models = []
|
553 |
+
for models in model_dict.values():
|
554 |
+
all_models.extend(models)
|
555 |
+
selected_models = all_models
|
556 |
+
else:
|
557 |
+
selected_models = model_dict[selection]
|
558 |
+
selected_nums = map(int, num_selection.replace(',', '').split())
|
559 |
+
for num in selected_nums:
|
560 |
+
if 1 <= num <= len(model_dict):
|
561 |
+
name = list(model_dict)[num - 1]
|
562 |
+
selected_models.extend(model_dict[name])
|
563 |
+
|
564 |
+
unique_models = list({model['name']: model for model in selected_models}.values())
|
565 |
+
for model in unique_models:
|
566 |
+
model['dst_dir'] = dst_dir
|
567 |
+
|
568 |
+
return unique_models
|
569 |
+
|
570 |
+
def handle_submodels(selection, num_selection, model_dict, dst_dir, url):
|
571 |
+
submodels = add_submodels(selection, num_selection, model_dict, dst_dir)
|
572 |
+
for submodel in submodels:
|
573 |
+
if not inpainting_model and "inpainting" in submodel['name']:
|
574 |
+
continue
|
575 |
+
url += f"{submodel['url']} {submodel['dst_dir']} {submodel['name']}, "
|
576 |
+
return url
|
577 |
+
|
578 |
+
url = handle_submodels(model, model_num, model_list, models_dir, url)
|
579 |
+
url = handle_submodels(vae, vae_num, vae_list, vaes_dir, url)
|
580 |
+
url = handle_submodels(controlnet, controlnet_num, controlnet_list, control_dir, url)
|
581 |
+
|
582 |
+
''' file.txt - added urls '''
|
583 |
+
|
584 |
+
def process_file_download(file_url, prefixes, unique_urls):
|
585 |
+
files_urls = ""
|
586 |
+
|
587 |
+
if file_url.startswith("http"):
|
588 |
+
if "blob" in file_url:
|
589 |
+
file_url = file_url.replace("blob", "raw")
|
590 |
+
response = requests.get(file_url)
|
591 |
+
lines = response.text.split('\n')
|
592 |
+
else:
|
593 |
+
with open(file_url, 'r') as file:
|
594 |
+
lines = file.readlines()
|
595 |
+
|
596 |
+
current_tag = None
|
597 |
+
for line in lines:
|
598 |
+
line = line.strip()
|
599 |
+
if any(f'# {tag}' in line.lower() for tag in prefixes):
|
600 |
+
current_tag = next((tag for tag in prefixes if tag in line.lower()))
|
601 |
+
|
602 |
+
urls = [url.split('#')[0].strip() for url in line.split(',')] # filter urls
|
603 |
+
for url in urls:
|
604 |
+
filter_url = url.split('[')[0] # same url filter
|
605 |
+
|
606 |
+
if url.startswith("http") and filter_url not in unique_urls:
|
607 |
+
files_urls += f"{current_tag}:{url}, "
|
608 |
+
unique_urls.add(filter_url)
|
609 |
+
|
610 |
+
return files_urls
|
611 |
+
|
612 |
+
file_urls = ""
|
613 |
+
unique_urls = set()
|
614 |
+
|
615 |
+
if custom_file_urls:
|
616 |
+
for custom_file_url in custom_file_urls.replace(',', '').split():
|
617 |
+
if not custom_file_url.endswith('.txt'):
|
618 |
+
custom_file_url += '.txt'
|
619 |
+
if not custom_file_url.startswith('http'):
|
620 |
+
if not custom_file_url.startswith(root_path):
|
621 |
+
custom_file_url = f'{root_path}/{custom_file_url}'
|
622 |
+
|
623 |
+
try:
|
624 |
+
file_urls += process_file_download(custom_file_url, prefixes, unique_urls)
|
625 |
+
except FileNotFoundError:
|
626 |
+
pass
|
627 |
+
|
628 |
+
# url prefixing
|
629 |
+
urls = (Model_url, Vae_url, LoRA_url, Embedding_url, Extensions_url)
|
630 |
+
prefixed_urls = (f"{prefix}:{url}" for prefix, url in zip(prefixes.keys(), urls) if url for url in url.replace(',', '').split())
|
631 |
+
url += ", ".join(prefixed_urls) + ", " + file_urls
|
632 |
+
|
633 |
+
if detailed_download == "on":
|
634 |
+
print("\n\n\033[33m# ====== Detailed Download ====== #\n\033[0m")
|
635 |
+
download(url)
|
636 |
+
print("\n\033[33m# =============================== #\n\033[0m")
|
637 |
+
else:
|
638 |
+
with capture.capture_output() as cap:
|
639 |
+
download(url)
|
640 |
+
del cap
|
641 |
+
|
642 |
+
print("\r🏁 Download Complete!" + " "*15)
|
643 |
+
|
644 |
+
|
645 |
+
# Cleaning shit after downloading...
|
646 |
+
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')
|
647 |
+
|
648 |
+
|
649 |
+
## Install of Custom extensions
|
650 |
+
if len(extension_repo) > 0:
|
651 |
+
print("✨ Installing custom extensions...", end='', flush=True)
|
652 |
+
with capture.capture_output() as cap:
|
653 |
+
for repo, repo_name in extension_repo:
|
654 |
+
if not repo_name:
|
655 |
+
repo_name = repo.split('/')[-1]
|
656 |
+
get_ipython().system('cd {extensions_dir} && git clone {repo} {repo_name} && cd {repo_name} && git fetch')
|
657 |
+
del cap
|
658 |
+
print(f"\r📦 Installed '{len(extension_repo)}', Custom extensions!")
|
659 |
+
|
660 |
+
|
661 |
+
## List Models and stuff V2
|
662 |
+
if detailed_download == "off":
|
663 |
+
print("\n\n\033[33mIf you don't see any downloaded files, enable the 'Detailed Downloads' feature in the widget.")
|
664 |
+
|
665 |
+
get_ipython().run_line_magic('run', '{root_path}/file_cell/special/dl_display_results.py # display widgets result')
|
666 |
+
|
files_cells/python/en/launch_en.py
CHANGED
@@ -1,129 +1,118 @@
|
|
1 |
-
##~ LAUNCH CODE | BY: ANXETY ~##
|
2 |
-
|
3 |
-
import os
|
4 |
-
import re
|
5 |
-
import time
|
6 |
-
import json
|
7 |
-
import requests
|
8 |
-
import cloudpickle as pickle
|
9 |
-
from datetime import timedelta
|
10 |
-
from IPython.display import clear_output
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
'
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
env, root_path, free_plan = detect_environment()
|
26 |
-
webui_path = f"{root_path}/sdw"
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
if
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
# after runnig
|
122 |
-
start_colab = float(open(f'{webui_path}/static/colabTimer.txt', 'r').read())
|
123 |
-
time_since_start = str(timedelta(seconds=time.time()-start_colab)).split('.')[0]
|
124 |
-
print(f"\n⌚️ \033[0mYou have been conducting this session for - \033[33m{time_since_start}\033[0m\n\n")
|
125 |
-
|
126 |
-
''' del zrok tunnel '''
|
127 |
-
if zrok_token:
|
128 |
-
get_ipython().system('zrok disable &> /dev/null')
|
129 |
-
|
|
|
1 |
+
##~ LAUNCH CODE | BY: ANXETY ~##
|
2 |
+
|
3 |
+
import os
|
4 |
+
import re
|
5 |
+
import time
|
6 |
+
import json
|
7 |
+
import requests
|
8 |
+
import cloudpickle as pickle
|
9 |
+
from datetime import timedelta
|
10 |
+
from IPython.display import clear_output
|
11 |
+
|
12 |
+
# ================= DETECT ENV =================
|
13 |
+
def detect_environment():
|
14 |
+
free_plan = (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024 ** 3) <= 20)
|
15 |
+
environments = {
|
16 |
+
'COLAB_GPU': ('Google Colab', "/root" if free_plan else "/content"),
|
17 |
+
'KAGGLE_URL_BASE': ('Kaggle', "/kaggle/working/content")
|
18 |
+
}
|
19 |
+
|
20 |
+
for env_var, (environment, path) in environments.items():
|
21 |
+
if env_var in os.environ:
|
22 |
+
return environment, path, free_plan
|
23 |
+
return 'Unknown', '/unknown/path', free_plan
|
24 |
+
|
25 |
+
env, root_path, free_plan = detect_environment()
|
26 |
+
webui_path = f"{root_path}/sdw"
|
27 |
+
|
28 |
+
def load_settings():
|
29 |
+
SETTINGS_FILE = f'{root_path}/settings.json'
|
30 |
+
if os.path.exists(SETTINGS_FILE):
|
31 |
+
with open(SETTINGS_FILE, 'r') as f:
|
32 |
+
return json.load(f)
|
33 |
+
return {}
|
34 |
+
|
35 |
+
settings = load_settings()
|
36 |
+
ngrok_token = settings.get('ngrok_token', "")
|
37 |
+
zrok_token = settings.get('zrok_token', "")
|
38 |
+
commandline_arguments = settings.get('commandline_arguments', "")
|
39 |
+
change_webui = settings.get('change_webui', "")
|
40 |
+
|
41 |
+
# ======================== TUNNEL V2 ========================
|
42 |
+
print('Please Wait...')
|
43 |
+
|
44 |
+
def get_public_ip(version='ipv4'):
|
45 |
+
try:
|
46 |
+
url = f'https://api64.ipify.org?format=json&{version}=true'
|
47 |
+
response = requests.get(url)
|
48 |
+
return response.json().get('ip', 'N/A')
|
49 |
+
except Exception as e:
|
50 |
+
print(f"Error getting public {version} address:", e)
|
51 |
+
|
52 |
+
# Check if public IP is already saved, if not then get it
|
53 |
+
public_ip_file = f"{root_path}/public_ip.txt"
|
54 |
+
if os.path.exists(public_ip_file):
|
55 |
+
with open(public_ip_file, 'r') as file:
|
56 |
+
public_ipv4 = file.read().strip()
|
57 |
+
else:
|
58 |
+
public_ipv4 = get_public_ip(version='ipv4')
|
59 |
+
with open(public_ip_file, 'w') as file:
|
60 |
+
file.write(public_ipv4)
|
61 |
+
|
62 |
+
tunnel_class = pickle.load(open(f"{root_path}/new_tunnel", "rb"), encoding="utf-8")
|
63 |
+
tunnel_port = 1834
|
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 |
+
|
68 |
+
if zrok_token:
|
69 |
+
get_ipython().system('zrok enable {zrok_token} &> /dev/null')
|
70 |
+
tunnel.add_tunnel(command="zrok share public http://localhost:{port}/ --headless", name="zrok", pattern=re.compile(r"[\w-]+\.share\.zrok\.io"))
|
71 |
+
|
72 |
+
clear_output()
|
73 |
+
|
74 |
+
# =============== Automatic Fixing Path V3 ===============
|
75 |
+
paths_to_check = {
|
76 |
+
"tagger_hf_cache_dir": f"{webui_path}/models/interrogators/",
|
77 |
+
"additional_networks_extra_lora_path": f"{webui_path}/models/Lora/",
|
78 |
+
"ad_extra_models_dir": f"{webui_path}/models/adetailer/",
|
79 |
+
"sd_checkpoint_hash": "",
|
80 |
+
"sd_model_checkpoint": "",
|
81 |
+
"sd_vae": "None"
|
82 |
+
}
|
83 |
+
|
84 |
+
config_path = f'{webui_path}/ui-config.json'
|
85 |
+
|
86 |
+
if os.path.exists(config_path):
|
87 |
+
with open(config_path, 'r') as file:
|
88 |
+
config_data = json.load(file)
|
89 |
+
|
90 |
+
for key, value in paths_to_check.items():
|
91 |
+
if key in config_data and config_data[key] != value:
|
92 |
+
sed_command = f"sed -i 's|\"{key}\": \".*\"|\"{key}\": \"{value}\"|' {config_path}"
|
93 |
+
os.system(sed_command)
|
94 |
+
|
95 |
+
if env == 'Kaggle':
|
96 |
+
get_ipython().system('sed -i \'s/"civitai_interface\\/NSFW content\\/value":.*/"civitai_interface\\/NSFW content\\/value": false/g\' {webui_path}/ui-config.json')
|
97 |
+
|
98 |
+
with tunnel:
|
99 |
+
get_ipython().run_line_magic('cd', '{webui_path}')
|
100 |
+
|
101 |
+
commandline_arguments += f' --port={tunnel_port}'
|
102 |
+
if ngrok_token:
|
103 |
+
commandline_arguments += f' --ngrok {ngrok_token}'
|
104 |
+
if env != "Google Colab":
|
105 |
+
commandline_arguments += f' --encrypt-pass={tunnel_port} --api'
|
106 |
+
|
107 |
+
if change_webui == 'Forge':
|
108 |
+
commandline_arguments += ' --cuda-stream --pin-shared-memory'
|
109 |
+
|
110 |
+
get_ipython().system('COMMANDLINE_ARGS="{commandline_arguments}" python launch.py')
|
111 |
+
|
112 |
+
start_colab = float(open(f'{webui_path}/static/colabTimer.txt', 'r').read())
|
113 |
+
time_since_start = str(timedelta(seconds=time.time()-start_colab)).split('.')[0]
|
114 |
+
print(f"\n⌚️ \033[0mYou have been conducting this session for - \033[33m{time_since_start}\033[0m\n\n")
|
115 |
+
|
116 |
+
if zrok_token:
|
117 |
+
get_ipython().system('zrok disable &> /dev/null')
|
118 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
files_cells/python/en/widgets_en.py
CHANGED
@@ -1,322 +1,322 @@
|
|
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 |
-
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 |
-
get_ipython().system('mkdir -p {root_path}')
|
25 |
-
|
26 |
-
|
27 |
-
# ==================== CSS JS ====================
|
28 |
-
##~ custom background images V1.5 ~##
|
29 |
-
import argparse
|
30 |
-
parser = argparse.ArgumentParser(description='This script processes an background image.')
|
31 |
-
parser.add_argument('-i', '--image', type=str, help='URL of the image to process', metavar='')
|
32 |
-
parser.add_argument('-o', '--opacity', type=float, help='Opacity level for the image, between 0 and 1', metavar='', default=0.3)
|
33 |
-
parser.add_argument('-b', '--blur', type=str, help='Blur level for the image', metavar='', default=0)
|
34 |
-
parser.add_argument('-y', type=int, help='Y coordinate for the image in px', metavar='', default=0)
|
35 |
-
parser.add_argument('-x', type=int, help='X coordinate for the image in px', metavar='', default=0)
|
36 |
-
parser.add_argument('-s', '--scale', type=int, help='Scale image in %%', metavar='', default=100)
|
37 |
-
parser.add_argument('-m', '--mode', action='store_true', help='Removes repetitive image tiles')
|
38 |
-
parser.add_argument('-t', '--transparent', action='store_true', help='Makes input/selection fields 35%% more transparent')
|
39 |
-
parser.add_argument('-bf', '--blur-fields', type=str, help='Background blur level for input/selection fields', metavar='', default=2)
|
40 |
-
|
41 |
-
args = parser.parse_args()
|
42 |
-
|
43 |
-
url_img = args.image
|
44 |
-
opacity_img = args.opacity
|
45 |
-
blur_img = args.blur
|
46 |
-
y_img = args.y
|
47 |
-
x_img = args.x
|
48 |
-
scale_img = args.scale
|
49 |
-
blur_fields = args.blur_fields
|
50 |
-
|
51 |
-
## ---
|
52 |
-
""" WTF KAGGLE - WHAT THE FUCK IS THE DIFFERENCE OF 35 PIXELS!?!?!? """
|
53 |
-
fix_heigh_img = "-810px" if env == "Kaggle" else "-775px"
|
54 |
-
|
55 |
-
""" transperent fields """
|
56 |
-
t_bg_alpha = "1" if not args.transparent else "0.65"
|
57 |
-
|
58 |
-
""" mode img - repeats """
|
59 |
-
mode_img = "repeat" if not args.mode else "no-repeat"
|
60 |
-
|
61 |
-
container_background = f'''
|
62 |
-
<style>
|
63 |
-
:root {{
|
64 |
-
/* for background container*/
|
65 |
-
--img_background: url({url_img});
|
66 |
-
--img_opacity: {opacity_img};
|
67 |
-
--img_blur: {blur_img}px;
|
68 |
-
--image_y: {y_img}px;
|
69 |
-
--image_x: {x_img}px;
|
70 |
-
--img_scale: {scale_img}%;
|
71 |
-
--img_mode: {mode_img};
|
72 |
-
--img_height_dif: {fix_heigh_img};
|
73 |
-
|
74 |
-
/* for fields */
|
75 |
-
--bg-field-color: rgba(28, 28, 28, {t_bg_alpha}); /* -> #1c1c1c */
|
76 |
-
--bg-field-color-hover: rgba(38, 38, 38, {t_bg_alpha}); /* -> #262626; */
|
77 |
-
--bg-field-blur-level: {blur_fields}px;
|
78 |
-
}}
|
79 |
-
'''
|
80 |
-
|
81 |
-
display(HTML(container_background))
|
82 |
-
|
83 |
-
# Main CSS
|
84 |
-
css_file_path = f"{root_path}/CSS/main_widgets.css"
|
85 |
-
with open(css_file_path , "r") as f:
|
86 |
-
CSS = f.read()
|
87 |
-
display(HTML(f"<style>{CSS}</style>"))
|
88 |
-
|
89 |
-
# Main JS
|
90 |
-
JS = '''
|
91 |
-
<!-- TOGGLE 'CustomDL' SCRIPT -->
|
92 |
-
<script>
|
93 |
-
function toggleContainer() {
|
94 |
-
let downloadContainer = document.querySelector('.container_custom_downlad');
|
95 |
-
let info = document.querySelector('.info');
|
96 |
-
|
97 |
-
downloadContainer.classList.toggle('expanded');
|
98 |
-
info.classList.toggle('showed');
|
99 |
-
}
|
100 |
-
</script>
|
101 |
-
'''
|
102 |
-
display(HTML(JS))
|
103 |
-
|
104 |
-
# ==================== WIDGETS V2 ====================
|
105 |
-
HR = widgets.HTML('<hr>')
|
106 |
-
|
107 |
-
class WidgetFactory:
|
108 |
-
def __init__(self, style=None, layout=None):
|
109 |
-
self.style = style if style else {'description_width': 'initial'}
|
110 |
-
self.layout = layout if layout else widgets.Layout(max_width='1080px', width='100%')
|
111 |
-
|
112 |
-
def create_html(self, content, class_name=None):
|
113 |
-
html_widget = widgets.HTML(content)
|
114 |
-
if class_name:
|
115 |
-
html_widget.add_class(class_name)
|
116 |
-
return html_widget
|
117 |
-
|
118 |
-
def create_header(self, name):
|
119 |
-
return widgets.HTML(f'<div class="header">{name}<div>')
|
120 |
-
|
121 |
-
def create_dropdown(self, options, value, description):
|
122 |
-
return widgets.Dropdown(options=options, value=value, description=description, style=self.style, layout=self.layout)
|
123 |
-
|
124 |
-
def create_text(self, description, placeholder='', value=''):
|
125 |
-
return widgets.Text(description=description, placeholder=placeholder, value=value, style=self.style, layout=self.layout)
|
126 |
-
|
127 |
-
def create_checkbox(self, value, description):
|
128 |
-
return widgets.Checkbox(value=value, description=description, style=self.style, layout=self.layout)
|
129 |
-
|
130 |
-
def create_button(self, description, class_name=None):
|
131 |
-
button = widgets.Button(description=description)
|
132 |
-
if class_name:
|
133 |
-
button.add_class(class_name)
|
134 |
-
return button
|
135 |
-
|
136 |
-
def create_hbox(self, children):
|
137 |
-
return widgets.HBox(children)
|
138 |
-
|
139 |
-
def create_vbox(self, children, class_names=None):
|
140 |
-
vbox = widgets.VBox(children)
|
141 |
-
if class_names:
|
142 |
-
for class_name in class_names:
|
143 |
-
vbox.add_class(class_name)
|
144 |
-
return vbox
|
145 |
-
|
146 |
-
def display(self, widget):
|
147 |
-
display(widget)
|
148 |
-
|
149 |
-
# Instantiate the factory
|
150 |
-
factory = WidgetFactory()
|
151 |
-
|
152 |
-
# --- MODEL ---
|
153 |
-
model_header = factory.create_header('Model Selection')
|
154 |
-
model_options = ['none',
|
155 |
-
'1.Anime (by XpucT) + INP',
|
156 |
-
'2.BluMix [Anime] [V7] + INP',
|
157 |
-
'3.Cetus-Mix [Anime] [V4] + INP',
|
158 |
-
'4.Counterfeit [Anime] [V3] + INP',
|
159 |
-
'5.CuteColor [Anime] [V3]',
|
160 |
-
'6.Dark-Sushi-Mix [Anime]',
|
161 |
-
'7.Deliberate [Realism] [V6] + INP',
|
162 |
-
'8.Meina-Mix [Anime] [V11] + INP',
|
163 |
-
'9.Mix-Pro [Anime] [V4] + INP']
|
164 |
-
model_widget = factory.create_dropdown(model_options, '4.Counterfeit [Anime] [V3] + INP', 'Model:')
|
165 |
-
model_num_widget = factory.create_text('Model Number:', 'Enter the model numbers to be downloaded using comma/space.')
|
166 |
-
inpainting_model_widget = factory.create_checkbox(False, 'Inpainting Models')
|
167 |
-
|
168 |
-
# Display Model
|
169 |
-
all_model_box = factory.create_vbox([model_header, model_widget, model_num_widget, inpainting_model_widget], class_names=["container", "image_1"])
|
170 |
-
factory.display(all_model_box)
|
171 |
-
|
172 |
-
# --- VAE ---
|
173 |
-
vae_header = factory.create_header('VAE Selection')
|
174 |
-
vae_options = ['none',
|
175 |
-
'1.Anime.vae',
|
176 |
-
'2.Anything.vae',
|
177 |
-
'3.Blessed2.vae',
|
178 |
-
'4.ClearVae.vae',
|
179 |
-
'5.WD.vae']
|
180 |
-
vae_widget = factory.create_dropdown(vae_options, '3.Blessed2.vae', 'Vae:')
|
181 |
-
vae_num_widget = factory.create_text('Vae Number:', 'Enter the vae numbers to be downloaded using comma/space.')
|
182 |
-
|
183 |
-
# Display Vae
|
184 |
-
all_vae_box = factory.create_vbox([vae_header, vae_widget, vae_num_widget], class_names=["container", "image_2"])
|
185 |
-
factory.display(all_vae_box)
|
186 |
-
|
187 |
-
# --- ADDITIONAL ---
|
188 |
-
additional_header = factory.create_header('Additional')
|
189 |
-
latest_webui_widget = factory.create_checkbox(True, 'Update WebUI')
|
190 |
-
latest_exstensions_widget = factory.create_checkbox(True, 'Update Extensions')
|
191 |
-
change_webui_widget = factory.create_dropdown(['A1111', 'Forge'], 'A1111', 'Change WebUI:')
|
192 |
-
detailed_download_widget = factory.create_dropdown(['off', 'on'], 'off', 'Detailed Download:')
|
193 |
-
choose_changes_widget = factory.create_hbox([latest_webui_widget, latest_exstensions_widget, change_webui_widget, detailed_download_widget])
|
194 |
-
|
195 |
-
controlnet_options = ['none', 'ALL', '1.canny',
|
196 |
-
'2.openpose', '3.depth',
|
197 |
-
'4.normal_map', '5.mlsd',
|
198 |
-
'6.lineart', '7.soft_edge',
|
199 |
-
'8.scribble', '9.segmentation',
|
200 |
-
'10.shuffle', '11.tile',
|
201 |
-
'12.inpaint', '13.instruct_p2p']
|
202 |
-
controlnet_widget = factory.create_dropdown(controlnet_options, 'none', 'ControlNet:')
|
203 |
-
controlnet_num_widget = factory.create_text('ControlNet Number:', 'Enter the ControlNet model numbers to be downloaded using comma/space.')
|
204 |
-
commit_hash_widget = factory.create_text('Commit Hash:')
|
205 |
-
huggingface_token_widget = factory.create_text('HuggingFace Token:')
|
206 |
-
|
207 |
-
ngrok_token_widget = factory.create_text('Ngrok Token:')
|
208 |
-
ngrock_button = factory.create_html('<a href="https://dashboard.ngrok.com/get-started/your-authtoken" target="_blank">Получить Ngrok Токен</a>', class_name="button_ngrok")
|
209 |
-
ngrok_widget = factory.create_hbox([ngrok_token_widget, ngrock_button])
|
210 |
-
|
211 |
-
zrok_token_widget = factory.create_text('Zrok Token:')
|
212 |
-
zrok_button = factory.create_html('<a href="https://colab.research.google.com/drive/1d2sjWDJi_GYBUavrHSuQyHTDuLy36WpU" target="_blank">Зарегать Zrok Токен</a>', class_name="button_ngrok")
|
213 |
-
zrok_widget = factory.create_hbox([zrok_token_widget, zrok_button])
|
214 |
-
|
215 |
-
commandline_arguments_options = "--listen --enable-insecure-extension-access --theme dark --no-half-vae --disable-console-progressbars --xformers"
|
216 |
-
commandline_arguments_widget = factory.create_text('Arguments:', value=commandline_arguments_options)
|
217 |
-
|
218 |
-
# Display Additional
|
219 |
-
additional_widget_list = [additional_header,
|
220 |
-
choose_changes_widget,
|
221 |
-
HR,
|
222 |
-
controlnet_widget,
|
223 |
-
controlnet_num_widget,
|
224 |
-
commit_hash_widget,
|
225 |
-
huggingface_token_widget,
|
226 |
-
ngrok_widget,
|
227 |
-
zrok_widget,
|
228 |
-
HR,
|
229 |
-
commandline_arguments_widget]
|
230 |
-
|
231 |
-
if free_plan and env == "Google Colab": # remove ngrok from colab
|
232 |
-
additional_widget_list.remove(ngrok_widget)
|
233 |
-
if os.path.exists(webui_path): # remove selection after selection ;3
|
234 |
-
choose_changes_widget.children = [widget for widget in choose_changes_widget.children if widget != change_webui_widget]
|
235 |
-
|
236 |
-
all_additional_box = factory.create_vbox(additional_widget_list, class_names=["container", "image_3"])
|
237 |
-
factory.display(all_additional_box)
|
238 |
-
|
239 |
-
# --- CUSTOM DOWNLOAD ---
|
240 |
-
custom_download_header_popup = factory.create_html('''
|
241 |
-
<style>
|
242 |
-
/* Term Colors */
|
243 |
-
.sample_label {color: #dbafff;}
|
244 |
-
.braces {color: #ffff00;}
|
245 |
-
.extension {color: #eb934b;}
|
246 |
-
.file_name {color: #ffffd8;}
|
247 |
-
</style>
|
248 |
-
|
249 |
-
<div class="header" style="cursor: pointer;" onclick="toggleContainer()">Custom Download</div>
|
250 |
-
<!-- PopUp Window -->
|
251 |
-
<div class="info">INFO</div>
|
252 |
-
<div class="popup">
|
253 |
-
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>
|
254 |
-
after the URL without spaces.
|
255 |
-
<span style="color: #ff9999">For files, be sure to specify</span> - <span class="extension">Filename Extension.</span>
|
256 |
-
<div class="sample">
|
257 |
-
<span class="sample_label">Example for File:</span>
|
258 |
-
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>
|
259 |
-
<br>
|
260 |
-
<span class="sample_label">Example for Extension:</span>
|
261 |
-
https://github.com/hako-mikan/sd-webui-regional-prompter<span class="braces">[</span><span class="file_name">Regional-Prompter</span><span class="braces">]</span>
|
262 |
-
</div>
|
263 |
-
</div>
|
264 |
-
''')
|
265 |
-
|
266 |
-
Model_url_widget = factory.create_text('Model:')
|
267 |
-
Vae_url_widget = factory.create_text('Vae:')
|
268 |
-
LoRA_url_widget = factory.create_text('LoRa:')
|
269 |
-
Embedding_url_widget = factory.create_text('Embedding:')
|
270 |
-
Extensions_url_widget = factory.create_text('Extensions:')
|
271 |
-
custom_file_urls_widget = factory.create_text('File (txt):')
|
272 |
-
|
273 |
-
# Display CustomDl
|
274 |
-
all_custom_box = factory.create_vbox([
|
275 |
-
custom_download_header_popup, Model_url_widget, Vae_url_widget, LoRA_url_widget, Embedding_url_widget, Extensions_url_widget, custom_file_urls_widget
|
276 |
-
], class_names=["container", "image_4", "container_custom_downlad"])
|
277 |
-
factory.display(all_custom_box)
|
278 |
-
|
279 |
-
# --- Save Button ---
|
280 |
-
save_button = factory.create_button('Save', class_name="button_save")
|
281 |
-
factory.display(save_button)
|
282 |
-
|
283 |
-
|
284 |
-
# ============ Load / Save - Settings V2 ============
|
285 |
-
SETTINGS_FILE = f'{root_path}/settings.json'
|
286 |
-
|
287 |
-
SETTINGS_KEYS = [
|
288 |
-
'model', 'model_num', 'inpainting_model',
|
289 |
-
'vae', 'vae_num', 'latest_webui', 'latest_exstensions',
|
290 |
-
'change_webui', 'detailed_download', 'controlnet',
|
291 |
-
'controlnet_num', 'commit_hash', 'huggingface_token',
|
292 |
-
'ngrok_token', 'zrok_token', 'commandline_arguments',
|
293 |
-
'Model_url', 'Vae_url', 'LoRA_url', 'Embedding_url',
|
294 |
-
'Extensions_url', 'custom_file_urls'
|
295 |
-
]
|
296 |
-
|
297 |
-
def save_settings():
|
298 |
-
settings = {key: globals()[f"{key}_widget"].value for key in SETTINGS_KEYS}
|
299 |
-
with open(SETTINGS_FILE, 'w') as f:
|
300 |
-
json.dump(settings, f, indent=2)
|
301 |
-
|
302 |
-
def load_settings():
|
303 |
-
if os.path.exists(SETTINGS_FILE):
|
304 |
-
with open(SETTINGS_FILE, 'r') as f:
|
305 |
-
settings = json.load(f)
|
306 |
-
for key in SETTINGS_KEYS:
|
307 |
-
globals()[f"{key}_widget"].value = settings.get(key, "")
|
308 |
-
|
309 |
-
def hide_widgets():
|
310 |
-
widgets_list = [all_model_box, all_vae_box, all_additional_box, all_custom_box, save_button]
|
311 |
-
for widget in widgets_list:
|
312 |
-
widget.add_class("hide")
|
313 |
-
time.sleep(0.5)
|
314 |
-
widgets.Widget.close_all()
|
315 |
-
|
316 |
-
def save_data(button):
|
317 |
-
save_settings()
|
318 |
-
hide_widgets()
|
319 |
-
|
320 |
-
load_settings()
|
321 |
-
save_button.on_click(save_data)
|
322 |
-
|
|
|
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 |
+
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 |
+
get_ipython().system('mkdir -p {root_path}')
|
25 |
+
|
26 |
+
|
27 |
+
# ==================== CSS JS ====================
|
28 |
+
##~ custom background images V1.5 ~##
|
29 |
+
import argparse
|
30 |
+
parser = argparse.ArgumentParser(description='This script processes an background image.')
|
31 |
+
parser.add_argument('-i', '--image', type=str, help='URL of the image to process', metavar='')
|
32 |
+
parser.add_argument('-o', '--opacity', type=float, help='Opacity level for the image, between 0 and 1', metavar='', default=0.3)
|
33 |
+
parser.add_argument('-b', '--blur', type=str, help='Blur level for the image', metavar='', default=0)
|
34 |
+
parser.add_argument('-y', type=int, help='Y coordinate for the image in px', metavar='', default=0)
|
35 |
+
parser.add_argument('-x', type=int, help='X coordinate for the image in px', metavar='', default=0)
|
36 |
+
parser.add_argument('-s', '--scale', type=int, help='Scale image in %%', metavar='', default=100)
|
37 |
+
parser.add_argument('-m', '--mode', action='store_true', help='Removes repetitive image tiles')
|
38 |
+
parser.add_argument('-t', '--transparent', action='store_true', help='Makes input/selection fields 35%% more transparent')
|
39 |
+
parser.add_argument('-bf', '--blur-fields', type=str, help='Background blur level for input/selection fields', metavar='', default=2)
|
40 |
+
|
41 |
+
args = parser.parse_args()
|
42 |
+
|
43 |
+
url_img = args.image
|
44 |
+
opacity_img = args.opacity
|
45 |
+
blur_img = args.blur
|
46 |
+
y_img = args.y
|
47 |
+
x_img = args.x
|
48 |
+
scale_img = args.scale
|
49 |
+
blur_fields = args.blur_fields
|
50 |
+
|
51 |
+
## ---
|
52 |
+
""" WTF KAGGLE - WHAT THE FUCK IS THE DIFFERENCE OF 35 PIXELS!?!?!? """
|
53 |
+
fix_heigh_img = "-810px" if env == "Kaggle" else "-775px"
|
54 |
+
|
55 |
+
""" transperent fields """
|
56 |
+
t_bg_alpha = "1" if not args.transparent else "0.65"
|
57 |
+
|
58 |
+
""" mode img - repeats """
|
59 |
+
mode_img = "repeat" if not args.mode else "no-repeat"
|
60 |
+
|
61 |
+
container_background = f'''
|
62 |
+
<style>
|
63 |
+
:root {{
|
64 |
+
/* for background container*/
|
65 |
+
--img_background: url({url_img});
|
66 |
+
--img_opacity: {opacity_img};
|
67 |
+
--img_blur: {blur_img}px;
|
68 |
+
--image_y: {y_img}px;
|
69 |
+
--image_x: {x_img}px;
|
70 |
+
--img_scale: {scale_img}%;
|
71 |
+
--img_mode: {mode_img};
|
72 |
+
--img_height_dif: {fix_heigh_img};
|
73 |
+
|
74 |
+
/* for fields */
|
75 |
+
--bg-field-color: rgba(28, 28, 28, {t_bg_alpha}); /* -> #1c1c1c */
|
76 |
+
--bg-field-color-hover: rgba(38, 38, 38, {t_bg_alpha}); /* -> #262626; */
|
77 |
+
--bg-field-blur-level: {blur_fields}px;
|
78 |
+
}}
|
79 |
+
'''
|
80 |
+
|
81 |
+
display(HTML(container_background))
|
82 |
+
|
83 |
+
# Main CSS
|
84 |
+
css_file_path = f"{root_path}/CSS/main_widgets.css"
|
85 |
+
with open(css_file_path , "r") as f:
|
86 |
+
CSS = f.read()
|
87 |
+
display(HTML(f"<style>{CSS}</style>"))
|
88 |
+
|
89 |
+
# Main JS
|
90 |
+
JS = '''
|
91 |
+
<!-- TOGGLE 'CustomDL' SCRIPT -->
|
92 |
+
<script>
|
93 |
+
function toggleContainer() {
|
94 |
+
let downloadContainer = document.querySelector('.container_custom_downlad');
|
95 |
+
let info = document.querySelector('.info');
|
96 |
+
|
97 |
+
downloadContainer.classList.toggle('expanded');
|
98 |
+
info.classList.toggle('showed');
|
99 |
+
}
|
100 |
+
</script>
|
101 |
+
'''
|
102 |
+
display(HTML(JS))
|
103 |
+
|
104 |
+
# ==================== WIDGETS V2 ====================
|
105 |
+
HR = widgets.HTML('<hr>')
|
106 |
+
|
107 |
+
class WidgetFactory:
|
108 |
+
def __init__(self, style=None, layout=None):
|
109 |
+
self.style = style if style else {'description_width': 'initial'}
|
110 |
+
self.layout = layout if layout else widgets.Layout(max_width='1080px', width='100%')
|
111 |
+
|
112 |
+
def create_html(self, content, class_name=None):
|
113 |
+
html_widget = widgets.HTML(content)
|
114 |
+
if class_name:
|
115 |
+
html_widget.add_class(class_name)
|
116 |
+
return html_widget
|
117 |
+
|
118 |
+
def create_header(self, name):
|
119 |
+
return widgets.HTML(f'<div class="header">{name}<div>')
|
120 |
+
|
121 |
+
def create_dropdown(self, options, value, description):
|
122 |
+
return widgets.Dropdown(options=options, value=value, description=description, style=self.style, layout=self.layout)
|
123 |
+
|
124 |
+
def create_text(self, description, placeholder='', value=''):
|
125 |
+
return widgets.Text(description=description, placeholder=placeholder, value=value, style=self.style, layout=self.layout)
|
126 |
+
|
127 |
+
def create_checkbox(self, value, description):
|
128 |
+
return widgets.Checkbox(value=value, description=description, style=self.style, layout=self.layout)
|
129 |
+
|
130 |
+
def create_button(self, description, class_name=None):
|
131 |
+
button = widgets.Button(description=description)
|
132 |
+
if class_name:
|
133 |
+
button.add_class(class_name)
|
134 |
+
return button
|
135 |
+
|
136 |
+
def create_hbox(self, children):
|
137 |
+
return widgets.HBox(children)
|
138 |
+
|
139 |
+
def create_vbox(self, children, class_names=None):
|
140 |
+
vbox = widgets.VBox(children)
|
141 |
+
if class_names:
|
142 |
+
for class_name in class_names:
|
143 |
+
vbox.add_class(class_name)
|
144 |
+
return vbox
|
145 |
+
|
146 |
+
def display(self, widget):
|
147 |
+
display(widget)
|
148 |
+
|
149 |
+
# Instantiate the factory
|
150 |
+
factory = WidgetFactory()
|
151 |
+
|
152 |
+
# --- MODEL ---
|
153 |
+
model_header = factory.create_header('Model Selection')
|
154 |
+
model_options = ['none',
|
155 |
+
'1.Anime (by XpucT) + INP',
|
156 |
+
'2.BluMix [Anime] [V7] + INP',
|
157 |
+
'3.Cetus-Mix [Anime] [V4] + INP',
|
158 |
+
'4.Counterfeit [Anime] [V3] + INP',
|
159 |
+
'5.CuteColor [Anime] [V3]',
|
160 |
+
'6.Dark-Sushi-Mix [Anime]',
|
161 |
+
'7.Deliberate [Realism] [V6] + INP',
|
162 |
+
'8.Meina-Mix [Anime] [V11] + INP',
|
163 |
+
'9.Mix-Pro [Anime] [V4] + INP']
|
164 |
+
model_widget = factory.create_dropdown(model_options, '4.Counterfeit [Anime] [V3] + INP', 'Model:')
|
165 |
+
model_num_widget = factory.create_text('Model Number:', 'Enter the model numbers to be downloaded using comma/space.')
|
166 |
+
inpainting_model_widget = factory.create_checkbox(False, 'Inpainting Models')
|
167 |
+
|
168 |
+
# Display Model
|
169 |
+
all_model_box = factory.create_vbox([model_header, model_widget, model_num_widget, inpainting_model_widget], class_names=["container", "image_1"])
|
170 |
+
factory.display(all_model_box)
|
171 |
+
|
172 |
+
# --- VAE ---
|
173 |
+
vae_header = factory.create_header('VAE Selection')
|
174 |
+
vae_options = ['none',
|
175 |
+
'1.Anime.vae',
|
176 |
+
'2.Anything.vae',
|
177 |
+
'3.Blessed2.vae',
|
178 |
+
'4.ClearVae.vae',
|
179 |
+
'5.WD.vae']
|
180 |
+
vae_widget = factory.create_dropdown(vae_options, '3.Blessed2.vae', 'Vae:')
|
181 |
+
vae_num_widget = factory.create_text('Vae Number:', 'Enter the vae numbers to be downloaded using comma/space.')
|
182 |
+
|
183 |
+
# Display Vae
|
184 |
+
all_vae_box = factory.create_vbox([vae_header, vae_widget, vae_num_widget], class_names=["container", "image_2"])
|
185 |
+
factory.display(all_vae_box)
|
186 |
+
|
187 |
+
# --- ADDITIONAL ---
|
188 |
+
additional_header = factory.create_header('Additional')
|
189 |
+
latest_webui_widget = factory.create_checkbox(True, 'Update WebUI')
|
190 |
+
latest_exstensions_widget = factory.create_checkbox(True, 'Update Extensions')
|
191 |
+
change_webui_widget = factory.create_dropdown(['A1111', 'Forge'], 'A1111', 'Change WebUI:')
|
192 |
+
detailed_download_widget = factory.create_dropdown(['off', 'on'], 'off', 'Detailed Download:')
|
193 |
+
choose_changes_widget = factory.create_hbox([latest_webui_widget, latest_exstensions_widget, change_webui_widget, detailed_download_widget])
|
194 |
+
|
195 |
+
controlnet_options = ['none', 'ALL', '1.canny',
|
196 |
+
'2.openpose', '3.depth',
|
197 |
+
'4.normal_map', '5.mlsd',
|
198 |
+
'6.lineart', '7.soft_edge',
|
199 |
+
'8.scribble', '9.segmentation',
|
200 |
+
'10.shuffle', '11.tile',
|
201 |
+
'12.inpaint', '13.instruct_p2p']
|
202 |
+
controlnet_widget = factory.create_dropdown(controlnet_options, 'none', 'ControlNet:')
|
203 |
+
controlnet_num_widget = factory.create_text('ControlNet Number:', 'Enter the ControlNet model numbers to be downloaded using comma/space.')
|
204 |
+
commit_hash_widget = factory.create_text('Commit Hash:')
|
205 |
+
huggingface_token_widget = factory.create_text('HuggingFace Token:')
|
206 |
+
|
207 |
+
ngrok_token_widget = factory.create_text('Ngrok Token:')
|
208 |
+
ngrock_button = factory.create_html('<a href="https://dashboard.ngrok.com/get-started/your-authtoken" target="_blank">Получить Ngrok Токен</a>', class_name="button_ngrok")
|
209 |
+
ngrok_widget = factory.create_hbox([ngrok_token_widget, ngrock_button])
|
210 |
+
|
211 |
+
zrok_token_widget = factory.create_text('Zrok Token:')
|
212 |
+
zrok_button = factory.create_html('<a href="https://colab.research.google.com/drive/1d2sjWDJi_GYBUavrHSuQyHTDuLy36WpU" target="_blank">Зарегать Zrok Токен</a>', class_name="button_ngrok")
|
213 |
+
zrok_widget = factory.create_hbox([zrok_token_widget, zrok_button])
|
214 |
+
|
215 |
+
commandline_arguments_options = "--listen --enable-insecure-extension-access --theme dark --no-half-vae --disable-console-progressbars --xformers"
|
216 |
+
commandline_arguments_widget = factory.create_text('Arguments:', value=commandline_arguments_options)
|
217 |
+
|
218 |
+
# Display Additional
|
219 |
+
additional_widget_list = [additional_header,
|
220 |
+
choose_changes_widget,
|
221 |
+
HR,
|
222 |
+
controlnet_widget,
|
223 |
+
controlnet_num_widget,
|
224 |
+
commit_hash_widget,
|
225 |
+
huggingface_token_widget,
|
226 |
+
ngrok_widget,
|
227 |
+
zrok_widget,
|
228 |
+
HR,
|
229 |
+
commandline_arguments_widget]
|
230 |
+
|
231 |
+
if free_plan and env == "Google Colab": # remove ngrok from colab
|
232 |
+
additional_widget_list.remove(ngrok_widget)
|
233 |
+
if os.path.exists(webui_path): # remove selection after selection ;3
|
234 |
+
choose_changes_widget.children = [widget for widget in choose_changes_widget.children if widget != change_webui_widget]
|
235 |
+
|
236 |
+
all_additional_box = factory.create_vbox(additional_widget_list, class_names=["container", "image_3"])
|
237 |
+
factory.display(all_additional_box)
|
238 |
+
|
239 |
+
# --- CUSTOM DOWNLOAD ---
|
240 |
+
custom_download_header_popup = factory.create_html('''
|
241 |
+
<style>
|
242 |
+
/* Term Colors */
|
243 |
+
.sample_label {color: #dbafff;}
|
244 |
+
.braces {color: #ffff00;}
|
245 |
+
.extension {color: #eb934b;}
|
246 |
+
.file_name {color: #ffffd8;}
|
247 |
+
</style>
|
248 |
+
|
249 |
+
<div class="header" style="cursor: pointer;" onclick="toggleContainer()">Custom Download</div>
|
250 |
+
<!-- PopUp Window -->
|
251 |
+
<div class="info">INFO</div>
|
252 |
+
<div class="popup">
|
253 |
+
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>
|
254 |
+
after the URL without spaces.
|
255 |
+
<span style="color: #ff9999">For files, be sure to specify</span> - <span class="extension">Filename Extension.</span>
|
256 |
+
<div class="sample">
|
257 |
+
<span class="sample_label">Example for File:</span>
|
258 |
+
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>
|
259 |
+
<br>
|
260 |
+
<span class="sample_label">Example for Extension:</span>
|
261 |
+
https://github.com/hako-mikan/sd-webui-regional-prompter<span class="braces">[</span><span class="file_name">Regional-Prompter</span><span class="braces">]</span>
|
262 |
+
</div>
|
263 |
+
</div>
|
264 |
+
''')
|
265 |
+
|
266 |
+
Model_url_widget = factory.create_text('Model:')
|
267 |
+
Vae_url_widget = factory.create_text('Vae:')
|
268 |
+
LoRA_url_widget = factory.create_text('LoRa:')
|
269 |
+
Embedding_url_widget = factory.create_text('Embedding:')
|
270 |
+
Extensions_url_widget = factory.create_text('Extensions:')
|
271 |
+
custom_file_urls_widget = factory.create_text('File (txt):')
|
272 |
+
|
273 |
+
# Display CustomDl
|
274 |
+
all_custom_box = factory.create_vbox([
|
275 |
+
custom_download_header_popup, Model_url_widget, Vae_url_widget, LoRA_url_widget, Embedding_url_widget, Extensions_url_widget, custom_file_urls_widget
|
276 |
+
], class_names=["container", "image_4", "container_custom_downlad"])
|
277 |
+
factory.display(all_custom_box)
|
278 |
+
|
279 |
+
# --- Save Button ---
|
280 |
+
save_button = factory.create_button('Save', class_name="button_save")
|
281 |
+
factory.display(save_button)
|
282 |
+
|
283 |
+
|
284 |
+
# ============ Load / Save - Settings V2 ============
|
285 |
+
SETTINGS_FILE = f'{root_path}/settings.json'
|
286 |
+
|
287 |
+
SETTINGS_KEYS = [
|
288 |
+
'model', 'model_num', 'inpainting_model',
|
289 |
+
'vae', 'vae_num', 'latest_webui', 'latest_exstensions',
|
290 |
+
'change_webui', 'detailed_download', 'controlnet',
|
291 |
+
'controlnet_num', 'commit_hash', 'huggingface_token',
|
292 |
+
'ngrok_token', 'zrok_token', 'commandline_arguments',
|
293 |
+
'Model_url', 'Vae_url', 'LoRA_url', 'Embedding_url',
|
294 |
+
'Extensions_url', 'custom_file_urls'
|
295 |
+
]
|
296 |
+
|
297 |
+
def save_settings():
|
298 |
+
settings = {key: globals()[f"{key}_widget"].value for key in SETTINGS_KEYS}
|
299 |
+
with open(SETTINGS_FILE, 'w') as f:
|
300 |
+
json.dump(settings, f, indent=2)
|
301 |
+
|
302 |
+
def load_settings():
|
303 |
+
if os.path.exists(SETTINGS_FILE):
|
304 |
+
with open(SETTINGS_FILE, 'r') as f:
|
305 |
+
settings = json.load(f)
|
306 |
+
for key in SETTINGS_KEYS:
|
307 |
+
globals()[f"{key}_widget"].value = settings.get(key, "")
|
308 |
+
|
309 |
+
def hide_widgets():
|
310 |
+
widgets_list = [all_model_box, all_vae_box, all_additional_box, all_custom_box, save_button]
|
311 |
+
for widget in widgets_list:
|
312 |
+
widget.add_class("hide")
|
313 |
+
time.sleep(0.5)
|
314 |
+
widgets.Widget.close_all()
|
315 |
+
|
316 |
+
def save_data(button):
|
317 |
+
save_settings()
|
318 |
+
hide_widgets()
|
319 |
+
|
320 |
+
load_settings()
|
321 |
+
save_button.on_click(save_data)
|
322 |
+
|
files_cells/python/ru/auto_cleaner_ru.py
CHANGED
@@ -1,138 +1,138 @@
|
|
1 |
-
##~ AutoCleaner V3.7 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 |
-
for env_var, (environment, path) in environments.items():
|
18 |
-
if env_var in os.environ:
|
19 |
-
return environment, path, free_plan
|
20 |
-
|
21 |
-
env, root_path, free_plan = detect_environment()
|
22 |
-
webui_path = f"{root_path}/sdw"
|
23 |
-
|
24 |
-
|
25 |
-
# ==================== CSS ====================
|
26 |
-
# Main CSS
|
27 |
-
css_file_path = f"{root_path}/CSS/auto_cleaner.css"
|
28 |
-
with open(css_file_path , "r") as f:
|
29 |
-
CSS_AC = f.read()
|
30 |
-
display(HTML(f"<style>{CSS_AC}</style>"))
|
31 |
-
|
32 |
-
|
33 |
-
# ================ AutoCleaner function ================
|
34 |
-
directories = {
|
35 |
-
"Изображения": f"{webui_path}/output",
|
36 |
-
"Модели": f"{webui_path}/models/Stable-diffusion/",
|
37 |
-
"Vae": f"{webui_path}/models/VAE/",
|
38 |
-
"LoRa": f"{webui_path}/models/Lora/",
|
39 |
-
"ControlNet Модели": f"{webui_path}/models/ControlNet/"
|
40 |
-
}
|
41 |
-
|
42 |
-
""" functions """
|
43 |
-
def clean_directory(directory):
|
44 |
-
deleted_files = 0
|
45 |
-
image_dir = directories['Изображения']
|
46 |
-
|
47 |
-
for root, dirs, files in os.walk(directory):
|
48 |
-
for file in files:
|
49 |
-
file_path = os.path.join(root, file)
|
50 |
-
|
51 |
-
if file.endswith(".txt"):
|
52 |
-
continue
|
53 |
-
if file.endswith((".safetensors", ".pt")) or root == image_dir: # fix for image counter
|
54 |
-
deleted_files += 1
|
55 |
-
|
56 |
-
os.remove(file_path)
|
57 |
-
return deleted_files
|
58 |
-
|
59 |
-
def update_memory_info():
|
60 |
-
disk_space = psutil.disk_usage(os.getcwd())
|
61 |
-
total = disk_space.total / (1024 ** 3)
|
62 |
-
used = disk_space.used / (1024 ** 3)
|
63 |
-
free = disk_space.free / (1024 ** 3)
|
64 |
-
|
65 |
-
storage_info.value = f'''
|
66 |
-
<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>
|
67 |
-
'''
|
68 |
-
|
69 |
-
def on_execute_button_press(button):
|
70 |
-
selected_cleaners = auto_cleaner_widget.value
|
71 |
-
deleted_files_dict = {}
|
72 |
-
|
73 |
-
for option in selected_cleaners:
|
74 |
-
if option in directories:
|
75 |
-
deleted_files_dict[option] = clean_directory(directories[option])
|
76 |
-
|
77 |
-
output.clear_output()
|
78 |
-
|
79 |
-
with output:
|
80 |
-
for message in generate_messages(deleted_files_dict):
|
81 |
-
message_widget = HTML(f'<p class="output_message_AC">{message}</p>')
|
82 |
-
display(message_widget)
|
83 |
-
|
84 |
-
update_memory_info()
|
85 |
-
|
86 |
-
def on_clear_button_press(button):
|
87 |
-
container.add_class("hide")
|
88 |
-
time.sleep(0.5)
|
89 |
-
widgets.Widget.close_all()
|
90 |
-
|
91 |
-
def generate_messages(deleted_files_dict):
|
92 |
-
messages = []
|
93 |
-
word_variants = {
|
94 |
-
"Изображения": "Изображений",
|
95 |
-
"Модели": "Моделей",
|
96 |
-
"Vae": "Vae",
|
97 |
-
"LoRa": "LoRa",
|
98 |
-
"ControlNet Модели": "ControlNet Моделей"
|
99 |
-
}
|
100 |
-
for key, value in deleted_files_dict.items():
|
101 |
-
object_word = word_variants.get(key)
|
102 |
-
messages.append(f"Удалено {value} {object_word}")
|
103 |
-
return messages
|
104 |
-
|
105 |
-
|
106 |
-
# --- storage memory ---
|
107 |
-
import psutil
|
108 |
-
disk_space = psutil.disk_usage(os.getcwd())
|
109 |
-
total = disk_space.total / (1024 ** 3)
|
110 |
-
used = disk_space.used / (1024 ** 3)
|
111 |
-
free = disk_space.free / (1024 ** 3)
|
112 |
-
|
113 |
-
|
114 |
-
# ================ Widgets ================
|
115 |
-
# UI Code
|
116 |
-
AutoCleaner_options = AutoCleaner_options = list(directories.keys())
|
117 |
-
instruction_label = widgets.HTML('''
|
118 |
-
<span class="instruction_AC">Используйте <span style="color: #B2B2B2;">ctrl</span> или <span style="color: #B2B2B2;">shift</span> для множественного выбора.</span>
|
119 |
-
''')
|
120 |
-
auto_cleaner_widget = widgets.SelectMultiple(options=AutoCleaner_options, layout=widgets.Layout(width="auto")).add_class("custom-select-multiple_AC")
|
121 |
-
output = widgets.Output().add_class("output_AC")
|
122 |
-
|
123 |
-
execute_button = Button(description='Выполнить Очистку').add_class("button_execute_AC").add_class("button_AC")
|
124 |
-
execute_button.on_click(on_execute_button_press)
|
125 |
-
clear_button = Button(description='Скрыть Виджет').add_class("button_clear_AC").add_class("button_AC")
|
126 |
-
clear_button.on_click(on_clear_button_press)
|
127 |
-
|
128 |
-
storage_info = widgets.HTML(f'''
|
129 |
-
<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>
|
130 |
-
''')
|
131 |
-
|
132 |
-
buttons = widgets.HBox([execute_button, clear_button])
|
133 |
-
lower_information_panel = widgets.HBox([buttons, storage_info]).add_class("lower_information_panel_AC")
|
134 |
-
|
135 |
-
container = VBox([instruction_label, widgets.HTML('<hr>'), auto_cleaner_widget, output, widgets.HTML('<hr>'), lower_information_panel]).add_class("container_AC")
|
136 |
-
|
137 |
-
display(container)
|
138 |
-
|
|
|
1 |
+
##~ AutoCleaner V3.7 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 |
+
for env_var, (environment, path) in environments.items():
|
18 |
+
if env_var in os.environ:
|
19 |
+
return environment, path, free_plan
|
20 |
+
|
21 |
+
env, root_path, free_plan = detect_environment()
|
22 |
+
webui_path = f"{root_path}/sdw"
|
23 |
+
|
24 |
+
|
25 |
+
# ==================== CSS ====================
|
26 |
+
# Main CSS
|
27 |
+
css_file_path = f"{root_path}/CSS/auto_cleaner.css"
|
28 |
+
with open(css_file_path , "r") as f:
|
29 |
+
CSS_AC = f.read()
|
30 |
+
display(HTML(f"<style>{CSS_AC}</style>"))
|
31 |
+
|
32 |
+
|
33 |
+
# ================ AutoCleaner function ================
|
34 |
+
directories = {
|
35 |
+
"Изображения": f"{webui_path}/output",
|
36 |
+
"Модели": f"{webui_path}/models/Stable-diffusion/",
|
37 |
+
"Vae": f"{webui_path}/models/VAE/",
|
38 |
+
"LoRa": f"{webui_path}/models/Lora/",
|
39 |
+
"ControlNet Модели": f"{webui_path}/models/ControlNet/"
|
40 |
+
}
|
41 |
+
|
42 |
+
""" functions """
|
43 |
+
def clean_directory(directory):
|
44 |
+
deleted_files = 0
|
45 |
+
image_dir = directories['Изображения']
|
46 |
+
|
47 |
+
for root, dirs, files in os.walk(directory):
|
48 |
+
for file in files:
|
49 |
+
file_path = os.path.join(root, file)
|
50 |
+
|
51 |
+
if file.endswith(".txt"):
|
52 |
+
continue
|
53 |
+
if file.endswith((".safetensors", ".pt")) or root == image_dir: # fix for image counter
|
54 |
+
deleted_files += 1
|
55 |
+
|
56 |
+
os.remove(file_path)
|
57 |
+
return deleted_files
|
58 |
+
|
59 |
+
def update_memory_info():
|
60 |
+
disk_space = psutil.disk_usage(os.getcwd())
|
61 |
+
total = disk_space.total / (1024 ** 3)
|
62 |
+
used = disk_space.used / (1024 ** 3)
|
63 |
+
free = disk_space.free / (1024 ** 3)
|
64 |
+
|
65 |
+
storage_info.value = f'''
|
66 |
+
<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>
|
67 |
+
'''
|
68 |
+
|
69 |
+
def on_execute_button_press(button):
|
70 |
+
selected_cleaners = auto_cleaner_widget.value
|
71 |
+
deleted_files_dict = {}
|
72 |
+
|
73 |
+
for option in selected_cleaners:
|
74 |
+
if option in directories:
|
75 |
+
deleted_files_dict[option] = clean_directory(directories[option])
|
76 |
+
|
77 |
+
output.clear_output()
|
78 |
+
|
79 |
+
with output:
|
80 |
+
for message in generate_messages(deleted_files_dict):
|
81 |
+
message_widget = HTML(f'<p class="output_message_AC">{message}</p>')
|
82 |
+
display(message_widget)
|
83 |
+
|
84 |
+
update_memory_info()
|
85 |
+
|
86 |
+
def on_clear_button_press(button):
|
87 |
+
container.add_class("hide")
|
88 |
+
time.sleep(0.5)
|
89 |
+
widgets.Widget.close_all()
|
90 |
+
|
91 |
+
def generate_messages(deleted_files_dict):
|
92 |
+
messages = []
|
93 |
+
word_variants = {
|
94 |
+
"Изображения": "Изображений",
|
95 |
+
"Модели": "Моделей",
|
96 |
+
"Vae": "Vae",
|
97 |
+
"LoRa": "LoRa",
|
98 |
+
"ControlNet Модели": "ControlNet Моделей"
|
99 |
+
}
|
100 |
+
for key, value in deleted_files_dict.items():
|
101 |
+
object_word = word_variants.get(key)
|
102 |
+
messages.append(f"Удалено {value} {object_word}")
|
103 |
+
return messages
|
104 |
+
|
105 |
+
|
106 |
+
# --- storage memory ---
|
107 |
+
import psutil
|
108 |
+
disk_space = psutil.disk_usage(os.getcwd())
|
109 |
+
total = disk_space.total / (1024 ** 3)
|
110 |
+
used = disk_space.used / (1024 ** 3)
|
111 |
+
free = disk_space.free / (1024 ** 3)
|
112 |
+
|
113 |
+
|
114 |
+
# ================ Widgets ================
|
115 |
+
# UI Code
|
116 |
+
AutoCleaner_options = AutoCleaner_options = list(directories.keys())
|
117 |
+
instruction_label = widgets.HTML('''
|
118 |
+
<span class="instruction_AC">Используйте <span style="color: #B2B2B2;">ctrl</span> или <span style="color: #B2B2B2;">shift</span> для множественного выбора.</span>
|
119 |
+
''')
|
120 |
+
auto_cleaner_widget = widgets.SelectMultiple(options=AutoCleaner_options, layout=widgets.Layout(width="auto")).add_class("custom-select-multiple_AC")
|
121 |
+
output = widgets.Output().add_class("output_AC")
|
122 |
+
|
123 |
+
execute_button = Button(description='Выполнить Очистку').add_class("button_execute_AC").add_class("button_AC")
|
124 |
+
execute_button.on_click(on_execute_button_press)
|
125 |
+
clear_button = Button(description='Скрыть Виджет').add_class("button_clear_AC").add_class("button_AC")
|
126 |
+
clear_button.on_click(on_clear_button_press)
|
127 |
+
|
128 |
+
storage_info = widgets.HTML(f'''
|
129 |
+
<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>
|
130 |
+
''')
|
131 |
+
|
132 |
+
buttons = widgets.HBox([execute_button, clear_button])
|
133 |
+
lower_information_panel = widgets.HBox([buttons, storage_info]).add_class("lower_information_panel_AC")
|
134 |
+
|
135 |
+
container = VBox([instruction_label, widgets.HTML('<hr>'), auto_cleaner_widget, output, widgets.HTML('<hr>'), lower_information_panel]).add_class("container_AC")
|
136 |
+
|
137 |
+
display(container)
|
138 |
+
|
files_cells/python/ru/downloading_ru.py
CHANGED
@@ -1,611 +1,666 @@
|
|
1 |
-
##~ DOWNLOADING CODE | BY: ANXETY ~##
|
2 |
-
|
3 |
-
import os
|
4 |
-
import re
|
5 |
-
import time
|
6 |
-
import json
|
7 |
-
import shutil
|
8 |
-
import zipfile
|
9 |
-
import requests
|
10 |
-
import subprocess
|
11 |
-
from datetime import timedelta
|
12 |
-
from subprocess import getoutput
|
13 |
-
from IPython.utils import capture
|
14 |
-
from IPython.display import clear_output
|
15 |
-
from urllib.parse import urlparse, parse_qs
|
16 |
-
|
17 |
-
|
18 |
-
# ================= DETECT ENV =================
|
19 |
-
def detect_environment():
|
20 |
-
free_plan = (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024 ** 3) <= 20)
|
21 |
-
environments = {
|
22 |
-
'COLAB_GPU': ('Google Colab', "/root" if free_plan else "/content"),
|
23 |
-
'KAGGLE_URL_BASE': ('Kaggle', "/kaggle/working/content")
|
24 |
-
}
|
25 |
-
for env_var, (environment, path) in environments.items():
|
26 |
-
if env_var in os.environ:
|
27 |
-
return environment, path, free_plan
|
28 |
-
|
29 |
-
env, root_path, free_plan = detect_environment()
|
30 |
-
webui_path = f"{root_path}/sdw"
|
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 |
-
"aria2": "apt -y install aria2",
|
41 |
-
"localtunnel": "npm install -g localtunnel",
|
42 |
-
"insightface": "pip install insightface"
|
43 |
-
}
|
44 |
-
|
45 |
-
additional_libs = {
|
46 |
-
"Google Colab": {
|
47 |
-
"xformers": "pip install xformers==0.0.26.post1 --no-deps"
|
48 |
-
},
|
49 |
-
"Kaggle": {
|
50 |
-
"xformers": "pip install xformers==0.0.26.post1",
|
51 |
-
# "torch": "pip install torch==2.1.2+cu121 torchvision==0.16.2+cu121 torchaudio==2.1.2 --extra-index-url https://download.pytorch.org/whl/cu121",
|
52 |
-
"aiohttp": "pip install trash-cli && trash-put /opt/conda/lib/python3.10/site-packages/aiohttp*" # fix install req
|
53 |
-
}
|
54 |
-
}
|
55 |
-
|
56 |
-
if env in additional_libs:
|
57 |
-
install_lib.update(additional_libs[env])
|
58 |
-
|
59 |
-
# Loop through libraries
|
60 |
-
for index, (package, install_cmd) in enumerate(install_lib.items(), start=1):
|
61 |
-
print(f"\r[{index}/{len(install_lib)}] \033[32m>>\033[0m Installing \033[33m{package}\033[0m..." + " "*35, end='')
|
62 |
-
subprocess.run(install_cmd, shell=True, capture_output=True)
|
63 |
-
|
64 |
-
# Additional specific packages
|
65 |
-
with capture.capture_output() as cap:
|
66 |
-
get_ipython().system('curl -s -OL https://github.com/DEX-1101/sd-webui-notebook/raw/main/res/new_tunnel --output-dir {root_path}')
|
67 |
-
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')
|
68 |
-
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')
|
69 |
-
del cap
|
70 |
-
|
71 |
-
clear_output()
|
72 |
-
|
73 |
-
# Save file install lib
|
74 |
-
with open(flag_file, "w") as f:
|
75 |
-
f.write(">W<'")
|
76 |
-
|
77 |
-
print("🍪 Библиотеки установлены!" + " "*35)
|
78 |
-
time.sleep(2)
|
79 |
-
clear_output()
|
80 |
-
|
81 |
-
|
82 |
-
# ================= loading settings V4 =================
|
83 |
-
def load_settings(path):
|
84 |
-
if os.path.exists(path):
|
85 |
-
with open(path, 'r') as file:
|
86 |
-
return json.load(file)
|
87 |
-
return {}
|
88 |
-
|
89 |
-
settings = load_settings(f'{root_path}/settings.json')
|
90 |
-
|
91 |
-
VARIABLES = [
|
92 |
-
'model', 'model_num', 'inpainting_model',
|
93 |
-
'vae', 'vae_num', 'latest_webui', 'latest_exstensions',
|
94 |
-
'change_webui', 'detailed_download', 'controlnet',
|
95 |
-
'controlnet_num', 'commit_hash', 'huggingface_token',
|
96 |
-
'ngrok_token', 'zrok_token', 'commandline_arguments',
|
97 |
-
'Model_url', 'Vae_url', 'LoRA_url', 'Embedding_url',
|
98 |
-
'Extensions_url', 'custom_file_urls'
|
99 |
-
]
|
100 |
-
|
101 |
-
locals().update({key: settings.get(key) for key in VARIABLES})
|
102 |
-
|
103 |
-
|
104 |
-
# ================= OTHER =================
|
105 |
-
try:
|
106 |
-
start_colab
|
107 |
-
except:
|
108 |
-
start_colab = int(time.time())-5
|
109 |
-
|
110 |
-
# CONFIG DIR
|
111 |
-
models_dir = f"{webui_path}/models/Stable-diffusion"
|
112 |
-
vaes_dir = f"{webui_path}/models/VAE"
|
113 |
-
embeddings_dir = f"{webui_path}/embeddings"
|
114 |
-
loras_dir = f"{webui_path}/models/Lora"
|
115 |
-
extensions_dir = f"{webui_path}/extensions"
|
116 |
-
control_dir = f"{webui_path}/models/ControlNet"
|
117 |
-
adetailer_dir = f"{webui_path}/models/adetailer"
|
118 |
-
|
119 |
-
|
120 |
-
# ================= MAIN CODE =================
|
121 |
-
if not os.path.exists(webui_path):
|
122 |
-
start_install = int(time.time())
|
123 |
-
print("⌚ Распаковка Stable Diffusion..." if change_webui != 'Forge' else "⌚ Распаковка Stable Diffusion (Forge)...", end='')
|
124 |
-
with capture.capture_output() as cap:
|
125 |
-
aria2_command = "aria2c --console-log-level=error -c -x 16 -s 16 -k 1M"
|
126 |
-
url = "https://huggingface.co/NagisaNao/fast_repo/resolve/main/FULL_REPO.zip" if change_webui != 'Forge' else "https://huggingface.co/NagisaNao/fast_repo/resolve/main/FULL_REPO_forge.zip"
|
127 |
-
get_ipython().system('{aria2_command} {url} -o repo.zip')
|
128 |
-
|
129 |
-
get_ipython().system('unzip -q -o repo.zip -d {webui_path}')
|
130 |
-
get_ipython().system('rm -rf repo.zip')
|
131 |
-
|
132 |
-
get_ipython().run_line_magic('cd', '{root_path}')
|
133 |
-
os.environ["SAFETENSORS_FAST_GPU"]='1'
|
134 |
-
os.environ["CUDA_MODULE_LOADING"]="LAZY"
|
135 |
-
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
|
136 |
-
os.environ["PYTHONWARNINGS"] = "ignore"
|
137 |
-
|
138 |
-
get_ipython().system('echo -n {start_colab} > {webui_path}/static/colabTimer.txt')
|
139 |
-
del cap
|
140 |
-
install_time = timedelta(seconds=time.time()-start_install)
|
141 |
-
print("\r🚀 Распаковка Завершена! За","%02d:%02d:%02d ⚡\n" % (install_time.seconds / 3600, (install_time.seconds / 60) % 60, install_time.seconds % 60), end='', flush=True)
|
142 |
-
else:
|
143 |
-
print("🚀 Все распакованно... Пропуск. ⚡")
|
144 |
-
start_colab = float(open(f'{webui_path}/static/colabTimer.txt', 'r').read())
|
145 |
-
time_since_start = str(timedelta(seconds=time.time()-start_colab)).split('.')[0]
|
146 |
-
print(f"⌚️ Вы проводите эту сессию в течение - \033[33m{time_since_start}\033[0m")
|
147 |
-
|
148 |
-
|
149 |
-
## Changes extensions and WebUi
|
150 |
-
if latest_webui or latest_exstensions:
|
151 |
-
action = "Обновление WebUI и Расширений" if latest_webui and latest_exstensions else ("Обновление WebUI" if latest_webui else "Обновление Расширений")
|
152 |
-
print(f"⌚️ {action}...", end='', flush=True)
|
153 |
-
with capture.capture_output() as cap:
|
154 |
-
get_ipython().system('git config --global user.email "[email protected]"')
|
155 |
-
get_ipython().system('git config --global user.name "Your Name"')
|
156 |
-
|
157 |
-
## Update Webui
|
158 |
-
if latest_webui:
|
159 |
-
get_ipython().run_line_magic('cd', '{webui_path}')
|
160 |
-
get_ipython().system('git restore .')
|
161 |
-
get_ipython().system('git pull -X theirs --rebase --autostash')
|
162 |
-
|
163 |
-
## Update extensions
|
164 |
-
if latest_exstensions:
|
165 |
-
get_ipython().system('{\'for dir in \' + webui_path + \'/extensions/*/; do cd \\"$dir\\" && git reset --hard && git pull; done\'}')
|
166 |
-
del cap
|
167 |
-
print(f"\r✨ {action} Завершено!")
|
168 |
-
|
169 |
-
|
170 |
-
# === FIXING EXTENSIONS ===
|
171 |
-
anxety_repos = "https://huggingface.co/NagisaNao/fast_repo/resolve/main"
|
172 |
-
|
173 |
-
with capture.capture_output() as cap:
|
174 |
-
# --- Umi-Wildcard ---
|
175 |
-
get_ipython().system("sed -i '521s/open=\\(False\\|True\\)/open=False/' {webui_path}/extensions/Umi-AI-Wildcards/scripts/wildcard_recursive.py # Closed accordion by default")
|
176 |
-
|
177 |
-
# --- Encrypt-Image ---
|
178 |
-
get_ipython().system("sed -i '9,37d' {webui_path}/extensions/Encrypt-Image/javascript/encrypt_images_info.js # Removes the weird text in webui")
|
179 |
-
|
180 |
-
# --- Additional-Networks ---
|
181 |
-
get_ipython().system('wget -O {webui_path}/extensions/additional-networks/scripts/metadata_editor.py {anxety_repos}/extensions/Additional-Networks/fix/metadata_editor.py # Fixing an error due to old style')
|
182 |
-
del cap
|
183 |
-
|
184 |
-
|
185 |
-
## Version switching
|
186 |
-
if commit_hash:
|
187 |
-
print('⏳ Активация машины времени...', end="", flush=True)
|
188 |
-
with capture.capture_output() as cap:
|
189 |
-
get_ipython().run_line_magic('cd', '{webui_path}')
|
190 |
-
get_ipython().system('git config --global user.email "[email protected]"')
|
191 |
-
get_ipython().system('git config --global user.name "Your Name"')
|
192 |
-
get_ipython().system('git reset --hard {commit_hash}')
|
193 |
-
del cap
|
194 |
-
print(f"\r⌛️ Машина времени активированна! Текущий коммит: \033[34m{commit_hash}\033[0m")
|
195 |
-
|
196 |
-
|
197 |
-
## Downloading model and stuff | oh~ Hey! If you're freaked out by that code too, don't worry, me too!
|
198 |
-
print("📦 Скачивание моделей и прочего...", end='')
|
199 |
-
model_list = {
|
200 |
-
"1.Anime (by XpucT) + INP": [
|
201 |
-
{"url": "https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2.safetensors", "name": "
|
202 |
-
{"url": "https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2-inpainting.safetensors", "name": "
|
203 |
-
],
|
204 |
-
"2.BluMix [Anime] [V7] + INP": [
|
205 |
-
{"url": "https://civitai.com/api/download/models/361779", "name": "
|
206 |
-
{"url": "https://civitai.com/api/download/models/363850", "name": "
|
207 |
-
],
|
208 |
-
"3.Cetus-Mix [Anime] [V4] + INP": [
|
209 |
-
{"url": "https://civitai.com/api/download/models/130298", "name": "CetusMix_V4.safetensors"},
|
210 |
-
{"url": "https://civitai.com/api/download/models/139882", "name": "CetusMix_V4-inpainting.safetensors"}
|
211 |
-
],
|
212 |
-
"4.Counterfeit [Anime] [V3] + INP": [
|
213 |
-
{"url": "https://
|
214 |
-
{"url": "https://civitai.com/api/download/models/137911", "name": "Counterfeit_V3-inpainting.safetensors"}
|
215 |
-
],
|
216 |
-
"5.CuteColor [Anime] [V3]": [
|
217 |
-
{"url": "https://civitai.com/api/download/models/138754", "name": "CuteColor_V3.safetensors"}
|
218 |
-
],
|
219 |
-
"6.Dark-Sushi-Mix [Anime]": [
|
220 |
-
{"url": "https://civitai.com/api/download/models/101640", "name": "DarkSushiMix_2_5D.safetensors"},
|
221 |
-
{"url": "https://civitai.com/api/download/models/56071", "name": "DarkSushiMix_colorful.safetensors"}
|
222 |
-
],
|
223 |
-
"7.Deliberate [Realism] [V6] + INP": [
|
224 |
-
{"url": "https://huggingface.co/XpucT/Deliberate/resolve/main/Deliberate_v6.safetensors", "name": "
|
225 |
-
{"url": "https://huggingface.co/XpucT/Deliberate/resolve/main/Deliberate_v6-inpainting.safetensors", "name": "
|
226 |
-
],
|
227 |
-
"8.Meina-Mix [Anime] [V11] + INP": [
|
228 |
-
{"url": "https://civitai.com/api/download/models/119057", "name": "MeinaMix_V11.safetensors"},
|
229 |
-
{"url": "https://civitai.com/api/download/models/120702", "name": "MeinaMix_V11-inpainting.safetensors"}
|
230 |
-
],
|
231 |
-
"9.Mix-Pro [Anime] [V4] + INP": [
|
232 |
-
{"url": "https://civitai.com/api/download/models/125668", "name": "MixPro_V4.safetensors"},
|
233 |
-
{"url": "https://civitai.com/api/download/models/139878", "name": "MixPro_V4-inpainting.safetensors"}
|
234 |
-
]
|
235 |
-
}
|
236 |
-
|
237 |
-
vae_list = {
|
238 |
-
"1.Anime.vae": [{"url": "https://civitai.com/api/download/models/311162", "name": "vae-ft-mse-840000-ema-pruned.vae.safetensors"}],
|
239 |
-
"2.Anything.vae": [{"url": "https://
|
240 |
-
"3.Blessed2.vae": [{"url": "https://huggingface.co/NoCrypt/
|
241 |
-
"4.ClearVae.vae": [{"url": "https://civitai.com/api/download/models/88156", "name": "ClearVae_23.vae.safetensors"}],
|
242 |
-
"5.WD.vae": [{"url": "https://huggingface.co/NoCrypt/resources/resolve/main/VAE/wd.vae.safetensors", "name": "WD.vae.safetensors"}]
|
243 |
-
}
|
244 |
-
|
245 |
-
controlnet_list = {
|
246 |
-
"1.canny": [
|
247 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny_fp16.safetensors", "name": "control_v11p_sd15_canny_fp16.safetensors"},
|
248 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_canny_fp16.yaml", "name": "control_v11p_sd15_canny_fp16.yaml"}
|
249 |
-
],
|
250 |
-
"2.openpose": [
|
251 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose_fp16.safetensors", "name": "control_v11p_sd15_openpose_fp16.safetensors"},
|
252 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_openpose_fp16.yaml", "name": "control_v11p_sd15_openpose_fp16.yaml"}
|
253 |
-
],
|
254 |
-
"3.depth": [
|
255 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth_fp16.safetensors", "name": "control_v11f1p_sd15_depth_fp16.safetensors"},
|
256 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1p_sd15_depth_fp16.yaml", "name": "control_v11f1p_sd15_depth_fp16.yaml"},
|
257 |
-
{"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"}
|
258 |
-
],
|
259 |
-
"4.normal_map": [
|
260 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_normalbae_fp16.safetensors", "name": "control_v11p_sd15_normalbae_fp16.safetensors"},
|
261 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_normalbae_fp16.yaml", "name": "control_v11p_sd15_normalbae_fp16.yaml"}
|
262 |
-
],
|
263 |
-
"5.mlsd": [
|
264 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_mlsd_fp16.safetensors", "name": "control_v11p_sd15_mlsd_fp16.safetensors"},
|
265 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_mlsd_fp16.yaml", "name": "control_v11p_sd15_mlsd_fp16.yaml"}
|
266 |
-
],
|
267 |
-
"6.lineart": [
|
268 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart_fp16.safetensors", "name": "control_v11p_sd15_lineart_fp16.safetensors"},
|
269 |
-
{"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"},
|
270 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_lineart_fp16.yaml", "name": "control_v11p_sd15_lineart_fp16.yaml"},
|
271 |
-
{"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"}
|
272 |
-
],
|
273 |
-
"7.soft_edge": [
|
274 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge_fp16.safetensors", "name": "control_v11p_sd15_softedge_fp16.safetensors"},
|
275 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_softedge_fp16.yaml", "name": "control_v11p_sd15_softedge_fp16.yaml"}
|
276 |
-
],
|
277 |
-
"8.scribble": [
|
278 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble_fp16.safetensors", "name": "control_v11p_sd15_scribble_fp16.safetensors"},
|
279 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_scribble_fp16.yaml", "name": "control_v11p_sd15_scribble_fp16.yaml"}
|
280 |
-
],
|
281 |
-
"9.segmentation": [
|
282 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg_fp16.safetensors", "name": "control_v11p_sd15_seg_fp16.safetensors"},
|
283 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_seg_fp16.yaml", "name": "control_v11p_sd15_seg_fp16.yaml"}
|
284 |
-
],
|
285 |
-
"10.shuffle": [
|
286 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle_fp16.safetensors", "name": "control_v11e_sd15_shuffle_fp16.safetensors"},
|
287 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_shuffle_fp16.yaml", "name": "control_v11e_sd15_shuffle_fp16.yaml"}
|
288 |
-
],
|
289 |
-
"11.tile": [
|
290 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile_fp16.safetensors", "name": "control_v11f1e_sd15_tile_fp16.safetensors"},
|
291 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1e_sd15_tile_fp16.yaml", "name": "control_v11f1e_sd15_tile_fp16.yaml"}
|
292 |
-
],
|
293 |
-
"12.inpaint": [
|
294 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_inpaint_fp16.safetensors", "name": "control_v11p_sd15_inpaint_fp16.safetensors"},
|
295 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_inpaint_fp16.yaml", "name": "control_v11p_sd15_inpaint_fp16.yaml"}
|
296 |
-
],
|
297 |
-
"13.instruct_p2p": [
|
298 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p_fp16.safetensors", "name": "control_v11e_sd15_ip2p_fp16.safetensors"},
|
299 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_ip2p_fp16.yaml", "name": "control_v11e_sd15_ip2p_fp16.yaml"}
|
300 |
-
]
|
301 |
-
}
|
302 |
-
|
303 |
-
url = ""
|
304 |
-
prefixes = {
|
305 |
-
"model": models_dir,
|
306 |
-
"vae": vaes_dir,
|
307 |
-
"lora": loras_dir,
|
308 |
-
"embed": embeddings_dir,
|
309 |
-
"extension": extensions_dir,
|
310 |
-
"control": control_dir,
|
311 |
-
"adetailer": adetailer_dir
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
info =
|
334 |
-
|
335 |
-
|
336 |
-
print(f"\
|
337 |
-
print(f"\033[
|
338 |
-
print(f"\033[
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
return
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
if
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
if
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
if
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
'
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
if
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
url
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
##~ DOWNLOADING CODE | BY: ANXETY ~##
|
2 |
+
|
3 |
+
import os
|
4 |
+
import re
|
5 |
+
import time
|
6 |
+
import json
|
7 |
+
import shutil
|
8 |
+
import zipfile
|
9 |
+
import requests
|
10 |
+
import subprocess
|
11 |
+
from datetime import timedelta
|
12 |
+
from subprocess import getoutput
|
13 |
+
from IPython.utils import capture
|
14 |
+
from IPython.display import clear_output
|
15 |
+
from urllib.parse import urlparse, parse_qs
|
16 |
+
|
17 |
+
|
18 |
+
# ================= DETECT ENV =================
|
19 |
+
def detect_environment():
|
20 |
+
free_plan = (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024 ** 3) <= 20)
|
21 |
+
environments = {
|
22 |
+
'COLAB_GPU': ('Google Colab', "/root" if free_plan else "/content"),
|
23 |
+
'KAGGLE_URL_BASE': ('Kaggle', "/kaggle/working/content")
|
24 |
+
}
|
25 |
+
for env_var, (environment, path) in environments.items():
|
26 |
+
if env_var in os.environ:
|
27 |
+
return environment, path, free_plan
|
28 |
+
|
29 |
+
env, root_path, free_plan = detect_environment()
|
30 |
+
webui_path = f"{root_path}/sdw"
|
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 |
+
"aria2": "apt -y install aria2",
|
41 |
+
"localtunnel": "npm install -g localtunnel",
|
42 |
+
"insightface": "pip install insightface"
|
43 |
+
}
|
44 |
+
|
45 |
+
additional_libs = {
|
46 |
+
"Google Colab": {
|
47 |
+
"xformers": "pip install xformers==0.0.26.post1 --no-deps"
|
48 |
+
},
|
49 |
+
"Kaggle": {
|
50 |
+
"xformers": "pip install xformers==0.0.26.post1",
|
51 |
+
# "torch": "pip install torch==2.1.2+cu121 torchvision==0.16.2+cu121 torchaudio==2.1.2 --extra-index-url https://download.pytorch.org/whl/cu121",
|
52 |
+
"aiohttp": "pip install trash-cli && trash-put /opt/conda/lib/python3.10/site-packages/aiohttp*" # fix install req
|
53 |
+
}
|
54 |
+
}
|
55 |
+
|
56 |
+
if env in additional_libs:
|
57 |
+
install_lib.update(additional_libs[env])
|
58 |
+
|
59 |
+
# Loop through libraries
|
60 |
+
for index, (package, install_cmd) in enumerate(install_lib.items(), start=1):
|
61 |
+
print(f"\r[{index}/{len(install_lib)}] \033[32m>>\033[0m Installing \033[33m{package}\033[0m..." + " "*35, end='')
|
62 |
+
subprocess.run(install_cmd, shell=True, capture_output=True)
|
63 |
+
|
64 |
+
# Additional specific packages
|
65 |
+
with capture.capture_output() as cap:
|
66 |
+
get_ipython().system('curl -s -OL https://github.com/DEX-1101/sd-webui-notebook/raw/main/res/new_tunnel --output-dir {root_path}')
|
67 |
+
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')
|
68 |
+
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')
|
69 |
+
del cap
|
70 |
+
|
71 |
+
clear_output()
|
72 |
+
|
73 |
+
# Save file install lib
|
74 |
+
with open(flag_file, "w") as f:
|
75 |
+
f.write(">W<'")
|
76 |
+
|
77 |
+
print("🍪 Библиотеки установлены!" + " "*35)
|
78 |
+
time.sleep(2)
|
79 |
+
clear_output()
|
80 |
+
|
81 |
+
|
82 |
+
# ================= loading settings V4 =================
|
83 |
+
def load_settings(path):
|
84 |
+
if os.path.exists(path):
|
85 |
+
with open(path, 'r') as file:
|
86 |
+
return json.load(file)
|
87 |
+
return {}
|
88 |
+
|
89 |
+
settings = load_settings(f'{root_path}/settings.json')
|
90 |
+
|
91 |
+
VARIABLES = [
|
92 |
+
'model', 'model_num', 'inpainting_model',
|
93 |
+
'vae', 'vae_num', 'latest_webui', 'latest_exstensions',
|
94 |
+
'change_webui', 'detailed_download', 'controlnet',
|
95 |
+
'controlnet_num', 'commit_hash', 'huggingface_token',
|
96 |
+
'ngrok_token', 'zrok_token', 'commandline_arguments',
|
97 |
+
'Model_url', 'Vae_url', 'LoRA_url', 'Embedding_url',
|
98 |
+
'Extensions_url', 'custom_file_urls'
|
99 |
+
]
|
100 |
+
|
101 |
+
locals().update({key: settings.get(key) for key in VARIABLES})
|
102 |
+
|
103 |
+
|
104 |
+
# ================= OTHER =================
|
105 |
+
try:
|
106 |
+
start_colab
|
107 |
+
except:
|
108 |
+
start_colab = int(time.time())-5
|
109 |
+
|
110 |
+
# CONFIG DIR
|
111 |
+
models_dir = f"{webui_path}/models/Stable-diffusion"
|
112 |
+
vaes_dir = f"{webui_path}/models/VAE"
|
113 |
+
embeddings_dir = f"{webui_path}/embeddings"
|
114 |
+
loras_dir = f"{webui_path}/models/Lora"
|
115 |
+
extensions_dir = f"{webui_path}/extensions"
|
116 |
+
control_dir = f"{webui_path}/models/ControlNet"
|
117 |
+
adetailer_dir = f"{webui_path}/models/adetailer"
|
118 |
+
|
119 |
+
|
120 |
+
# ================= MAIN CODE =================
|
121 |
+
if not os.path.exists(webui_path):
|
122 |
+
start_install = int(time.time())
|
123 |
+
print("⌚ Распаковка Stable Diffusion..." if change_webui != 'Forge' else "⌚ Распаковка Stable Diffusion (Forge)...", end='')
|
124 |
+
with capture.capture_output() as cap:
|
125 |
+
aria2_command = "aria2c --console-log-level=error -c -x 16 -s 16 -k 1M"
|
126 |
+
url = "https://huggingface.co/NagisaNao/fast_repo/resolve/main/FULL_REPO.zip" if change_webui != 'Forge' else "https://huggingface.co/NagisaNao/fast_repo/resolve/main/FULL_REPO_forge.zip"
|
127 |
+
get_ipython().system('{aria2_command} {url} -o repo.zip')
|
128 |
+
|
129 |
+
get_ipython().system('unzip -q -o repo.zip -d {webui_path}')
|
130 |
+
get_ipython().system('rm -rf repo.zip')
|
131 |
+
|
132 |
+
get_ipython().run_line_magic('cd', '{root_path}')
|
133 |
+
os.environ["SAFETENSORS_FAST_GPU"]='1'
|
134 |
+
os.environ["CUDA_MODULE_LOADING"]="LAZY"
|
135 |
+
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
|
136 |
+
os.environ["PYTHONWARNINGS"] = "ignore"
|
137 |
+
|
138 |
+
get_ipython().system('echo -n {start_colab} > {webui_path}/static/colabTimer.txt')
|
139 |
+
del cap
|
140 |
+
install_time = timedelta(seconds=time.time()-start_install)
|
141 |
+
print("\r🚀 Распаковка Завершена! За","%02d:%02d:%02d ⚡\n" % (install_time.seconds / 3600, (install_time.seconds / 60) % 60, install_time.seconds % 60), end='', flush=True)
|
142 |
+
else:
|
143 |
+
print("🚀 Все распакованно... Пропуск. ⚡")
|
144 |
+
start_colab = float(open(f'{webui_path}/static/colabTimer.txt', 'r').read())
|
145 |
+
time_since_start = str(timedelta(seconds=time.time()-start_colab)).split('.')[0]
|
146 |
+
print(f"⌚️ Вы проводите эту сессию в течение - \033[33m{time_since_start}\033[0m")
|
147 |
+
|
148 |
+
|
149 |
+
## Changes extensions and WebUi
|
150 |
+
if latest_webui or latest_exstensions:
|
151 |
+
action = "Обновление WebUI и Расширений" if latest_webui and latest_exstensions else ("Обновление WebUI" if latest_webui else "Обновление Расширений")
|
152 |
+
print(f"⌚️ {action}...", end='', flush=True)
|
153 |
+
with capture.capture_output() as cap:
|
154 |
+
get_ipython().system('git config --global user.email "[email protected]"')
|
155 |
+
get_ipython().system('git config --global user.name "Your Name"')
|
156 |
+
|
157 |
+
## Update Webui
|
158 |
+
if latest_webui:
|
159 |
+
get_ipython().run_line_magic('cd', '{webui_path}')
|
160 |
+
get_ipython().system('git restore .')
|
161 |
+
get_ipython().system('git pull -X theirs --rebase --autostash')
|
162 |
+
|
163 |
+
## Update extensions
|
164 |
+
if latest_exstensions:
|
165 |
+
get_ipython().system('{\'for dir in \' + webui_path + \'/extensions/*/; do cd \\"$dir\\" && git reset --hard && git pull; done\'}')
|
166 |
+
del cap
|
167 |
+
print(f"\r✨ {action} Завершено!")
|
168 |
+
|
169 |
+
|
170 |
+
# === FIXING EXTENSIONS ===
|
171 |
+
anxety_repos = "https://huggingface.co/NagisaNao/fast_repo/resolve/main"
|
172 |
+
|
173 |
+
with capture.capture_output() as cap:
|
174 |
+
# --- Umi-Wildcard ---
|
175 |
+
get_ipython().system("sed -i '521s/open=\\(False\\|True\\)/open=False/' {webui_path}/extensions/Umi-AI-Wildcards/scripts/wildcard_recursive.py # Closed accordion by default")
|
176 |
+
|
177 |
+
# --- Encrypt-Image ---
|
178 |
+
get_ipython().system("sed -i '9,37d' {webui_path}/extensions/Encrypt-Image/javascript/encrypt_images_info.js # Removes the weird text in webui")
|
179 |
+
|
180 |
+
# --- Additional-Networks ---
|
181 |
+
get_ipython().system('wget -O {webui_path}/extensions/additional-networks/scripts/metadata_editor.py {anxety_repos}/extensions/Additional-Networks/fix/metadata_editor.py # Fixing an error due to old style')
|
182 |
+
del cap
|
183 |
+
|
184 |
+
|
185 |
+
## Version switching
|
186 |
+
if commit_hash:
|
187 |
+
print('⏳ Активация машины времени...', end="", flush=True)
|
188 |
+
with capture.capture_output() as cap:
|
189 |
+
get_ipython().run_line_magic('cd', '{webui_path}')
|
190 |
+
get_ipython().system('git config --global user.email "[email protected]"')
|
191 |
+
get_ipython().system('git config --global user.name "Your Name"')
|
192 |
+
get_ipython().system('git reset --hard {commit_hash}')
|
193 |
+
del cap
|
194 |
+
print(f"\r⌛️ Машина времени активированна! Текущий коммит: \033[34m{commit_hash}\033[0m")
|
195 |
+
|
196 |
+
|
197 |
+
## Downloading model and stuff | oh~ Hey! If you're freaked out by that code too, don't worry, me too!
|
198 |
+
print("📦 Скачивание моделей и прочего...", end='')
|
199 |
+
model_list = {
|
200 |
+
"1.Anime (by XpucT) + INP": [
|
201 |
+
{"url": "https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2.safetensors", "name": "Anime_V2.safetensors"},
|
202 |
+
{"url": "https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2-inpainting.safetensors", "name": "Anime_V2-inpainting.safetensors"}
|
203 |
+
],
|
204 |
+
"2.BluMix [Anime] [V7] + INP": [
|
205 |
+
{"url": "https://civitai.com/api/download/models/361779", "name": "BluMix_V7.safetensors"},
|
206 |
+
{"url": "https://civitai.com/api/download/models/363850", "name": "BluMix_V7-inpainting.safetensors"}
|
207 |
+
],
|
208 |
+
"3.Cetus-Mix [Anime] [V4] + INP": [
|
209 |
+
{"url": "https://civitai.com/api/download/models/130298", "name": "CetusMix_V4.safetensors"},
|
210 |
+
{"url": "https://civitai.com/api/download/models/139882", "name": "CetusMix_V4-inpainting.safetensors"}
|
211 |
+
],
|
212 |
+
"4.Counterfeit [Anime] [V3] + INP": [
|
213 |
+
{"url": "https://huggingface.co/gsdf/Counterfeit-V3.0/resolve/main/Counterfeit-V3.0_fix_fp16.safetensors", "name": "Counterfeit_V3.safetensors"},
|
214 |
+
{"url": "https://civitai.com/api/download/models/137911", "name": "Counterfeit_V3-inpainting.safetensors"}
|
215 |
+
],
|
216 |
+
"5.CuteColor [Anime] [V3]": [
|
217 |
+
{"url": "https://civitai.com/api/download/models/138754", "name": "CuteColor_V3.safetensors"}
|
218 |
+
],
|
219 |
+
"6.Dark-Sushi-Mix [Anime]": [
|
220 |
+
{"url": "https://civitai.com/api/download/models/101640", "name": "DarkSushiMix_2_5D.safetensors"},
|
221 |
+
{"url": "https://civitai.com/api/download/models/56071", "name": "DarkSushiMix_colorful.safetensors"}
|
222 |
+
],
|
223 |
+
"7.Deliberate [Realism] [V6] + INP": [
|
224 |
+
{"url": "https://huggingface.co/XpucT/Deliberate/resolve/main/Deliberate_v6.safetensors", "name": "Deliberate_V6.safetensors"},
|
225 |
+
{"url": "https://huggingface.co/XpucT/Deliberate/resolve/main/Deliberate_v6-inpainting.safetensors", "name": "Deliberate_V6-inpainting.safetensors"}
|
226 |
+
],
|
227 |
+
"8.Meina-Mix [Anime] [V11] + INP": [
|
228 |
+
{"url": "https://civitai.com/api/download/models/119057", "name": "MeinaMix_V11.safetensors"},
|
229 |
+
{"url": "https://civitai.com/api/download/models/120702", "name": "MeinaMix_V11-inpainting.safetensors"}
|
230 |
+
],
|
231 |
+
"9.Mix-Pro [Anime] [V4] + INP": [
|
232 |
+
{"url": "https://civitai.com/api/download/models/125668", "name": "MixPro_V4.safetensors"},
|
233 |
+
{"url": "https://civitai.com/api/download/models/139878", "name": "MixPro_V4-inpainting.safetensors"}
|
234 |
+
]
|
235 |
+
}
|
236 |
+
|
237 |
+
vae_list = {
|
238 |
+
"1.Anime.vae": [{"url": "https://civitai.com/api/download/models/311162", "name": "vae-ft-mse-840000-ema-pruned.vae.safetensors"}],
|
239 |
+
"2.Anything.vae": [{"url": "https://huggingface.co/NoCrypt/resources/resolve/main/VAE/any.vae.safetensors", "name": "Anything.vae.safetensors"}],
|
240 |
+
"3.Blessed2.vae": [{"url": "https://huggingface.co/NoCrypt/resources/resolve/main/VAE/blessed2.vae.safetensors", "name": "Blessed2.vae.safetensors"}],
|
241 |
+
"4.ClearVae.vae": [{"url": "https://civitai.com/api/download/models/88156", "name": "ClearVae_23.vae.safetensors"}],
|
242 |
+
"5.WD.vae": [{"url": "https://huggingface.co/NoCrypt/resources/resolve/main/VAE/wd.vae.safetensors", "name": "WD.vae.safetensors"}]
|
243 |
+
}
|
244 |
+
|
245 |
+
controlnet_list = {
|
246 |
+
"1.canny": [
|
247 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny_fp16.safetensors", "name": "control_v11p_sd15_canny_fp16.safetensors"},
|
248 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_canny_fp16.yaml", "name": "control_v11p_sd15_canny_fp16.yaml"}
|
249 |
+
],
|
250 |
+
"2.openpose": [
|
251 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose_fp16.safetensors", "name": "control_v11p_sd15_openpose_fp16.safetensors"},
|
252 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_openpose_fp16.yaml", "name": "control_v11p_sd15_openpose_fp16.yaml"}
|
253 |
+
],
|
254 |
+
"3.depth": [
|
255 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth_fp16.safetensors", "name": "control_v11f1p_sd15_depth_fp16.safetensors"},
|
256 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1p_sd15_depth_fp16.yaml", "name": "control_v11f1p_sd15_depth_fp16.yaml"},
|
257 |
+
{"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"}
|
258 |
+
],
|
259 |
+
"4.normal_map": [
|
260 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_normalbae_fp16.safetensors", "name": "control_v11p_sd15_normalbae_fp16.safetensors"},
|
261 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_normalbae_fp16.yaml", "name": "control_v11p_sd15_normalbae_fp16.yaml"}
|
262 |
+
],
|
263 |
+
"5.mlsd": [
|
264 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_mlsd_fp16.safetensors", "name": "control_v11p_sd15_mlsd_fp16.safetensors"},
|
265 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_mlsd_fp16.yaml", "name": "control_v11p_sd15_mlsd_fp16.yaml"}
|
266 |
+
],
|
267 |
+
"6.lineart": [
|
268 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart_fp16.safetensors", "name": "control_v11p_sd15_lineart_fp16.safetensors"},
|
269 |
+
{"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"},
|
270 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_lineart_fp16.yaml", "name": "control_v11p_sd15_lineart_fp16.yaml"},
|
271 |
+
{"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"}
|
272 |
+
],
|
273 |
+
"7.soft_edge": [
|
274 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge_fp16.safetensors", "name": "control_v11p_sd15_softedge_fp16.safetensors"},
|
275 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_softedge_fp16.yaml", "name": "control_v11p_sd15_softedge_fp16.yaml"}
|
276 |
+
],
|
277 |
+
"8.scribble": [
|
278 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble_fp16.safetensors", "name": "control_v11p_sd15_scribble_fp16.safetensors"},
|
279 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_scribble_fp16.yaml", "name": "control_v11p_sd15_scribble_fp16.yaml"}
|
280 |
+
],
|
281 |
+
"9.segmentation": [
|
282 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg_fp16.safetensors", "name": "control_v11p_sd15_seg_fp16.safetensors"},
|
283 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_seg_fp16.yaml", "name": "control_v11p_sd15_seg_fp16.yaml"}
|
284 |
+
],
|
285 |
+
"10.shuffle": [
|
286 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle_fp16.safetensors", "name": "control_v11e_sd15_shuffle_fp16.safetensors"},
|
287 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_shuffle_fp16.yaml", "name": "control_v11e_sd15_shuffle_fp16.yaml"}
|
288 |
+
],
|
289 |
+
"11.tile": [
|
290 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile_fp16.safetensors", "name": "control_v11f1e_sd15_tile_fp16.safetensors"},
|
291 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1e_sd15_tile_fp16.yaml", "name": "control_v11f1e_sd15_tile_fp16.yaml"}
|
292 |
+
],
|
293 |
+
"12.inpaint": [
|
294 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_inpaint_fp16.safetensors", "name": "control_v11p_sd15_inpaint_fp16.safetensors"},
|
295 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_inpaint_fp16.yaml", "name": "control_v11p_sd15_inpaint_fp16.yaml"}
|
296 |
+
],
|
297 |
+
"13.instruct_p2p": [
|
298 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p_fp16.safetensors", "name": "control_v11e_sd15_ip2p_fp16.safetensors"},
|
299 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_ip2p_fp16.yaml", "name": "control_v11e_sd15_ip2p_fp16.yaml"}
|
300 |
+
]
|
301 |
+
}
|
302 |
+
|
303 |
+
url = ""
|
304 |
+
prefixes = {
|
305 |
+
"model": models_dir,
|
306 |
+
"vae": vaes_dir,
|
307 |
+
"lora": loras_dir,
|
308 |
+
"embed": embeddings_dir,
|
309 |
+
"extension": extensions_dir,
|
310 |
+
"control": control_dir,
|
311 |
+
"adetailer": adetailer_dir,
|
312 |
+
"config": webui_path
|
313 |
+
}
|
314 |
+
|
315 |
+
extension_repo = []
|
316 |
+
directories = [value for key, value in prefixes.items()] # for unpucking zip files
|
317 |
+
get_ipython().system('mkdir -p {" ".join(directories)}')
|
318 |
+
|
319 |
+
hf_token = huggingface_token if huggingface_token else "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"
|
320 |
+
user_header = f"\"Authorization: Bearer {hf_token}\""
|
321 |
+
|
322 |
+
''' Formatted Info Output '''
|
323 |
+
|
324 |
+
from math import floor
|
325 |
+
|
326 |
+
def center_text(text, terminal_width=45):
|
327 |
+
text_length = len(text)
|
328 |
+
left_padding = floor((terminal_width - text_length) / 2)
|
329 |
+
right_padding = terminal_width - text_length - left_padding
|
330 |
+
return f"\033[1m\033[36m{' ' * left_padding}{text}{' ' * right_padding}\033[0m\033[32m"
|
331 |
+
|
332 |
+
def format_output(url, dst_dir, file_name):
|
333 |
+
info = f"[{file_name.split('.')[0]}]"
|
334 |
+
info = center_text(info)
|
335 |
+
|
336 |
+
print(f"\n\033[32m{'---'*20}]{info}[{'---'*20}")
|
337 |
+
print(f"\033[33mURL: \033[34m{url}")
|
338 |
+
print(f"\033[33mSAVE DIR: \033[34m{dst_dir}")
|
339 |
+
print(f"\033[33mFILE NAME: \033[34m{file_name}\033[0m")
|
340 |
+
|
341 |
+
''' GET CivitAi API - DATA '''
|
342 |
+
|
343 |
+
def strip_(url, file_name=None):
|
344 |
+
if 'github.com' in url:
|
345 |
+
if '/blob/' in url:
|
346 |
+
url = url.replace('/blob/', '/raw/')
|
347 |
+
|
348 |
+
elif "civitai.com" in url:
|
349 |
+
return CivitAi_API(url, file_name)
|
350 |
+
|
351 |
+
elif "huggingface.co" in url:
|
352 |
+
if '/blob/' in url:
|
353 |
+
url = url.replace('/blob/', '/resolve/')
|
354 |
+
if '?' in url:
|
355 |
+
url = url.split('?')[0]
|
356 |
+
|
357 |
+
return url
|
358 |
+
|
359 |
+
def CivitAi_API(url, file_name=None):
|
360 |
+
support_types = ('Checkpoint', 'Model', 'TextualInversion', 'LORA')
|
361 |
+
civitai_token = "62c0c5956b2f9defbd844d754000180b"
|
362 |
+
|
363 |
+
if '?token=' in url:
|
364 |
+
url = url.split('?token=')[0]
|
365 |
+
if '?type=' in url:
|
366 |
+
url = url.replace('?type=', f'?token={civitai_token}&type=')
|
367 |
+
else:
|
368 |
+
url = f"{url}?token={civitai_token}"
|
369 |
+
|
370 |
+
# Determine model or version id
|
371 |
+
if "civitai.com/models/" in url:
|
372 |
+
if '?modelVersionId=' in url:
|
373 |
+
version_id = url.split('?modelVersionId=')[1]
|
374 |
+
response = requests.get(f"https://civitai.com/api/v1/model-versions/{version_id}")
|
375 |
+
# print(f"end - https://civitai.com/api/v1/model-versions/{version_id}")
|
376 |
+
else:
|
377 |
+
model_id = url.split('/models/')[1].split('/')[0]
|
378 |
+
response = requests.get(f"https://civitai.com/api/v1/models/{model_id}")
|
379 |
+
# print(f"end - https://civitai.com/api/v1/models/{model_id}")
|
380 |
+
else:
|
381 |
+
version_id = url.split('/models/')[1].split('/')[0]
|
382 |
+
response = requests.get(f"https://civitai.com/api/v1/model-versions/{version_id}")
|
383 |
+
# print(f"end - https://civitai.com/api/v1/model-versions/{version_id}")
|
384 |
+
|
385 |
+
data = response.json()
|
386 |
+
|
387 |
+
if response.status_code != 200:
|
388 |
+
return None, None, None, None, None, None, None
|
389 |
+
|
390 |
+
# Define model type and name
|
391 |
+
if "civitai.com/models/" in url:
|
392 |
+
if '?modelVersionId=' in url:
|
393 |
+
model_type = data['model']['type']
|
394 |
+
model_name = data['files'][0]['name']
|
395 |
+
else:
|
396 |
+
model_type = data['type']
|
397 |
+
model_name = data['modelVersions'][0]['files'][0]['name']
|
398 |
+
elif 'type=' in url:
|
399 |
+
model_type = parse_qs(urlparse(url).query).get('type', [''])[0]
|
400 |
+
if 'model' in model_type.lower():
|
401 |
+
model_name = data['files'][0]['name']
|
402 |
+
else:
|
403 |
+
model_name = data['files'][1]['name']
|
404 |
+
else:
|
405 |
+
model_type = data['model']['type']
|
406 |
+
model_name = data['files'][0]['name']
|
407 |
+
|
408 |
+
model_name = file_name or model_name
|
409 |
+
|
410 |
+
# Determine DownloadUrl
|
411 |
+
if "civitai.com/models/" in url:
|
412 |
+
if '?modelVersionId=' in url:
|
413 |
+
download_url = data.get('downloadUrl')
|
414 |
+
else:
|
415 |
+
download_url = data["modelVersions"][0].get("downloadUrl", "")
|
416 |
+
elif 'type=' in url:
|
417 |
+
if any(t.lower() in model_type.lower() for t in support_types):
|
418 |
+
download_url = data['files'][0]['downloadUrl']
|
419 |
+
else:
|
420 |
+
download_url = data['files'][1]['downloadUrl']
|
421 |
+
else:
|
422 |
+
download_url = data.get('downloadUrl')
|
423 |
+
|
424 |
+
clean_url = re.sub(r'[?&]token=[^&]*', '', download_url) # hide token
|
425 |
+
|
426 |
+
# Find a safe image: level less than 4 | Kaggle
|
427 |
+
image_url, image_name = None, None
|
428 |
+
if any(t in model_type for t in support_types):
|
429 |
+
try:
|
430 |
+
images = data.get('images') or data['modelVersions'][0].get('images', [])
|
431 |
+
if env == 'Kaggle':
|
432 |
+
image_url = next((image['url'] for image in images if image['nsfwLevel'] < 4), None)
|
433 |
+
else:
|
434 |
+
image_url = images[0]['url'] if images else None
|
435 |
+
except KeyError:
|
436 |
+
pass
|
437 |
+
|
438 |
+
# Generate a name to save the image
|
439 |
+
image_name = f"{model_name.split('.')[0]}.preview.{image_url.split('.')[-1]}" if image_url else None
|
440 |
+
|
441 |
+
return f"{download_url}{'&' if '?' in download_url else '?'}token={civitai_token}", clean_url, model_type, model_name, image_url, image_name, data
|
442 |
+
|
443 |
+
''' Main Download Code '''
|
444 |
+
|
445 |
+
def download(url):
|
446 |
+
links_and_paths = [link_or_path.strip() for link_or_path in url.split(',') if link_or_path.strip()]
|
447 |
+
|
448 |
+
for link_or_path in links_and_paths:
|
449 |
+
if any(link_or_path.lower().startswith(prefix) for prefix in prefixes):
|
450 |
+
handle_manual(link_or_path)
|
451 |
+
else:
|
452 |
+
url, dst_dir, file_name = link_or_path.split()
|
453 |
+
manual_download(url, dst_dir, file_name)
|
454 |
+
|
455 |
+
unpack_zip_files()
|
456 |
+
|
457 |
+
def unpack_zip_files():
|
458 |
+
for directory in directories:
|
459 |
+
for root, _, files in os.walk(directory):
|
460 |
+
for file in files:
|
461 |
+
if file.endswith(".zip"):
|
462 |
+
zip_path = os.path.join(root, file)
|
463 |
+
extract_path = os.path.splitext(zip_path)[0]
|
464 |
+
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
465 |
+
zip_ref.extractall(extract_path)
|
466 |
+
os.remove(zip_path)
|
467 |
+
|
468 |
+
def handle_manual(url):
|
469 |
+
url_parts = url.split(':', 1)
|
470 |
+
prefix, path = url_parts[0], url_parts[1]
|
471 |
+
|
472 |
+
file_name_match = re.search(r'\[(.*?)\]', path)
|
473 |
+
file_name = file_name_match.group(1) if file_name_match else None
|
474 |
+
if file_name:
|
475 |
+
path = re.sub(r'\[.*?\]', '', path)
|
476 |
+
|
477 |
+
if prefix in prefixes:
|
478 |
+
dir = prefixes[prefix]
|
479 |
+
if prefix != "extension":
|
480 |
+
try:
|
481 |
+
manual_download(path, dir, file_name=file_name)
|
482 |
+
except Exception as e:
|
483 |
+
print(f"Error downloading file: {e}")
|
484 |
+
else:
|
485 |
+
extension_repo.append((path, file_name))
|
486 |
+
|
487 |
+
def manual_download(url, dst_dir, file_name):
|
488 |
+
aria2_args = '--optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c'
|
489 |
+
basename = url.split("/")[-1] if file_name is None else file_name
|
490 |
+
header_option = f"--header={user_header}"
|
491 |
+
|
492 |
+
if 'github.com' in url:
|
493 |
+
url = strip_(url)
|
494 |
+
|
495 |
+
# -- CivitAi APi+ V2 --
|
496 |
+
elif 'civitai' in url:
|
497 |
+
url, clean_url, model_type, file_name, image_url, image_name, data = strip_(url, file_name)
|
498 |
+
|
499 |
+
if image_url and image_name:
|
500 |
+
with capture.capture_output() as cap:
|
501 |
+
get_ipython().system("aria2c {aria2_args} -d {dst_dir} -o '{image_name}' '{image_url}'")
|
502 |
+
del cap
|
503 |
+
|
504 |
+
elif "huggingface.co" in url:
|
505 |
+
clean_url = strip_(url)
|
506 |
+
|
507 |
+
""" Formatted info output """
|
508 |
+
model_name_or_basename = file_name if not 'huggingface' in url else basename
|
509 |
+
format_output(clean_url or url, dst_dir, model_name_or_basename)
|
510 |
+
|
511 |
+
# ## -- for my tests --
|
512 |
+
# print(url, dst_dir, model_name_or_basename)
|
513 |
+
print(f"\033[31m[Data Info]:\033[0m Failed to retrieve data from the API.\n") if 'civitai' in url and not data else None
|
514 |
+
if 'civitai' in url and data and image_name:
|
515 |
+
print(f"\033[32m[Preview DL]:\033[0m {image_name} - {image_url}\n")
|
516 |
+
# =====================
|
517 |
+
|
518 |
+
# # -- Git Hub --
|
519 |
+
if 'github.com' in url or 'githubusercontent.com' in url:
|
520 |
+
get_ipython().system("aria2c {aria2_args} -d {dst_dir} -o '{basename}' '{url}'")
|
521 |
+
|
522 |
+
# -- GDrive --
|
523 |
+
elif 'drive.google' in url:
|
524 |
+
try:
|
525 |
+
have_drive_link
|
526 |
+
except:
|
527 |
+
get_ipython().system('pip install -U gdown > /dev/null')
|
528 |
+
have_drive_link = True
|
529 |
+
|
530 |
+
if 'folders' in url:
|
531 |
+
get_ipython().system('gdown --folder "{url}" -O {dst_dir} --fuzzy -c')
|
532 |
+
else:
|
533 |
+
if file_name:
|
534 |
+
get_ipython().system('gdown "{url}" -O {dst_dir}/{file_name} --fuzzy -c')
|
535 |
+
else:
|
536 |
+
get_ipython().system('gdown "{url}" -O {dst_dir} --fuzzy -c')
|
537 |
+
|
538 |
+
# -- Hugging Face --
|
539 |
+
elif 'huggingface' in url:
|
540 |
+
get_ipython().system("aria2c {header_option} {aria2_args} -d {dst_dir} -o '{basename}' '{url}'")
|
541 |
+
|
542 |
+
# -- Other --
|
543 |
+
elif 'http' in url:
|
544 |
+
get_ipython().system("aria2c {aria2_args} -d {dst_dir} '{'-o' + file_name if file_name else ''}' '{url}'")
|
545 |
+
|
546 |
+
''' SubModels - Added URLs '''
|
547 |
+
|
548 |
+
def add_submodels(selection, num_selection, model_dict, dst_dir):
|
549 |
+
if selection == "none":
|
550 |
+
return []
|
551 |
+
if selection == "ALL":
|
552 |
+
all_models = []
|
553 |
+
for models in model_dict.values():
|
554 |
+
all_models.extend(models)
|
555 |
+
selected_models = all_models
|
556 |
+
else:
|
557 |
+
selected_models = model_dict[selection]
|
558 |
+
selected_nums = map(int, num_selection.replace(',', '').split())
|
559 |
+
for num in selected_nums:
|
560 |
+
if 1 <= num <= len(model_dict):
|
561 |
+
name = list(model_dict)[num - 1]
|
562 |
+
selected_models.extend(model_dict[name])
|
563 |
+
|
564 |
+
unique_models = list({model['name']: model for model in selected_models}.values())
|
565 |
+
for model in unique_models:
|
566 |
+
model['dst_dir'] = dst_dir
|
567 |
+
|
568 |
+
return unique_models
|
569 |
+
|
570 |
+
def handle_submodels(selection, num_selection, model_dict, dst_dir, url):
|
571 |
+
submodels = add_submodels(selection, num_selection, model_dict, dst_dir)
|
572 |
+
for submodel in submodels:
|
573 |
+
if not inpainting_model and "inpainting" in submodel['name']:
|
574 |
+
continue
|
575 |
+
url += f"{submodel['url']} {submodel['dst_dir']} {submodel['name']}, "
|
576 |
+
return url
|
577 |
+
|
578 |
+
url = handle_submodels(model, model_num, model_list, models_dir, url)
|
579 |
+
url = handle_submodels(vae, vae_num, vae_list, vaes_dir, url)
|
580 |
+
url = handle_submodels(controlnet, controlnet_num, controlnet_list, control_dir, url)
|
581 |
+
|
582 |
+
''' file.txt - added urls '''
|
583 |
+
|
584 |
+
def process_file_download(file_url, prefixes, unique_urls):
|
585 |
+
files_urls = ""
|
586 |
+
|
587 |
+
if file_url.startswith("http"):
|
588 |
+
if "blob" in file_url:
|
589 |
+
file_url = file_url.replace("blob", "raw")
|
590 |
+
response = requests.get(file_url)
|
591 |
+
lines = response.text.split('\n')
|
592 |
+
else:
|
593 |
+
with open(file_url, 'r') as file:
|
594 |
+
lines = file.readlines()
|
595 |
+
|
596 |
+
current_tag = None
|
597 |
+
for line in lines:
|
598 |
+
line = line.strip()
|
599 |
+
if any(f'# {tag}' in line.lower() for tag in prefixes):
|
600 |
+
current_tag = next((tag for tag in prefixes if tag in line.lower()))
|
601 |
+
|
602 |
+
urls = [url.split('#')[0].strip() for url in line.split(',')] # filter urls
|
603 |
+
for url in urls:
|
604 |
+
filter_url = url.split('[')[0] # same url filter
|
605 |
+
|
606 |
+
if url.startswith("http") and filter_url not in unique_urls:
|
607 |
+
files_urls += f"{current_tag}:{url}, "
|
608 |
+
unique_urls.add(filter_url)
|
609 |
+
|
610 |
+
return files_urls
|
611 |
+
|
612 |
+
file_urls = ""
|
613 |
+
unique_urls = set()
|
614 |
+
|
615 |
+
if custom_file_urls:
|
616 |
+
for custom_file_url in custom_file_urls.replace(',', '').split():
|
617 |
+
if not custom_file_url.endswith('.txt'):
|
618 |
+
custom_file_url += '.txt'
|
619 |
+
if not custom_file_url.startswith('http'):
|
620 |
+
if not custom_file_url.startswith(root_path):
|
621 |
+
custom_file_url = f'{root_path}/{custom_file_url}'
|
622 |
+
|
623 |
+
try:
|
624 |
+
file_urls += process_file_download(custom_file_url, prefixes, unique_urls)
|
625 |
+
except FileNotFoundError:
|
626 |
+
pass
|
627 |
+
|
628 |
+
# url prefixing
|
629 |
+
urls = (Model_url, Vae_url, LoRA_url, Embedding_url, Extensions_url)
|
630 |
+
prefixed_urls = (f"{prefix}:{url}" for prefix, url in zip(prefixes.keys(), urls) if url for url in url.replace(',', '').split())
|
631 |
+
url += ", ".join(prefixed_urls) + ", " + file_urls
|
632 |
+
|
633 |
+
if detailed_download == "on":
|
634 |
+
print("\n\n\033[33m# ====== Подробная Загрузка ====== #\n\033[0m")
|
635 |
+
download(url)
|
636 |
+
print("\n\033[33m# =============================== #\n\033[0m")
|
637 |
+
else:
|
638 |
+
with capture.capture_output() as cap:
|
639 |
+
download(url)
|
640 |
+
del cap
|
641 |
+
|
642 |
+
print("\r🏁 Скачивание Завершено!" + " "*15)
|
643 |
+
|
644 |
+
|
645 |
+
# Cleaning shit after downloading...
|
646 |
+
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')
|
647 |
+
|
648 |
+
|
649 |
+
## Install of Custom extensions
|
650 |
+
if len(extension_repo) > 0:
|
651 |
+
print("✨ Установка кастомных расширений...", end='', flush=True)
|
652 |
+
with capture.capture_output() as cap:
|
653 |
+
for repo, repo_name in extension_repo:
|
654 |
+
if not repo_name:
|
655 |
+
repo_name = repo.split('/')[-1]
|
656 |
+
get_ipython().system('cd {extensions_dir} && git clone {repo} {repo_name} && cd {repo_name} && git fetch')
|
657 |
+
del cap
|
658 |
+
print(f"\r📦 Установлено '{len(extension_repo)}', Кастомных расширений!")
|
659 |
+
|
660 |
+
|
661 |
+
## List Models and stuff V2
|
662 |
+
if detailed_download == "off":
|
663 |
+
print("\n\n\033[33mЕсли вы не видете каких-то скаченных файлов, включите в виджетах функцию 'Подробная Загрузка'.")
|
664 |
+
|
665 |
+
get_ipython().run_line_magic('run', '{root_path}/file_cell/special/dl_display_results.py # display widgets result')
|
666 |
+
|
files_cells/python/ru/launch_ru.py
CHANGED
@@ -1,129 +1,118 @@
|
|
1 |
-
##~ LAUNCH CODE | BY: ANXETY ~##
|
2 |
-
|
3 |
-
import os
|
4 |
-
import re
|
5 |
-
import time
|
6 |
-
import json
|
7 |
-
import requests
|
8 |
-
import cloudpickle as pickle
|
9 |
-
from datetime import timedelta
|
10 |
-
from IPython.display import clear_output
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
'
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
env, root_path, free_plan = detect_environment()
|
26 |
-
webui_path = f"{root_path}/sdw"
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
if
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
# after runnig
|
122 |
-
start_colab = float(open(f'{webui_path}/static/colabTimer.txt', 'r').read())
|
123 |
-
time_since_start = str(timedelta(seconds=time.time()-start_colab)).split('.')[0]
|
124 |
-
print(f"\n⌚️ \033[0mВы проводите эту сессию в течение - \033[33m{time_since_start}\033[0m\n\n")
|
125 |
-
|
126 |
-
''' del zrok tunnel '''
|
127 |
-
if zrok_token:
|
128 |
-
get_ipython().system('zrok disable &> /dev/null')
|
129 |
-
|
|
|
1 |
+
##~ LAUNCH CODE | BY: ANXETY ~##
|
2 |
+
|
3 |
+
import os
|
4 |
+
import re
|
5 |
+
import time
|
6 |
+
import json
|
7 |
+
import requests
|
8 |
+
import cloudpickle as pickle
|
9 |
+
from datetime import timedelta
|
10 |
+
from IPython.display import clear_output
|
11 |
+
|
12 |
+
# ================= DETECT ENV =================
|
13 |
+
def detect_environment():
|
14 |
+
free_plan = (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024 ** 3) <= 20)
|
15 |
+
environments = {
|
16 |
+
'COLAB_GPU': ('Google Colab', "/root" if free_plan else "/content"),
|
17 |
+
'KAGGLE_URL_BASE': ('Kaggle', "/kaggle/working/content")
|
18 |
+
}
|
19 |
+
|
20 |
+
for env_var, (environment, path) in environments.items():
|
21 |
+
if env_var in os.environ:
|
22 |
+
return environment, path, free_plan
|
23 |
+
return 'Unknown', '/unknown/path', free_plan
|
24 |
+
|
25 |
+
env, root_path, free_plan = detect_environment()
|
26 |
+
webui_path = f"{root_path}/sdw"
|
27 |
+
|
28 |
+
def load_settings():
|
29 |
+
SETTINGS_FILE = f'{root_path}/settings.json'
|
30 |
+
if os.path.exists(SETTINGS_FILE):
|
31 |
+
with open(SETTINGS_FILE, 'r') as f:
|
32 |
+
return json.load(f)
|
33 |
+
return {}
|
34 |
+
|
35 |
+
settings = load_settings()
|
36 |
+
ngrok_token = settings.get('ngrok_token', "")
|
37 |
+
zrok_token = settings.get('zrok_token', "")
|
38 |
+
commandline_arguments = settings.get('commandline_arguments', "")
|
39 |
+
change_webui = settings.get('change_webui', "")
|
40 |
+
|
41 |
+
# ======================== TUNNEL V2 ========================
|
42 |
+
print('Please Wait...')
|
43 |
+
|
44 |
+
def get_public_ip(version='ipv4'):
|
45 |
+
try:
|
46 |
+
url = f'https://api64.ipify.org?format=json&{version}=true'
|
47 |
+
response = requests.get(url)
|
48 |
+
return response.json().get('ip', 'N/A')
|
49 |
+
except Exception as e:
|
50 |
+
print(f"Error getting public {version} address:", e)
|
51 |
+
|
52 |
+
# Check if public IP is already saved, if not then get it
|
53 |
+
public_ip_file = f"{root_path}/public_ip.txt"
|
54 |
+
if os.path.exists(public_ip_file):
|
55 |
+
with open(public_ip_file, 'r') as file:
|
56 |
+
public_ipv4 = file.read().strip()
|
57 |
+
else:
|
58 |
+
public_ipv4 = get_public_ip(version='ipv4')
|
59 |
+
with open(public_ip_file, 'w') as file:
|
60 |
+
file.write(public_ipv4)
|
61 |
+
|
62 |
+
tunnel_class = pickle.load(open(f"{root_path}/new_tunnel", "rb"), encoding="utf-8")
|
63 |
+
tunnel_port = 1834
|
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 |
+
|
68 |
+
if zrok_token:
|
69 |
+
get_ipython().system('zrok enable {zrok_token} &> /dev/null')
|
70 |
+
tunnel.add_tunnel(command="zrok share public http://localhost:{port}/ --headless", name="zrok", pattern=re.compile(r"[\w-]+\.share\.zrok\.io"))
|
71 |
+
|
72 |
+
clear_output()
|
73 |
+
|
74 |
+
# =============== Automatic Fixing Path V3 ===============
|
75 |
+
paths_to_check = {
|
76 |
+
"tagger_hf_cache_dir": f"{webui_path}/models/interrogators/",
|
77 |
+
"additional_networks_extra_lora_path": f"{webui_path}/models/Lora/",
|
78 |
+
"ad_extra_models_dir": f"{webui_path}/models/adetailer/",
|
79 |
+
"sd_checkpoint_hash": "",
|
80 |
+
"sd_model_checkpoint": "",
|
81 |
+
"sd_vae": "None"
|
82 |
+
}
|
83 |
+
|
84 |
+
config_path = f'{webui_path}/ui-config.json'
|
85 |
+
|
86 |
+
if os.path.exists(config_path):
|
87 |
+
with open(config_path, 'r') as file:
|
88 |
+
config_data = json.load(file)
|
89 |
+
|
90 |
+
for key, value in paths_to_check.items():
|
91 |
+
if key in config_data and config_data[key] != value:
|
92 |
+
sed_command = f"sed -i 's|\"{key}\": \".*\"|\"{key}\": \"{value}\"|' {config_path}"
|
93 |
+
os.system(sed_command)
|
94 |
+
|
95 |
+
if env == 'Kaggle':
|
96 |
+
get_ipython().system('sed -i \'s/"civitai_interface\\/NSFW content\\/value":.*/"civitai_interface\\/NSFW content\\/value": false/g\' {webui_path}/ui-config.json')
|
97 |
+
|
98 |
+
with tunnel:
|
99 |
+
get_ipython().run_line_magic('cd', '{webui_path}')
|
100 |
+
|
101 |
+
commandline_arguments += f' --port={tunnel_port}'
|
102 |
+
if ngrok_token:
|
103 |
+
commandline_arguments += f' --ngrok {ngrok_token}'
|
104 |
+
if env != "Google Colab":
|
105 |
+
commandline_arguments += f' --encrypt-pass={tunnel_port} --api'
|
106 |
+
|
107 |
+
if change_webui == 'Forge':
|
108 |
+
commandline_arguments += ' --cuda-stream --pin-shared-memory'
|
109 |
+
|
110 |
+
get_ipython().system('COMMANDLINE_ARGS="{commandline_arguments}" python launch.py')
|
111 |
+
|
112 |
+
start_colab = float(open(f'{webui_path}/static/colabTimer.txt', 'r').read())
|
113 |
+
time_since_start = str(timedelta(seconds=time.time()-start_colab)).split('.')[0]
|
114 |
+
print(f"\n⌚️ \033[0mВы проводите эту сессию в течение - \033[33m{time_since_start}\033[0m\n\n")
|
115 |
+
|
116 |
+
if zrok_token:
|
117 |
+
get_ipython().system('zrok disable &> /dev/null')
|
118 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
files_cells/python/ru/widgets_ru.py
CHANGED
@@ -1,322 +1,322 @@
|
|
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 |
-
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 |
-
get_ipython().system('mkdir -p {root_path}')
|
25 |
-
|
26 |
-
|
27 |
-
# ==================== CSS JS ====================
|
28 |
-
##~ custom background images V1.5 ~##
|
29 |
-
import argparse
|
30 |
-
parser = argparse.ArgumentParser(description='This script processes an background image.')
|
31 |
-
parser.add_argument('-i', '--image', type=str, help='URL of the image to process', metavar='')
|
32 |
-
parser.add_argument('-o', '--opacity', type=float, help='Opacity level for the image, between 0 and 1', metavar='', default=0.3)
|
33 |
-
parser.add_argument('-b', '--blur', type=str, help='Blur level for the image', metavar='', default=0)
|
34 |
-
parser.add_argument('-y', type=int, help='Y coordinate for the image in px', metavar='', default=0)
|
35 |
-
parser.add_argument('-x', type=int, help='X coordinate for the image in px', metavar='', default=0)
|
36 |
-
parser.add_argument('-s', '--scale', type=int, help='Scale image in %%', metavar='', default=100)
|
37 |
-
parser.add_argument('-m', '--mode', action='store_true', help='Removes repetitive image tiles')
|
38 |
-
parser.add_argument('-t', '--transparent', action='store_true', help='Makes input/selection fields 35%% more transparent')
|
39 |
-
parser.add_argument('-bf', '--blur-fields', type=str, help='Background blur level for input/selection fields', metavar='', default=2)
|
40 |
-
|
41 |
-
args = parser.parse_args()
|
42 |
-
|
43 |
-
url_img = args.image
|
44 |
-
opacity_img = args.opacity
|
45 |
-
blur_img = args.blur
|
46 |
-
y_img = args.y
|
47 |
-
x_img = args.x
|
48 |
-
scale_img = args.scale
|
49 |
-
blur_fields = args.blur_fields
|
50 |
-
|
51 |
-
## ---
|
52 |
-
""" WTF KAGGLE - WHAT THE FUCK IS THE DIFFERENCE OF 35 PIXELS!?!?!? """
|
53 |
-
fix_heigh_img = "-810px" if env == "Kaggle" else "-775px"
|
54 |
-
|
55 |
-
""" transperent fields """
|
56 |
-
t_bg_alpha = "1" if not args.transparent else "0.65"
|
57 |
-
|
58 |
-
""" mode img - repeats """
|
59 |
-
mode_img = "repeat" if not args.mode else "no-repeat"
|
60 |
-
|
61 |
-
container_background = f'''
|
62 |
-
<style>
|
63 |
-
:root {{
|
64 |
-
/* for background container*/
|
65 |
-
--img_background: url({url_img});
|
66 |
-
--img_opacity: {opacity_img};
|
67 |
-
--img_blur: {blur_img}px;
|
68 |
-
--image_y: {y_img}px;
|
69 |
-
--image_x: {x_img}px;
|
70 |
-
--img_scale: {scale_img}%;
|
71 |
-
--img_mode: {mode_img};
|
72 |
-
--img_height_dif: {fix_heigh_img};
|
73 |
-
|
74 |
-
/* for fields */
|
75 |
-
--bg-field-color: rgba(28, 28, 28, {t_bg_alpha}); /* -> #1c1c1c */
|
76 |
-
--bg-field-color-hover: rgba(38, 38, 38, {t_bg_alpha}); /* -> #262626; */
|
77 |
-
--bg-field-blur-level: {blur_fields}px;
|
78 |
-
}}
|
79 |
-
'''
|
80 |
-
|
81 |
-
display(HTML(container_background))
|
82 |
-
|
83 |
-
# Main CSS
|
84 |
-
css_file_path = f"{root_path}/CSS/main_widgets.css"
|
85 |
-
with open(css_file_path , "r") as f:
|
86 |
-
CSS = f.read()
|
87 |
-
display(HTML(f"<style>{CSS}</style>"))
|
88 |
-
|
89 |
-
# Main JS
|
90 |
-
JS = '''
|
91 |
-
<!-- TOGGLE 'CustomDL' SCRIPT -->
|
92 |
-
<script>
|
93 |
-
function toggleContainer() {
|
94 |
-
let downloadContainer = document.querySelector('.container_custom_downlad');
|
95 |
-
let info = document.querySelector('.info');
|
96 |
-
|
97 |
-
downloadContainer.classList.toggle('expanded');
|
98 |
-
info.classList.toggle('showed');
|
99 |
-
}
|
100 |
-
</script>
|
101 |
-
'''
|
102 |
-
display(HTML(JS))
|
103 |
-
|
104 |
-
# ==================== WIDGETS V2 ====================
|
105 |
-
HR = widgets.HTML('<hr>')
|
106 |
-
|
107 |
-
class WidgetFactory:
|
108 |
-
def __init__(self, style=None, layout=None):
|
109 |
-
self.style = style if style else {'description_width': 'initial'}
|
110 |
-
self.layout = layout if layout else widgets.Layout(max_width='1080px', width='100%')
|
111 |
-
|
112 |
-
def create_html(self, content, class_name=None):
|
113 |
-
html_widget = widgets.HTML(content)
|
114 |
-
if class_name:
|
115 |
-
html_widget.add_class(class_name)
|
116 |
-
return html_widget
|
117 |
-
|
118 |
-
def create_header(self, name):
|
119 |
-
return widgets.HTML(f'<div class="header">{name}<div>')
|
120 |
-
|
121 |
-
def create_dropdown(self, options, value, description):
|
122 |
-
return widgets.Dropdown(options=options, value=value, description=description, style=self.style, layout=self.layout)
|
123 |
-
|
124 |
-
def create_text(self, description, placeholder='', value=''):
|
125 |
-
return widgets.Text(description=description, placeholder=placeholder, value=value, style=self.style, layout=self.layout)
|
126 |
-
|
127 |
-
def create_checkbox(self, value, description):
|
128 |
-
return widgets.Checkbox(value=value, description=description, style=self.style, layout=self.layout)
|
129 |
-
|
130 |
-
def create_button(self, description, class_name=None):
|
131 |
-
button = widgets.Button(description=description)
|
132 |
-
if class_name:
|
133 |
-
button.add_class(class_name)
|
134 |
-
return button
|
135 |
-
|
136 |
-
def create_hbox(self, children):
|
137 |
-
return widgets.HBox(children)
|
138 |
-
|
139 |
-
def create_vbox(self, children, class_names=None):
|
140 |
-
vbox = widgets.VBox(children)
|
141 |
-
if class_names:
|
142 |
-
for class_name in class_names:
|
143 |
-
vbox.add_class(class_name)
|
144 |
-
return vbox
|
145 |
-
|
146 |
-
def display(self, widget):
|
147 |
-
display(widget)
|
148 |
-
|
149 |
-
# Instantiate the factory
|
150 |
-
factory = WidgetFactory()
|
151 |
-
|
152 |
-
# --- MODEL ---
|
153 |
-
model_header = factory.create_header('Выбор Модели')
|
154 |
-
model_options = ['none',
|
155 |
-
'1.Anime (by XpucT) + INP',
|
156 |
-
'2.BluMix [Anime] [V7] + INP',
|
157 |
-
'3.Cetus-Mix [Anime] [V4] + INP',
|
158 |
-
'4.Counterfeit [Anime] [V3] + INP',
|
159 |
-
'5.CuteColor [Anime] [V3]',
|
160 |
-
'6.Dark-Sushi-Mix [Anime]',
|
161 |
-
'7.Deliberate [Realism] [V6] + INP',
|
162 |
-
'8.Meina-Mix [Anime] [V11] + INP',
|
163 |
-
'9.Mix-Pro [Anime] [V4] + INP']
|
164 |
-
model_widget = factory.create_dropdown(model_options, '4.Counterfeit [Anime] [V3] + INP', 'Модель:')
|
165 |
-
model_num_widget = factory.create_text('Номер Модели:', 'Введите номера моделей для скачивания через запятую/пробел.')
|
166 |
-
inpainting_model_widget = factory.create_checkbox(False, 'Inpainting Модели')
|
167 |
-
|
168 |
-
# Display Model
|
169 |
-
all_model_box = factory.create_vbox([model_header, model_widget, model_num_widget, inpainting_model_widget], class_names=["container", "image_1"])
|
170 |
-
factory.display(all_model_box)
|
171 |
-
|
172 |
-
# --- VAE ---
|
173 |
-
vae_header = factory.create_header('Выбор VAE')
|
174 |
-
vae_options = ['none',
|
175 |
-
'1.Anime.vae',
|
176 |
-
'2.Anything.vae',
|
177 |
-
'3.Blessed2.vae',
|
178 |
-
'4.ClearVae.vae',
|
179 |
-
'5.WD.vae']
|
180 |
-
vae_widget = factory.create_dropdown(vae_options, '3.Blessed2.vae', 'Vae:')
|
181 |
-
vae_num_widget = factory.create_text('Номер Vae:', 'Введите номера vae для скачивания через запятую/пробел.')
|
182 |
-
|
183 |
-
# Display Vae
|
184 |
-
all_vae_box = factory.create_vbox([vae_header, vae_widget, vae_num_widget], class_names=["container", "image_2"])
|
185 |
-
factory.display(all_vae_box)
|
186 |
-
|
187 |
-
# --- ADDITIONAL ---
|
188 |
-
additional_header = factory.create_header('Дополнительно')
|
189 |
-
latest_webui_widget = factory.create_checkbox(True, 'Обновить WebUI')
|
190 |
-
latest_exstensions_widget = factory.create_checkbox(True, 'Обновить Расширения')
|
191 |
-
change_webui_widget = factory.create_dropdown(['A1111', 'Forge'], 'A1111', 'Изменить WebUI:')
|
192 |
-
detailed_download_widget = factory.create_dropdown(['off', 'on'], 'off', 'Подробная Загрузка:')
|
193 |
-
choose_changes_widget = factory.create_hbox([latest_webui_widget, latest_exstensions_widget, change_webui_widget, detailed_download_widget])
|
194 |
-
|
195 |
-
controlnet_options = ['none', 'ALL', '1.canny',
|
196 |
-
'2.openpose', '3.depth',
|
197 |
-
'4.normal_map', '5.mlsd',
|
198 |
-
'6.lineart', '7.soft_edge',
|
199 |
-
'8.scribble', '9.segmentation',
|
200 |
-
'10.shuffle', '11.tile',
|
201 |
-
'12.inpaint', '13.instruct_p2p']
|
202 |
-
controlnet_widget = factory.create_dropdown(controlnet_options, 'none', 'ControlNet:')
|
203 |
-
controlnet_num_widget = factory.create_text('Номер ControlNet:', 'Введите номера моделей ControlNet для скачивания через запятую/пробел.')
|
204 |
-
commit_hash_widget = factory.create_text('Commit Hash:')
|
205 |
-
huggingface_token_widget = factory.create_text('Токен HuggingFace:')
|
206 |
-
|
207 |
-
ngrok_token_widget = factory.create_text('Токен Ngrok:')
|
208 |
-
ngrock_button = factory.create_html('<a href="https://dashboard.ngrok.com/get-started/your-authtoken" target="_blank">Получить Ngrok Токен</a>', class_name="button_ngrok")
|
209 |
-
ngrok_widget = factory.create_hbox([ngrok_token_widget, ngrock_button])
|
210 |
-
|
211 |
-
zrok_token_widget = factory.create_text('Токен Zrok:')
|
212 |
-
zrok_button = factory.create_html('<a href="https://colab.research.google.com/drive/1d2sjWDJi_GYBUavrHSuQyHTDuLy36WpU" target="_blank">Зарегать Zrok Токен</a>', class_name="button_ngrok")
|
213 |
-
zrok_widget = factory.create_hbox([zrok_token_widget, zrok_button])
|
214 |
-
|
215 |
-
commandline_arguments_options = "--listen --enable-insecure-extension-access --theme dark --no-half-vae --disable-console-progressbars --xformers"
|
216 |
-
commandline_arguments_widget = factory.create_text('Аргументы:', value=commandline_arguments_options)
|
217 |
-
|
218 |
-
# Display Additional
|
219 |
-
additional_widget_list = [additional_header,
|
220 |
-
choose_changes_widget,
|
221 |
-
HR,
|
222 |
-
controlnet_widget,
|
223 |
-
controlnet_num_widget,
|
224 |
-
commit_hash_widget,
|
225 |
-
huggingface_token_widget,
|
226 |
-
ngrok_widget,
|
227 |
-
zrok_widget,
|
228 |
-
HR,
|
229 |
-
commandline_arguments_widget]
|
230 |
-
|
231 |
-
if free_plan and env == "Google Colab": # remove ngrok from colab
|
232 |
-
additional_widget_list.remove(ngrok_widget)
|
233 |
-
if os.path.exists(webui_path): # remove selection after selection ;3
|
234 |
-
choose_changes_widget.children = [widget for widget in choose_changes_widget.children if widget != change_webui_widget]
|
235 |
-
|
236 |
-
all_additional_box = factory.create_vbox(additional_widget_list, class_names=["container", "image_3"])
|
237 |
-
factory.display(all_additional_box)
|
238 |
-
|
239 |
-
# --- CUSTOM DOWNLOAD ---
|
240 |
-
custom_download_header_popup = factory.create_html('''
|
241 |
-
<style>
|
242 |
-
/* Term Colors */
|
243 |
-
.sample_label {color: #dbafff;}
|
244 |
-
.braces {color: #ffff00;}
|
245 |
-
.extension {color: #eb934b;}
|
246 |
-
.file_name {color: #ffffd8;}
|
247 |
-
</style>
|
248 |
-
|
249 |
-
<div class="header" style="cursor: pointer;" onclick="toggleContainer()">Кастомная Загрузка</div>
|
250 |
-
<!-- PopUp Window -->
|
251 |
-
<div class="info" id="info_dl">INFO</div>
|
252 |
-
<div class="popup">
|
253 |
-
Разделите несколько URL-адресов запятой/пробелом. Для <span class="file_name">пользовательского имени</span> файла/расширения укажите его через <span class="braces">[]</span>
|
254 |
-
после URL без пробелов.
|
255 |
-
<span style="color: #ff9999">Для файлов обязательно укажите</span> - <span class="extension">Расширение Файла.</span>
|
256 |
-
<div class="sample">
|
257 |
-
<span class="sample_label">Пример для Файла:</span>
|
258 |
-
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>
|
259 |
-
<br>
|
260 |
-
<span class="sample_label">Пример для Расширения:</span>
|
261 |
-
https://github.com/hako-mikan/sd-webui-regional-prompter<span class="braces">[</span><span class="file_name">Regional-Prompter</span><span class="braces">]</span>
|
262 |
-
</div>
|
263 |
-
</div>
|
264 |
-
''')
|
265 |
-
|
266 |
-
Model_url_widget = factory.create_text('Model:')
|
267 |
-
Vae_url_widget = factory.create_text('Vae:')
|
268 |
-
LoRA_url_widget = factory.create_text('LoRa:')
|
269 |
-
Embedding_url_widget = factory.create_text('Embedding:')
|
270 |
-
Extensions_url_widget = factory.create_text('Extensions:')
|
271 |
-
custom_file_urls_widget = factory.create_text('Файл (txt):')
|
272 |
-
|
273 |
-
# Display CustomDl
|
274 |
-
all_custom_box = factory.create_vbox([
|
275 |
-
custom_download_header_popup, Model_url_widget, Vae_url_widget, LoRA_url_widget, Embedding_url_widget, Extensions_url_widget, custom_file_urls_widget
|
276 |
-
], class_names=["container", "image_4", "container_custom_downlad"])
|
277 |
-
factory.display(all_custom_box)
|
278 |
-
|
279 |
-
# --- Save Button ---
|
280 |
-
save_button = factory.create_button('Сохранить', class_name="button_save")
|
281 |
-
factory.display(save_button)
|
282 |
-
|
283 |
-
|
284 |
-
# ============ Load / Save - Settings V2 ============
|
285 |
-
SETTINGS_FILE = f'{root_path}/settings.json'
|
286 |
-
|
287 |
-
SETTINGS_KEYS = [
|
288 |
-
'model', 'model_num', 'inpainting_model',
|
289 |
-
'vae', 'vae_num', 'latest_webui', 'latest_exstensions',
|
290 |
-
'change_webui', 'detailed_download', 'controlnet',
|
291 |
-
'controlnet_num', 'commit_hash', 'huggingface_token',
|
292 |
-
'ngrok_token', 'zrok_token', 'commandline_arguments',
|
293 |
-
'Model_url', 'Vae_url', 'LoRA_url', 'Embedding_url',
|
294 |
-
'Extensions_url', 'custom_file_urls'
|
295 |
-
]
|
296 |
-
|
297 |
-
def save_settings():
|
298 |
-
settings = {key: globals()[f"{key}_widget"].value for key in SETTINGS_KEYS}
|
299 |
-
with open(SETTINGS_FILE, 'w') as f:
|
300 |
-
json.dump(settings, f, indent=2)
|
301 |
-
|
302 |
-
def load_settings():
|
303 |
-
if os.path.exists(SETTINGS_FILE):
|
304 |
-
with open(SETTINGS_FILE, 'r') as f:
|
305 |
-
settings = json.load(f)
|
306 |
-
for key in SETTINGS_KEYS:
|
307 |
-
globals()[f"{key}_widget"].value = settings.get(key, "")
|
308 |
-
|
309 |
-
def hide_widgets():
|
310 |
-
widgets_list = [all_model_box, all_vae_box, all_additional_box, all_custom_box, save_button]
|
311 |
-
for widget in widgets_list:
|
312 |
-
widget.add_class("hide")
|
313 |
-
time.sleep(0.5)
|
314 |
-
widgets.Widget.close_all()
|
315 |
-
|
316 |
-
def save_data(button):
|
317 |
-
save_settings()
|
318 |
-
hide_widgets()
|
319 |
-
|
320 |
-
load_settings()
|
321 |
-
save_button.on_click(save_data)
|
322 |
-
|
|
|
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 |
+
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 |
+
get_ipython().system('mkdir -p {root_path}')
|
25 |
+
|
26 |
+
|
27 |
+
# ==================== CSS JS ====================
|
28 |
+
##~ custom background images V1.5 ~##
|
29 |
+
import argparse
|
30 |
+
parser = argparse.ArgumentParser(description='This script processes an background image.')
|
31 |
+
parser.add_argument('-i', '--image', type=str, help='URL of the image to process', metavar='')
|
32 |
+
parser.add_argument('-o', '--opacity', type=float, help='Opacity level for the image, between 0 and 1', metavar='', default=0.3)
|
33 |
+
parser.add_argument('-b', '--blur', type=str, help='Blur level for the image', metavar='', default=0)
|
34 |
+
parser.add_argument('-y', type=int, help='Y coordinate for the image in px', metavar='', default=0)
|
35 |
+
parser.add_argument('-x', type=int, help='X coordinate for the image in px', metavar='', default=0)
|
36 |
+
parser.add_argument('-s', '--scale', type=int, help='Scale image in %%', metavar='', default=100)
|
37 |
+
parser.add_argument('-m', '--mode', action='store_true', help='Removes repetitive image tiles')
|
38 |
+
parser.add_argument('-t', '--transparent', action='store_true', help='Makes input/selection fields 35%% more transparent')
|
39 |
+
parser.add_argument('-bf', '--blur-fields', type=str, help='Background blur level for input/selection fields', metavar='', default=2)
|
40 |
+
|
41 |
+
args = parser.parse_args()
|
42 |
+
|
43 |
+
url_img = args.image
|
44 |
+
opacity_img = args.opacity
|
45 |
+
blur_img = args.blur
|
46 |
+
y_img = args.y
|
47 |
+
x_img = args.x
|
48 |
+
scale_img = args.scale
|
49 |
+
blur_fields = args.blur_fields
|
50 |
+
|
51 |
+
## ---
|
52 |
+
""" WTF KAGGLE - WHAT THE FUCK IS THE DIFFERENCE OF 35 PIXELS!?!?!? """
|
53 |
+
fix_heigh_img = "-810px" if env == "Kaggle" else "-775px"
|
54 |
+
|
55 |
+
""" transperent fields """
|
56 |
+
t_bg_alpha = "1" if not args.transparent else "0.65"
|
57 |
+
|
58 |
+
""" mode img - repeats """
|
59 |
+
mode_img = "repeat" if not args.mode else "no-repeat"
|
60 |
+
|
61 |
+
container_background = f'''
|
62 |
+
<style>
|
63 |
+
:root {{
|
64 |
+
/* for background container*/
|
65 |
+
--img_background: url({url_img});
|
66 |
+
--img_opacity: {opacity_img};
|
67 |
+
--img_blur: {blur_img}px;
|
68 |
+
--image_y: {y_img}px;
|
69 |
+
--image_x: {x_img}px;
|
70 |
+
--img_scale: {scale_img}%;
|
71 |
+
--img_mode: {mode_img};
|
72 |
+
--img_height_dif: {fix_heigh_img};
|
73 |
+
|
74 |
+
/* for fields */
|
75 |
+
--bg-field-color: rgba(28, 28, 28, {t_bg_alpha}); /* -> #1c1c1c */
|
76 |
+
--bg-field-color-hover: rgba(38, 38, 38, {t_bg_alpha}); /* -> #262626; */
|
77 |
+
--bg-field-blur-level: {blur_fields}px;
|
78 |
+
}}
|
79 |
+
'''
|
80 |
+
|
81 |
+
display(HTML(container_background))
|
82 |
+
|
83 |
+
# Main CSS
|
84 |
+
css_file_path = f"{root_path}/CSS/main_widgets.css"
|
85 |
+
with open(css_file_path , "r") as f:
|
86 |
+
CSS = f.read()
|
87 |
+
display(HTML(f"<style>{CSS}</style>"))
|
88 |
+
|
89 |
+
# Main JS
|
90 |
+
JS = '''
|
91 |
+
<!-- TOGGLE 'CustomDL' SCRIPT -->
|
92 |
+
<script>
|
93 |
+
function toggleContainer() {
|
94 |
+
let downloadContainer = document.querySelector('.container_custom_downlad');
|
95 |
+
let info = document.querySelector('.info');
|
96 |
+
|
97 |
+
downloadContainer.classList.toggle('expanded');
|
98 |
+
info.classList.toggle('showed');
|
99 |
+
}
|
100 |
+
</script>
|
101 |
+
'''
|
102 |
+
display(HTML(JS))
|
103 |
+
|
104 |
+
# ==================== WIDGETS V2 ====================
|
105 |
+
HR = widgets.HTML('<hr>')
|
106 |
+
|
107 |
+
class WidgetFactory:
|
108 |
+
def __init__(self, style=None, layout=None):
|
109 |
+
self.style = style if style else {'description_width': 'initial'}
|
110 |
+
self.layout = layout if layout else widgets.Layout(max_width='1080px', width='100%')
|
111 |
+
|
112 |
+
def create_html(self, content, class_name=None):
|
113 |
+
html_widget = widgets.HTML(content)
|
114 |
+
if class_name:
|
115 |
+
html_widget.add_class(class_name)
|
116 |
+
return html_widget
|
117 |
+
|
118 |
+
def create_header(self, name):
|
119 |
+
return widgets.HTML(f'<div class="header">{name}<div>')
|
120 |
+
|
121 |
+
def create_dropdown(self, options, value, description):
|
122 |
+
return widgets.Dropdown(options=options, value=value, description=description, style=self.style, layout=self.layout)
|
123 |
+
|
124 |
+
def create_text(self, description, placeholder='', value=''):
|
125 |
+
return widgets.Text(description=description, placeholder=placeholder, value=value, style=self.style, layout=self.layout)
|
126 |
+
|
127 |
+
def create_checkbox(self, value, description):
|
128 |
+
return widgets.Checkbox(value=value, description=description, style=self.style, layout=self.layout)
|
129 |
+
|
130 |
+
def create_button(self, description, class_name=None):
|
131 |
+
button = widgets.Button(description=description)
|
132 |
+
if class_name:
|
133 |
+
button.add_class(class_name)
|
134 |
+
return button
|
135 |
+
|
136 |
+
def create_hbox(self, children):
|
137 |
+
return widgets.HBox(children)
|
138 |
+
|
139 |
+
def create_vbox(self, children, class_names=None):
|
140 |
+
vbox = widgets.VBox(children)
|
141 |
+
if class_names:
|
142 |
+
for class_name in class_names:
|
143 |
+
vbox.add_class(class_name)
|
144 |
+
return vbox
|
145 |
+
|
146 |
+
def display(self, widget):
|
147 |
+
display(widget)
|
148 |
+
|
149 |
+
# Instantiate the factory
|
150 |
+
factory = WidgetFactory()
|
151 |
+
|
152 |
+
# --- MODEL ---
|
153 |
+
model_header = factory.create_header('Выбор Модели')
|
154 |
+
model_options = ['none',
|
155 |
+
'1.Anime (by XpucT) + INP',
|
156 |
+
'2.BluMix [Anime] [V7] + INP',
|
157 |
+
'3.Cetus-Mix [Anime] [V4] + INP',
|
158 |
+
'4.Counterfeit [Anime] [V3] + INP',
|
159 |
+
'5.CuteColor [Anime] [V3]',
|
160 |
+
'6.Dark-Sushi-Mix [Anime]',
|
161 |
+
'7.Deliberate [Realism] [V6] + INP',
|
162 |
+
'8.Meina-Mix [Anime] [V11] + INP',
|
163 |
+
'9.Mix-Pro [Anime] [V4] + INP']
|
164 |
+
model_widget = factory.create_dropdown(model_options, '4.Counterfeit [Anime] [V3] + INP', 'Модель:')
|
165 |
+
model_num_widget = factory.create_text('Номер Модели:', 'Введите номера моделей для скачивания через запятую/пробел.')
|
166 |
+
inpainting_model_widget = factory.create_checkbox(False, 'Inpainting Модели')
|
167 |
+
|
168 |
+
# Display Model
|
169 |
+
all_model_box = factory.create_vbox([model_header, model_widget, model_num_widget, inpainting_model_widget], class_names=["container", "image_1"])
|
170 |
+
factory.display(all_model_box)
|
171 |
+
|
172 |
+
# --- VAE ---
|
173 |
+
vae_header = factory.create_header('Выбор VAE')
|
174 |
+
vae_options = ['none',
|
175 |
+
'1.Anime.vae',
|
176 |
+
'2.Anything.vae',
|
177 |
+
'3.Blessed2.vae',
|
178 |
+
'4.ClearVae.vae',
|
179 |
+
'5.WD.vae']
|
180 |
+
vae_widget = factory.create_dropdown(vae_options, '3.Blessed2.vae', 'Vae:')
|
181 |
+
vae_num_widget = factory.create_text('Номер Vae:', 'Введите номера vae для скачивания через запятую/пробел.')
|
182 |
+
|
183 |
+
# Display Vae
|
184 |
+
all_vae_box = factory.create_vbox([vae_header, vae_widget, vae_num_widget], class_names=["container", "image_2"])
|
185 |
+
factory.display(all_vae_box)
|
186 |
+
|
187 |
+
# --- ADDITIONAL ---
|
188 |
+
additional_header = factory.create_header('Дополнительно')
|
189 |
+
latest_webui_widget = factory.create_checkbox(True, 'Обновить WebUI')
|
190 |
+
latest_exstensions_widget = factory.create_checkbox(True, 'Обновить Расширения')
|
191 |
+
change_webui_widget = factory.create_dropdown(['A1111', 'Forge'], 'A1111', 'Изменить WebUI:')
|
192 |
+
detailed_download_widget = factory.create_dropdown(['off', 'on'], 'off', 'Подробная Загрузка:')
|
193 |
+
choose_changes_widget = factory.create_hbox([latest_webui_widget, latest_exstensions_widget, change_webui_widget, detailed_download_widget])
|
194 |
+
|
195 |
+
controlnet_options = ['none', 'ALL', '1.canny',
|
196 |
+
'2.openpose', '3.depth',
|
197 |
+
'4.normal_map', '5.mlsd',
|
198 |
+
'6.lineart', '7.soft_edge',
|
199 |
+
'8.scribble', '9.segmentation',
|
200 |
+
'10.shuffle', '11.tile',
|
201 |
+
'12.inpaint', '13.instruct_p2p']
|
202 |
+
controlnet_widget = factory.create_dropdown(controlnet_options, 'none', 'ControlNet:')
|
203 |
+
controlnet_num_widget = factory.create_text('Номер ControlNet:', 'Введите номера моделей ControlNet для скачивания через запятую/пробел.')
|
204 |
+
commit_hash_widget = factory.create_text('Commit Hash:')
|
205 |
+
huggingface_token_widget = factory.create_text('Токен HuggingFace:')
|
206 |
+
|
207 |
+
ngrok_token_widget = factory.create_text('Токен Ngrok:')
|
208 |
+
ngrock_button = factory.create_html('<a href="https://dashboard.ngrok.com/get-started/your-authtoken" target="_blank">Получить Ngrok Токен</a>', class_name="button_ngrok")
|
209 |
+
ngrok_widget = factory.create_hbox([ngrok_token_widget, ngrock_button])
|
210 |
+
|
211 |
+
zrok_token_widget = factory.create_text('Токен Zrok:')
|
212 |
+
zrok_button = factory.create_html('<a href="https://colab.research.google.com/drive/1d2sjWDJi_GYBUavrHSuQyHTDuLy36WpU" target="_blank">Зарегать Zrok Токен</a>', class_name="button_ngrok")
|
213 |
+
zrok_widget = factory.create_hbox([zrok_token_widget, zrok_button])
|
214 |
+
|
215 |
+
commandline_arguments_options = "--listen --enable-insecure-extension-access --theme dark --no-half-vae --disable-console-progressbars --xformers"
|
216 |
+
commandline_arguments_widget = factory.create_text('Аргументы:', value=commandline_arguments_options)
|
217 |
+
|
218 |
+
# Display Additional
|
219 |
+
additional_widget_list = [additional_header,
|
220 |
+
choose_changes_widget,
|
221 |
+
HR,
|
222 |
+
controlnet_widget,
|
223 |
+
controlnet_num_widget,
|
224 |
+
commit_hash_widget,
|
225 |
+
huggingface_token_widget,
|
226 |
+
ngrok_widget,
|
227 |
+
zrok_widget,
|
228 |
+
HR,
|
229 |
+
commandline_arguments_widget]
|
230 |
+
|
231 |
+
if free_plan and env == "Google Colab": # remove ngrok from colab
|
232 |
+
additional_widget_list.remove(ngrok_widget)
|
233 |
+
if os.path.exists(webui_path): # remove selection after selection ;3
|
234 |
+
choose_changes_widget.children = [widget for widget in choose_changes_widget.children if widget != change_webui_widget]
|
235 |
+
|
236 |
+
all_additional_box = factory.create_vbox(additional_widget_list, class_names=["container", "image_3"])
|
237 |
+
factory.display(all_additional_box)
|
238 |
+
|
239 |
+
# --- CUSTOM DOWNLOAD ---
|
240 |
+
custom_download_header_popup = factory.create_html('''
|
241 |
+
<style>
|
242 |
+
/* Term Colors */
|
243 |
+
.sample_label {color: #dbafff;}
|
244 |
+
.braces {color: #ffff00;}
|
245 |
+
.extension {color: #eb934b;}
|
246 |
+
.file_name {color: #ffffd8;}
|
247 |
+
</style>
|
248 |
+
|
249 |
+
<div class="header" style="cursor: pointer;" onclick="toggleContainer()">Кастомная Загрузка</div>
|
250 |
+
<!-- PopUp Window -->
|
251 |
+
<div class="info" id="info_dl">INFO</div>
|
252 |
+
<div class="popup">
|
253 |
+
Разделите несколько URL-адресов запятой/пробелом. Для <span class="file_name">пользовательского имени</span> файла/расширения укажите его через <span class="braces">[]</span>
|
254 |
+
после URL без пробелов.
|
255 |
+
<span style="color: #ff9999">Для файлов обязательно укажите</span> - <span class="extension">Расширение Файла.</span>
|
256 |
+
<div class="sample">
|
257 |
+
<span class="sample_label">Пример для Файла:</span>
|
258 |
+
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>
|
259 |
+
<br>
|
260 |
+
<span class="sample_label">Пример для Расширения:</span>
|
261 |
+
https://github.com/hako-mikan/sd-webui-regional-prompter<span class="braces">[</span><span class="file_name">Regional-Prompter</span><span class="braces">]</span>
|
262 |
+
</div>
|
263 |
+
</div>
|
264 |
+
''')
|
265 |
+
|
266 |
+
Model_url_widget = factory.create_text('Model:')
|
267 |
+
Vae_url_widget = factory.create_text('Vae:')
|
268 |
+
LoRA_url_widget = factory.create_text('LoRa:')
|
269 |
+
Embedding_url_widget = factory.create_text('Embedding:')
|
270 |
+
Extensions_url_widget = factory.create_text('Extensions:')
|
271 |
+
custom_file_urls_widget = factory.create_text('Файл (txt):')
|
272 |
+
|
273 |
+
# Display CustomDl
|
274 |
+
all_custom_box = factory.create_vbox([
|
275 |
+
custom_download_header_popup, Model_url_widget, Vae_url_widget, LoRA_url_widget, Embedding_url_widget, Extensions_url_widget, custom_file_urls_widget
|
276 |
+
], class_names=["container", "image_4", "container_custom_downlad"])
|
277 |
+
factory.display(all_custom_box)
|
278 |
+
|
279 |
+
# --- Save Button ---
|
280 |
+
save_button = factory.create_button('Сохранить', class_name="button_save")
|
281 |
+
factory.display(save_button)
|
282 |
+
|
283 |
+
|
284 |
+
# ============ Load / Save - Settings V2 ============
|
285 |
+
SETTINGS_FILE = f'{root_path}/settings.json'
|
286 |
+
|
287 |
+
SETTINGS_KEYS = [
|
288 |
+
'model', 'model_num', 'inpainting_model',
|
289 |
+
'vae', 'vae_num', 'latest_webui', 'latest_exstensions',
|
290 |
+
'change_webui', 'detailed_download', 'controlnet',
|
291 |
+
'controlnet_num', 'commit_hash', 'huggingface_token',
|
292 |
+
'ngrok_token', 'zrok_token', 'commandline_arguments',
|
293 |
+
'Model_url', 'Vae_url', 'LoRA_url', 'Embedding_url',
|
294 |
+
'Extensions_url', 'custom_file_urls'
|
295 |
+
]
|
296 |
+
|
297 |
+
def save_settings():
|
298 |
+
settings = {key: globals()[f"{key}_widget"].value for key in SETTINGS_KEYS}
|
299 |
+
with open(SETTINGS_FILE, 'w') as f:
|
300 |
+
json.dump(settings, f, indent=2)
|
301 |
+
|
302 |
+
def load_settings():
|
303 |
+
if os.path.exists(SETTINGS_FILE):
|
304 |
+
with open(SETTINGS_FILE, 'r') as f:
|
305 |
+
settings = json.load(f)
|
306 |
+
for key in SETTINGS_KEYS:
|
307 |
+
globals()[f"{key}_widget"].value = settings.get(key, "")
|
308 |
+
|
309 |
+
def hide_widgets():
|
310 |
+
widgets_list = [all_model_box, all_vae_box, all_additional_box, all_custom_box, save_button]
|
311 |
+
for widget in widgets_list:
|
312 |
+
widget.add_class("hide")
|
313 |
+
time.sleep(0.5)
|
314 |
+
widgets.Widget.close_all()
|
315 |
+
|
316 |
+
def save_data(button):
|
317 |
+
save_settings()
|
318 |
+
hide_widgets()
|
319 |
+
|
320 |
+
load_settings()
|
321 |
+
save_button.on_click(save_data)
|
322 |
+
|
special/dl_display_results.py
CHANGED
@@ -194,7 +194,7 @@ header_widget = widgets.HTML(value=f'''
|
|
194 |
''')
|
195 |
|
196 |
# Models
|
197 |
-
models_list = get_files_list(models_dir, '.safetensors')
|
198 |
models_widget = output_container_generator('Models', models_list)
|
199 |
# Vaes
|
200 |
vaes_list = get_files_list(vaes_dir, '.safetensors')
|
|
|
194 |
''')
|
195 |
|
196 |
# Models
|
197 |
+
models_list = get_files_list(models_dir, ('.safetensors', '.ckpt'))
|
198 |
models_widget = output_container_generator('Models', models_list)
|
199 |
# Vaes
|
200 |
vaes_list = get_files_list(vaes_dir, '.safetensors')
|