✨ yay for modularity~
Browse files- files_cells/notebooks/en/auto_cleaner_en.ipynb +156 -164
- files_cells/notebooks/en/downloading_en.ipynb +125 -256
- files_cells/notebooks/en/launch_en.ipynb +9 -15
- files_cells/notebooks/en/widgets_en.ipynb +339 -348
- files_cells/notebooks/ru/auto_cleaner_ru.ipynb +156 -164
- files_cells/notebooks/ru/downloading_ru.ipynb +125 -256
- files_cells/notebooks/ru/launch_ru.ipynb +9 -15
- files_cells/notebooks/ru/widgets_ru.ipynb +339 -348
- files_cells/python/en/auto_cleaner_en.py +5 -13
- files_cells/python/en/downloading_en.py +125 -256
- files_cells/python/en/launch_en.py +9 -15
- files_cells/python/en/widgets_en.py +5 -14
- files_cells/python/ru/auto_cleaner_ru.py +5 -13
- files_cells/python/ru/downloading_ru.py +125 -256
- files_cells/python/ru/launch_ru.py +9 -15
- files_cells/python/ru/widgets_ru.py +5 -14
- modules/models_data.py +103 -0
- modules/setup_en.py +88 -0
- modules/setup_ru.py +88 -0
files_cells/notebooks/en/auto_cleaner_en.ipynb
CHANGED
@@ -1,165 +1,157 @@
|
|
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 |
-
"#
|
30 |
-
"
|
31 |
-
"
|
32 |
-
"
|
33 |
-
"
|
34 |
-
"
|
35 |
-
"
|
36 |
-
"
|
37 |
-
"
|
38 |
-
"
|
39 |
-
"\n",
|
40 |
-
"
|
41 |
-
"
|
42 |
-
"\n",
|
43 |
-
"\n",
|
44 |
-
"#
|
45 |
-
"
|
46 |
-
"
|
47 |
-
"
|
48 |
-
"
|
49 |
-
"
|
50 |
-
"\n",
|
51 |
-
"\n",
|
52 |
-
"
|
53 |
-
"
|
54 |
-
"
|
55 |
-
"
|
56 |
-
"
|
57 |
-
"
|
58 |
-
"
|
59 |
-
"
|
60 |
-
"\n",
|
61 |
-
"\
|
62 |
-
"
|
63 |
-
"
|
64 |
-
"
|
65 |
-
"\n",
|
66 |
-
"
|
67 |
-
"
|
68 |
-
"
|
69 |
-
"\n",
|
70 |
-
"
|
71 |
-
"
|
72 |
-
"
|
73 |
-
"
|
74 |
-
"\n",
|
75 |
-
"
|
76 |
-
"
|
77 |
-
"\n",
|
78 |
-
"
|
79 |
-
"
|
80 |
-
"
|
81 |
-
"
|
82 |
-
"
|
83 |
-
"\n",
|
84 |
-
"
|
85 |
-
"
|
86 |
-
"
|
87 |
-
"\n",
|
88 |
-
"
|
89 |
-
"
|
90 |
-
"
|
91 |
-
"
|
92 |
-
"
|
93 |
-
"
|
94 |
-
"
|
95 |
-
"\n",
|
96 |
-
"
|
97 |
-
"
|
98 |
-
"
|
99 |
-
"
|
100 |
-
"
|
101 |
-
"
|
102 |
-
"
|
103 |
-
"
|
104 |
-
"\n",
|
105 |
-
"
|
106 |
-
"
|
107 |
-
"
|
108 |
-
"
|
109 |
-
"\n",
|
110 |
-
"
|
111 |
-
"
|
112 |
-
"
|
113 |
-
" \"
|
114 |
-
"
|
115 |
-
"
|
116 |
-
"
|
117 |
-
"
|
118 |
-
"
|
119 |
-
"
|
120 |
-
"
|
121 |
-
"
|
122 |
-
"
|
123 |
-
"
|
124 |
-
"\n",
|
125 |
-
"\n",
|
126 |
-
"#
|
127 |
-
"
|
128 |
-
"
|
129 |
-
"
|
130 |
-
"
|
131 |
-
"
|
132 |
-
"\n",
|
133 |
-
"
|
134 |
-
"
|
135 |
-
"
|
136 |
-
"
|
137 |
-
"
|
138 |
-
"
|
139 |
-
"
|
140 |
-
"
|
141 |
-
"
|
142 |
-
"
|
143 |
-
"
|
144 |
-
"
|
145 |
-
"
|
146 |
-
"
|
147 |
-
"
|
148 |
-
"
|
149 |
-
|
150 |
-
|
151 |
-
"
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
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 |
+
"# Setup Env\n",
|
30 |
+
"env = os.environ.get('ENV_NAME')\n",
|
31 |
+
"root_path = os.environ.get('ROOT_PATH')\n",
|
32 |
+
"webui_path = os.environ.get('WEBUI_PATH')\n",
|
33 |
+
"free_plan = os.environ.get('FREE_PLAN')\n",
|
34 |
+
"\n",
|
35 |
+
"\n",
|
36 |
+
"# ==================== CSS ====================\n",
|
37 |
+
"# Main CSS\n",
|
38 |
+
"css_file_path = f\"{root_path}/CSS/auto_cleaner.css\"\n",
|
39 |
+
"with open(css_file_path , \"r\") as f:\n",
|
40 |
+
" CSS_AC = f.read()\n",
|
41 |
+
"display(HTML(f\"<style>{CSS_AC}</style>\"))\n",
|
42 |
+
"\n",
|
43 |
+
"\n",
|
44 |
+
"# ================ AutoCleaner function ================\n",
|
45 |
+
"directories = {\n",
|
46 |
+
" \"Images\": f\"{webui_path}/output\",\n",
|
47 |
+
" \"Models\": f\"{webui_path}/models/Stable-diffusion/\",\n",
|
48 |
+
" \"Vae\": f\"{webui_path}/models/VAE/\",\n",
|
49 |
+
" \"LoRa\": f\"{webui_path}/models/Lora/\",\n",
|
50 |
+
" \"ControlNet Models\": f\"{webui_path}/models/ControlNet/\"\n",
|
51 |
+
"}\n",
|
52 |
+
"\n",
|
53 |
+
"\"\"\" functions \"\"\"\n",
|
54 |
+
"def clean_directory(directory):\n",
|
55 |
+
" deleted_files = 0\n",
|
56 |
+
" image_dir = directories['Images']\n",
|
57 |
+
"\n",
|
58 |
+
" for root, dirs, files in os.walk(directory):\n",
|
59 |
+
" for file in files:\n",
|
60 |
+
" file_path = os.path.join(root, file)\n",
|
61 |
+
"\n",
|
62 |
+
" if file.endswith(\".txt\"):\n",
|
63 |
+
" continue\n",
|
64 |
+
" if file.endswith((\".safetensors\", \".pt\")) or root == image_dir: # fix for image counter\n",
|
65 |
+
" deleted_files += 1\n",
|
66 |
+
"\n",
|
67 |
+
" os.remove(file_path)\n",
|
68 |
+
" return deleted_files\n",
|
69 |
+
"\n",
|
70 |
+
"def update_memory_info():\n",
|
71 |
+
" disk_space = psutil.disk_usage(os.getcwd())\n",
|
72 |
+
" total = disk_space.total / (1024 ** 3)\n",
|
73 |
+
" used = disk_space.used / (1024 ** 3)\n",
|
74 |
+
" free = disk_space.free / (1024 ** 3)\n",
|
75 |
+
"\n",
|
76 |
+
" storage_info.value = f'''\n",
|
77 |
+
" <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",
|
78 |
+
" '''\n",
|
79 |
+
"\n",
|
80 |
+
"def on_execute_button_press(button):\n",
|
81 |
+
" selected_cleaners = auto_cleaner_widget.value\n",
|
82 |
+
" deleted_files_dict = {}\n",
|
83 |
+
"\n",
|
84 |
+
" for option in selected_cleaners:\n",
|
85 |
+
" if option in directories:\n",
|
86 |
+
" deleted_files_dict[option] = clean_directory(directories[option])\n",
|
87 |
+
"\n",
|
88 |
+
" output.clear_output()\n",
|
89 |
+
"\n",
|
90 |
+
" with output:\n",
|
91 |
+
" for message in generate_messages(deleted_files_dict):\n",
|
92 |
+
" message_widget = HTML(f'<p class=\"output_message_AC\">{message}</p>')\n",
|
93 |
+
" display(message_widget)\n",
|
94 |
+
"\n",
|
95 |
+
" update_memory_info()\n",
|
96 |
+
"\n",
|
97 |
+
"def on_clear_button_press(button):\n",
|
98 |
+
" container.add_class(\"hide\")\n",
|
99 |
+
" time.sleep(0.5)\n",
|
100 |
+
" widgets.Widget.close_all()\n",
|
101 |
+
"\n",
|
102 |
+
"def generate_messages(deleted_files_dict):\n",
|
103 |
+
" messages = []\n",
|
104 |
+
" word_variants = {\n",
|
105 |
+
" \"Images\": \"Images\",\n",
|
106 |
+
" \"Models\": \"Models\",\n",
|
107 |
+
" \"Vae\": \"Vae\",\n",
|
108 |
+
" \"LoRa\": \"LoRa\",\n",
|
109 |
+
" \"ControlNet Models\": \"ControlNet Models\"\n",
|
110 |
+
" }\n",
|
111 |
+
" for key, value in deleted_files_dict.items():\n",
|
112 |
+
" object_word = word_variants.get(key)\n",
|
113 |
+
" messages.append(f\"Deleted {value} {object_word}\")\n",
|
114 |
+
" return messages\n",
|
115 |
+
"# ================ AutoCleaner function ================\n",
|
116 |
+
"\n",
|
117 |
+
"\n",
|
118 |
+
"# --- storage memory ---\n",
|
119 |
+
"import psutil\n",
|
120 |
+
"disk_space = psutil.disk_usage(os.getcwd())\n",
|
121 |
+
"total = disk_space.total / (1024 ** 3)\n",
|
122 |
+
"used = disk_space.used / (1024 ** 3)\n",
|
123 |
+
"free = disk_space.free / (1024 ** 3)\n",
|
124 |
+
"\n",
|
125 |
+
"\n",
|
126 |
+
"# UI Code\n",
|
127 |
+
"AutoCleaner_options = AutoCleaner_options = list(directories.keys())\n",
|
128 |
+
"instruction_label = widgets.HTML('''\n",
|
129 |
+
"<span class=\"instruction_AC\">Use <span style=\"color: #B2B2B2;\">ctrl</span> or <span style=\"color: #B2B2B2;\">shift</span> for multiple selections.</span>\n",
|
130 |
+
"''')\n",
|
131 |
+
"auto_cleaner_widget = widgets.SelectMultiple(options=AutoCleaner_options, layout=widgets.Layout(width='auto')).add_class(\"custom-select-multiple_AC\")\n",
|
132 |
+
"output = widgets.Output().add_class(\"output_AC\")\n",
|
133 |
+
"# ---\n",
|
134 |
+
"execute_button = Button(description='Execute Cleaning').add_class(\"button_execute_AC\").add_class(\"button_AC\")\n",
|
135 |
+
"execute_button.on_click(on_execute_button_press)\n",
|
136 |
+
"clear_button = Button(description='Hide Widget').add_class(\"button_clear_AC\").add_class(\"button_AC\")\n",
|
137 |
+
"clear_button.on_click(on_clear_button_press)\n",
|
138 |
+
"# ---\n",
|
139 |
+
"storage_info = widgets.HTML(f'''\n",
|
140 |
+
"<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",
|
141 |
+
"''')\n",
|
142 |
+
"# ---\n",
|
143 |
+
"buttons = widgets.HBox([execute_button, clear_button])\n",
|
144 |
+
"lower_information_panel = widgets.HBox([buttons, storage_info]).add_class(\"lower_information_panel_AC\")\n",
|
145 |
+
"\n",
|
146 |
+
"container = VBox([instruction_label, widgets.HTML('<hr>'), auto_cleaner_widget, output, widgets.HTML('<hr>'), lower_information_panel]).add_class(\"container_AC\")\n",
|
147 |
+
"\n",
|
148 |
+
"display(container)"
|
149 |
+
],
|
150 |
+
"metadata": {
|
151 |
+
"id": "I22dFg7F2j3G"
|
152 |
+
},
|
153 |
+
"execution_count": null,
|
154 |
+
"outputs": []
|
155 |
+
}
|
156 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
}
|
files_cells/notebooks/en/downloading_en.ipynb
CHANGED
@@ -10,6 +10,8 @@
|
|
10 |
"source": [
|
11 |
"##~ DOWNLOADING CODE | BY: ANXETY ~##\n",
|
12 |
"\n",
|
|
|
|
|
13 |
"import os\n",
|
14 |
"import re\n",
|
15 |
"import time\n",
|
@@ -25,19 +27,11 @@
|
|
25 |
"from urllib.parse import urlparse, parse_qs\n",
|
26 |
"\n",
|
27 |
"\n",
|
28 |
-
"#
|
29 |
-
"
|
30 |
-
"
|
31 |
-
"
|
32 |
-
"
|
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",
|
@@ -207,112 +201,9 @@
|
|
207 |
"\n",
|
208 |
"## Downloading model and stuff | oh~ Hey! If you're freaked out by that code too, don't worry, me too!\n",
|
209 |
"print(\"📦 Downloading models and stuff...\", end='')\n",
|
210 |
-
"model_list = {\n",
|
211 |
-
" \"1.Anime (by XpucT) + INP\": [\n",
|
212 |
-
" {\"url\": \"https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2.safetensors\", \"name\": \"Anime_V2.safetensors\"},\n",
|
213 |
-
" {\"url\": \"https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2-inpainting.safetensors\", \"name\": \"Anime_V2-inpainting.safetensors\"}\n",
|
214 |
-
" ],\n",
|
215 |
-
" \"2.BluMix [Anime] [V7] + INP\": [\n",
|
216 |
-
" {\"url\": \"https://civitai.com/api/download/models/361779\", \"name\": \"BluMix_V7.safetensors\"},\n",
|
217 |
-
" {\"url\": \"https://civitai.com/api/download/models/363850\", \"name\": \"BluMix_V7-inpainting.safetensors\"}\n",
|
218 |
-
" ],\n",
|
219 |
-
" \"3.Cetus-Mix [Anime] [V4] + INP\": [\n",
|
220 |
-
" {\"url\": \"https://civitai.com/api/download/models/130298\", \"name\": \"CetusMix_V4.safetensors\"},\n",
|
221 |
-
" {\"url\": \"https://civitai.com/api/download/models/139882\", \"name\": \"CetusMix_V4-inpainting.safetensors\"}\n",
|
222 |
-
" ],\n",
|
223 |
-
" \"4.Counterfeit [Anime] [V3] + INP\": [\n",
|
224 |
-
" {\"url\": \"https://huggingface.co/gsdf/Counterfeit-V3.0/resolve/main/Counterfeit-V3.0_fix_fp16.safetensors\", \"name\": \"Counterfeit_V3.safetensors\"},\n",
|
225 |
-
" {\"url\": \"https://civitai.com/api/download/models/137911\", \"name\": \"Counterfeit_V3-inpainting.safetensors\"}\n",
|
226 |
-
" ],\n",
|
227 |
-
" \"5.CuteColor [Anime] [V3]\": [\n",
|
228 |
-
" {\"url\": \"https://civitai.com/api/download/models/138754\", \"name\": \"CuteColor_V3.safetensors\"}\n",
|
229 |
-
" ],\n",
|
230 |
-
" \"6.Dark-Sushi-Mix [Anime]\": [\n",
|
231 |
-
" {\"url\": \"https://civitai.com/api/download/models/101640\", \"name\": \"DarkSushiMix_2_5D.safetensors\"},\n",
|
232 |
-
" {\"url\": \"https://civitai.com/api/download/models/56071\", \"name\": \"DarkSushiMix_colorful.safetensors\"}\n",
|
233 |
-
" ],\n",
|
234 |
-
" \"7.Deliberate [Realism] [V6] + INP\": [\n",
|
235 |
-
" {\"url\": \"https://huggingface.co/XpucT/Deliberate/resolve/main/Deliberate_v6.safetensors\", \"name\": \"Deliberate_V6.safetensors\"},\n",
|
236 |
-
" {\"url\": \"https://huggingface.co/XpucT/Deliberate/resolve/main/Deliberate_v6-inpainting.safetensors\", \"name\": \"Deliberate_V6-inpainting.safetensors\"}\n",
|
237 |
-
" ],\n",
|
238 |
-
" \"8.Meina-Mix [Anime] [V11] + INP\": [\n",
|
239 |
-
" {\"url\": \"https://civitai.com/api/download/models/119057\", \"name\": \"MeinaMix_V11.safetensors\"},\n",
|
240 |
-
" {\"url\": \"https://civitai.com/api/download/models/120702\", \"name\": \"MeinaMix_V11-inpainting.safetensors\"}\n",
|
241 |
-
" ],\n",
|
242 |
-
" \"9.Mix-Pro [Anime] [V4] + INP\": [\n",
|
243 |
-
" {\"url\": \"https://civitai.com/api/download/models/125668\", \"name\": \"MixPro_V4.safetensors\"},\n",
|
244 |
-
" {\"url\": \"https://civitai.com/api/download/models/139878\", \"name\": \"MixPro_V4-inpainting.safetensors\"}\n",
|
245 |
-
" ]\n",
|
246 |
-
"}\n",
|
247 |
-
"\n",
|
248 |
-
"vae_list = {\n",
|
249 |
-
" \"1.Anime.vae\": [{\"url\": \"https://civitai.com/api/download/models/311162\", \"name\": \"Anime.vae.safetensors\"}],\n",
|
250 |
-
" \"2.Anything.vae\": [{\"url\": \"https://huggingface.co/NoCrypt/resources/resolve/main/VAE/any.vae.safetensors\", \"name\": \"Anything.vae.safetensors\"}],\n",
|
251 |
-
" \"3.Blessed2.vae\": [{\"url\": \"https://huggingface.co/NoCrypt/resources/resolve/main/VAE/blessed2.vae.safetensors\", \"name\": \"Blessed2.vae.safetensors\"}],\n",
|
252 |
-
" \"4.ClearVae.vae\": [{\"url\": \"https://civitai.com/api/download/models/88156\", \"name\": \"ClearVae_23.vae.safetensors\"}],\n",
|
253 |
-
" \"5.WD.vae\": [{\"url\": \"https://huggingface.co/NoCrypt/resources/resolve/main/VAE/wd.vae.safetensors\", \"name\": \"WD.vae.safetensors\"}]\n",
|
254 |
-
"}\n",
|
255 |
-
"\n",
|
256 |
-
"controlnet_list = {\n",
|
257 |
-
" \"1.canny\": [\n",
|
258 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny_fp16.safetensors\", \"name\": \"control_v11p_sd15_canny_fp16.safetensors\"},\n",
|
259 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_canny_fp16.yaml\", \"name\": \"control_v11p_sd15_canny_fp16.yaml\"}\n",
|
260 |
-
" ],\n",
|
261 |
-
" \"2.openpose\": [\n",
|
262 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose_fp16.safetensors\", \"name\": \"control_v11p_sd15_openpose_fp16.safetensors\"},\n",
|
263 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_openpose_fp16.yaml\", \"name\": \"control_v11p_sd15_openpose_fp16.yaml\"}\n",
|
264 |
-
" ],\n",
|
265 |
-
" \"3.depth\": [\n",
|
266 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth_fp16.safetensors\", \"name\": \"control_v11f1p_sd15_depth_fp16.safetensors\"},\n",
|
267 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1p_sd15_depth_fp16.yaml\", \"name\": \"control_v11f1p_sd15_depth_fp16.yaml\"},\n",
|
268 |
-
" {\"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",
|
269 |
-
" ],\n",
|
270 |
-
" \"4.normal_map\": [\n",
|
271 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_normalbae_fp16.safetensors\", \"name\": \"control_v11p_sd15_normalbae_fp16.safetensors\"},\n",
|
272 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_normalbae_fp16.yaml\", \"name\": \"control_v11p_sd15_normalbae_fp16.yaml\"}\n",
|
273 |
-
" ],\n",
|
274 |
-
" \"5.mlsd\": [\n",
|
275 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_mlsd_fp16.safetensors\", \"name\": \"control_v11p_sd15_mlsd_fp16.safetensors\"},\n",
|
276 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_mlsd_fp16.yaml\", \"name\": \"control_v11p_sd15_mlsd_fp16.yaml\"}\n",
|
277 |
-
" ],\n",
|
278 |
-
" \"6.lineart\": [\n",
|
279 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart_fp16.safetensors\", \"name\": \"control_v11p_sd15_lineart_fp16.safetensors\"},\n",
|
280 |
-
" {\"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",
|
281 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_lineart_fp16.yaml\", \"name\": \"control_v11p_sd15_lineart_fp16.yaml\"},\n",
|
282 |
-
" {\"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",
|
283 |
-
" ],\n",
|
284 |
-
" \"7.soft_edge\": [\n",
|
285 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge_fp16.safetensors\", \"name\": \"control_v11p_sd15_softedge_fp16.safetensors\"},\n",
|
286 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_softedge_fp16.yaml\", \"name\": \"control_v11p_sd15_softedge_fp16.yaml\"}\n",
|
287 |
-
" ],\n",
|
288 |
-
" \"8.scribble\": [\n",
|
289 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble_fp16.safetensors\", \"name\": \"control_v11p_sd15_scribble_fp16.safetensors\"},\n",
|
290 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_scribble_fp16.yaml\", \"name\": \"control_v11p_sd15_scribble_fp16.yaml\"}\n",
|
291 |
-
" ],\n",
|
292 |
-
" \"9.segmentation\": [\n",
|
293 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg_fp16.safetensors\", \"name\": \"control_v11p_sd15_seg_fp16.safetensors\"},\n",
|
294 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_seg_fp16.yaml\", \"name\": \"control_v11p_sd15_seg_fp16.yaml\"}\n",
|
295 |
-
" ],\n",
|
296 |
-
" \"10.shuffle\": [\n",
|
297 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle_fp16.safetensors\", \"name\": \"control_v11e_sd15_shuffle_fp16.safetensors\"},\n",
|
298 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_shuffle_fp16.yaml\", \"name\": \"control_v11e_sd15_shuffle_fp16.yaml\"}\n",
|
299 |
-
" ],\n",
|
300 |
-
" \"11.tile\": [\n",
|
301 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile_fp16.safetensors\", \"name\": \"control_v11f1e_sd15_tile_fp16.safetensors\"},\n",
|
302 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1e_sd15_tile_fp16.yaml\", \"name\": \"control_v11f1e_sd15_tile_fp16.yaml\"}\n",
|
303 |
-
" ],\n",
|
304 |
-
" \"12.inpaint\": [\n",
|
305 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_inpaint_fp16.safetensors\", \"name\": \"control_v11p_sd15_inpaint_fp16.safetensors\"},\n",
|
306 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_inpaint_fp16.yaml\", \"name\": \"control_v11p_sd15_inpaint_fp16.yaml\"}\n",
|
307 |
-
" ],\n",
|
308 |
-
" \"13.instruct_p2p\": [\n",
|
309 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p_fp16.safetensors\", \"name\": \"control_v11e_sd15_ip2p_fp16.safetensors\"},\n",
|
310 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_ip2p_fp16.yaml\", \"name\": \"control_v11e_sd15_ip2p_fp16.yaml\"}\n",
|
311 |
-
" ]\n",
|
312 |
-
"}\n",
|
313 |
"\n",
|
314 |
"url = \"\"\n",
|
315 |
-
"
|
316 |
" \"model\": models_dir,\n",
|
317 |
" \"vae\": vaes_dir,\n",
|
318 |
" \"lora\": loras_dir,\n",
|
@@ -324,7 +215,7 @@
|
|
324 |
"}\n",
|
325 |
"\n",
|
326 |
"extension_repo = []\n",
|
327 |
-
"directories = [value for key, value in
|
328 |
"!mkdir -p {\" \".join(directories)}\n",
|
329 |
"\n",
|
330 |
"hf_token = huggingface_token if huggingface_token else \"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\"\n",
|
@@ -335,137 +226,123 @@
|
|
335 |
"from math import floor\n",
|
336 |
"\n",
|
337 |
"def center_text(text, terminal_width=45):\n",
|
338 |
-
"
|
339 |
-
"
|
340 |
-
" right_padding = terminal_width - text_length - left_padding\n",
|
341 |
-
" return f\"\\033[1m\\033[36m{' ' * left_padding}{text}{' ' * right_padding}\\033[0m\\033[32m\"\n",
|
342 |
"\n",
|
343 |
"def format_output(url, dst_dir, file_name):\n",
|
344 |
-
" info = f\"[{file_name.split('.')[0]}]\"\n",
|
345 |
-
"
|
346 |
"\n",
|
347 |
-
" print(f\"\\n
|
348 |
" print(f\"\\033[33mURL: \\033[34m{url}\")\n",
|
349 |
" print(f\"\\033[33mSAVE DIR: \\033[34m{dst_dir}\")\n",
|
350 |
" print(f\"\\033[33mFILE NAME: \\033[34m{file_name}\\033[0m\")\n",
|
351 |
"\n",
|
352 |
"''' GET CivitAi API - DATA '''\n",
|
353 |
"\n",
|
354 |
-
"def strip_(url, file_name=None):\n",
|
355 |
-
" if 'github.com' in url:\n",
|
356 |
-
" if '/blob/' in url:\n",
|
357 |
-
" url = url.replace('/blob/', '/raw/')\n",
|
358 |
-
"\n",
|
359 |
-
" elif \"civitai.com\" in url:\n",
|
360 |
-
" return CivitAi_API(url, file_name)\n",
|
361 |
-
"\n",
|
362 |
-
" elif \"huggingface.co\" in url:\n",
|
363 |
-
" if '/blob/' in url:\n",
|
364 |
-
" url = url.replace('/blob/', '/resolve/')\n",
|
365 |
-
" if '?' in url:\n",
|
366 |
-
" url = url.split('?')[0]\n",
|
367 |
-
"\n",
|
368 |
-
" return url\n",
|
369 |
-
"\n",
|
370 |
"def CivitAi_API(url, file_name=None):\n",
|
371 |
-
"
|
372 |
-
"
|
373 |
"\n",
|
374 |
-
" if '?token=' in url
|
375 |
-
"
|
376 |
-
"
|
377 |
-
"
|
378 |
-
"
|
379 |
-
"
|
380 |
-
"\n",
|
381 |
-
"
|
382 |
-
"
|
383 |
-
"
|
384 |
-
"
|
385 |
-
" response = requests.get(f\"https://civitai.com/api/v1/model-versions/{version_id}\")\n",
|
386 |
-
" # print(f\"end - https://civitai.com/api/v1/model-versions/{version_id}\")\n",
|
387 |
" else:\n",
|
388 |
-
"
|
389 |
-
"
|
390 |
-
" # print(f\"end - https://civitai.com/api/v1/models/{model_id}\")\n",
|
391 |
-
" else:\n",
|
392 |
-
" version_id = url.split('/models/')[1].split('/')[0]\n",
|
393 |
-
" response = requests.get(f\"https://civitai.com/api/v1/model-versions/{version_id}\")\n",
|
394 |
-
" # print(f\"end - https://civitai.com/api/v1/model-versions/{version_id}\")\n",
|
395 |
"\n",
|
396 |
-
" data =
|
397 |
"\n",
|
398 |
-
" if
|
399 |
" return None, None, None, None, None, None, None\n",
|
400 |
"\n",
|
401 |
-
"
|
402 |
-
"
|
403 |
-
"
|
404 |
-
"
|
405 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
406 |
" else:\n",
|
407 |
-
" model_type = data['type']\n",
|
408 |
-
" model_name = data['modelVersions'][0]['files'][0]['name']\n",
|
409 |
-
" elif 'type=' in url:\n",
|
410 |
-
" model_type = parse_qs(urlparse(url).query).get('type', [''])[0]\n",
|
411 |
-
" if 'model' in model_type.lower():\n",
|
412 |
" model_name = data['files'][0]['name']\n",
|
413 |
-
"
|
414 |
-
" model_name = data['files'][1]['name']\n",
|
415 |
-
" else:\n",
|
416 |
-
" model_type = data['model']['type']\n",
|
417 |
-
" model_name = data['files'][0]['name']\n",
|
418 |
"\n",
|
|
|
419 |
" model_name = file_name or model_name\n",
|
420 |
"\n",
|
421 |
-
"
|
422 |
-
"
|
423 |
-
"
|
424 |
-
"
|
425 |
-
"
|
426 |
-
"
|
427 |
-
"
|
428 |
-
"
|
429 |
-
"
|
|
|
|
|
430 |
" else:\n",
|
431 |
-
"
|
432 |
-
" else:\n",
|
433 |
-
" download_url = data.get('downloadUrl')\n",
|
434 |
"\n",
|
435 |
-
"
|
|
|
436 |
"\n",
|
437 |
-
"
|
438 |
-
"
|
439 |
-
"
|
440 |
-
"
|
441 |
-
"
|
442 |
-
"
|
443 |
-
"
|
444 |
-
"
|
445 |
-
"
|
446 |
-
"
|
447 |
-
"
|
|
|
|
|
|
|
448 |
"\n",
|
449 |
-
"
|
450 |
-
" image_name = f\"{model_name.split('.')[0]}.preview.{image_url.split('.')[-1]}\" if image_url else None\n",
|
451 |
"\n",
|
452 |
-
" return f\"{download_url}{'&' if '?' in download_url else '?'}token={
|
453 |
"\n",
|
454 |
"''' Main Download Code '''\n",
|
455 |
"\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
456 |
"def download(url):\n",
|
457 |
" links_and_paths = [link_or_path.strip() for link_or_path in url.split(',') if link_or_path.strip()]\n",
|
458 |
"\n",
|
459 |
" for link_or_path in links_and_paths:\n",
|
460 |
-
" if any(link_or_path.lower().startswith(prefix) for prefix in
|
461 |
" handle_manual(link_or_path)\n",
|
462 |
" else:\n",
|
463 |
" url, dst_dir, file_name = link_or_path.split()\n",
|
464 |
" manual_download(url, dst_dir, file_name)\n",
|
465 |
"\n",
|
466 |
-
"
|
467 |
-
"\n",
|
468 |
-
"def unpack_zip_files():\n",
|
469 |
" for directory in directories:\n",
|
470 |
" for root, _, files in os.walk(directory):\n",
|
471 |
" for file in files:\n",
|
@@ -485,8 +362,8 @@
|
|
485 |
" if file_name:\n",
|
486 |
" path = re.sub(r'\\[.*?\\]', '', path)\n",
|
487 |
"\n",
|
488 |
-
" if prefix in
|
489 |
-
" dir =
|
490 |
" if prefix != \"extension\":\n",
|
491 |
" try:\n",
|
492 |
" manual_download(path, dir, file_name=file_name)\n",
|
@@ -500,60 +377,52 @@
|
|
500 |
" aria2c_header = \"--header='User-Agent: Mozilla/5.0' --allow-overwrite=true\"\n",
|
501 |
" aria2_args = \"--optimize-concurrent-downloads --console-log-level=error --summary-interval=10 --stderr=true -c -x16 -s16 -k1M -j5\"\n",
|
502 |
"\n",
|
503 |
-
"
|
504 |
-
" url = strip_(url)\n",
|
505 |
-
"\n",
|
506 |
-
" # -- CivitAi APi+ V2 --\n",
|
507 |
-
" elif 'civitai' in url:\n",
|
508 |
-
" url, clean_url, model_type, file_name, image_url, image_name, data = strip_(url, file_name)\n",
|
509 |
"\n",
|
|
|
|
|
510 |
" if image_url and image_name:\n",
|
511 |
-
"
|
512 |
-
"
|
513 |
-
" del cap\n",
|
514 |
"\n",
|
515 |
-
" elif \"huggingface.co\" in url:\n",
|
516 |
-
"
|
517 |
-
" basename = clean_url.split(\"/\")[-1] if file_name is None else file_name\n",
|
518 |
"\n",
|
519 |
" \"\"\" Formatted info output \"\"\"\n",
|
520 |
-
" model_name_or_basename = file_name if
|
521 |
" format_output(clean_url or url, dst_dir, model_name_or_basename)\n",
|
522 |
"\n",
|
523 |
-
" # ## -- for my tests --\n",
|
524 |
" # print(url, dst_dir, model_name_or_basename)\n",
|
525 |
-
"
|
526 |
-
"
|
527 |
-
"
|
|
|
|
|
|
|
528 |
" # =====================\n",
|
|
|
|
|
|
|
529 |
"\n",
|
530 |
-
" # --
|
531 |
-
" if '
|
532 |
-
"
|
533 |
-
"\n",
|
534 |
-
"
|
535 |
-
" elif 'drive.google' in url:\n",
|
536 |
-
" try:\n",
|
537 |
-
" have_drive_link\n",
|
538 |
-
" except:\n",
|
539 |
-
" !pip install -q gdown==5.2.0 > /dev/null\n",
|
540 |
-
" have_drive_link = True\n",
|
541 |
"\n",
|
542 |
" if 'folders' in url:\n",
|
543 |
-
"
|
544 |
" else:\n",
|
545 |
-
" if file_name
|
546 |
-
"
|
547 |
-
" else:\n",
|
548 |
-
" !gdown \"{url}\" -O {dst_dir} --fuzzy -c\n",
|
549 |
"\n",
|
550 |
-
" # -- Hugging Face --\n",
|
551 |
-
" elif 'huggingface' in url:\n",
|
552 |
-
"
|
553 |
"\n",
|
554 |
-
" # -- Other --\n",
|
555 |
" elif 'http' in url:\n",
|
556 |
-
"
|
557 |
"\n",
|
558 |
"''' SubModels - Added URLs '''\n",
|
559 |
"\n",
|
@@ -593,7 +462,7 @@
|
|
593 |
"\n",
|
594 |
"''' file.txt - added urls '''\n",
|
595 |
"\n",
|
596 |
-
"def process_file_download(file_url,
|
597 |
" files_urls = \"\"\n",
|
598 |
"\n",
|
599 |
" if file_url.startswith(\"http\"):\n",
|
@@ -608,8 +477,8 @@
|
|
608 |
" current_tag = None\n",
|
609 |
" for line in lines:\n",
|
610 |
" line = line.strip()\n",
|
611 |
-
" if any(f'# {tag}' in line.lower() for tag in
|
612 |
-
" current_tag = next((tag for tag in
|
613 |
"\n",
|
614 |
" urls = [url.split('#')[0].strip() for url in line.split(',')] # filter urls\n",
|
615 |
" for url in urls:\n",
|
@@ -633,13 +502,13 @@
|
|
633 |
" custom_file_url = f'{root_path}/{custom_file_url}'\n",
|
634 |
"\n",
|
635 |
" try:\n",
|
636 |
-
" file_urls += process_file_download(custom_file_url,
|
637 |
" except FileNotFoundError:\n",
|
638 |
" pass\n",
|
639 |
"\n",
|
640 |
"# url prefixing\n",
|
641 |
"urls = (Model_url, Vae_url, LoRA_url, Embedding_url, Extensions_url)\n",
|
642 |
-
"prefixed_urls = (f\"{prefix}:{url}\" for prefix, url in zip(
|
643 |
"url += \", \".join(prefixed_urls) + \", \" + file_urls\n",
|
644 |
"\n",
|
645 |
"if detailed_download == \"on\":\n",
|
|
|
10 |
"source": [
|
11 |
"##~ DOWNLOADING CODE | BY: ANXETY ~##\n",
|
12 |
"\n",
|
13 |
+
"from models_data import model_list, vae_list, controlnet_list\n",
|
14 |
+
"\n",
|
15 |
"import os\n",
|
16 |
"import re\n",
|
17 |
"import time\n",
|
|
|
27 |
"from urllib.parse import urlparse, parse_qs\n",
|
28 |
"\n",
|
29 |
"\n",
|
30 |
+
"# Setup Env\n",
|
31 |
+
"env = os.environ.get('ENV_NAME')\n",
|
32 |
+
"root_path = os.environ.get('ROOT_PATH')\n",
|
33 |
+
"webui_path = os.environ.get('WEBUI_PATH')\n",
|
34 |
+
"free_plan = os.environ.get('FREE_PLAN')\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
"\n",
|
36 |
"\n",
|
37 |
"# ================ LIBRARIES V2 ================\n",
|
|
|
201 |
"\n",
|
202 |
"## Downloading model and stuff | oh~ Hey! If you're freaked out by that code too, don't worry, me too!\n",
|
203 |
"print(\"📦 Downloading models and stuff...\", end='')\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
204 |
"\n",
|
205 |
"url = \"\"\n",
|
206 |
+
"PREFIXES = {\n",
|
207 |
" \"model\": models_dir,\n",
|
208 |
" \"vae\": vaes_dir,\n",
|
209 |
" \"lora\": loras_dir,\n",
|
|
|
215 |
"}\n",
|
216 |
"\n",
|
217 |
"extension_repo = []\n",
|
218 |
+
"directories = [value for key, value in PREFIXES.items()] # for unpucking zip files\n",
|
219 |
"!mkdir -p {\" \".join(directories)}\n",
|
220 |
"\n",
|
221 |
"hf_token = huggingface_token if huggingface_token else \"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\"\n",
|
|
|
226 |
"from math import floor\n",
|
227 |
"\n",
|
228 |
"def center_text(text, terminal_width=45):\n",
|
229 |
+
" padding = (terminal_width - len(text)) // 2\n",
|
230 |
+
" return f\"\\033[1m\\033[36m{' ' * padding}{text}{' ' * padding}\\033[0m\\033[32m\"\n",
|
|
|
|
|
231 |
"\n",
|
232 |
"def format_output(url, dst_dir, file_name):\n",
|
233 |
+
" info = center_text(f\"[{file_name.split('.')[0]}]\")\n",
|
234 |
+
" separation_line = '\\033[32m' + '---' * 20\n",
|
235 |
"\n",
|
236 |
+
" print(f\"\\n{separation_line}{info}{separation_line}\")\n",
|
237 |
" print(f\"\\033[33mURL: \\033[34m{url}\")\n",
|
238 |
" print(f\"\\033[33mSAVE DIR: \\033[34m{dst_dir}\")\n",
|
239 |
" print(f\"\\033[33mFILE NAME: \\033[34m{file_name}\\033[0m\")\n",
|
240 |
"\n",
|
241 |
"''' GET CivitAi API - DATA '''\n",
|
242 |
"\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
243 |
"def CivitAi_API(url, file_name=None):\n",
|
244 |
+
" SUPPORT_TYPES = ('Checkpoint', 'Model', 'TextualInversion', 'LORA')\n",
|
245 |
+
" CIVITAI_TOKEN = \"62c0c5956b2f9defbd844d754000180b\"\n",
|
246 |
"\n",
|
247 |
+
" url = url.split('?token=')[0] if '?token=' in url else url\n",
|
248 |
+
" url = url.replace('?type=', f'?token={CIVITAI_TOKEN}&type=') if '?type=' in url else f\"{url}?token={CIVITAI_TOKEN}\"\n",
|
249 |
+
"\n",
|
250 |
+
" def get_model_data(url):\n",
|
251 |
+
" if \"civitai.com/models/\" in url:\n",
|
252 |
+
" if '?modelVersionId=' in url:\n",
|
253 |
+
" version_id = url.split('?modelVersionId=')[1]\n",
|
254 |
+
" return requests.get(f\"https://civitai.com/api/v1/model-versions/{version_id}\").json()\n",
|
255 |
+
" else:\n",
|
256 |
+
" model_id = url.split('/models/')[1].split('/')[0]\n",
|
257 |
+
" return requests.get(f\"https://civitai.com/api/v1/models/{model_id}\").json()\n",
|
|
|
|
|
258 |
" else:\n",
|
259 |
+
" version_id = url.split('/models/')[1].split('/')[0]\n",
|
260 |
+
" return requests.get(f\"https://civitai.com/api/v1/model-versions/{version_id}\").json()\n",
|
|
|
|
|
|
|
|
|
|
|
261 |
"\n",
|
262 |
+
" data = get_model_data(url)\n",
|
263 |
"\n",
|
264 |
+
" if not data:\n",
|
265 |
" return None, None, None, None, None, None, None\n",
|
266 |
"\n",
|
267 |
+
" def extract_model_info(url, data):\n",
|
268 |
+
" if \"civitai.com/models/\" in url:\n",
|
269 |
+
" if '?modelVersionId=' in url:\n",
|
270 |
+
" model_type = data['model']['type']\n",
|
271 |
+
" model_name = data['files'][0]['name']\n",
|
272 |
+
" else:\n",
|
273 |
+
" model_type = data['type']\n",
|
274 |
+
" model_name = data['modelVersions'][0]['files'][0]['name']\n",
|
275 |
+
" elif 'type=' in url:\n",
|
276 |
+
" model_type = parse_qs(urlparse(url).query).get('type', [''])[0]\n",
|
277 |
+
" if 'model' in model_type.lower():\n",
|
278 |
+
" model_name = data['files'][0]['name']\n",
|
279 |
+
" else:\n",
|
280 |
+
" model_name = data['files'][1]['name']\n",
|
281 |
" else:\n",
|
282 |
+
" model_type = data['model']['type']\n",
|
|
|
|
|
|
|
|
|
283 |
" model_name = data['files'][0]['name']\n",
|
284 |
+
" return model_type, model_name\n",
|
|
|
|
|
|
|
|
|
285 |
"\n",
|
286 |
+
" model_type, model_name = extract_model_info(url, data)\n",
|
287 |
" model_name = file_name or model_name\n",
|
288 |
"\n",
|
289 |
+
" def get_download_url(url, data, model_type):\n",
|
290 |
+
" if \"civitai.com/models/\" in url:\n",
|
291 |
+
" if '?modelVersionId=' in url:\n",
|
292 |
+
" return data.get('downloadUrl')\n",
|
293 |
+
" else:\n",
|
294 |
+
" return data[\"modelVersions\"][0].get(\"downloadUrl\", \"\")\n",
|
295 |
+
" elif 'type=' in url:\n",
|
296 |
+
" if any(t.lower() in model_type.lower() for t in SUPPORT_TYPES):\n",
|
297 |
+
" return data['files'][0]['downloadUrl']\n",
|
298 |
+
" else:\n",
|
299 |
+
" return data['files'][1]['downloadUrl']\n",
|
300 |
" else:\n",
|
301 |
+
" return data.get('downloadUrl')\n",
|
|
|
|
|
302 |
"\n",
|
303 |
+
" download_url = get_download_url(url, data, model_type)\n",
|
304 |
+
" clean_url = re.sub(r'[?&]token=[^&]*', '', download_url)\n",
|
305 |
"\n",
|
306 |
+
" def get_image_info(data, model_type, model_name):\n",
|
307 |
+
" image_url, image_name = None, None\n",
|
308 |
+
" if any(t in model_type for t in SUPPORT_TYPES):\n",
|
309 |
+
" try:\n",
|
310 |
+
" images = data.get('images') or data['modelVersions'][0].get('images', [])\n",
|
311 |
+
" if env == 'Kaggle':\n",
|
312 |
+
" image_url = next((image['url'] for image in images if image['nsfwLevel'] < 4), None)\n",
|
313 |
+
" else:\n",
|
314 |
+
" image_url = images[0]['url'] if images else None\n",
|
315 |
+
" except KeyError:\n",
|
316 |
+
" pass\n",
|
317 |
+
"\n",
|
318 |
+
" image_name = f\"{model_name.split('.')[0]}.preview.{image_url.split('.')[-1]}\" if image_url else None\n",
|
319 |
+
" return image_url, image_name\n",
|
320 |
"\n",
|
321 |
+
" image_url, image_name = get_image_info(data, model_type, model_name)\n",
|
|
|
322 |
"\n",
|
323 |
+
" return f\"{download_url}{'&' if '?' in download_url else '?'}token={CIVITAI_TOKEN}\", clean_url, model_type, model_name, image_url, image_name, data\n",
|
324 |
"\n",
|
325 |
"''' Main Download Code '''\n",
|
326 |
"\n",
|
327 |
+
"def strip_(url):\n",
|
328 |
+
" if 'github.com' in url:\n",
|
329 |
+
" return url.replace('/blob/', '/raw/')\n",
|
330 |
+
" elif \"huggingface.co\" in url:\n",
|
331 |
+
" url = url.replace('/blob/', '/resolve/')\n",
|
332 |
+
" return url.split('?')[0] if '?' in url else url\n",
|
333 |
+
" return url\n",
|
334 |
+
"\n",
|
335 |
"def download(url):\n",
|
336 |
" links_and_paths = [link_or_path.strip() for link_or_path in url.split(',') if link_or_path.strip()]\n",
|
337 |
"\n",
|
338 |
" for link_or_path in links_and_paths:\n",
|
339 |
+
" if any(link_or_path.lower().startswith(prefix) for prefix in PREFIXES):\n",
|
340 |
" handle_manual(link_or_path)\n",
|
341 |
" else:\n",
|
342 |
" url, dst_dir, file_name = link_or_path.split()\n",
|
343 |
" manual_download(url, dst_dir, file_name)\n",
|
344 |
"\n",
|
345 |
+
" # Unpuck ZIPs Files\n",
|
|
|
|
|
346 |
" for directory in directories:\n",
|
347 |
" for root, _, files in os.walk(directory):\n",
|
348 |
" for file in files:\n",
|
|
|
362 |
" if file_name:\n",
|
363 |
" path = re.sub(r'\\[.*?\\]', '', path)\n",
|
364 |
"\n",
|
365 |
+
" if prefix in PREFIXES:\n",
|
366 |
+
" dir = PREFIXES[prefix]\n",
|
367 |
" if prefix != \"extension\":\n",
|
368 |
" try:\n",
|
369 |
" manual_download(path, dir, file_name=file_name)\n",
|
|
|
377 |
" aria2c_header = \"--header='User-Agent: Mozilla/5.0' --allow-overwrite=true\"\n",
|
378 |
" aria2_args = \"--optimize-concurrent-downloads --console-log-level=error --summary-interval=10 --stderr=true -c -x16 -s16 -k1M -j5\"\n",
|
379 |
"\n",
|
380 |
+
" clean_url = strip_(url)\n",
|
|
|
|
|
|
|
|
|
|
|
381 |
"\n",
|
382 |
+
" if 'civitai' in url:\n",
|
383 |
+
" url, clean_url, model_type, file_name, image_url, image_name, data = CivitAi_API(url, file_name)\n",
|
384 |
" if image_url and image_name:\n",
|
385 |
+
" command = [\"aria2c\"] + aria2_args.split() + [\"-d\", dst_dir, \"-o\", image_name, image_url]\n",
|
386 |
+
" subprocess.run(command, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)\n",
|
|
|
387 |
"\n",
|
388 |
+
" elif 'github' in url or \"huggingface.co\" in url:\n",
|
389 |
+
" basename = url.split(\"/\")[-1] if file_name is None else file_name\n",
|
|
|
390 |
"\n",
|
391 |
" \"\"\" Formatted info output \"\"\"\n",
|
392 |
+
" model_name_or_basename = file_name if file_name else basename\n",
|
393 |
" format_output(clean_url or url, dst_dir, model_name_or_basename)\n",
|
394 |
"\n",
|
|
|
395 |
" # print(url, dst_dir, model_name_or_basename)\n",
|
396 |
+
" if 'civitai' in url:\n",
|
397 |
+
" if not data:\n",
|
398 |
+
" print(\"\\033[31m[Data Info]:\\033[0m Failed to retrieve data from the API.\\n\")\n",
|
399 |
+
" if data and image_name:\n",
|
400 |
+
" print(f\"\\033[32m[Preview DL]:\\033[0m {image_name} - {image_url}\\n\")\n",
|
401 |
+
"\n",
|
402 |
" # =====================\n",
|
403 |
+
" def run_aria2c(url, dst_dir, file_name=None, args=\"\", header=\"\"):\n",
|
404 |
+
" out = f\"-o '{file_name}'\" if file_name else \"\"\n",
|
405 |
+
" !aria2c {header} {args} -d {dst_dir} {out} '{url}'\n",
|
406 |
"\n",
|
407 |
+
" # -- Google Drive --\n",
|
408 |
+
" if 'drive.google' in url:\n",
|
409 |
+
" if not globals().get('have_drive_link', False):\n",
|
410 |
+
" os.system(\"pip install -U gdown > /dev/null\")\n",
|
411 |
+
" globals()['have_drive_link'] = True\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
412 |
"\n",
|
413 |
" if 'folders' in url:\n",
|
414 |
+
" os.system(f\"gdown --folder \\\"{url}\\\" -O {dst_dir} --fuzzy -c\")\n",
|
415 |
" else:\n",
|
416 |
+
" out_path = f\"{dst_dir}/{file_name}\" if file_name else dst_dir\n",
|
417 |
+
" os.system(f\"gdown \\\"{url}\\\" -O {out_path} --fuzzy -c\")\n",
|
|
|
|
|
418 |
"\n",
|
419 |
+
" # -- GitHub or Hugging Face --\n",
|
420 |
+
" elif 'github' in url or 'huggingface' in url:\n",
|
421 |
+
" run_aria2c(clean_url, dst_dir, basename, aria2_args, header_option if 'huggingface' in url else '')\n",
|
422 |
"\n",
|
423 |
+
" # -- Other HTTP/Sources --\n",
|
424 |
" elif 'http' in url:\n",
|
425 |
+
" run_aria2c(url, dst_dir, file_name, aria2_args, aria2c_header)\n",
|
426 |
"\n",
|
427 |
"''' SubModels - Added URLs '''\n",
|
428 |
"\n",
|
|
|
462 |
"\n",
|
463 |
"''' file.txt - added urls '''\n",
|
464 |
"\n",
|
465 |
+
"def process_file_download(file_url, PREFIXES, unique_urls):\n",
|
466 |
" files_urls = \"\"\n",
|
467 |
"\n",
|
468 |
" if file_url.startswith(\"http\"):\n",
|
|
|
477 |
" current_tag = None\n",
|
478 |
" for line in lines:\n",
|
479 |
" line = line.strip()\n",
|
480 |
+
" if any(f'# {tag}' in line.lower() for tag in PREFIXES):\n",
|
481 |
+
" current_tag = next((tag for tag in PREFIXES if tag in line.lower()))\n",
|
482 |
"\n",
|
483 |
" urls = [url.split('#')[0].strip() for url in line.split(',')] # filter urls\n",
|
484 |
" for url in urls:\n",
|
|
|
502 |
" custom_file_url = f'{root_path}/{custom_file_url}'\n",
|
503 |
"\n",
|
504 |
" try:\n",
|
505 |
+
" file_urls += process_file_download(custom_file_url, PREFIXES, unique_urls)\n",
|
506 |
" except FileNotFoundError:\n",
|
507 |
" pass\n",
|
508 |
"\n",
|
509 |
"# url prefixing\n",
|
510 |
"urls = (Model_url, Vae_url, LoRA_url, Embedding_url, Extensions_url)\n",
|
511 |
+
"prefixed_urls = (f\"{prefix}:{url}\" for prefix, url in zip(PREFIXES.keys(), urls) if url for url in url.replace(',', '').split())\n",
|
512 |
"url += \", \".join(prefixed_urls) + \", \" + file_urls\n",
|
513 |
"\n",
|
514 |
"if detailed_download == \"on\":\n",
|
files_cells/notebooks/en/launch_en.ipynb
CHANGED
@@ -33,21 +33,13 @@
|
|
33 |
"from datetime import timedelta\n",
|
34 |
"from IPython.display import clear_output\n",
|
35 |
"\n",
|
36 |
-
"
|
37 |
-
"
|
38 |
-
"
|
39 |
-
"
|
40 |
-
"
|
41 |
-
"
|
42 |
-
"
|
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",
|
@@ -62,6 +54,7 @@
|
|
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",
|
@@ -95,6 +88,7 @@
|
|
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",
|
|
|
33 |
"from datetime import timedelta\n",
|
34 |
"from IPython.display import clear_output\n",
|
35 |
"\n",
|
36 |
+
"\n",
|
37 |
+
"# Setup Env\n",
|
38 |
+
"env = os.environ.get('ENV_NAME')\n",
|
39 |
+
"root_path = os.environ.get('ROOT_PATH')\n",
|
40 |
+
"webui_path = os.environ.get('WEBUI_PATH')\n",
|
41 |
+
"free_plan = os.environ.get('FREE_PLAN')\n",
|
42 |
+
"\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
"\n",
|
44 |
"def load_settings():\n",
|
45 |
" SETTINGS_FILE = f'{root_path}/settings.json'\n",
|
|
|
54 |
"commandline_arguments = settings.get('commandline_arguments', \"\")\n",
|
55 |
"change_webui = settings.get('change_webui', \"\")\n",
|
56 |
"\n",
|
57 |
+
"\n",
|
58 |
"# ======================== TUNNEL V2 ========================\n",
|
59 |
"print('Please Wait...')\n",
|
60 |
"\n",
|
|
|
88 |
"\n",
|
89 |
"clear_output()\n",
|
90 |
"\n",
|
91 |
+
"\n",
|
92 |
"# =============== Automatic Fixing Path V3 ===============\n",
|
93 |
"paths_to_check = {\n",
|
94 |
" \"tagger_hf_cache_dir\": f\"{webui_path}/models/interrogators/\",\n",
|
files_cells/notebooks/en/widgets_en.ipynb
CHANGED
@@ -1,349 +1,340 @@
|
|
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 |
-
"#
|
36 |
-
"
|
37 |
-
"
|
38 |
-
"
|
39 |
-
"
|
40 |
-
"
|
41 |
-
"
|
42 |
-
"
|
43 |
-
"
|
44 |
-
"
|
45 |
-
"\n",
|
46 |
-
"
|
47 |
-
"
|
48 |
-
"
|
49 |
-
"\n",
|
50 |
-
"\n",
|
51 |
-
"
|
52 |
-
"
|
53 |
-
"
|
54 |
-
"parser =
|
55 |
-
"
|
56 |
-
"
|
57 |
-
"
|
58 |
-
"
|
59 |
-
"
|
60 |
-
"
|
61 |
-
"
|
62 |
-
"
|
63 |
-
"
|
64 |
-
"\n",
|
65 |
-
"
|
66 |
-
"
|
67 |
-
"
|
68 |
-
"
|
69 |
-
"
|
70 |
-
"
|
71 |
-
"
|
72 |
-
"
|
73 |
-
"
|
74 |
-
"\n",
|
75 |
-
"
|
76 |
-
"
|
77 |
-
"
|
78 |
-
"\n",
|
79 |
-
"
|
80 |
-
"
|
81 |
-
"
|
82 |
-
"
|
83 |
-
"
|
84 |
-
"
|
85 |
-
"
|
86 |
-
"
|
87 |
-
":
|
88 |
-
"
|
89 |
-
"
|
90 |
-
" --
|
91 |
-
" --
|
92 |
-
" --
|
93 |
-
"
|
94 |
-
"
|
95 |
-
"
|
96 |
-
"
|
97 |
-
"\n",
|
98 |
-
"
|
99 |
-
"
|
100 |
-
"
|
101 |
-
"
|
102 |
-
"}
|
103 |
-
"
|
104 |
-
"\n",
|
105 |
-
"
|
106 |
-
"
|
107 |
-
"
|
108 |
-
"
|
109 |
-
"
|
110 |
-
"
|
111 |
-
"
|
112 |
-
"
|
113 |
-
"
|
114 |
-
"
|
115 |
-
"
|
116 |
-
"
|
117 |
-
"
|
118 |
-
"
|
119 |
-
"
|
120 |
-
"\n",
|
121 |
-
"
|
122 |
-
"
|
123 |
-
"
|
124 |
-
"
|
125 |
-
"'''\n",
|
126 |
-
"
|
127 |
-
"
|
128 |
-
"
|
129 |
-
"
|
130 |
-
"\n",
|
131 |
-
"
|
132 |
-
"
|
133 |
-
"
|
134 |
-
"
|
135 |
-
"\n",
|
136 |
-
" def
|
137 |
-
"
|
138 |
-
"
|
139 |
-
"
|
140 |
-
" return
|
141 |
-
"\n",
|
142 |
-
" def
|
143 |
-
" return widgets.
|
144 |
-
"\n",
|
145 |
-
" def
|
146 |
-
"
|
147 |
-
"
|
148 |
-
"
|
149 |
-
" return
|
150 |
-
"\n",
|
151 |
-
" def
|
152 |
-
" return widgets.
|
153 |
-
"\n",
|
154 |
-
" def
|
155 |
-
"
|
156 |
-
" if
|
157 |
-
"
|
158 |
-
"
|
159 |
-
"\n",
|
160 |
-
"
|
161 |
-
"
|
162 |
-
"\n",
|
163 |
-
"
|
164 |
-
"
|
165 |
-
"
|
166 |
-
"
|
167 |
-
"
|
168 |
-
"
|
169 |
-
"
|
170 |
-
"
|
171 |
-
"
|
172 |
-
"
|
173 |
-
"
|
174 |
-
"
|
175 |
-
"
|
176 |
-
"
|
177 |
-
"
|
178 |
-
"
|
179 |
-
"
|
180 |
-
"
|
181 |
-
"
|
182 |
-
"
|
183 |
-
"
|
184 |
-
"
|
185 |
-
"
|
186 |
-
"
|
187 |
-
"
|
188 |
-
"
|
189 |
-
"
|
190 |
-
"
|
191 |
-
"
|
192 |
-
"
|
193 |
-
"
|
194 |
-
"
|
195 |
-
"\n",
|
196 |
-
"
|
197 |
-
"
|
198 |
-
"
|
199 |
-
"
|
200 |
-
"
|
201 |
-
"
|
202 |
-
"
|
203 |
-
"
|
204 |
-
"
|
205 |
-
"
|
206 |
-
"\n",
|
207 |
-
"
|
208 |
-
"
|
209 |
-
"
|
210 |
-
"
|
211 |
-
"
|
212 |
-
"
|
213 |
-
"
|
214 |
-
"
|
215 |
-
"
|
216 |
-
"
|
217 |
-
"
|
218 |
-
"\n",
|
219 |
-
"
|
220 |
-
"
|
221 |
-
"
|
222 |
-
"
|
223 |
-
"
|
224 |
-
"
|
225 |
-
"
|
226 |
-
"
|
227 |
-
"
|
228 |
-
"
|
229 |
-
"
|
230 |
-
"\n",
|
231 |
-
"
|
232 |
-
"
|
233 |
-
"
|
234 |
-
"
|
235 |
-
"
|
236 |
-
"
|
237 |
-
"
|
238 |
-
"
|
239 |
-
"
|
240 |
-
"
|
241 |
-
"
|
242 |
-
"
|
243 |
-
"
|
244 |
-
"
|
245 |
-
"
|
246 |
-
"
|
247 |
-
"
|
248 |
-
"
|
249 |
-
"
|
250 |
-
"
|
251 |
-
"
|
252 |
-
"
|
253 |
-
"
|
254 |
-
"
|
255 |
-
"
|
256 |
-
"
|
257 |
-
"
|
258 |
-
"
|
259 |
-
"\n",
|
260 |
-
"
|
261 |
-
"
|
262 |
-
"
|
263 |
-
"
|
264 |
-
"
|
265 |
-
"
|
266 |
-
"
|
267 |
-
"
|
268 |
-
".
|
269 |
-
"
|
270 |
-
"
|
271 |
-
"
|
272 |
-
"\n",
|
273 |
-
"<
|
274 |
-
"
|
275 |
-
"<
|
276 |
-
"<
|
277 |
-
"
|
278 |
-
"
|
279 |
-
"
|
280 |
-
"
|
281 |
-
"
|
282 |
-
"
|
283 |
-
"
|
284 |
-
"
|
285 |
-
"
|
286 |
-
"
|
287 |
-
"
|
288 |
-
"
|
289 |
-
"\n",
|
290 |
-
"Model_url_widget
|
291 |
-
"
|
292 |
-
"
|
293 |
-
"
|
294 |
-
"
|
295 |
-
"
|
296 |
-
"\n",
|
297 |
-
"
|
298 |
-
"
|
299 |
-
"
|
300 |
-
"
|
301 |
-
"
|
302 |
-
"\n",
|
303 |
-
"
|
304 |
-
"
|
305 |
-
"
|
306 |
-
"
|
307 |
-
"
|
308 |
-
"
|
309 |
-
"
|
310 |
-
"\n",
|
311 |
-
"
|
312 |
-
"
|
313 |
-
"
|
314 |
-
"
|
315 |
-
"
|
316 |
-
"
|
317 |
-
"
|
318 |
-
"
|
319 |
-
"
|
320 |
-
"\n",
|
321 |
-
"
|
322 |
-
"
|
323 |
-
"
|
324 |
-
"
|
325 |
-
"\n",
|
326 |
-
"
|
327 |
-
"
|
328 |
-
"
|
329 |
-
"
|
330 |
-
"
|
331 |
-
"
|
332 |
-
"\n",
|
333 |
-
"
|
334 |
-
"
|
335 |
-
"
|
336 |
-
"
|
337 |
-
|
338 |
-
|
339 |
-
|
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 |
+
"# Setup Env\n",
|
36 |
+
"env = os.environ.get('ENV_NAME')\n",
|
37 |
+
"root_path = os.environ.get('ROOT_PATH')\n",
|
38 |
+
"webui_path = os.environ.get('WEBUI_PATH')\n",
|
39 |
+
"free_plan = os.environ.get('FREE_PLAN')\n",
|
40 |
+
"\n",
|
41 |
+
"\n",
|
42 |
+
"# ==================== CSS JS ====================\n",
|
43 |
+
"##~ custom background images V1.5 ~##\n",
|
44 |
+
"import argparse\n",
|
45 |
+
"parser = argparse.ArgumentParser(description='This script processes an background image.')\n",
|
46 |
+
"parser.add_argument('-i', '--image', type=str, help='URL of the image to process', metavar='')\n",
|
47 |
+
"parser.add_argument('-o', '--opacity', type=float, help='Opacity level for the image, between 0 and 1', metavar='', default=0.3)\n",
|
48 |
+
"parser.add_argument('-b', '--blur', type=str, help='Blur level for the image', metavar='', default=0)\n",
|
49 |
+
"parser.add_argument('-y', type=int, help='Y coordinate for the image in px', metavar='', default=0)\n",
|
50 |
+
"parser.add_argument('-x', type=int, help='X coordinate for the image in px', metavar='', default=0)\n",
|
51 |
+
"parser.add_argument('-s', '--scale', type=int, help='Scale image in %%', metavar='', default=100)\n",
|
52 |
+
"parser.add_argument('-m', '--mode', action='store_true', help='Removes repetitive image tiles')\n",
|
53 |
+
"parser.add_argument('-t', '--transparent', action='store_true', help='Makes input/selection fields 35%% more transparent')\n",
|
54 |
+
"parser.add_argument('-bf', '--blur-fields', type=str, help='Background blur level for input/selection fields', metavar='', default=2)\n",
|
55 |
+
"\n",
|
56 |
+
"args = parser.parse_args()\n",
|
57 |
+
"\n",
|
58 |
+
"url_img = args.image\n",
|
59 |
+
"opacity_img = args.opacity\n",
|
60 |
+
"blur_img = args.blur\n",
|
61 |
+
"y_img = args.y\n",
|
62 |
+
"x_img = args.x\n",
|
63 |
+
"scale_img = args.scale\n",
|
64 |
+
"blur_fields = args.blur_fields\n",
|
65 |
+
"\n",
|
66 |
+
"## ---\n",
|
67 |
+
"\"\"\" WTF KAGGLE - WHAT THE FUCK IS THE DIFFERENCE OF 35 PIXELS!?!?!? \"\"\"\n",
|
68 |
+
"fix_heigh_img = \"-810px\" if env == \"Kaggle\" else \"-775px\"\n",
|
69 |
+
"\n",
|
70 |
+
"\"\"\" transperent fields \"\"\"\n",
|
71 |
+
"t_bg_alpha = \"1\" if not args.transparent else \"0.65\"\n",
|
72 |
+
"\n",
|
73 |
+
"\"\"\" mode img - repeats \"\"\"\n",
|
74 |
+
"mode_img = \"repeat\" if not args.mode else \"no-repeat\"\n",
|
75 |
+
"\n",
|
76 |
+
"container_background = f'''\n",
|
77 |
+
"<style>\n",
|
78 |
+
":root {{\n",
|
79 |
+
" /* for background container*/\n",
|
80 |
+
" --img_background: url({url_img});\n",
|
81 |
+
" --img_opacity: {opacity_img};\n",
|
82 |
+
" --img_blur: {blur_img}px;\n",
|
83 |
+
" --image_y: {y_img}px;\n",
|
84 |
+
" --image_x: {x_img}px;\n",
|
85 |
+
" --img_scale: {scale_img}%;\n",
|
86 |
+
" --img_mode: {mode_img};\n",
|
87 |
+
" --img_height_dif: {fix_heigh_img};\n",
|
88 |
+
"\n",
|
89 |
+
" /* for fields */\n",
|
90 |
+
" --bg-field-color: rgba(28, 28, 28, {t_bg_alpha}); /* -> #1c1c1c */\n",
|
91 |
+
" --bg-field-color-hover: rgba(38, 38, 38, {t_bg_alpha}); /* -> #262626; */\n",
|
92 |
+
" --bg-field-blur-level: {blur_fields}px;\n",
|
93 |
+
"}}\n",
|
94 |
+
"'''\n",
|
95 |
+
"\n",
|
96 |
+
"display(HTML(container_background))\n",
|
97 |
+
"\n",
|
98 |
+
"# Main CSS\n",
|
99 |
+
"css_file_path = f\"{root_path}/CSS/main_widgets.css\"\n",
|
100 |
+
"with open(css_file_path , \"r\") as f:\n",
|
101 |
+
" CSS = f.read()\n",
|
102 |
+
"display(HTML(f\"<style>{CSS}</style>\"))\n",
|
103 |
+
"\n",
|
104 |
+
"# Main JS\n",
|
105 |
+
"JS = '''\n",
|
106 |
+
"<!-- TOGGLE 'CustomDL' SCRIPT -->\n",
|
107 |
+
"<script>\n",
|
108 |
+
"function toggleContainer() {\n",
|
109 |
+
" let downloadContainer = document.querySelector('.container_custom_downlad');\n",
|
110 |
+
" let info = document.querySelector('.info');\n",
|
111 |
+
"\n",
|
112 |
+
" downloadContainer.classList.toggle('expanded');\n",
|
113 |
+
" info.classList.toggle('showed');\n",
|
114 |
+
"}\n",
|
115 |
+
"</script>\n",
|
116 |
+
"'''\n",
|
117 |
+
"display(HTML(JS))\n",
|
118 |
+
"\n",
|
119 |
+
"# ==================== WIDGETS V2 ====================\n",
|
120 |
+
"HR = widgets.HTML('<hr>')\n",
|
121 |
+
"\n",
|
122 |
+
"class WidgetFactory:\n",
|
123 |
+
" def __init__(self, style=None, layout=None):\n",
|
124 |
+
" self.style = style if style else {'description_width': 'initial'}\n",
|
125 |
+
" self.layout = layout if layout else widgets.Layout(max_width='1080px', width='100%')\n",
|
126 |
+
"\n",
|
127 |
+
" def create_html(self, content, class_name=None):\n",
|
128 |
+
" html_widget = widgets.HTML(content)\n",
|
129 |
+
" if class_name:\n",
|
130 |
+
" html_widget.add_class(class_name)\n",
|
131 |
+
" return html_widget\n",
|
132 |
+
"\n",
|
133 |
+
" def create_header(self, name):\n",
|
134 |
+
" return widgets.HTML(f'<div class=\"header\">{name}<div>')\n",
|
135 |
+
"\n",
|
136 |
+
" def create_dropdown(self, options, value, description):\n",
|
137 |
+
" return widgets.Dropdown(options=options, value=value, description=description, style=self.style, layout=self.layout)\n",
|
138 |
+
"\n",
|
139 |
+
" def create_text(self, description, placeholder='', value=''):\n",
|
140 |
+
" return widgets.Text(description=description, placeholder=placeholder, value=value, style=self.style, layout=self.layout)\n",
|
141 |
+
"\n",
|
142 |
+
" def create_checkbox(self, value, description):\n",
|
143 |
+
" return widgets.Checkbox(value=value, description=description, style=self.style, layout=self.layout)\n",
|
144 |
+
"\n",
|
145 |
+
" def create_button(self, description, class_name=None):\n",
|
146 |
+
" button = widgets.Button(description=description)\n",
|
147 |
+
" if class_name:\n",
|
148 |
+
" button.add_class(class_name)\n",
|
149 |
+
" return button\n",
|
150 |
+
"\n",
|
151 |
+
" def create_hbox(self, children):\n",
|
152 |
+
" return widgets.HBox(children)\n",
|
153 |
+
"\n",
|
154 |
+
" def create_vbox(self, children, class_names=None):\n",
|
155 |
+
" vbox = widgets.VBox(children)\n",
|
156 |
+
" if class_names:\n",
|
157 |
+
" for class_name in class_names:\n",
|
158 |
+
" vbox.add_class(class_name)\n",
|
159 |
+
" return vbox\n",
|
160 |
+
"\n",
|
161 |
+
" def display(self, widget):\n",
|
162 |
+
" display(widget)\n",
|
163 |
+
"\n",
|
164 |
+
"# Instantiate the factory\n",
|
165 |
+
"factory = WidgetFactory()\n",
|
166 |
+
"\n",
|
167 |
+
"# --- MODEL ---\n",
|
168 |
+
"model_header = factory.create_header('Model Selection')\n",
|
169 |
+
"model_options = ['none',\n",
|
170 |
+
" '1.Anime (by XpucT) + INP',\n",
|
171 |
+
" '2.BluMix [Anime] [V7] + INP',\n",
|
172 |
+
" '3.Cetus-Mix [Anime] [V4] + INP',\n",
|
173 |
+
" '4.Counterfeit [Anime] [V3] + INP',\n",
|
174 |
+
" '5.CuteColor [Anime] [V3]',\n",
|
175 |
+
" '6.Dark-Sushi-Mix [Anime]',\n",
|
176 |
+
" '7.Deliberate [Realism] [V6] + INP',\n",
|
177 |
+
" '8.Meina-Mix [Anime] [V11] + INP',\n",
|
178 |
+
" '9.Mix-Pro [Anime] [V4] + INP']\n",
|
179 |
+
"model_widget = factory.create_dropdown(model_options, '4.Counterfeit [Anime] [V3] + INP', 'Model:')\n",
|
180 |
+
"model_num_widget = factory.create_text('Model Number:', 'Enter the model numbers to be downloaded using comma/space.')\n",
|
181 |
+
"inpainting_model_widget = factory.create_checkbox(False, 'Inpainting Models')\n",
|
182 |
+
"\n",
|
183 |
+
"# Display Model\n",
|
184 |
+
"all_model_box = factory.create_vbox([model_header, model_widget, model_num_widget, inpainting_model_widget], class_names=[\"container\", \"image_1\"])\n",
|
185 |
+
"factory.display(all_model_box)\n",
|
186 |
+
"\n",
|
187 |
+
"# --- VAE ---\n",
|
188 |
+
"vae_header = factory.create_header('VAE Selection')\n",
|
189 |
+
"vae_options = ['none',\n",
|
190 |
+
" '1.Anime.vae',\n",
|
191 |
+
" '2.Anything.vae',\n",
|
192 |
+
" '3.Blessed2.vae',\n",
|
193 |
+
" '4.ClearVae.vae',\n",
|
194 |
+
" '5.WD.vae']\n",
|
195 |
+
"vae_widget = factory.create_dropdown(vae_options, '3.Blessed2.vae', 'Vae:')\n",
|
196 |
+
"vae_num_widget = factory.create_text('Vae Number:', 'Enter the vae numbers to be downloaded using comma/space.')\n",
|
197 |
+
"\n",
|
198 |
+
"# Display Vae\n",
|
199 |
+
"all_vae_box = factory.create_vbox([vae_header, vae_widget, vae_num_widget], class_names=[\"container\", \"image_2\"])\n",
|
200 |
+
"factory.display(all_vae_box)\n",
|
201 |
+
"\n",
|
202 |
+
"# --- ADDITIONAL ---\n",
|
203 |
+
"additional_header = factory.create_header('Additional')\n",
|
204 |
+
"latest_webui_widget = factory.create_checkbox(True, 'Update WebUI')\n",
|
205 |
+
"latest_exstensions_widget = factory.create_checkbox(True, 'Update Extensions')\n",
|
206 |
+
"change_webui_widget = factory.create_dropdown(['A1111', 'Forge'], 'A1111', 'Change WebUI:')\n",
|
207 |
+
"detailed_download_widget = factory.create_dropdown(['off', 'on'], 'off', 'Detailed Download:')\n",
|
208 |
+
"choose_changes_widget = factory.create_hbox([latest_webui_widget, latest_exstensions_widget, change_webui_widget, detailed_download_widget])\n",
|
209 |
+
"\n",
|
210 |
+
"controlnet_options = ['none', 'ALL', '1.canny',\n",
|
211 |
+
" '2.openpose', '3.depth',\n",
|
212 |
+
" '4.normal_map', '5.mlsd',\n",
|
213 |
+
" '6.lineart', '7.soft_edge',\n",
|
214 |
+
" '8.scribble', '9.segmentation',\n",
|
215 |
+
" '10.shuffle', '11.tile',\n",
|
216 |
+
" '12.inpaint', '13.instruct_p2p']\n",
|
217 |
+
"controlnet_widget = factory.create_dropdown(controlnet_options, 'none', 'ControlNet:')\n",
|
218 |
+
"controlnet_num_widget = factory.create_text('ControlNet Number:', 'Enter the ControlNet model numbers to be downloaded using comma/space.')\n",
|
219 |
+
"commit_hash_widget = factory.create_text('Commit Hash:')\n",
|
220 |
+
"huggingface_token_widget = factory.create_text('HuggingFace Token:')\n",
|
221 |
+
"\n",
|
222 |
+
"ngrok_token_widget = factory.create_text('Ngrok Token:')\n",
|
223 |
+
"ngrock_button = factory.create_html('<a href=\"https://dashboard.ngrok.com/get-started/your-authtoken\" target=\"_blank\">Получить Ngrok Токен</a>', class_name=\"button_ngrok\")\n",
|
224 |
+
"ngrok_widget = factory.create_hbox([ngrok_token_widget, ngrock_button])\n",
|
225 |
+
"\n",
|
226 |
+
"zrok_token_widget = factory.create_text('Zrok Token:')\n",
|
227 |
+
"zrok_button = factory.create_html('<a href=\"https://colab.research.google.com/drive/1d2sjWDJi_GYBUavrHSuQyHTDuLy36WpU\" target=\"_blank\">Зарегать Zrok Токен</a>', class_name=\"button_ngrok\")\n",
|
228 |
+
"zrok_widget = factory.create_hbox([zrok_token_widget, zrok_button])\n",
|
229 |
+
"\n",
|
230 |
+
"commandline_arguments_options = \"--listen --enable-insecure-extension-access --theme dark --no-half-vae --disable-console-progressbars --xformers\"\n",
|
231 |
+
"commandline_arguments_widget = factory.create_text('Arguments:', value=commandline_arguments_options)\n",
|
232 |
+
"\n",
|
233 |
+
"# Display Additional\n",
|
234 |
+
"additional_widget_list = [additional_header,\n",
|
235 |
+
" choose_changes_widget,\n",
|
236 |
+
" HR,\n",
|
237 |
+
" controlnet_widget,\n",
|
238 |
+
" controlnet_num_widget,\n",
|
239 |
+
" commit_hash_widget,\n",
|
240 |
+
" huggingface_token_widget,\n",
|
241 |
+
" ngrok_widget,\n",
|
242 |
+
" zrok_widget,\n",
|
243 |
+
" HR,\n",
|
244 |
+
" commandline_arguments_widget]\n",
|
245 |
+
"\n",
|
246 |
+
"if free_plan and env == \"Google Colab\": # remove ngrok from colab\n",
|
247 |
+
" additional_widget_list.remove(ngrok_widget)\n",
|
248 |
+
"if os.path.exists(webui_path): # remove selection after selection ;3\n",
|
249 |
+
" choose_changes_widget.children = [widget for widget in choose_changes_widget.children if widget != change_webui_widget]\n",
|
250 |
+
"\n",
|
251 |
+
"all_additional_box = factory.create_vbox(additional_widget_list, class_names=[\"container\", \"image_3\"])\n",
|
252 |
+
"factory.display(all_additional_box)\n",
|
253 |
+
"\n",
|
254 |
+
"# --- CUSTOM DOWNLOAD ---\n",
|
255 |
+
"custom_download_header_popup = factory.create_html('''\n",
|
256 |
+
"<style>\n",
|
257 |
+
"/* Term Colors */\n",
|
258 |
+
".sample_label {color: #dbafff;}\n",
|
259 |
+
".braces {color: #ffff00;}\n",
|
260 |
+
".extension {color: #eb934b;}\n",
|
261 |
+
".file_name {color: #ffffd8;}\n",
|
262 |
+
"</style>\n",
|
263 |
+
"\n",
|
264 |
+
"<div class=\"header\" style=\"cursor: pointer;\" onclick=\"toggleContainer()\">Custom Download</div>\n",
|
265 |
+
"<!-- PopUp Window -->\n",
|
266 |
+
"<div class=\"info\">INFO</div>\n",
|
267 |
+
"<div class=\"popup\">\n",
|
268 |
+
" 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",
|
269 |
+
" after the URL without spaces.\n",
|
270 |
+
" <span style=\"color: #ff9999\">For files, be sure to specify</span> - <span class=\"extension\">Filename Extension.</span>\n",
|
271 |
+
" <div class=\"sample\">\n",
|
272 |
+
" <span class=\"sample_label\">Example for File:</span>\n",
|
273 |
+
" 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",
|
274 |
+
" <br>\n",
|
275 |
+
" <span class=\"sample_label\">Example for Extension:</span>\n",
|
276 |
+
" 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",
|
277 |
+
" </div>\n",
|
278 |
+
"</div>\n",
|
279 |
+
"''')\n",
|
280 |
+
"\n",
|
281 |
+
"Model_url_widget = factory.create_text('Model:')\n",
|
282 |
+
"Vae_url_widget = factory.create_text('Vae:')\n",
|
283 |
+
"LoRA_url_widget = factory.create_text('LoRa:')\n",
|
284 |
+
"Embedding_url_widget = factory.create_text('Embedding:')\n",
|
285 |
+
"Extensions_url_widget = factory.create_text('Extensions:')\n",
|
286 |
+
"custom_file_urls_widget = factory.create_text('File (txt):')\n",
|
287 |
+
"\n",
|
288 |
+
"# Display CustomDl\n",
|
289 |
+
"all_custom_box = factory.create_vbox([\n",
|
290 |
+
" custom_download_header_popup, Model_url_widget, Vae_url_widget, LoRA_url_widget, Embedding_url_widget, Extensions_url_widget, custom_file_urls_widget\n",
|
291 |
+
"], class_names=[\"container\", \"image_4\", \"container_custom_downlad\"])\n",
|
292 |
+
"factory.display(all_custom_box)\n",
|
293 |
+
"\n",
|
294 |
+
"# --- Save Button ---\n",
|
295 |
+
"save_button = factory.create_button('Save', class_name=\"button_save\")\n",
|
296 |
+
"factory.display(save_button)\n",
|
297 |
+
"\n",
|
298 |
+
"\n",
|
299 |
+
"# ============ Load / Save - Settings V2 ============\n",
|
300 |
+
"SETTINGS_FILE = f'{root_path}/settings.json'\n",
|
301 |
+
"\n",
|
302 |
+
"SETTINGS_KEYS = [\n",
|
303 |
+
" 'model', 'model_num', 'inpainting_model',\n",
|
304 |
+
" 'vae', 'vae_num', 'latest_webui', 'latest_exstensions',\n",
|
305 |
+
" 'change_webui', 'detailed_download', 'controlnet',\n",
|
306 |
+
" 'controlnet_num', 'commit_hash', 'huggingface_token',\n",
|
307 |
+
" 'ngrok_token', 'zrok_token', 'commandline_arguments',\n",
|
308 |
+
" 'Model_url', 'Vae_url', 'LoRA_url', 'Embedding_url',\n",
|
309 |
+
" 'Extensions_url', 'custom_file_urls'\n",
|
310 |
+
"]\n",
|
311 |
+
"\n",
|
312 |
+
"def save_settings():\n",
|
313 |
+
" settings = {key: globals()[f\"{key}_widget\"].value for key in SETTINGS_KEYS}\n",
|
314 |
+
" with open(SETTINGS_FILE, 'w') as f:\n",
|
315 |
+
" json.dump(settings, f, indent=2)\n",
|
316 |
+
"\n",
|
317 |
+
"def load_settings():\n",
|
318 |
+
" if os.path.exists(SETTINGS_FILE):\n",
|
319 |
+
" with open(SETTINGS_FILE, 'r') as f:\n",
|
320 |
+
" settings = json.load(f)\n",
|
321 |
+
" for key in SETTINGS_KEYS:\n",
|
322 |
+
" globals()[f\"{key}_widget\"].value = settings.get(key, \"\")\n",
|
323 |
+
"\n",
|
324 |
+
"def hide_widgets():\n",
|
325 |
+
" widgets_list = [all_model_box, all_vae_box, all_additional_box, all_custom_box, save_button]\n",
|
326 |
+
" for widget in widgets_list:\n",
|
327 |
+
" widget.add_class(\"hide\")\n",
|
328 |
+
" time.sleep(0.5)\n",
|
329 |
+
" widgets.Widget.close_all()\n",
|
330 |
+
"\n",
|
331 |
+
"def save_data(button):\n",
|
332 |
+
" save_settings()\n",
|
333 |
+
" hide_widgets()\n",
|
334 |
+
"\n",
|
335 |
+
"load_settings()\n",
|
336 |
+
"save_button.on_click(save_data)"
|
337 |
+
]
|
338 |
+
}
|
339 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
340 |
}
|
files_cells/notebooks/ru/auto_cleaner_ru.ipynb
CHANGED
@@ -1,165 +1,157 @@
|
|
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 |
-
"#
|
35 |
-
"
|
36 |
-
"
|
37 |
-
"
|
38 |
-
"
|
39 |
-
"
|
40 |
-
"
|
41 |
-
"
|
42 |
-
"
|
43 |
-
"
|
44 |
-
"\n",
|
45 |
-
"
|
46 |
-
"
|
47 |
-
"\n",
|
48 |
-
"\n",
|
49 |
-
"#
|
50 |
-
"
|
51 |
-
"
|
52 |
-
"
|
53 |
-
"
|
54 |
-
"
|
55 |
-
"\n",
|
56 |
-
"\n",
|
57 |
-
"
|
58 |
-
"
|
59 |
-
"
|
60 |
-
"
|
61 |
-
"
|
62 |
-
"
|
63 |
-
"
|
64 |
-
"
|
65 |
-
"\n",
|
66 |
-
"\
|
67 |
-
"
|
68 |
-
"
|
69 |
-
"
|
70 |
-
"\n",
|
71 |
-
"
|
72 |
-
"
|
73 |
-
"
|
74 |
-
"\n",
|
75 |
-
"
|
76 |
-
"
|
77 |
-
"
|
78 |
-
"
|
79 |
-
"\n",
|
80 |
-
"
|
81 |
-
"
|
82 |
-
"\n",
|
83 |
-
"
|
84 |
-
"
|
85 |
-
"
|
86 |
-
"
|
87 |
-
"
|
88 |
-
"\n",
|
89 |
-
"
|
90 |
-
"
|
91 |
-
"
|
92 |
-
"\n",
|
93 |
-
"
|
94 |
-
"
|
95 |
-
"
|
96 |
-
"
|
97 |
-
"
|
98 |
-
"
|
99 |
-
"
|
100 |
-
"\n",
|
101 |
-
"
|
102 |
-
"
|
103 |
-
"
|
104 |
-
"
|
105 |
-
"
|
106 |
-
"
|
107 |
-
"
|
108 |
-
"
|
109 |
-
"\n",
|
110 |
-
"
|
111 |
-
"
|
112 |
-
"
|
113 |
-
"
|
114 |
-
"\n",
|
115 |
-
"
|
116 |
-
"
|
117 |
-
"
|
118 |
-
" \"
|
119 |
-
"
|
120 |
-
"
|
121 |
-
"
|
122 |
-
"
|
123 |
-
"
|
124 |
-
"
|
125 |
-
"
|
126 |
-
"
|
127 |
-
"
|
128 |
-
"\n",
|
129 |
-
"\n",
|
130 |
-
"#
|
131 |
-
"
|
132 |
-
"
|
133 |
-
"
|
134 |
-
"
|
135 |
-
"
|
136 |
-
"\n",
|
137 |
-
"\n",
|
138 |
-
"
|
139 |
-
"
|
140 |
-
"
|
141 |
-
"
|
142 |
-
"
|
143 |
-
"
|
144 |
-
"
|
145 |
-
"
|
146 |
-
"\n",
|
147 |
-
"
|
148 |
-
"
|
149 |
-
"
|
150 |
-
"
|
151 |
-
"\n",
|
152 |
-
"
|
153 |
-
"
|
154 |
-
|
155 |
-
|
156 |
-
|
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 |
+
"# Setup Env\n",
|
35 |
+
"env = os.environ.get('ENV_NAME')\n",
|
36 |
+
"root_path = os.environ.get('ROOT_PATH')\n",
|
37 |
+
"webui_path = os.environ.get('WEBUI_PATH')\n",
|
38 |
+
"free_plan = os.environ.get('FREE_PLAN')\n",
|
39 |
+
"\n",
|
40 |
+
"\n",
|
41 |
+
"# ==================== CSS ====================\n",
|
42 |
+
"# Main CSS\n",
|
43 |
+
"css_file_path = f\"{root_path}/CSS/auto_cleaner.css\"\n",
|
44 |
+
"with open(css_file_path , \"r\") as f:\n",
|
45 |
+
" CSS_AC = f.read()\n",
|
46 |
+
"display(HTML(f\"<style>{CSS_AC}</style>\"))\n",
|
47 |
+
"\n",
|
48 |
+
"\n",
|
49 |
+
"# ================ AutoCleaner function ================\n",
|
50 |
+
"directories = {\n",
|
51 |
+
" \"Изображения\": f\"{webui_path}/output\",\n",
|
52 |
+
" \"Модели\": f\"{webui_path}/models/Stable-diffusion/\",\n",
|
53 |
+
" \"Vae\": f\"{webui_path}/models/VAE/\",\n",
|
54 |
+
" \"LoRa\": f\"{webui_path}/models/Lora/\",\n",
|
55 |
+
" \"ControlNet Модели\": f\"{webui_path}/models/ControlNet/\"\n",
|
56 |
+
"}\n",
|
57 |
+
"\n",
|
58 |
+
"\"\"\" functions \"\"\"\n",
|
59 |
+
"def clean_directory(directory):\n",
|
60 |
+
" deleted_files = 0\n",
|
61 |
+
" image_dir = directories['Изображения']\n",
|
62 |
+
"\n",
|
63 |
+
" for root, dirs, files in os.walk(directory):\n",
|
64 |
+
" for file in files:\n",
|
65 |
+
" file_path = os.path.join(root, file)\n",
|
66 |
+
"\n",
|
67 |
+
" if file.endswith(\".txt\"):\n",
|
68 |
+
" continue\n",
|
69 |
+
" if file.endswith((\".safetensors\", \".pt\")) or root == image_dir: # fix for image counter\n",
|
70 |
+
" deleted_files += 1\n",
|
71 |
+
"\n",
|
72 |
+
" os.remove(file_path)\n",
|
73 |
+
" return deleted_files\n",
|
74 |
+
"\n",
|
75 |
+
"def update_memory_info():\n",
|
76 |
+
" disk_space = psutil.disk_usage(os.getcwd())\n",
|
77 |
+
" total = disk_space.total / (1024 ** 3)\n",
|
78 |
+
" used = disk_space.used / (1024 ** 3)\n",
|
79 |
+
" free = disk_space.free / (1024 ** 3)\n",
|
80 |
+
"\n",
|
81 |
+
" storage_info.value = f'''\n",
|
82 |
+
" <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",
|
83 |
+
" '''\n",
|
84 |
+
"\n",
|
85 |
+
"def on_execute_button_press(button):\n",
|
86 |
+
" selected_cleaners = auto_cleaner_widget.value\n",
|
87 |
+
" deleted_files_dict = {}\n",
|
88 |
+
"\n",
|
89 |
+
" for option in selected_cleaners:\n",
|
90 |
+
" if option in directories:\n",
|
91 |
+
" deleted_files_dict[option] = clean_directory(directories[option])\n",
|
92 |
+
"\n",
|
93 |
+
" output.clear_output()\n",
|
94 |
+
"\n",
|
95 |
+
" with output:\n",
|
96 |
+
" for message in generate_messages(deleted_files_dict):\n",
|
97 |
+
" message_widget = HTML(f'<p class=\"output_message_AC\">{message}</p>')\n",
|
98 |
+
" display(message_widget)\n",
|
99 |
+
"\n",
|
100 |
+
" update_memory_info()\n",
|
101 |
+
"\n",
|
102 |
+
"def on_clear_button_press(button):\n",
|
103 |
+
" container.add_class(\"hide\")\n",
|
104 |
+
" time.sleep(0.5)\n",
|
105 |
+
" widgets.Widget.close_all()\n",
|
106 |
+
"\n",
|
107 |
+
"def generate_messages(deleted_files_dict):\n",
|
108 |
+
" messages = []\n",
|
109 |
+
" word_variants = {\n",
|
110 |
+
" \"Изображения\": \"Изображений\",\n",
|
111 |
+
" \"Модели\": \"Моделей\",\n",
|
112 |
+
" \"Vae\": \"Vae\",\n",
|
113 |
+
" \"LoRa\": \"LoRa\",\n",
|
114 |
+
" \"ControlNet Модели\": \"ControlNet Моделей\"\n",
|
115 |
+
" }\n",
|
116 |
+
" for key, value in deleted_files_dict.items():\n",
|
117 |
+
" object_word = word_variants.get(key)\n",
|
118 |
+
" messages.append(f\"Удалено {value} {object_word}\")\n",
|
119 |
+
" return messages\n",
|
120 |
+
"\n",
|
121 |
+
"\n",
|
122 |
+
"# --- storage memory ---\n",
|
123 |
+
"import psutil\n",
|
124 |
+
"disk_space = psutil.disk_usage(os.getcwd())\n",
|
125 |
+
"total = disk_space.total / (1024 ** 3)\n",
|
126 |
+
"used = disk_space.used / (1024 ** 3)\n",
|
127 |
+
"free = disk_space.free / (1024 ** 3)\n",
|
128 |
+
"\n",
|
129 |
+
"\n",
|
130 |
+
"# ================ Widgets ================\n",
|
131 |
+
"# UI Code\n",
|
132 |
+
"AutoCleaner_options = AutoCleaner_options = list(directories.keys())\n",
|
133 |
+
"instruction_label = widgets.HTML('''\n",
|
134 |
+
"<span class=\"instruction_AC\">Используйте <span style=\"color: #B2B2B2;\">ctrl</span> или <span style=\"color: #B2B2B2;\">shift</span> для множественного выбора.</span>\n",
|
135 |
+
"''')\n",
|
136 |
+
"auto_cleaner_widget = widgets.SelectMultiple(options=AutoCleaner_options, layout=widgets.Layout(width=\"auto\")).add_class(\"custom-select-multiple_AC\")\n",
|
137 |
+
"output = widgets.Output().add_class(\"output_AC\")\n",
|
138 |
+
"\n",
|
139 |
+
"execute_button = Button(description='Выполнить Очистку').add_class(\"button_execute_AC\").add_class(\"button_AC\")\n",
|
140 |
+
"execute_button.on_click(on_execute_button_press)\n",
|
141 |
+
"clear_button = Button(description='Скрыть Виджет').add_class(\"button_clear_AC\").add_class(\"button_AC\")\n",
|
142 |
+
"clear_button.on_click(on_clear_button_press)\n",
|
143 |
+
"\n",
|
144 |
+
"storage_info = widgets.HTML(f'''\n",
|
145 |
+
"<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",
|
146 |
+
"''')\n",
|
147 |
+
"\n",
|
148 |
+
"buttons = widgets.HBox([execute_button, clear_button])\n",
|
149 |
+
"lower_information_panel = widgets.HBox([buttons, storage_info]).add_class(\"lower_information_panel_AC\")\n",
|
150 |
+
"\n",
|
151 |
+
"container = VBox([instruction_label, widgets.HTML('<hr>'), auto_cleaner_widget, output, widgets.HTML('<hr>'), lower_information_panel]).add_class(\"container_AC\")\n",
|
152 |
+
"\n",
|
153 |
+
"display(container)"
|
154 |
+
]
|
155 |
+
}
|
156 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
}
|
files_cells/notebooks/ru/downloading_ru.ipynb
CHANGED
@@ -10,6 +10,8 @@
|
|
10 |
"source": [
|
11 |
"##~ DOWNLOADING CODE | BY: ANXETY ~##\n",
|
12 |
"\n",
|
|
|
|
|
13 |
"import os\n",
|
14 |
"import re\n",
|
15 |
"import time\n",
|
@@ -25,19 +27,11 @@
|
|
25 |
"from urllib.parse import urlparse, parse_qs\n",
|
26 |
"\n",
|
27 |
"\n",
|
28 |
-
"#
|
29 |
-
"
|
30 |
-
"
|
31 |
-
"
|
32 |
-
"
|
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",
|
@@ -207,112 +201,9 @@
|
|
207 |
"\n",
|
208 |
"## Downloading model and stuff | oh~ Hey! If you're freaked out by that code too, don't worry, me too!\n",
|
209 |
"print(\"📦 Скачивание моделей и прочего...\", end='')\n",
|
210 |
-
"model_list = {\n",
|
211 |
-
" \"1.Anime (by XpucT) + INP\": [\n",
|
212 |
-
" {\"url\": \"https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2.safetensors\", \"name\": \"Anime_V2.safetensors\"},\n",
|
213 |
-
" {\"url\": \"https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2-inpainting.safetensors\", \"name\": \"Anime_V2-inpainting.safetensors\"}\n",
|
214 |
-
" ],\n",
|
215 |
-
" \"2.BluMix [Anime] [V7] + INP\": [\n",
|
216 |
-
" {\"url\": \"https://civitai.com/api/download/models/361779\", \"name\": \"BluMix_V7.safetensors\"},\n",
|
217 |
-
" {\"url\": \"https://civitai.com/api/download/models/363850\", \"name\": \"BluMix_V7-inpainting.safetensors\"}\n",
|
218 |
-
" ],\n",
|
219 |
-
" \"3.Cetus-Mix [Anime] [V4] + INP\": [\n",
|
220 |
-
" {\"url\": \"https://civitai.com/api/download/models/130298\", \"name\": \"CetusMix_V4.safetensors\"},\n",
|
221 |
-
" {\"url\": \"https://civitai.com/api/download/models/139882\", \"name\": \"CetusMix_V4-inpainting.safetensors\"}\n",
|
222 |
-
" ],\n",
|
223 |
-
" \"4.Counterfeit [Anime] [V3] + INP\": [\n",
|
224 |
-
" {\"url\": \"https://huggingface.co/gsdf/Counterfeit-V3.0/resolve/main/Counterfeit-V3.0_fix_fp16.safetensors\", \"name\": \"Counterfeit_V3.safetensors\"},\n",
|
225 |
-
" {\"url\": \"https://civitai.com/api/download/models/137911\", \"name\": \"Counterfeit_V3-inpainting.safetensors\"}\n",
|
226 |
-
" ],\n",
|
227 |
-
" \"5.CuteColor [Anime] [V3]\": [\n",
|
228 |
-
" {\"url\": \"https://civitai.com/api/download/models/138754\", \"name\": \"CuteColor_V3.safetensors\"}\n",
|
229 |
-
" ],\n",
|
230 |
-
" \"6.Dark-Sushi-Mix [Anime]\": [\n",
|
231 |
-
" {\"url\": \"https://civitai.com/api/download/models/101640\", \"name\": \"DarkSushiMix_2_5D.safetensors\"},\n",
|
232 |
-
" {\"url\": \"https://civitai.com/api/download/models/56071\", \"name\": \"DarkSushiMix_colorful.safetensors\"}\n",
|
233 |
-
" ],\n",
|
234 |
-
" \"7.Deliberate [Realism] [V6] + INP\": [\n",
|
235 |
-
" {\"url\": \"https://huggingface.co/XpucT/Deliberate/resolve/main/Deliberate_v6.safetensors\", \"name\": \"Deliberate_V6.safetensors\"},\n",
|
236 |
-
" {\"url\": \"https://huggingface.co/XpucT/Deliberate/resolve/main/Deliberate_v6-inpainting.safetensors\", \"name\": \"Deliberate_V6-inpainting.safetensors\"}\n",
|
237 |
-
" ],\n",
|
238 |
-
" \"8.Meina-Mix [Anime] [V11] + INP\": [\n",
|
239 |
-
" {\"url\": \"https://civitai.com/api/download/models/119057\", \"name\": \"MeinaMix_V11.safetensors\"},\n",
|
240 |
-
" {\"url\": \"https://civitai.com/api/download/models/120702\", \"name\": \"MeinaMix_V11-inpainting.safetensors\"}\n",
|
241 |
-
" ],\n",
|
242 |
-
" \"9.Mix-Pro [Anime] [V4] + INP\": [\n",
|
243 |
-
" {\"url\": \"https://civitai.com/api/download/models/125668\", \"name\": \"MixPro_V4.safetensors\"},\n",
|
244 |
-
" {\"url\": \"https://civitai.com/api/download/models/139878\", \"name\": \"MixPro_V4-inpainting.safetensors\"}\n",
|
245 |
-
" ]\n",
|
246 |
-
"}\n",
|
247 |
-
"\n",
|
248 |
-
"vae_list = {\n",
|
249 |
-
" \"1.Anime.vae\": [{\"url\": \"https://civitai.com/api/download/models/311162\", \"name\": \"Anime.vae.safetensors\"}],\n",
|
250 |
-
" \"2.Anything.vae\": [{\"url\": \"https://huggingface.co/NoCrypt/resources/resolve/main/VAE/any.vae.safetensors\", \"name\": \"Anything.vae.safetensors\"}],\n",
|
251 |
-
" \"3.Blessed2.vae\": [{\"url\": \"https://huggingface.co/NoCrypt/resources/resolve/main/VAE/blessed2.vae.safetensors\", \"name\": \"Blessed2.vae.safetensors\"}],\n",
|
252 |
-
" \"4.ClearVae.vae\": [{\"url\": \"https://civitai.com/api/download/models/88156\", \"name\": \"ClearVae_23.vae.safetensors\"}],\n",
|
253 |
-
" \"5.WD.vae\": [{\"url\": \"https://huggingface.co/NoCrypt/resources/resolve/main/VAE/wd.vae.safetensors\", \"name\": \"WD.vae.safetensors\"}]\n",
|
254 |
-
"}\n",
|
255 |
-
"\n",
|
256 |
-
"controlnet_list = {\n",
|
257 |
-
" \"1.canny\": [\n",
|
258 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny_fp16.safetensors\", \"name\": \"control_v11p_sd15_canny_fp16.safetensors\"},\n",
|
259 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_canny_fp16.yaml\", \"name\": \"control_v11p_sd15_canny_fp16.yaml\"}\n",
|
260 |
-
" ],\n",
|
261 |
-
" \"2.openpose\": [\n",
|
262 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose_fp16.safetensors\", \"name\": \"control_v11p_sd15_openpose_fp16.safetensors\"},\n",
|
263 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_openpose_fp16.yaml\", \"name\": \"control_v11p_sd15_openpose_fp16.yaml\"}\n",
|
264 |
-
" ],\n",
|
265 |
-
" \"3.depth\": [\n",
|
266 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth_fp16.safetensors\", \"name\": \"control_v11f1p_sd15_depth_fp16.safetensors\"},\n",
|
267 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1p_sd15_depth_fp16.yaml\", \"name\": \"control_v11f1p_sd15_depth_fp16.yaml\"},\n",
|
268 |
-
" {\"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",
|
269 |
-
" ],\n",
|
270 |
-
" \"4.normal_map\": [\n",
|
271 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_normalbae_fp16.safetensors\", \"name\": \"control_v11p_sd15_normalbae_fp16.safetensors\"},\n",
|
272 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_normalbae_fp16.yaml\", \"name\": \"control_v11p_sd15_normalbae_fp16.yaml\"}\n",
|
273 |
-
" ],\n",
|
274 |
-
" \"5.mlsd\": [\n",
|
275 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_mlsd_fp16.safetensors\", \"name\": \"control_v11p_sd15_mlsd_fp16.safetensors\"},\n",
|
276 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_mlsd_fp16.yaml\", \"name\": \"control_v11p_sd15_mlsd_fp16.yaml\"}\n",
|
277 |
-
" ],\n",
|
278 |
-
" \"6.lineart\": [\n",
|
279 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart_fp16.safetensors\", \"name\": \"control_v11p_sd15_lineart_fp16.safetensors\"},\n",
|
280 |
-
" {\"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",
|
281 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_lineart_fp16.yaml\", \"name\": \"control_v11p_sd15_lineart_fp16.yaml\"},\n",
|
282 |
-
" {\"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",
|
283 |
-
" ],\n",
|
284 |
-
" \"7.soft_edge\": [\n",
|
285 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge_fp16.safetensors\", \"name\": \"control_v11p_sd15_softedge_fp16.safetensors\"},\n",
|
286 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_softedge_fp16.yaml\", \"name\": \"control_v11p_sd15_softedge_fp16.yaml\"}\n",
|
287 |
-
" ],\n",
|
288 |
-
" \"8.scribble\": [\n",
|
289 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble_fp16.safetensors\", \"name\": \"control_v11p_sd15_scribble_fp16.safetensors\"},\n",
|
290 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_scribble_fp16.yaml\", \"name\": \"control_v11p_sd15_scribble_fp16.yaml\"}\n",
|
291 |
-
" ],\n",
|
292 |
-
" \"9.segmentation\": [\n",
|
293 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg_fp16.safetensors\", \"name\": \"control_v11p_sd15_seg_fp16.safetensors\"},\n",
|
294 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_seg_fp16.yaml\", \"name\": \"control_v11p_sd15_seg_fp16.yaml\"}\n",
|
295 |
-
" ],\n",
|
296 |
-
" \"10.shuffle\": [\n",
|
297 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle_fp16.safetensors\", \"name\": \"control_v11e_sd15_shuffle_fp16.safetensors\"},\n",
|
298 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_shuffle_fp16.yaml\", \"name\": \"control_v11e_sd15_shuffle_fp16.yaml\"}\n",
|
299 |
-
" ],\n",
|
300 |
-
" \"11.tile\": [\n",
|
301 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile_fp16.safetensors\", \"name\": \"control_v11f1e_sd15_tile_fp16.safetensors\"},\n",
|
302 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1e_sd15_tile_fp16.yaml\", \"name\": \"control_v11f1e_sd15_tile_fp16.yaml\"}\n",
|
303 |
-
" ],\n",
|
304 |
-
" \"12.inpaint\": [\n",
|
305 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_inpaint_fp16.safetensors\", \"name\": \"control_v11p_sd15_inpaint_fp16.safetensors\"},\n",
|
306 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_inpaint_fp16.yaml\", \"name\": \"control_v11p_sd15_inpaint_fp16.yaml\"}\n",
|
307 |
-
" ],\n",
|
308 |
-
" \"13.instruct_p2p\": [\n",
|
309 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p_fp16.safetensors\", \"name\": \"control_v11e_sd15_ip2p_fp16.safetensors\"},\n",
|
310 |
-
" {\"url\": \"https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_ip2p_fp16.yaml\", \"name\": \"control_v11e_sd15_ip2p_fp16.yaml\"}\n",
|
311 |
-
" ]\n",
|
312 |
-
"}\n",
|
313 |
"\n",
|
314 |
"url = \"\"\n",
|
315 |
-
"
|
316 |
" \"model\": models_dir,\n",
|
317 |
" \"vae\": vaes_dir,\n",
|
318 |
" \"lora\": loras_dir,\n",
|
@@ -324,7 +215,7 @@
|
|
324 |
"}\n",
|
325 |
"\n",
|
326 |
"extension_repo = []\n",
|
327 |
-
"directories = [value for key, value in
|
328 |
"!mkdir -p {\" \".join(directories)}\n",
|
329 |
"\n",
|
330 |
"hf_token = huggingface_token if huggingface_token else \"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\"\n",
|
@@ -335,137 +226,123 @@
|
|
335 |
"from math import floor\n",
|
336 |
"\n",
|
337 |
"def center_text(text, terminal_width=45):\n",
|
338 |
-
"
|
339 |
-
"
|
340 |
-
" right_padding = terminal_width - text_length - left_padding\n",
|
341 |
-
" return f\"\\033[1m\\033[36m{' ' * left_padding}{text}{' ' * right_padding}\\033[0m\\033[32m\"\n",
|
342 |
"\n",
|
343 |
"def format_output(url, dst_dir, file_name):\n",
|
344 |
-
" info = f\"[{file_name.split('.')[0]}]\"\n",
|
345 |
-
"
|
346 |
"\n",
|
347 |
-
" print(f\"\\n
|
348 |
" print(f\"\\033[33mURL: \\033[34m{url}\")\n",
|
349 |
" print(f\"\\033[33mSAVE DIR: \\033[34m{dst_dir}\")\n",
|
350 |
" print(f\"\\033[33mFILE NAME: \\033[34m{file_name}\\033[0m\")\n",
|
351 |
"\n",
|
352 |
"''' GET CivitAi API - DATA '''\n",
|
353 |
"\n",
|
354 |
-
"def strip_(url, file_name=None):\n",
|
355 |
-
" if 'github.com' in url:\n",
|
356 |
-
" if '/blob/' in url:\n",
|
357 |
-
" url = url.replace('/blob/', '/raw/')\n",
|
358 |
-
"\n",
|
359 |
-
" elif \"civitai.com\" in url:\n",
|
360 |
-
" return CivitAi_API(url, file_name)\n",
|
361 |
-
"\n",
|
362 |
-
" elif \"huggingface.co\" in url:\n",
|
363 |
-
" if '/blob/' in url:\n",
|
364 |
-
" url = url.replace('/blob/', '/resolve/')\n",
|
365 |
-
" if '?' in url:\n",
|
366 |
-
" url = url.split('?')[0]\n",
|
367 |
-
"\n",
|
368 |
-
" return url\n",
|
369 |
-
"\n",
|
370 |
"def CivitAi_API(url, file_name=None):\n",
|
371 |
-
"
|
372 |
-
"
|
373 |
"\n",
|
374 |
-
" if '?token=' in url
|
375 |
-
"
|
376 |
-
"
|
377 |
-
"
|
378 |
-
"
|
379 |
-
"
|
380 |
-
"\n",
|
381 |
-
"
|
382 |
-
"
|
383 |
-
"
|
384 |
-
"
|
385 |
-
" response = requests.get(f\"https://civitai.com/api/v1/model-versions/{version_id}\")\n",
|
386 |
-
" # print(f\"end - https://civitai.com/api/v1/model-versions/{version_id}\")\n",
|
387 |
" else:\n",
|
388 |
-
"
|
389 |
-
"
|
390 |
-
" # print(f\"end - https://civitai.com/api/v1/models/{model_id}\")\n",
|
391 |
-
" else:\n",
|
392 |
-
" version_id = url.split('/models/')[1].split('/')[0]\n",
|
393 |
-
" response = requests.get(f\"https://civitai.com/api/v1/model-versions/{version_id}\")\n",
|
394 |
-
" # print(f\"end - https://civitai.com/api/v1/model-versions/{version_id}\")\n",
|
395 |
"\n",
|
396 |
-
" data =
|
397 |
"\n",
|
398 |
-
" if
|
399 |
" return None, None, None, None, None, None, None\n",
|
400 |
"\n",
|
401 |
-
"
|
402 |
-
"
|
403 |
-
"
|
404 |
-
"
|
405 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
406 |
" else:\n",
|
407 |
-
" model_type = data['type']\n",
|
408 |
-
" model_name = data['modelVersions'][0]['files'][0]['name']\n",
|
409 |
-
" elif 'type=' in url:\n",
|
410 |
-
" model_type = parse_qs(urlparse(url).query).get('type', [''])[0]\n",
|
411 |
-
" if 'model' in model_type.lower():\n",
|
412 |
" model_name = data['files'][0]['name']\n",
|
413 |
-
"
|
414 |
-
" model_name = data['files'][1]['name']\n",
|
415 |
-
" else:\n",
|
416 |
-
" model_type = data['model']['type']\n",
|
417 |
-
" model_name = data['files'][0]['name']\n",
|
418 |
"\n",
|
|
|
419 |
" model_name = file_name or model_name\n",
|
420 |
"\n",
|
421 |
-
"
|
422 |
-
"
|
423 |
-
"
|
424 |
-
"
|
425 |
-
"
|
426 |
-
"
|
427 |
-
"
|
428 |
-
"
|
429 |
-
"
|
|
|
|
|
430 |
" else:\n",
|
431 |
-
"
|
432 |
-
" else:\n",
|
433 |
-
" download_url = data.get('downloadUrl')\n",
|
434 |
"\n",
|
435 |
-
"
|
|
|
436 |
"\n",
|
437 |
-
"
|
438 |
-
"
|
439 |
-
"
|
440 |
-
"
|
441 |
-
"
|
442 |
-
"
|
443 |
-
"
|
444 |
-
"
|
445 |
-
"
|
446 |
-
"
|
447 |
-
"
|
|
|
|
|
|
|
448 |
"\n",
|
449 |
-
"
|
450 |
-
" image_name = f\"{model_name.split('.')[0]}.preview.{image_url.split('.')[-1]}\" if image_url else None\n",
|
451 |
"\n",
|
452 |
-
" return f\"{download_url}{'&' if '?' in download_url else '?'}token={
|
453 |
"\n",
|
454 |
"''' Main Download Code '''\n",
|
455 |
"\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
456 |
"def download(url):\n",
|
457 |
" links_and_paths = [link_or_path.strip() for link_or_path in url.split(',') if link_or_path.strip()]\n",
|
458 |
"\n",
|
459 |
" for link_or_path in links_and_paths:\n",
|
460 |
-
" if any(link_or_path.lower().startswith(prefix) for prefix in
|
461 |
" handle_manual(link_or_path)\n",
|
462 |
" else:\n",
|
463 |
" url, dst_dir, file_name = link_or_path.split()\n",
|
464 |
" manual_download(url, dst_dir, file_name)\n",
|
465 |
"\n",
|
466 |
-
"
|
467 |
-
"\n",
|
468 |
-
"def unpack_zip_files():\n",
|
469 |
" for directory in directories:\n",
|
470 |
" for root, _, files in os.walk(directory):\n",
|
471 |
" for file in files:\n",
|
@@ -485,8 +362,8 @@
|
|
485 |
" if file_name:\n",
|
486 |
" path = re.sub(r'\\[.*?\\]', '', path)\n",
|
487 |
"\n",
|
488 |
-
" if prefix in
|
489 |
-
" dir =
|
490 |
" if prefix != \"extension\":\n",
|
491 |
" try:\n",
|
492 |
" manual_download(path, dir, file_name=file_name)\n",
|
@@ -500,60 +377,52 @@
|
|
500 |
" aria2c_header = \"--header='User-Agent: Mozilla/5.0' --allow-overwrite=true\"\n",
|
501 |
" aria2_args = \"--optimize-concurrent-downloads --console-log-level=error --summary-interval=10 --stderr=true -c -x16 -s16 -k1M -j5\"\n",
|
502 |
"\n",
|
503 |
-
"
|
504 |
-
" url = strip_(url)\n",
|
505 |
-
"\n",
|
506 |
-
" # -- CivitAi APi+ V2 --\n",
|
507 |
-
" elif 'civitai' in url:\n",
|
508 |
-
" url, clean_url, model_type, file_name, image_url, image_name, data = strip_(url, file_name)\n",
|
509 |
"\n",
|
|
|
|
|
510 |
" if image_url and image_name:\n",
|
511 |
-
"
|
512 |
-
"
|
513 |
-
" del cap\n",
|
514 |
"\n",
|
515 |
-
" elif \"huggingface.co\" in url:\n",
|
516 |
-
"
|
517 |
-
" basename = clean_url.split(\"/\")[-1] if file_name is None else file_name\n",
|
518 |
"\n",
|
519 |
" \"\"\" Formatted info output \"\"\"\n",
|
520 |
-
" model_name_or_basename = file_name if
|
521 |
" format_output(clean_url or url, dst_dir, model_name_or_basename)\n",
|
522 |
"\n",
|
523 |
-
" # ## -- for my tests --\n",
|
524 |
" # print(url, dst_dir, model_name_or_basename)\n",
|
525 |
-
"
|
526 |
-
"
|
527 |
-
"
|
|
|
|
|
|
|
528 |
" # =====================\n",
|
|
|
|
|
|
|
529 |
"\n",
|
530 |
-
" # --
|
531 |
-
" if '
|
532 |
-
"
|
533 |
-
"\n",
|
534 |
-
"
|
535 |
-
" elif 'drive.google' in url:\n",
|
536 |
-
" try:\n",
|
537 |
-
" have_drive_link\n",
|
538 |
-
" except:\n",
|
539 |
-
" !pip install -q gdown==5.2.0 > /dev/null\n",
|
540 |
-
" have_drive_link = True\n",
|
541 |
"\n",
|
542 |
" if 'folders' in url:\n",
|
543 |
-
"
|
544 |
" else:\n",
|
545 |
-
" if file_name
|
546 |
-
"
|
547 |
-
" else:\n",
|
548 |
-
" !gdown \"{url}\" -O {dst_dir} --fuzzy -c\n",
|
549 |
"\n",
|
550 |
-
" # -- Hugging Face --\n",
|
551 |
-
" elif 'huggingface' in url:\n",
|
552 |
-
"
|
553 |
"\n",
|
554 |
-
" # -- Other --\n",
|
555 |
" elif 'http' in url:\n",
|
556 |
-
"
|
557 |
"\n",
|
558 |
"''' SubModels - Added URLs '''\n",
|
559 |
"\n",
|
@@ -593,7 +462,7 @@
|
|
593 |
"\n",
|
594 |
"''' file.txt - added urls '''\n",
|
595 |
"\n",
|
596 |
-
"def process_file_download(file_url,
|
597 |
" files_urls = \"\"\n",
|
598 |
"\n",
|
599 |
" if file_url.startswith(\"http\"):\n",
|
@@ -608,8 +477,8 @@
|
|
608 |
" current_tag = None\n",
|
609 |
" for line in lines:\n",
|
610 |
" line = line.strip()\n",
|
611 |
-
" if any(f'# {tag}' in line.lower() for tag in
|
612 |
-
" current_tag = next((tag for tag in
|
613 |
"\n",
|
614 |
" urls = [url.split('#')[0].strip() for url in line.split(',')] # filter urls\n",
|
615 |
" for url in urls:\n",
|
@@ -633,13 +502,13 @@
|
|
633 |
" custom_file_url = f'{root_path}/{custom_file_url}'\n",
|
634 |
"\n",
|
635 |
" try:\n",
|
636 |
-
" file_urls += process_file_download(custom_file_url,
|
637 |
" except FileNotFoundError:\n",
|
638 |
" pass\n",
|
639 |
"\n",
|
640 |
"# url prefixing\n",
|
641 |
"urls = (Model_url, Vae_url, LoRA_url, Embedding_url, Extensions_url)\n",
|
642 |
-
"prefixed_urls = (f\"{prefix}:{url}\" for prefix, url in zip(
|
643 |
"url += \", \".join(prefixed_urls) + \", \" + file_urls\n",
|
644 |
"\n",
|
645 |
"if detailed_download == \"on\":\n",
|
|
|
10 |
"source": [
|
11 |
"##~ DOWNLOADING CODE | BY: ANXETY ~##\n",
|
12 |
"\n",
|
13 |
+
"from models_data import model_list, vae_list, controlnet_list\n",
|
14 |
+
"\n",
|
15 |
"import os\n",
|
16 |
"import re\n",
|
17 |
"import time\n",
|
|
|
27 |
"from urllib.parse import urlparse, parse_qs\n",
|
28 |
"\n",
|
29 |
"\n",
|
30 |
+
"# Setup Env\n",
|
31 |
+
"env = os.environ.get('ENV_NAME')\n",
|
32 |
+
"root_path = os.environ.get('ROOT_PATH')\n",
|
33 |
+
"webui_path = os.environ.get('WEBUI_PATH')\n",
|
34 |
+
"free_plan = os.environ.get('FREE_PLAN')\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
"\n",
|
36 |
"\n",
|
37 |
"# ================ LIBRARIES V2 ================\n",
|
|
|
201 |
"\n",
|
202 |
"## Downloading model and stuff | oh~ Hey! If you're freaked out by that code too, don't worry, me too!\n",
|
203 |
"print(\"📦 Скачивание моделей и прочего...\", end='')\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
204 |
"\n",
|
205 |
"url = \"\"\n",
|
206 |
+
"PREFIXES = {\n",
|
207 |
" \"model\": models_dir,\n",
|
208 |
" \"vae\": vaes_dir,\n",
|
209 |
" \"lora\": loras_dir,\n",
|
|
|
215 |
"}\n",
|
216 |
"\n",
|
217 |
"extension_repo = []\n",
|
218 |
+
"directories = [value for key, value in PREFIXES.items()] # for unpucking zip files\n",
|
219 |
"!mkdir -p {\" \".join(directories)}\n",
|
220 |
"\n",
|
221 |
"hf_token = huggingface_token if huggingface_token else \"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\"\n",
|
|
|
226 |
"from math import floor\n",
|
227 |
"\n",
|
228 |
"def center_text(text, terminal_width=45):\n",
|
229 |
+
" padding = (terminal_width - len(text)) // 2\n",
|
230 |
+
" return f\"\\033[1m\\033[36m{' ' * padding}{text}{' ' * padding}\\033[0m\\033[32m\"\n",
|
|
|
|
|
231 |
"\n",
|
232 |
"def format_output(url, dst_dir, file_name):\n",
|
233 |
+
" info = center_text(f\"[{file_name.split('.')[0]}]\")\n",
|
234 |
+
" separation_line = '\\033[32m' + '---' * 20\n",
|
235 |
"\n",
|
236 |
+
" print(f\"\\n{separation_line}{info}{separation_line}\")\n",
|
237 |
" print(f\"\\033[33mURL: \\033[34m{url}\")\n",
|
238 |
" print(f\"\\033[33mSAVE DIR: \\033[34m{dst_dir}\")\n",
|
239 |
" print(f\"\\033[33mFILE NAME: \\033[34m{file_name}\\033[0m\")\n",
|
240 |
"\n",
|
241 |
"''' GET CivitAi API - DATA '''\n",
|
242 |
"\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
243 |
"def CivitAi_API(url, file_name=None):\n",
|
244 |
+
" SUPPORT_TYPES = ('Checkpoint', 'Model', 'TextualInversion', 'LORA')\n",
|
245 |
+
" CIVITAI_TOKEN = \"62c0c5956b2f9defbd844d754000180b\"\n",
|
246 |
"\n",
|
247 |
+
" url = url.split('?token=')[0] if '?token=' in url else url\n",
|
248 |
+
" url = url.replace('?type=', f'?token={CIVITAI_TOKEN}&type=') if '?type=' in url else f\"{url}?token={CIVITAI_TOKEN}\"\n",
|
249 |
+
"\n",
|
250 |
+
" def get_model_data(url):\n",
|
251 |
+
" if \"civitai.com/models/\" in url:\n",
|
252 |
+
" if '?modelVersionId=' in url:\n",
|
253 |
+
" version_id = url.split('?modelVersionId=')[1]\n",
|
254 |
+
" return requests.get(f\"https://civitai.com/api/v1/model-versions/{version_id}\").json()\n",
|
255 |
+
" else:\n",
|
256 |
+
" model_id = url.split('/models/')[1].split('/')[0]\n",
|
257 |
+
" return requests.get(f\"https://civitai.com/api/v1/models/{model_id}\").json()\n",
|
|
|
|
|
258 |
" else:\n",
|
259 |
+
" version_id = url.split('/models/')[1].split('/')[0]\n",
|
260 |
+
" return requests.get(f\"https://civitai.com/api/v1/model-versions/{version_id}\").json()\n",
|
|
|
|
|
|
|
|
|
|
|
261 |
"\n",
|
262 |
+
" data = get_model_data(url)\n",
|
263 |
"\n",
|
264 |
+
" if not data:\n",
|
265 |
" return None, None, None, None, None, None, None\n",
|
266 |
"\n",
|
267 |
+
" def extract_model_info(url, data):\n",
|
268 |
+
" if \"civitai.com/models/\" in url:\n",
|
269 |
+
" if '?modelVersionId=' in url:\n",
|
270 |
+
" model_type = data['model']['type']\n",
|
271 |
+
" model_name = data['files'][0]['name']\n",
|
272 |
+
" else:\n",
|
273 |
+
" model_type = data['type']\n",
|
274 |
+
" model_name = data['modelVersions'][0]['files'][0]['name']\n",
|
275 |
+
" elif 'type=' in url:\n",
|
276 |
+
" model_type = parse_qs(urlparse(url).query).get('type', [''])[0]\n",
|
277 |
+
" if 'model' in model_type.lower():\n",
|
278 |
+
" model_name = data['files'][0]['name']\n",
|
279 |
+
" else:\n",
|
280 |
+
" model_name = data['files'][1]['name']\n",
|
281 |
" else:\n",
|
282 |
+
" model_type = data['model']['type']\n",
|
|
|
|
|
|
|
|
|
283 |
" model_name = data['files'][0]['name']\n",
|
284 |
+
" return model_type, model_name\n",
|
|
|
|
|
|
|
|
|
285 |
"\n",
|
286 |
+
" model_type, model_name = extract_model_info(url, data)\n",
|
287 |
" model_name = file_name or model_name\n",
|
288 |
"\n",
|
289 |
+
" def get_download_url(url, data, model_type):\n",
|
290 |
+
" if \"civitai.com/models/\" in url:\n",
|
291 |
+
" if '?modelVersionId=' in url:\n",
|
292 |
+
" return data.get('downloadUrl')\n",
|
293 |
+
" else:\n",
|
294 |
+
" return data[\"modelVersions\"][0].get(\"downloadUrl\", \"\")\n",
|
295 |
+
" elif 'type=' in url:\n",
|
296 |
+
" if any(t.lower() in model_type.lower() for t in SUPPORT_TYPES):\n",
|
297 |
+
" return data['files'][0]['downloadUrl']\n",
|
298 |
+
" else:\n",
|
299 |
+
" return data['files'][1]['downloadUrl']\n",
|
300 |
" else:\n",
|
301 |
+
" return data.get('downloadUrl')\n",
|
|
|
|
|
302 |
"\n",
|
303 |
+
" download_url = get_download_url(url, data, model_type)\n",
|
304 |
+
" clean_url = re.sub(r'[?&]token=[^&]*', '', download_url)\n",
|
305 |
"\n",
|
306 |
+
" def get_image_info(data, model_type, model_name):\n",
|
307 |
+
" image_url, image_name = None, None\n",
|
308 |
+
" if any(t in model_type for t in SUPPORT_TYPES):\n",
|
309 |
+
" try:\n",
|
310 |
+
" images = data.get('images') or data['modelVersions'][0].get('images', [])\n",
|
311 |
+
" if env == 'Kaggle':\n",
|
312 |
+
" image_url = next((image['url'] for image in images if image['nsfwLevel'] < 4), None)\n",
|
313 |
+
" else:\n",
|
314 |
+
" image_url = images[0]['url'] if images else None\n",
|
315 |
+
" except KeyError:\n",
|
316 |
+
" pass\n",
|
317 |
+
"\n",
|
318 |
+
" image_name = f\"{model_name.split('.')[0]}.preview.{image_url.split('.')[-1]}\" if image_url else None\n",
|
319 |
+
" return image_url, image_name\n",
|
320 |
"\n",
|
321 |
+
" image_url, image_name = get_image_info(data, model_type, model_name)\n",
|
|
|
322 |
"\n",
|
323 |
+
" return f\"{download_url}{'&' if '?' in download_url else '?'}token={CIVITAI_TOKEN}\", clean_url, model_type, model_name, image_url, image_name, data\n",
|
324 |
"\n",
|
325 |
"''' Main Download Code '''\n",
|
326 |
"\n",
|
327 |
+
"def strip_(url):\n",
|
328 |
+
" if 'github.com' in url:\n",
|
329 |
+
" return url.replace('/blob/', '/raw/')\n",
|
330 |
+
" elif \"huggingface.co\" in url:\n",
|
331 |
+
" url = url.replace('/blob/', '/resolve/')\n",
|
332 |
+
" return url.split('?')[0] if '?' in url else url\n",
|
333 |
+
" return url\n",
|
334 |
+
"\n",
|
335 |
"def download(url):\n",
|
336 |
" links_and_paths = [link_or_path.strip() for link_or_path in url.split(',') if link_or_path.strip()]\n",
|
337 |
"\n",
|
338 |
" for link_or_path in links_and_paths:\n",
|
339 |
+
" if any(link_or_path.lower().startswith(prefix) for prefix in PREFIXES):\n",
|
340 |
" handle_manual(link_or_path)\n",
|
341 |
" else:\n",
|
342 |
" url, dst_dir, file_name = link_or_path.split()\n",
|
343 |
" manual_download(url, dst_dir, file_name)\n",
|
344 |
"\n",
|
345 |
+
" # Unpuck ZIPs Files\n",
|
|
|
|
|
346 |
" for directory in directories:\n",
|
347 |
" for root, _, files in os.walk(directory):\n",
|
348 |
" for file in files:\n",
|
|
|
362 |
" if file_name:\n",
|
363 |
" path = re.sub(r'\\[.*?\\]', '', path)\n",
|
364 |
"\n",
|
365 |
+
" if prefix in PREFIXES:\n",
|
366 |
+
" dir = PREFIXES[prefix]\n",
|
367 |
" if prefix != \"extension\":\n",
|
368 |
" try:\n",
|
369 |
" manual_download(path, dir, file_name=file_name)\n",
|
|
|
377 |
" aria2c_header = \"--header='User-Agent: Mozilla/5.0' --allow-overwrite=true\"\n",
|
378 |
" aria2_args = \"--optimize-concurrent-downloads --console-log-level=error --summary-interval=10 --stderr=true -c -x16 -s16 -k1M -j5\"\n",
|
379 |
"\n",
|
380 |
+
" clean_url = strip_(url)\n",
|
|
|
|
|
|
|
|
|
|
|
381 |
"\n",
|
382 |
+
" if 'civitai' in url:\n",
|
383 |
+
" url, clean_url, model_type, file_name, image_url, image_name, data = CivitAi_API(url, file_name)\n",
|
384 |
" if image_url and image_name:\n",
|
385 |
+
" command = [\"aria2c\"] + aria2_args.split() + [\"-d\", dst_dir, \"-o\", image_name, image_url]\n",
|
386 |
+
" subprocess.run(command, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)\n",
|
|
|
387 |
"\n",
|
388 |
+
" elif 'github' in url or \"huggingface.co\" in url:\n",
|
389 |
+
" basename = url.split(\"/\")[-1] if file_name is None else file_name\n",
|
|
|
390 |
"\n",
|
391 |
" \"\"\" Formatted info output \"\"\"\n",
|
392 |
+
" model_name_or_basename = file_name if file_name else basename\n",
|
393 |
" format_output(clean_url or url, dst_dir, model_name_or_basename)\n",
|
394 |
"\n",
|
|
|
395 |
" # print(url, dst_dir, model_name_or_basename)\n",
|
396 |
+
" if 'civitai' in url:\n",
|
397 |
+
" if not data:\n",
|
398 |
+
" print(\"\\033[31m[Data Info]:\\033[0m Failed to retrieve data from the API.\\n\")\n",
|
399 |
+
" if data and image_name:\n",
|
400 |
+
" print(f\"\\033[32m[Preview DL]:\\033[0m {image_name} - {image_url}\\n\")\n",
|
401 |
+
"\n",
|
402 |
" # =====================\n",
|
403 |
+
" def run_aria2c(url, dst_dir, file_name=None, args=\"\", header=\"\"):\n",
|
404 |
+
" out = f\"-o '{file_name}'\" if file_name else \"\"\n",
|
405 |
+
" !aria2c {header} {args} -d {dst_dir} {out} '{url}'\n",
|
406 |
"\n",
|
407 |
+
" # -- Google Drive --\n",
|
408 |
+
" if 'drive.google' in url:\n",
|
409 |
+
" if not globals().get('have_drive_link', False):\n",
|
410 |
+
" os.system(\"pip install -U gdown > /dev/null\")\n",
|
411 |
+
" globals()['have_drive_link'] = True\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
412 |
"\n",
|
413 |
" if 'folders' in url:\n",
|
414 |
+
" os.system(f\"gdown --folder \\\"{url}\\\" -O {dst_dir} --fuzzy -c\")\n",
|
415 |
" else:\n",
|
416 |
+
" out_path = f\"{dst_dir}/{file_name}\" if file_name else dst_dir\n",
|
417 |
+
" os.system(f\"gdown \\\"{url}\\\" -O {out_path} --fuzzy -c\")\n",
|
|
|
|
|
418 |
"\n",
|
419 |
+
" # -- GitHub or Hugging Face --\n",
|
420 |
+
" elif 'github' in url or 'huggingface' in url:\n",
|
421 |
+
" run_aria2c(clean_url, dst_dir, basename, aria2_args, header_option if 'huggingface' in url else '')\n",
|
422 |
"\n",
|
423 |
+
" # -- Other HTTP/Sources --\n",
|
424 |
" elif 'http' in url:\n",
|
425 |
+
" run_aria2c(url, dst_dir, file_name, aria2_args, aria2c_header)\n",
|
426 |
"\n",
|
427 |
"''' SubModels - Added URLs '''\n",
|
428 |
"\n",
|
|
|
462 |
"\n",
|
463 |
"''' file.txt - added urls '''\n",
|
464 |
"\n",
|
465 |
+
"def process_file_download(file_url, PREFIXES, unique_urls):\n",
|
466 |
" files_urls = \"\"\n",
|
467 |
"\n",
|
468 |
" if file_url.startswith(\"http\"):\n",
|
|
|
477 |
" current_tag = None\n",
|
478 |
" for line in lines:\n",
|
479 |
" line = line.strip()\n",
|
480 |
+
" if any(f'# {tag}' in line.lower() for tag in PREFIXES):\n",
|
481 |
+
" current_tag = next((tag for tag in PREFIXES if tag in line.lower()))\n",
|
482 |
"\n",
|
483 |
" urls = [url.split('#')[0].strip() for url in line.split(',')] # filter urls\n",
|
484 |
" for url in urls:\n",
|
|
|
502 |
" custom_file_url = f'{root_path}/{custom_file_url}'\n",
|
503 |
"\n",
|
504 |
" try:\n",
|
505 |
+
" file_urls += process_file_download(custom_file_url, PREFIXES, unique_urls)\n",
|
506 |
" except FileNotFoundError:\n",
|
507 |
" pass\n",
|
508 |
"\n",
|
509 |
"# url prefixing\n",
|
510 |
"urls = (Model_url, Vae_url, LoRA_url, Embedding_url, Extensions_url)\n",
|
511 |
+
"prefixed_urls = (f\"{prefix}:{url}\" for prefix, url in zip(PREFIXES.keys(), urls) if url for url in url.replace(',', '').split())\n",
|
512 |
"url += \", \".join(prefixed_urls) + \", \" + file_urls\n",
|
513 |
"\n",
|
514 |
"if detailed_download == \"on\":\n",
|
files_cells/notebooks/ru/launch_ru.ipynb
CHANGED
@@ -33,21 +33,13 @@
|
|
33 |
"from datetime import timedelta\n",
|
34 |
"from IPython.display import clear_output\n",
|
35 |
"\n",
|
36 |
-
"
|
37 |
-
"
|
38 |
-
"
|
39 |
-
"
|
40 |
-
"
|
41 |
-
"
|
42 |
-
"
|
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",
|
@@ -62,6 +54,7 @@
|
|
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",
|
@@ -95,6 +88,7 @@
|
|
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",
|
|
|
33 |
"from datetime import timedelta\n",
|
34 |
"from IPython.display import clear_output\n",
|
35 |
"\n",
|
36 |
+
"\n",
|
37 |
+
"# Setup Env\n",
|
38 |
+
"env = os.environ.get('ENV_NAME')\n",
|
39 |
+
"root_path = os.environ.get('ROOT_PATH')\n",
|
40 |
+
"webui_path = os.environ.get('WEBUI_PATH')\n",
|
41 |
+
"free_plan = os.environ.get('FREE_PLAN')\n",
|
42 |
+
"\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
"\n",
|
44 |
"def load_settings():\n",
|
45 |
" SETTINGS_FILE = f'{root_path}/settings.json'\n",
|
|
|
54 |
"commandline_arguments = settings.get('commandline_arguments', \"\")\n",
|
55 |
"change_webui = settings.get('change_webui', \"\")\n",
|
56 |
"\n",
|
57 |
+
"\n",
|
58 |
"# ======================== TUNNEL V2 ========================\n",
|
59 |
"print('Please Wait...')\n",
|
60 |
"\n",
|
|
|
88 |
"\n",
|
89 |
"clear_output()\n",
|
90 |
"\n",
|
91 |
+
"\n",
|
92 |
"# =============== Automatic Fixing Path V3 ===============\n",
|
93 |
"paths_to_check = {\n",
|
94 |
" \"tagger_hf_cache_dir\": f\"{webui_path}/models/interrogators/\",\n",
|
files_cells/notebooks/ru/widgets_ru.ipynb
CHANGED
@@ -1,349 +1,340 @@
|
|
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 |
-
"#
|
36 |
-
"
|
37 |
-
"
|
38 |
-
"
|
39 |
-
"
|
40 |
-
"
|
41 |
-
"
|
42 |
-
"
|
43 |
-
"
|
44 |
-
"
|
45 |
-
"\n",
|
46 |
-
"
|
47 |
-
"
|
48 |
-
"
|
49 |
-
"\n",
|
50 |
-
"\n",
|
51 |
-
"
|
52 |
-
"
|
53 |
-
"
|
54 |
-
"parser =
|
55 |
-
"
|
56 |
-
"
|
57 |
-
"
|
58 |
-
"
|
59 |
-
"
|
60 |
-
"
|
61 |
-
"
|
62 |
-
"
|
63 |
-
"
|
64 |
-
"\n",
|
65 |
-
"
|
66 |
-
"
|
67 |
-
"
|
68 |
-
"
|
69 |
-
"
|
70 |
-
"
|
71 |
-
"
|
72 |
-
"
|
73 |
-
"
|
74 |
-
"\n",
|
75 |
-
"
|
76 |
-
"
|
77 |
-
"
|
78 |
-
"\n",
|
79 |
-
"
|
80 |
-
"
|
81 |
-
"
|
82 |
-
"
|
83 |
-
"
|
84 |
-
"
|
85 |
-
"
|
86 |
-
"
|
87 |
-
":
|
88 |
-
"
|
89 |
-
"
|
90 |
-
" --
|
91 |
-
" --
|
92 |
-
" --
|
93 |
-
"
|
94 |
-
"
|
95 |
-
"
|
96 |
-
"
|
97 |
-
"\n",
|
98 |
-
"
|
99 |
-
"
|
100 |
-
"
|
101 |
-
"
|
102 |
-
"}
|
103 |
-
"
|
104 |
-
"\n",
|
105 |
-
"
|
106 |
-
"
|
107 |
-
"
|
108 |
-
"
|
109 |
-
"
|
110 |
-
"
|
111 |
-
"
|
112 |
-
"
|
113 |
-
"
|
114 |
-
"
|
115 |
-
"
|
116 |
-
"
|
117 |
-
"
|
118 |
-
"
|
119 |
-
"
|
120 |
-
"\n",
|
121 |
-
"
|
122 |
-
"
|
123 |
-
"
|
124 |
-
"
|
125 |
-
"'''\n",
|
126 |
-
"
|
127 |
-
"
|
128 |
-
"
|
129 |
-
"
|
130 |
-
"\n",
|
131 |
-
"
|
132 |
-
"
|
133 |
-
"
|
134 |
-
"
|
135 |
-
"\n",
|
136 |
-
" def
|
137 |
-
"
|
138 |
-
"
|
139 |
-
"
|
140 |
-
" return
|
141 |
-
"\n",
|
142 |
-
" def
|
143 |
-
" return widgets.
|
144 |
-
"\n",
|
145 |
-
" def
|
146 |
-
"
|
147 |
-
"
|
148 |
-
"
|
149 |
-
" return
|
150 |
-
"\n",
|
151 |
-
" def
|
152 |
-
" return widgets.
|
153 |
-
"\n",
|
154 |
-
" def
|
155 |
-
"
|
156 |
-
" if
|
157 |
-
"
|
158 |
-
"
|
159 |
-
"\n",
|
160 |
-
"
|
161 |
-
"
|
162 |
-
"\n",
|
163 |
-
"
|
164 |
-
"
|
165 |
-
"
|
166 |
-
"
|
167 |
-
"
|
168 |
-
"
|
169 |
-
"
|
170 |
-
"
|
171 |
-
"
|
172 |
-
"
|
173 |
-
"
|
174 |
-
"
|
175 |
-
"
|
176 |
-
"
|
177 |
-
"
|
178 |
-
"
|
179 |
-
"
|
180 |
-
"
|
181 |
-
"
|
182 |
-
"
|
183 |
-
"
|
184 |
-
"
|
185 |
-
"
|
186 |
-
"
|
187 |
-
"
|
188 |
-
"
|
189 |
-
"
|
190 |
-
"
|
191 |
-
"
|
192 |
-
"
|
193 |
-
"
|
194 |
-
"
|
195 |
-
"\n",
|
196 |
-
"
|
197 |
-
"
|
198 |
-
"
|
199 |
-
"
|
200 |
-
"
|
201 |
-
"
|
202 |
-
"
|
203 |
-
"
|
204 |
-
"
|
205 |
-
"
|
206 |
-
"\n",
|
207 |
-
"
|
208 |
-
"
|
209 |
-
"
|
210 |
-
"
|
211 |
-
"
|
212 |
-
"
|
213 |
-
"
|
214 |
-
"
|
215 |
-
"
|
216 |
-
"
|
217 |
-
"
|
218 |
-
"\n",
|
219 |
-
"
|
220 |
-
"
|
221 |
-
"
|
222 |
-
"
|
223 |
-
"
|
224 |
-
"
|
225 |
-
"
|
226 |
-
"
|
227 |
-
"
|
228 |
-
"
|
229 |
-
"
|
230 |
-
"\n",
|
231 |
-
"
|
232 |
-
"
|
233 |
-
"
|
234 |
-
"
|
235 |
-
"
|
236 |
-
"
|
237 |
-
"
|
238 |
-
"
|
239 |
-
"
|
240 |
-
"
|
241 |
-
"
|
242 |
-
"
|
243 |
-
"
|
244 |
-
"
|
245 |
-
"
|
246 |
-
"
|
247 |
-
"
|
248 |
-
"
|
249 |
-
"
|
250 |
-
"
|
251 |
-
"
|
252 |
-
"
|
253 |
-
"
|
254 |
-
"
|
255 |
-
"
|
256 |
-
"
|
257 |
-
"
|
258 |
-
"
|
259 |
-
"\n",
|
260 |
-
"
|
261 |
-
"
|
262 |
-
"
|
263 |
-
"
|
264 |
-
"
|
265 |
-
"
|
266 |
-
"
|
267 |
-
"
|
268 |
-
"
|
269 |
-
"
|
270 |
-
"
|
271 |
-
"
|
272 |
-
"\n",
|
273 |
-
"<
|
274 |
-
"
|
275 |
-
"<
|
276 |
-
"<
|
277 |
-
"
|
278 |
-
"
|
279 |
-
"
|
280 |
-
"
|
281 |
-
"
|
282 |
-
"
|
283 |
-
"
|
284 |
-
"
|
285 |
-
"
|
286 |
-
"
|
287 |
-
"
|
288 |
-
"
|
289 |
-
"\n",
|
290 |
-
"Model_url_widget
|
291 |
-
"
|
292 |
-
"
|
293 |
-
"
|
294 |
-
"
|
295 |
-
"
|
296 |
-
"\n",
|
297 |
-
"
|
298 |
-
"
|
299 |
-
"
|
300 |
-
"
|
301 |
-
"
|
302 |
-
"\n",
|
303 |
-
"
|
304 |
-
"
|
305 |
-
"
|
306 |
-
"
|
307 |
-
"
|
308 |
-
"
|
309 |
-
"
|
310 |
-
"\n",
|
311 |
-
"
|
312 |
-
"
|
313 |
-
"
|
314 |
-
"
|
315 |
-
"
|
316 |
-
"
|
317 |
-
"
|
318 |
-
"
|
319 |
-
"
|
320 |
-
"\n",
|
321 |
-
"
|
322 |
-
"
|
323 |
-
"
|
324 |
-
"
|
325 |
-
"\n",
|
326 |
-
"
|
327 |
-
"
|
328 |
-
"
|
329 |
-
"
|
330 |
-
"
|
331 |
-
"
|
332 |
-
"\n",
|
333 |
-
"
|
334 |
-
"
|
335 |
-
"
|
336 |
-
"
|
337 |
-
|
338 |
-
|
339 |
-
|
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 |
+
"# Setup Env\n",
|
36 |
+
"env = os.environ.get('ENV_NAME')\n",
|
37 |
+
"root_path = os.environ.get('ROOT_PATH')\n",
|
38 |
+
"webui_path = os.environ.get('WEBUI_PATH')\n",
|
39 |
+
"free_plan = os.environ.get('FREE_PLAN')\n",
|
40 |
+
"\n",
|
41 |
+
"\n",
|
42 |
+
"# ==================== CSS JS ====================\n",
|
43 |
+
"##~ custom background images V1.5 ~##\n",
|
44 |
+
"import argparse\n",
|
45 |
+
"parser = argparse.ArgumentParser(description='This script processes an background image.')\n",
|
46 |
+
"parser.add_argument('-i', '--image', type=str, help='URL of the image to process', metavar='')\n",
|
47 |
+
"parser.add_argument('-o', '--opacity', type=float, help='Opacity level for the image, between 0 and 1', metavar='', default=0.3)\n",
|
48 |
+
"parser.add_argument('-b', '--blur', type=str, help='Blur level for the image', metavar='', default=0)\n",
|
49 |
+
"parser.add_argument('-y', type=int, help='Y coordinate for the image in px', metavar='', default=0)\n",
|
50 |
+
"parser.add_argument('-x', type=int, help='X coordinate for the image in px', metavar='', default=0)\n",
|
51 |
+
"parser.add_argument('-s', '--scale', type=int, help='Scale image in %%', metavar='', default=100)\n",
|
52 |
+
"parser.add_argument('-m', '--mode', action='store_true', help='Removes repetitive image tiles')\n",
|
53 |
+
"parser.add_argument('-t', '--transparent', action='store_true', help='Makes input/selection fields 35%% more transparent')\n",
|
54 |
+
"parser.add_argument('-bf', '--blur-fields', type=str, help='Background blur level for input/selection fields', metavar='', default=2)\n",
|
55 |
+
"\n",
|
56 |
+
"args = parser.parse_args()\n",
|
57 |
+
"\n",
|
58 |
+
"url_img = args.image\n",
|
59 |
+
"opacity_img = args.opacity\n",
|
60 |
+
"blur_img = args.blur\n",
|
61 |
+
"y_img = args.y\n",
|
62 |
+
"x_img = args.x\n",
|
63 |
+
"scale_img = args.scale\n",
|
64 |
+
"blur_fields = args.blur_fields\n",
|
65 |
+
"\n",
|
66 |
+
"## ---\n",
|
67 |
+
"\"\"\" WTF KAGGLE - WHAT THE FUCK IS THE DIFFERENCE OF 35 PIXELS!?!?!? \"\"\"\n",
|
68 |
+
"fix_heigh_img = \"-810px\" if env == \"Kaggle\" else \"-775px\"\n",
|
69 |
+
"\n",
|
70 |
+
"\"\"\" transperent fields \"\"\"\n",
|
71 |
+
"t_bg_alpha = \"1\" if not args.transparent else \"0.65\"\n",
|
72 |
+
"\n",
|
73 |
+
"\"\"\" mode img - repeats \"\"\"\n",
|
74 |
+
"mode_img = \"repeat\" if not args.mode else \"no-repeat\"\n",
|
75 |
+
"\n",
|
76 |
+
"container_background = f'''\n",
|
77 |
+
"<style>\n",
|
78 |
+
":root {{\n",
|
79 |
+
" /* for background container*/\n",
|
80 |
+
" --img_background: url({url_img});\n",
|
81 |
+
" --img_opacity: {opacity_img};\n",
|
82 |
+
" --img_blur: {blur_img}px;\n",
|
83 |
+
" --image_y: {y_img}px;\n",
|
84 |
+
" --image_x: {x_img}px;\n",
|
85 |
+
" --img_scale: {scale_img}%;\n",
|
86 |
+
" --img_mode: {mode_img};\n",
|
87 |
+
" --img_height_dif: {fix_heigh_img};\n",
|
88 |
+
"\n",
|
89 |
+
" /* for fields */\n",
|
90 |
+
" --bg-field-color: rgba(28, 28, 28, {t_bg_alpha}); /* -> #1c1c1c */\n",
|
91 |
+
" --bg-field-color-hover: rgba(38, 38, 38, {t_bg_alpha}); /* -> #262626; */\n",
|
92 |
+
" --bg-field-blur-level: {blur_fields}px;\n",
|
93 |
+
"}}\n",
|
94 |
+
"'''\n",
|
95 |
+
"\n",
|
96 |
+
"display(HTML(container_background))\n",
|
97 |
+
"\n",
|
98 |
+
"# Main CSS\n",
|
99 |
+
"css_file_path = f\"{root_path}/CSS/main_widgets.css\"\n",
|
100 |
+
"with open(css_file_path , \"r\") as f:\n",
|
101 |
+
" CSS = f.read()\n",
|
102 |
+
"display(HTML(f\"<style>{CSS}</style>\"))\n",
|
103 |
+
"\n",
|
104 |
+
"# Main JS\n",
|
105 |
+
"JS = '''\n",
|
106 |
+
"<!-- TOGGLE 'CustomDL' SCRIPT -->\n",
|
107 |
+
"<script>\n",
|
108 |
+
"function toggleContainer() {\n",
|
109 |
+
" let downloadContainer = document.querySelector('.container_custom_downlad');\n",
|
110 |
+
" let info = document.querySelector('.info');\n",
|
111 |
+
"\n",
|
112 |
+
" downloadContainer.classList.toggle('expanded');\n",
|
113 |
+
" info.classList.toggle('showed');\n",
|
114 |
+
"}\n",
|
115 |
+
"</script>\n",
|
116 |
+
"'''\n",
|
117 |
+
"display(HTML(JS))\n",
|
118 |
+
"\n",
|
119 |
+
"# ==================== WIDGETS V2 ====================\n",
|
120 |
+
"HR = widgets.HTML('<hr>')\n",
|
121 |
+
"\n",
|
122 |
+
"class WidgetFactory:\n",
|
123 |
+
" def __init__(self, style=None, layout=None):\n",
|
124 |
+
" self.style = style if style else {'description_width': 'initial'}\n",
|
125 |
+
" self.layout = layout if layout else widgets.Layout(max_width='1080px', width='100%')\n",
|
126 |
+
"\n",
|
127 |
+
" def create_html(self, content, class_name=None):\n",
|
128 |
+
" html_widget = widgets.HTML(content)\n",
|
129 |
+
" if class_name:\n",
|
130 |
+
" html_widget.add_class(class_name)\n",
|
131 |
+
" return html_widget\n",
|
132 |
+
"\n",
|
133 |
+
" def create_header(self, name):\n",
|
134 |
+
" return widgets.HTML(f'<div class=\"header\">{name}<div>')\n",
|
135 |
+
"\n",
|
136 |
+
" def create_dropdown(self, options, value, description):\n",
|
137 |
+
" return widgets.Dropdown(options=options, value=value, description=description, style=self.style, layout=self.layout)\n",
|
138 |
+
"\n",
|
139 |
+
" def create_text(self, description, placeholder='', value=''):\n",
|
140 |
+
" return widgets.Text(description=description, placeholder=placeholder, value=value, style=self.style, layout=self.layout)\n",
|
141 |
+
"\n",
|
142 |
+
" def create_checkbox(self, value, description):\n",
|
143 |
+
" return widgets.Checkbox(value=value, description=description, style=self.style, layout=self.layout)\n",
|
144 |
+
"\n",
|
145 |
+
" def create_button(self, description, class_name=None):\n",
|
146 |
+
" button = widgets.Button(description=description)\n",
|
147 |
+
" if class_name:\n",
|
148 |
+
" button.add_class(class_name)\n",
|
149 |
+
" return button\n",
|
150 |
+
"\n",
|
151 |
+
" def create_hbox(self, children):\n",
|
152 |
+
" return widgets.HBox(children)\n",
|
153 |
+
"\n",
|
154 |
+
" def create_vbox(self, children, class_names=None):\n",
|
155 |
+
" vbox = widgets.VBox(children)\n",
|
156 |
+
" if class_names:\n",
|
157 |
+
" for class_name in class_names:\n",
|
158 |
+
" vbox.add_class(class_name)\n",
|
159 |
+
" return vbox\n",
|
160 |
+
"\n",
|
161 |
+
" def display(self, widget):\n",
|
162 |
+
" display(widget)\n",
|
163 |
+
"\n",
|
164 |
+
"# Instantiate the factory\n",
|
165 |
+
"factory = WidgetFactory()\n",
|
166 |
+
"\n",
|
167 |
+
"# --- MODEL ---\n",
|
168 |
+
"model_header = factory.create_header('Выбор Модели')\n",
|
169 |
+
"model_options = ['none',\n",
|
170 |
+
" '1.Anime (by XpucT) + INP',\n",
|
171 |
+
" '2.BluMix [Anime] [V7] + INP',\n",
|
172 |
+
" '3.Cetus-Mix [Anime] [V4] + INP',\n",
|
173 |
+
" '4.Counterfeit [Anime] [V3] + INP',\n",
|
174 |
+
" '5.CuteColor [Anime] [V3]',\n",
|
175 |
+
" '6.Dark-Sushi-Mix [Anime]',\n",
|
176 |
+
" '7.Deliberate [Realism] [V6] + INP',\n",
|
177 |
+
" '8.Meina-Mix [Anime] [V11] + INP',\n",
|
178 |
+
" '9.Mix-Pro [Anime] [V4] + INP']\n",
|
179 |
+
"model_widget = factory.create_dropdown(model_options, '4.Counterfeit [Anime] [V3] + INP', 'Модель:')\n",
|
180 |
+
"model_num_widget = factory.create_text('Номер Модели:', 'Введите номера моделей для скачивания через запятую/пробел.')\n",
|
181 |
+
"inpainting_model_widget = factory.create_checkbox(False, 'Inpainting Модели')\n",
|
182 |
+
"\n",
|
183 |
+
"# Display Model\n",
|
184 |
+
"all_model_box = factory.create_vbox([model_header, model_widget, model_num_widget, inpainting_model_widget], class_names=[\"container\", \"image_1\"])\n",
|
185 |
+
"factory.display(all_model_box)\n",
|
186 |
+
"\n",
|
187 |
+
"# --- VAE ---\n",
|
188 |
+
"vae_header = factory.create_header('Выбор VAE')\n",
|
189 |
+
"vae_options = ['none',\n",
|
190 |
+
" '1.Anime.vae',\n",
|
191 |
+
" '2.Anything.vae',\n",
|
192 |
+
" '3.Blessed2.vae',\n",
|
193 |
+
" '4.ClearVae.vae',\n",
|
194 |
+
" '5.WD.vae']\n",
|
195 |
+
"vae_widget = factory.create_dropdown(vae_options, '3.Blessed2.vae', 'Vae:')\n",
|
196 |
+
"vae_num_widget = factory.create_text('Номер Vae:', 'Введите номера vae для скачивания через запятую/пробел.')\n",
|
197 |
+
"\n",
|
198 |
+
"# Display Vae\n",
|
199 |
+
"all_vae_box = factory.create_vbox([vae_header, vae_widget, vae_num_widget], class_names=[\"container\", \"image_2\"])\n",
|
200 |
+
"factory.display(all_vae_box)\n",
|
201 |
+
"\n",
|
202 |
+
"# --- ADDITIONAL ---\n",
|
203 |
+
"additional_header = factory.create_header('Дополнительно')\n",
|
204 |
+
"latest_webui_widget = factory.create_checkbox(True, 'Обновить WebUI')\n",
|
205 |
+
"latest_exstensions_widget = factory.create_checkbox(True, 'Обновить Расширения')\n",
|
206 |
+
"change_webui_widget = factory.create_dropdown(['A1111', 'Forge'], 'A1111', 'Изменить WebUI:')\n",
|
207 |
+
"detailed_download_widget = factory.create_dropdown(['off', 'on'], 'off', 'Подробная Загрузка:')\n",
|
208 |
+
"choose_changes_widget = factory.create_hbox([latest_webui_widget, latest_exstensions_widget, change_webui_widget, detailed_download_widget])\n",
|
209 |
+
"\n",
|
210 |
+
"controlnet_options = ['none', 'ALL', '1.canny',\n",
|
211 |
+
" '2.openpose', '3.depth',\n",
|
212 |
+
" '4.normal_map', '5.mlsd',\n",
|
213 |
+
" '6.lineart', '7.soft_edge',\n",
|
214 |
+
" '8.scribble', '9.segmentation',\n",
|
215 |
+
" '10.shuffle', '11.tile',\n",
|
216 |
+
" '12.inpaint', '13.instruct_p2p']\n",
|
217 |
+
"controlnet_widget = factory.create_dropdown(controlnet_options, 'none', 'ControlNet:')\n",
|
218 |
+
"controlnet_num_widget = factory.create_text('Номер ControlNet:', 'Введите номера моделей ControlNet для скачивания через запятую/пробел.')\n",
|
219 |
+
"commit_hash_widget = factory.create_text('Commit Hash:')\n",
|
220 |
+
"huggingface_token_widget = factory.create_text('Токен HuggingFace:')\n",
|
221 |
+
"\n",
|
222 |
+
"ngrok_token_widget = factory.create_text('Токен Ngrok:')\n",
|
223 |
+
"ngrock_button = factory.create_html('<a href=\"https://dashboard.ngrok.com/get-started/your-authtoken\" target=\"_blank\">Получить Ngrok Токен</a>', class_name=\"button_ngrok\")\n",
|
224 |
+
"ngrok_widget = factory.create_hbox([ngrok_token_widget, ngrock_button])\n",
|
225 |
+
"\n",
|
226 |
+
"zrok_token_widget = factory.create_text('Токен Zrok:')\n",
|
227 |
+
"zrok_button = factory.create_html('<a href=\"https://colab.research.google.com/drive/1d2sjWDJi_GYBUavrHSuQyHTDuLy36WpU\" target=\"_blank\">Зарегать Zrok Токен</a>', class_name=\"button_ngrok\")\n",
|
228 |
+
"zrok_widget = factory.create_hbox([zrok_token_widget, zrok_button])\n",
|
229 |
+
"\n",
|
230 |
+
"commandline_arguments_options = \"--listen --enable-insecure-extension-access --theme dark --no-half-vae --disable-console-progressbars --xformers\"\n",
|
231 |
+
"commandline_arguments_widget = factory.create_text('Аргументы:', value=commandline_arguments_options)\n",
|
232 |
+
"\n",
|
233 |
+
"# Display Additional\n",
|
234 |
+
"additional_widget_list = [additional_header,\n",
|
235 |
+
" choose_changes_widget,\n",
|
236 |
+
" HR,\n",
|
237 |
+
" controlnet_widget,\n",
|
238 |
+
" controlnet_num_widget,\n",
|
239 |
+
" commit_hash_widget,\n",
|
240 |
+
" huggingface_token_widget,\n",
|
241 |
+
" ngrok_widget,\n",
|
242 |
+
" zrok_widget,\n",
|
243 |
+
" HR,\n",
|
244 |
+
" commandline_arguments_widget]\n",
|
245 |
+
"\n",
|
246 |
+
"if free_plan and env == \"Google Colab\": # remove ngrok from colab\n",
|
247 |
+
" additional_widget_list.remove(ngrok_widget)\n",
|
248 |
+
"if os.path.exists(webui_path): # remove selection after selection ;3\n",
|
249 |
+
" choose_changes_widget.children = [widget for widget in choose_changes_widget.children if widget != change_webui_widget]\n",
|
250 |
+
"\n",
|
251 |
+
"all_additional_box = factory.create_vbox(additional_widget_list, class_names=[\"container\", \"image_3\"])\n",
|
252 |
+
"factory.display(all_additional_box)\n",
|
253 |
+
"\n",
|
254 |
+
"# --- CUSTOM DOWNLOAD ---\n",
|
255 |
+
"custom_download_header_popup = factory.create_html('''\n",
|
256 |
+
"<style>\n",
|
257 |
+
"/* Term Colors */\n",
|
258 |
+
".sample_label {color: #dbafff;}\n",
|
259 |
+
".braces {color: #ffff00;}\n",
|
260 |
+
".extension {color: #eb934b;}\n",
|
261 |
+
".file_name {color: #ffffd8;}\n",
|
262 |
+
"</style>\n",
|
263 |
+
"\n",
|
264 |
+
"<div class=\"header\" style=\"cursor: pointer;\" onclick=\"toggleContainer()\">Кастомная Загрузка</div>\n",
|
265 |
+
"<!-- PopUp Window -->\n",
|
266 |
+
"<div class=\"info\" id=\"info_dl\">INFO</div>\n",
|
267 |
+
"<div class=\"popup\">\n",
|
268 |
+
" Разделите несколько URL-адресов запятой/пробелом. Для <span class=\"file_name\">пользовательского имени</span> файла/расширения укажите его через <span class=\"braces\">[]</span>\n",
|
269 |
+
" после URL без пробелов.\n",
|
270 |
+
" <span style=\"color: #ff9999\">Для файлов обязательно укажите</span> - <span class=\"extension\">Расширение Файла.</span>\n",
|
271 |
+
" <div class=\"sample\">\n",
|
272 |
+
" <span class=\"sample_label\">Пример для Файла:</span>\n",
|
273 |
+
" 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",
|
274 |
+
" <br>\n",
|
275 |
+
" <span class=\"sample_label\">Пример для Расширения:</span>\n",
|
276 |
+
" 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",
|
277 |
+
" </div>\n",
|
278 |
+
"</div>\n",
|
279 |
+
"''')\n",
|
280 |
+
"\n",
|
281 |
+
"Model_url_widget = factory.create_text('Model:')\n",
|
282 |
+
"Vae_url_widget = factory.create_text('Vae:')\n",
|
283 |
+
"LoRA_url_widget = factory.create_text('LoRa:')\n",
|
284 |
+
"Embedding_url_widget = factory.create_text('Embedding:')\n",
|
285 |
+
"Extensions_url_widget = factory.create_text('Extensions:')\n",
|
286 |
+
"custom_file_urls_widget = factory.create_text('Файл (txt):')\n",
|
287 |
+
"\n",
|
288 |
+
"# Display CustomDl\n",
|
289 |
+
"all_custom_box = factory.create_vbox([\n",
|
290 |
+
" custom_download_header_popup, Model_url_widget, Vae_url_widget, LoRA_url_widget, Embedding_url_widget, Extensions_url_widget, custom_file_urls_widget\n",
|
291 |
+
"], class_names=[\"container\", \"image_4\", \"container_custom_downlad\"])\n",
|
292 |
+
"factory.display(all_custom_box)\n",
|
293 |
+
"\n",
|
294 |
+
"# --- Save Button ---\n",
|
295 |
+
"save_button = factory.create_button('Сохранить', class_name=\"button_save\")\n",
|
296 |
+
"factory.display(save_button)\n",
|
297 |
+
"\n",
|
298 |
+
"\n",
|
299 |
+
"# ============ Load / Save - Settings V2 ============\n",
|
300 |
+
"SETTINGS_FILE = f'{root_path}/settings.json'\n",
|
301 |
+
"\n",
|
302 |
+
"SETTINGS_KEYS = [\n",
|
303 |
+
" 'model', 'model_num', 'inpainting_model',\n",
|
304 |
+
" 'vae', 'vae_num', 'latest_webui', 'latest_exstensions',\n",
|
305 |
+
" 'change_webui', 'detailed_download', 'controlnet',\n",
|
306 |
+
" 'controlnet_num', 'commit_hash', 'huggingface_token',\n",
|
307 |
+
" 'ngrok_token', 'zrok_token', 'commandline_arguments',\n",
|
308 |
+
" 'Model_url', 'Vae_url', 'LoRA_url', 'Embedding_url',\n",
|
309 |
+
" 'Extensions_url', 'custom_file_urls'\n",
|
310 |
+
"]\n",
|
311 |
+
"\n",
|
312 |
+
"def save_settings():\n",
|
313 |
+
" settings = {key: globals()[f\"{key}_widget\"].value for key in SETTINGS_KEYS}\n",
|
314 |
+
" with open(SETTINGS_FILE, 'w') as f:\n",
|
315 |
+
" json.dump(settings, f, indent=2)\n",
|
316 |
+
"\n",
|
317 |
+
"def load_settings():\n",
|
318 |
+
" if os.path.exists(SETTINGS_FILE):\n",
|
319 |
+
" with open(SETTINGS_FILE, 'r') as f:\n",
|
320 |
+
" settings = json.load(f)\n",
|
321 |
+
" for key in SETTINGS_KEYS:\n",
|
322 |
+
" globals()[f\"{key}_widget\"].value = settings.get(key, \"\")\n",
|
323 |
+
"\n",
|
324 |
+
"def hide_widgets():\n",
|
325 |
+
" widgets_list = [all_model_box, all_vae_box, all_additional_box, all_custom_box, save_button]\n",
|
326 |
+
" for widget in widgets_list:\n",
|
327 |
+
" widget.add_class(\"hide\")\n",
|
328 |
+
" time.sleep(0.5)\n",
|
329 |
+
" widgets.Widget.close_all()\n",
|
330 |
+
"\n",
|
331 |
+
"def save_data(button):\n",
|
332 |
+
" save_settings()\n",
|
333 |
+
" hide_widgets()\n",
|
334 |
+
"\n",
|
335 |
+
"load_settings()\n",
|
336 |
+
"save_button.on_click(save_data)"
|
337 |
+
]
|
338 |
+
}
|
339 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
340 |
}
|
files_cells/python/en/auto_cleaner_en.py
CHANGED
@@ -7,19 +7,11 @@ from ipywidgets import Label, Button, VBox, HBox
|
|
7 |
from IPython.display import display, HTML, Javascript
|
8 |
|
9 |
|
10 |
-
#
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
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 ====================
|
|
|
7 |
from IPython.display import display, HTML, Javascript
|
8 |
|
9 |
|
10 |
+
# Setup Env
|
11 |
+
env = os.environ.get('ENV_NAME')
|
12 |
+
root_path = os.environ.get('ROOT_PATH')
|
13 |
+
webui_path = os.environ.get('WEBUI_PATH')
|
14 |
+
free_plan = os.environ.get('FREE_PLAN')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
|
17 |
# ==================== CSS ====================
|
files_cells/python/en/downloading_en.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
##~ DOWNLOADING CODE | BY: ANXETY ~##
|
2 |
|
|
|
|
|
3 |
import os
|
4 |
import re
|
5 |
import time
|
@@ -15,19 +17,11 @@ from IPython.display import clear_output
|
|
15 |
from urllib.parse import urlparse, parse_qs
|
16 |
|
17 |
|
18 |
-
#
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
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 ================
|
@@ -197,112 +191,9 @@ if commit_hash:
|
|
197 |
|
198 |
## Downloading model and stuff | oh~ Hey! If you're freaked out by that code too, don't worry, me too!
|
199 |
print("📦 Downloading models and stuff...", end='')
|
200 |
-
model_list = {
|
201 |
-
"1.Anime (by XpucT) + INP": [
|
202 |
-
{"url": "https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2.safetensors", "name": "Anime_V2.safetensors"},
|
203 |
-
{"url": "https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2-inpainting.safetensors", "name": "Anime_V2-inpainting.safetensors"}
|
204 |
-
],
|
205 |
-
"2.BluMix [Anime] [V7] + INP": [
|
206 |
-
{"url": "https://civitai.com/api/download/models/361779", "name": "BluMix_V7.safetensors"},
|
207 |
-
{"url": "https://civitai.com/api/download/models/363850", "name": "BluMix_V7-inpainting.safetensors"}
|
208 |
-
],
|
209 |
-
"3.Cetus-Mix [Anime] [V4] + INP": [
|
210 |
-
{"url": "https://civitai.com/api/download/models/130298", "name": "CetusMix_V4.safetensors"},
|
211 |
-
{"url": "https://civitai.com/api/download/models/139882", "name": "CetusMix_V4-inpainting.safetensors"}
|
212 |
-
],
|
213 |
-
"4.Counterfeit [Anime] [V3] + INP": [
|
214 |
-
{"url": "https://huggingface.co/gsdf/Counterfeit-V3.0/resolve/main/Counterfeit-V3.0_fix_fp16.safetensors", "name": "Counterfeit_V3.safetensors"},
|
215 |
-
{"url": "https://civitai.com/api/download/models/137911", "name": "Counterfeit_V3-inpainting.safetensors"}
|
216 |
-
],
|
217 |
-
"5.CuteColor [Anime] [V3]": [
|
218 |
-
{"url": "https://civitai.com/api/download/models/138754", "name": "CuteColor_V3.safetensors"}
|
219 |
-
],
|
220 |
-
"6.Dark-Sushi-Mix [Anime]": [
|
221 |
-
{"url": "https://civitai.com/api/download/models/101640", "name": "DarkSushiMix_2_5D.safetensors"},
|
222 |
-
{"url": "https://civitai.com/api/download/models/56071", "name": "DarkSushiMix_colorful.safetensors"}
|
223 |
-
],
|
224 |
-
"7.Deliberate [Realism] [V6] + INP": [
|
225 |
-
{"url": "https://huggingface.co/XpucT/Deliberate/resolve/main/Deliberate_v6.safetensors", "name": "Deliberate_V6.safetensors"},
|
226 |
-
{"url": "https://huggingface.co/XpucT/Deliberate/resolve/main/Deliberate_v6-inpainting.safetensors", "name": "Deliberate_V6-inpainting.safetensors"}
|
227 |
-
],
|
228 |
-
"8.Meina-Mix [Anime] [V11] + INP": [
|
229 |
-
{"url": "https://civitai.com/api/download/models/119057", "name": "MeinaMix_V11.safetensors"},
|
230 |
-
{"url": "https://civitai.com/api/download/models/120702", "name": "MeinaMix_V11-inpainting.safetensors"}
|
231 |
-
],
|
232 |
-
"9.Mix-Pro [Anime] [V4] + INP": [
|
233 |
-
{"url": "https://civitai.com/api/download/models/125668", "name": "MixPro_V4.safetensors"},
|
234 |
-
{"url": "https://civitai.com/api/download/models/139878", "name": "MixPro_V4-inpainting.safetensors"}
|
235 |
-
]
|
236 |
-
}
|
237 |
-
|
238 |
-
vae_list = {
|
239 |
-
"1.Anime.vae": [{"url": "https://civitai.com/api/download/models/311162", "name": "Anime.vae.safetensors"}],
|
240 |
-
"2.Anything.vae": [{"url": "https://huggingface.co/NoCrypt/resources/resolve/main/VAE/any.vae.safetensors", "name": "Anything.vae.safetensors"}],
|
241 |
-
"3.Blessed2.vae": [{"url": "https://huggingface.co/NoCrypt/resources/resolve/main/VAE/blessed2.vae.safetensors", "name": "Blessed2.vae.safetensors"}],
|
242 |
-
"4.ClearVae.vae": [{"url": "https://civitai.com/api/download/models/88156", "name": "ClearVae_23.vae.safetensors"}],
|
243 |
-
"5.WD.vae": [{"url": "https://huggingface.co/NoCrypt/resources/resolve/main/VAE/wd.vae.safetensors", "name": "WD.vae.safetensors"}]
|
244 |
-
}
|
245 |
-
|
246 |
-
controlnet_list = {
|
247 |
-
"1.canny": [
|
248 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny_fp16.safetensors", "name": "control_v11p_sd15_canny_fp16.safetensors"},
|
249 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_canny_fp16.yaml", "name": "control_v11p_sd15_canny_fp16.yaml"}
|
250 |
-
],
|
251 |
-
"2.openpose": [
|
252 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose_fp16.safetensors", "name": "control_v11p_sd15_openpose_fp16.safetensors"},
|
253 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_openpose_fp16.yaml", "name": "control_v11p_sd15_openpose_fp16.yaml"}
|
254 |
-
],
|
255 |
-
"3.depth": [
|
256 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth_fp16.safetensors", "name": "control_v11f1p_sd15_depth_fp16.safetensors"},
|
257 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1p_sd15_depth_fp16.yaml", "name": "control_v11f1p_sd15_depth_fp16.yaml"},
|
258 |
-
{"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"}
|
259 |
-
],
|
260 |
-
"4.normal_map": [
|
261 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_normalbae_fp16.safetensors", "name": "control_v11p_sd15_normalbae_fp16.safetensors"},
|
262 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_normalbae_fp16.yaml", "name": "control_v11p_sd15_normalbae_fp16.yaml"}
|
263 |
-
],
|
264 |
-
"5.mlsd": [
|
265 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_mlsd_fp16.safetensors", "name": "control_v11p_sd15_mlsd_fp16.safetensors"},
|
266 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_mlsd_fp16.yaml", "name": "control_v11p_sd15_mlsd_fp16.yaml"}
|
267 |
-
],
|
268 |
-
"6.lineart": [
|
269 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart_fp16.safetensors", "name": "control_v11p_sd15_lineart_fp16.safetensors"},
|
270 |
-
{"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"},
|
271 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_lineart_fp16.yaml", "name": "control_v11p_sd15_lineart_fp16.yaml"},
|
272 |
-
{"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"}
|
273 |
-
],
|
274 |
-
"7.soft_edge": [
|
275 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge_fp16.safetensors", "name": "control_v11p_sd15_softedge_fp16.safetensors"},
|
276 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_softedge_fp16.yaml", "name": "control_v11p_sd15_softedge_fp16.yaml"}
|
277 |
-
],
|
278 |
-
"8.scribble": [
|
279 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble_fp16.safetensors", "name": "control_v11p_sd15_scribble_fp16.safetensors"},
|
280 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_scribble_fp16.yaml", "name": "control_v11p_sd15_scribble_fp16.yaml"}
|
281 |
-
],
|
282 |
-
"9.segmentation": [
|
283 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg_fp16.safetensors", "name": "control_v11p_sd15_seg_fp16.safetensors"},
|
284 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_seg_fp16.yaml", "name": "control_v11p_sd15_seg_fp16.yaml"}
|
285 |
-
],
|
286 |
-
"10.shuffle": [
|
287 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle_fp16.safetensors", "name": "control_v11e_sd15_shuffle_fp16.safetensors"},
|
288 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_shuffle_fp16.yaml", "name": "control_v11e_sd15_shuffle_fp16.yaml"}
|
289 |
-
],
|
290 |
-
"11.tile": [
|
291 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile_fp16.safetensors", "name": "control_v11f1e_sd15_tile_fp16.safetensors"},
|
292 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1e_sd15_tile_fp16.yaml", "name": "control_v11f1e_sd15_tile_fp16.yaml"}
|
293 |
-
],
|
294 |
-
"12.inpaint": [
|
295 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_inpaint_fp16.safetensors", "name": "control_v11p_sd15_inpaint_fp16.safetensors"},
|
296 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_inpaint_fp16.yaml", "name": "control_v11p_sd15_inpaint_fp16.yaml"}
|
297 |
-
],
|
298 |
-
"13.instruct_p2p": [
|
299 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p_fp16.safetensors", "name": "control_v11e_sd15_ip2p_fp16.safetensors"},
|
300 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_ip2p_fp16.yaml", "name": "control_v11e_sd15_ip2p_fp16.yaml"}
|
301 |
-
]
|
302 |
-
}
|
303 |
|
304 |
url = ""
|
305 |
-
|
306 |
"model": models_dir,
|
307 |
"vae": vaes_dir,
|
308 |
"lora": loras_dir,
|
@@ -314,7 +205,7 @@ prefixes = {
|
|
314 |
}
|
315 |
|
316 |
extension_repo = []
|
317 |
-
directories = [value for key, value in
|
318 |
get_ipython().system('mkdir -p {" ".join(directories)}')
|
319 |
|
320 |
hf_token = huggingface_token if huggingface_token else "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"
|
@@ -325,137 +216,123 @@ user_header = f"\"Authorization: Bearer {hf_token}\""
|
|
325 |
from math import floor
|
326 |
|
327 |
def center_text(text, terminal_width=45):
|
328 |
-
|
329 |
-
|
330 |
-
right_padding = terminal_width - text_length - left_padding
|
331 |
-
return f"\033[1m\033[36m{' ' * left_padding}{text}{' ' * right_padding}\033[0m\033[32m"
|
332 |
|
333 |
def format_output(url, dst_dir, file_name):
|
334 |
-
info = f"[{file_name.split('.')[0]}]"
|
335 |
-
|
336 |
|
337 |
-
print(f"\n
|
338 |
print(f"\033[33mURL: \033[34m{url}")
|
339 |
print(f"\033[33mSAVE DIR: \033[34m{dst_dir}")
|
340 |
print(f"\033[33mFILE NAME: \033[34m{file_name}\033[0m")
|
341 |
|
342 |
''' GET CivitAi API - DATA '''
|
343 |
|
344 |
-
def strip_(url, file_name=None):
|
345 |
-
if 'github.com' in url:
|
346 |
-
if '/blob/' in url:
|
347 |
-
url = url.replace('/blob/', '/raw/')
|
348 |
-
|
349 |
-
elif "civitai.com" in url:
|
350 |
-
return CivitAi_API(url, file_name)
|
351 |
-
|
352 |
-
elif "huggingface.co" in url:
|
353 |
-
if '/blob/' in url:
|
354 |
-
url = url.replace('/blob/', '/resolve/')
|
355 |
-
if '?' in url:
|
356 |
-
url = url.split('?')[0]
|
357 |
-
|
358 |
-
return url
|
359 |
-
|
360 |
def CivitAi_API(url, file_name=None):
|
361 |
-
|
362 |
-
|
363 |
|
364 |
-
if '?token=' in url
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
response = requests.get(f"https://civitai.com/api/v1/model-versions/{version_id}")
|
376 |
-
# print(f"end - https://civitai.com/api/v1/model-versions/{version_id}")
|
377 |
else:
|
378 |
-
|
379 |
-
|
380 |
-
# print(f"end - https://civitai.com/api/v1/models/{model_id}")
|
381 |
-
else:
|
382 |
-
version_id = url.split('/models/')[1].split('/')[0]
|
383 |
-
response = requests.get(f"https://civitai.com/api/v1/model-versions/{version_id}")
|
384 |
-
# print(f"end - https://civitai.com/api/v1/model-versions/{version_id}")
|
385 |
|
386 |
-
data =
|
387 |
|
388 |
-
if
|
389 |
return None, None, None, None, None, None, None
|
390 |
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
396 |
else:
|
397 |
-
model_type = data['type']
|
398 |
-
model_name = data['modelVersions'][0]['files'][0]['name']
|
399 |
-
elif 'type=' in url:
|
400 |
-
model_type = parse_qs(urlparse(url).query).get('type', [''])[0]
|
401 |
-
if 'model' in model_type.lower():
|
402 |
model_name = data['files'][0]['name']
|
403 |
-
|
404 |
-
model_name = data['files'][1]['name']
|
405 |
-
else:
|
406 |
-
model_type = data['model']['type']
|
407 |
-
model_name = data['files'][0]['name']
|
408 |
|
|
|
409 |
model_name = file_name or model_name
|
410 |
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
|
|
|
|
420 |
else:
|
421 |
-
|
422 |
-
else:
|
423 |
-
download_url = data.get('downloadUrl')
|
424 |
|
425 |
-
|
|
|
426 |
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
|
|
|
|
|
|
438 |
|
439 |
-
|
440 |
-
image_name = f"{model_name.split('.')[0]}.preview.{image_url.split('.')[-1]}" if image_url else None
|
441 |
|
442 |
-
return f"{download_url}{'&' if '?' in download_url else '?'}token={
|
443 |
|
444 |
''' Main Download Code '''
|
445 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
446 |
def download(url):
|
447 |
links_and_paths = [link_or_path.strip() for link_or_path in url.split(',') if link_or_path.strip()]
|
448 |
|
449 |
for link_or_path in links_and_paths:
|
450 |
-
if any(link_or_path.lower().startswith(prefix) for prefix in
|
451 |
handle_manual(link_or_path)
|
452 |
else:
|
453 |
url, dst_dir, file_name = link_or_path.split()
|
454 |
manual_download(url, dst_dir, file_name)
|
455 |
|
456 |
-
|
457 |
-
|
458 |
-
def unpack_zip_files():
|
459 |
for directory in directories:
|
460 |
for root, _, files in os.walk(directory):
|
461 |
for file in files:
|
@@ -475,8 +352,8 @@ def handle_manual(url):
|
|
475 |
if file_name:
|
476 |
path = re.sub(r'\[.*?\]', '', path)
|
477 |
|
478 |
-
if prefix in
|
479 |
-
dir =
|
480 |
if prefix != "extension":
|
481 |
try:
|
482 |
manual_download(path, dir, file_name=file_name)
|
@@ -490,60 +367,52 @@ def manual_download(url, dst_dir, file_name):
|
|
490 |
aria2c_header = "--header='User-Agent: Mozilla/5.0' --allow-overwrite=true"
|
491 |
aria2_args = "--optimize-concurrent-downloads --console-log-level=error --summary-interval=10 --stderr=true -c -x16 -s16 -k1M -j5"
|
492 |
|
493 |
-
|
494 |
-
url = strip_(url)
|
495 |
-
|
496 |
-
# -- CivitAi APi+ V2 --
|
497 |
-
elif 'civitai' in url:
|
498 |
-
url, clean_url, model_type, file_name, image_url, image_name, data = strip_(url, file_name)
|
499 |
|
|
|
|
|
500 |
if image_url and image_name:
|
501 |
-
|
502 |
-
|
503 |
-
del cap
|
504 |
|
505 |
-
elif "huggingface.co" in url:
|
506 |
-
|
507 |
-
basename = clean_url.split("/")[-1] if file_name is None else file_name
|
508 |
|
509 |
""" Formatted info output """
|
510 |
-
model_name_or_basename = file_name if
|
511 |
format_output(clean_url or url, dst_dir, model_name_or_basename)
|
512 |
|
513 |
-
# ## -- for my tests --
|
514 |
# print(url, dst_dir, model_name_or_basename)
|
515 |
-
|
516 |
-
|
517 |
-
|
|
|
|
|
|
|
518 |
# =====================
|
|
|
|
|
|
|
519 |
|
520 |
-
# --
|
521 |
-
if '
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
elif 'drive.google' in url:
|
526 |
-
try:
|
527 |
-
have_drive_link
|
528 |
-
except:
|
529 |
-
get_ipython().system('pip install -q gdown==5.2.0 > /dev/null')
|
530 |
-
have_drive_link = True
|
531 |
|
532 |
if 'folders' in url:
|
533 |
-
|
534 |
else:
|
535 |
-
if file_name
|
536 |
-
|
537 |
-
else:
|
538 |
-
get_ipython().system('gdown "{url}" -O {dst_dir} --fuzzy -c')
|
539 |
|
540 |
-
# -- Hugging Face --
|
541 |
-
elif 'huggingface' in url:
|
542 |
-
|
543 |
|
544 |
-
# -- Other --
|
545 |
elif 'http' in url:
|
546 |
-
|
547 |
|
548 |
''' SubModels - Added URLs '''
|
549 |
|
@@ -583,7 +452,7 @@ url = handle_submodels(controlnet, controlnet_num, controlnet_list, control_dir,
|
|
583 |
|
584 |
''' file.txt - added urls '''
|
585 |
|
586 |
-
def process_file_download(file_url,
|
587 |
files_urls = ""
|
588 |
|
589 |
if file_url.startswith("http"):
|
@@ -598,8 +467,8 @@ def process_file_download(file_url, prefixes, unique_urls):
|
|
598 |
current_tag = None
|
599 |
for line in lines:
|
600 |
line = line.strip()
|
601 |
-
if any(f'# {tag}' in line.lower() for tag in
|
602 |
-
current_tag = next((tag for tag in
|
603 |
|
604 |
urls = [url.split('#')[0].strip() for url in line.split(',')] # filter urls
|
605 |
for url in urls:
|
@@ -623,13 +492,13 @@ if custom_file_urls:
|
|
623 |
custom_file_url = f'{root_path}/{custom_file_url}'
|
624 |
|
625 |
try:
|
626 |
-
file_urls += process_file_download(custom_file_url,
|
627 |
except FileNotFoundError:
|
628 |
pass
|
629 |
|
630 |
# url prefixing
|
631 |
urls = (Model_url, Vae_url, LoRA_url, Embedding_url, Extensions_url)
|
632 |
-
prefixed_urls = (f"{prefix}:{url}" for prefix, url in zip(
|
633 |
url += ", ".join(prefixed_urls) + ", " + file_urls
|
634 |
|
635 |
if detailed_download == "on":
|
|
|
1 |
##~ DOWNLOADING CODE | BY: ANXETY ~##
|
2 |
|
3 |
+
from models_data import model_list, vae_list, controlnet_list
|
4 |
+
|
5 |
import os
|
6 |
import re
|
7 |
import time
|
|
|
17 |
from urllib.parse import urlparse, parse_qs
|
18 |
|
19 |
|
20 |
+
# Setup Env
|
21 |
+
env = os.environ.get('ENV_NAME')
|
22 |
+
root_path = os.environ.get('ROOT_PATH')
|
23 |
+
webui_path = os.environ.get('WEBUI_PATH')
|
24 |
+
free_plan = os.environ.get('FREE_PLAN')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
|
27 |
# ================ LIBRARIES V2 ================
|
|
|
191 |
|
192 |
## Downloading model and stuff | oh~ Hey! If you're freaked out by that code too, don't worry, me too!
|
193 |
print("📦 Downloading models and stuff...", end='')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
194 |
|
195 |
url = ""
|
196 |
+
PREFIXES = {
|
197 |
"model": models_dir,
|
198 |
"vae": vaes_dir,
|
199 |
"lora": loras_dir,
|
|
|
205 |
}
|
206 |
|
207 |
extension_repo = []
|
208 |
+
directories = [value for key, value in PREFIXES.items()] # for unpucking zip files
|
209 |
get_ipython().system('mkdir -p {" ".join(directories)}')
|
210 |
|
211 |
hf_token = huggingface_token if huggingface_token else "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"
|
|
|
216 |
from math import floor
|
217 |
|
218 |
def center_text(text, terminal_width=45):
|
219 |
+
padding = (terminal_width - len(text)) // 2
|
220 |
+
return f"\033[1m\033[36m{' ' * padding}{text}{' ' * padding}\033[0m\033[32m"
|
|
|
|
|
221 |
|
222 |
def format_output(url, dst_dir, file_name):
|
223 |
+
info = center_text(f"[{file_name.split('.')[0]}]")
|
224 |
+
separation_line = '\033[32m' + '---' * 20
|
225 |
|
226 |
+
print(f"\n{separation_line}{info}{separation_line}")
|
227 |
print(f"\033[33mURL: \033[34m{url}")
|
228 |
print(f"\033[33mSAVE DIR: \033[34m{dst_dir}")
|
229 |
print(f"\033[33mFILE NAME: \033[34m{file_name}\033[0m")
|
230 |
|
231 |
''' GET CivitAi API - DATA '''
|
232 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
233 |
def CivitAi_API(url, file_name=None):
|
234 |
+
SUPPORT_TYPES = ('Checkpoint', 'Model', 'TextualInversion', 'LORA')
|
235 |
+
CIVITAI_TOKEN = "62c0c5956b2f9defbd844d754000180b"
|
236 |
|
237 |
+
url = url.split('?token=')[0] if '?token=' in url else url
|
238 |
+
url = url.replace('?type=', f'?token={CIVITAI_TOKEN}&type=') if '?type=' in url else f"{url}?token={CIVITAI_TOKEN}"
|
239 |
+
|
240 |
+
def get_model_data(url):
|
241 |
+
if "civitai.com/models/" in url:
|
242 |
+
if '?modelVersionId=' in url:
|
243 |
+
version_id = url.split('?modelVersionId=')[1]
|
244 |
+
return requests.get(f"https://civitai.com/api/v1/model-versions/{version_id}").json()
|
245 |
+
else:
|
246 |
+
model_id = url.split('/models/')[1].split('/')[0]
|
247 |
+
return requests.get(f"https://civitai.com/api/v1/models/{model_id}").json()
|
|
|
|
|
248 |
else:
|
249 |
+
version_id = url.split('/models/')[1].split('/')[0]
|
250 |
+
return requests.get(f"https://civitai.com/api/v1/model-versions/{version_id}").json()
|
|
|
|
|
|
|
|
|
|
|
251 |
|
252 |
+
data = get_model_data(url)
|
253 |
|
254 |
+
if not data:
|
255 |
return None, None, None, None, None, None, None
|
256 |
|
257 |
+
def extract_model_info(url, data):
|
258 |
+
if "civitai.com/models/" in url:
|
259 |
+
if '?modelVersionId=' in url:
|
260 |
+
model_type = data['model']['type']
|
261 |
+
model_name = data['files'][0]['name']
|
262 |
+
else:
|
263 |
+
model_type = data['type']
|
264 |
+
model_name = data['modelVersions'][0]['files'][0]['name']
|
265 |
+
elif 'type=' in url:
|
266 |
+
model_type = parse_qs(urlparse(url).query).get('type', [''])[0]
|
267 |
+
if 'model' in model_type.lower():
|
268 |
+
model_name = data['files'][0]['name']
|
269 |
+
else:
|
270 |
+
model_name = data['files'][1]['name']
|
271 |
else:
|
272 |
+
model_type = data['model']['type']
|
|
|
|
|
|
|
|
|
273 |
model_name = data['files'][0]['name']
|
274 |
+
return model_type, model_name
|
|
|
|
|
|
|
|
|
275 |
|
276 |
+
model_type, model_name = extract_model_info(url, data)
|
277 |
model_name = file_name or model_name
|
278 |
|
279 |
+
def get_download_url(url, data, model_type):
|
280 |
+
if "civitai.com/models/" in url:
|
281 |
+
if '?modelVersionId=' in url:
|
282 |
+
return data.get('downloadUrl')
|
283 |
+
else:
|
284 |
+
return data["modelVersions"][0].get("downloadUrl", "")
|
285 |
+
elif 'type=' in url:
|
286 |
+
if any(t.lower() in model_type.lower() for t in SUPPORT_TYPES):
|
287 |
+
return data['files'][0]['downloadUrl']
|
288 |
+
else:
|
289 |
+
return data['files'][1]['downloadUrl']
|
290 |
else:
|
291 |
+
return data.get('downloadUrl')
|
|
|
|
|
292 |
|
293 |
+
download_url = get_download_url(url, data, model_type)
|
294 |
+
clean_url = re.sub(r'[?&]token=[^&]*', '', download_url)
|
295 |
|
296 |
+
def get_image_info(data, model_type, model_name):
|
297 |
+
image_url, image_name = None, None
|
298 |
+
if any(t in model_type for t in SUPPORT_TYPES):
|
299 |
+
try:
|
300 |
+
images = data.get('images') or data['modelVersions'][0].get('images', [])
|
301 |
+
if env == 'Kaggle':
|
302 |
+
image_url = next((image['url'] for image in images if image['nsfwLevel'] < 4), None)
|
303 |
+
else:
|
304 |
+
image_url = images[0]['url'] if images else None
|
305 |
+
except KeyError:
|
306 |
+
pass
|
307 |
+
|
308 |
+
image_name = f"{model_name.split('.')[0]}.preview.{image_url.split('.')[-1]}" if image_url else None
|
309 |
+
return image_url, image_name
|
310 |
|
311 |
+
image_url, image_name = get_image_info(data, model_type, model_name)
|
|
|
312 |
|
313 |
+
return f"{download_url}{'&' if '?' in download_url else '?'}token={CIVITAI_TOKEN}", clean_url, model_type, model_name, image_url, image_name, data
|
314 |
|
315 |
''' Main Download Code '''
|
316 |
|
317 |
+
def strip_(url):
|
318 |
+
if 'github.com' in url:
|
319 |
+
return url.replace('/blob/', '/raw/')
|
320 |
+
elif "huggingface.co" in url:
|
321 |
+
url = url.replace('/blob/', '/resolve/')
|
322 |
+
return url.split('?')[0] if '?' in url else url
|
323 |
+
return url
|
324 |
+
|
325 |
def download(url):
|
326 |
links_and_paths = [link_or_path.strip() for link_or_path in url.split(',') if link_or_path.strip()]
|
327 |
|
328 |
for link_or_path in links_and_paths:
|
329 |
+
if any(link_or_path.lower().startswith(prefix) for prefix in PREFIXES):
|
330 |
handle_manual(link_or_path)
|
331 |
else:
|
332 |
url, dst_dir, file_name = link_or_path.split()
|
333 |
manual_download(url, dst_dir, file_name)
|
334 |
|
335 |
+
# Unpuck ZIPs Files
|
|
|
|
|
336 |
for directory in directories:
|
337 |
for root, _, files in os.walk(directory):
|
338 |
for file in files:
|
|
|
352 |
if file_name:
|
353 |
path = re.sub(r'\[.*?\]', '', path)
|
354 |
|
355 |
+
if prefix in PREFIXES:
|
356 |
+
dir = PREFIXES[prefix]
|
357 |
if prefix != "extension":
|
358 |
try:
|
359 |
manual_download(path, dir, file_name=file_name)
|
|
|
367 |
aria2c_header = "--header='User-Agent: Mozilla/5.0' --allow-overwrite=true"
|
368 |
aria2_args = "--optimize-concurrent-downloads --console-log-level=error --summary-interval=10 --stderr=true -c -x16 -s16 -k1M -j5"
|
369 |
|
370 |
+
clean_url = strip_(url)
|
|
|
|
|
|
|
|
|
|
|
371 |
|
372 |
+
if 'civitai' in url:
|
373 |
+
url, clean_url, model_type, file_name, image_url, image_name, data = CivitAi_API(url, file_name)
|
374 |
if image_url and image_name:
|
375 |
+
command = ["aria2c"] + aria2_args.split() + ["-d", dst_dir, "-o", image_name, image_url]
|
376 |
+
subprocess.run(command, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
|
377 |
|
378 |
+
elif 'github' in url or "huggingface.co" in url:
|
379 |
+
basename = url.split("/")[-1] if file_name is None else file_name
|
|
|
380 |
|
381 |
""" Formatted info output """
|
382 |
+
model_name_or_basename = file_name if file_name else basename
|
383 |
format_output(clean_url or url, dst_dir, model_name_or_basename)
|
384 |
|
|
|
385 |
# print(url, dst_dir, model_name_or_basename)
|
386 |
+
if 'civitai' in url:
|
387 |
+
if not data:
|
388 |
+
print("\033[31m[Data Info]:\033[0m Failed to retrieve data from the API.\n")
|
389 |
+
if data and image_name:
|
390 |
+
print(f"\033[32m[Preview DL]:\033[0m {image_name} - {image_url}\n")
|
391 |
+
|
392 |
# =====================
|
393 |
+
def run_aria2c(url, dst_dir, file_name=None, args="", header=""):
|
394 |
+
out = f"-o '{file_name}'" if file_name else ""
|
395 |
+
get_ipython().system("aria2c {header} {args} -d {dst_dir} {out} '{url}'")
|
396 |
|
397 |
+
# -- Google Drive --
|
398 |
+
if 'drive.google' in url:
|
399 |
+
if not globals().get('have_drive_link', False):
|
400 |
+
os.system("pip install -U gdown > /dev/null")
|
401 |
+
globals()['have_drive_link'] = True
|
|
|
|
|
|
|
|
|
|
|
|
|
402 |
|
403 |
if 'folders' in url:
|
404 |
+
os.system(f"gdown --folder \"{url}\" -O {dst_dir} --fuzzy -c")
|
405 |
else:
|
406 |
+
out_path = f"{dst_dir}/{file_name}" if file_name else dst_dir
|
407 |
+
os.system(f"gdown \"{url}\" -O {out_path} --fuzzy -c")
|
|
|
|
|
408 |
|
409 |
+
# -- GitHub or Hugging Face --
|
410 |
+
elif 'github' in url or 'huggingface' in url:
|
411 |
+
run_aria2c(clean_url, dst_dir, basename, aria2_args, header_option if 'huggingface' in url else '')
|
412 |
|
413 |
+
# -- Other HTTP/Sources --
|
414 |
elif 'http' in url:
|
415 |
+
run_aria2c(url, dst_dir, file_name, aria2_args, aria2c_header)
|
416 |
|
417 |
''' SubModels - Added URLs '''
|
418 |
|
|
|
452 |
|
453 |
''' file.txt - added urls '''
|
454 |
|
455 |
+
def process_file_download(file_url, PREFIXES, unique_urls):
|
456 |
files_urls = ""
|
457 |
|
458 |
if file_url.startswith("http"):
|
|
|
467 |
current_tag = None
|
468 |
for line in lines:
|
469 |
line = line.strip()
|
470 |
+
if any(f'# {tag}' in line.lower() for tag in PREFIXES):
|
471 |
+
current_tag = next((tag for tag in PREFIXES if tag in line.lower()))
|
472 |
|
473 |
urls = [url.split('#')[0].strip() for url in line.split(',')] # filter urls
|
474 |
for url in urls:
|
|
|
492 |
custom_file_url = f'{root_path}/{custom_file_url}'
|
493 |
|
494 |
try:
|
495 |
+
file_urls += process_file_download(custom_file_url, PREFIXES, unique_urls)
|
496 |
except FileNotFoundError:
|
497 |
pass
|
498 |
|
499 |
# url prefixing
|
500 |
urls = (Model_url, Vae_url, LoRA_url, Embedding_url, Extensions_url)
|
501 |
+
prefixed_urls = (f"{prefix}:{url}" for prefix, url in zip(PREFIXES.keys(), urls) if url for url in url.replace(',', '').split())
|
502 |
url += ", ".join(prefixed_urls) + ", " + file_urls
|
503 |
|
504 |
if detailed_download == "on":
|
files_cells/python/en/launch_en.py
CHANGED
@@ -9,21 +9,13 @@ 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 |
-
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'
|
@@ -38,6 +30,7 @@ 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 |
|
@@ -71,6 +64,7 @@ if zrok_token:
|
|
71 |
|
72 |
clear_output()
|
73 |
|
|
|
74 |
# =============== Automatic Fixing Path V3 ===============
|
75 |
paths_to_check = {
|
76 |
"tagger_hf_cache_dir": f"{webui_path}/models/interrogators/",
|
|
|
9 |
from datetime import timedelta
|
10 |
from IPython.display import clear_output
|
11 |
|
12 |
+
|
13 |
+
# Setup Env
|
14 |
+
env = os.environ.get('ENV_NAME')
|
15 |
+
root_path = os.environ.get('ROOT_PATH')
|
16 |
+
webui_path = os.environ.get('WEBUI_PATH')
|
17 |
+
free_plan = os.environ.get('FREE_PLAN')
|
18 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
def load_settings():
|
21 |
SETTINGS_FILE = f'{root_path}/settings.json'
|
|
|
30 |
commandline_arguments = settings.get('commandline_arguments', "")
|
31 |
change_webui = settings.get('change_webui', "")
|
32 |
|
33 |
+
|
34 |
# ======================== TUNNEL V2 ========================
|
35 |
print('Please Wait...')
|
36 |
|
|
|
64 |
|
65 |
clear_output()
|
66 |
|
67 |
+
|
68 |
# =============== Automatic Fixing Path V3 ===============
|
69 |
paths_to_check = {
|
70 |
"tagger_hf_cache_dir": f"{webui_path}/models/interrogators/",
|
files_cells/python/en/widgets_en.py
CHANGED
@@ -8,20 +8,11 @@ from ipywidgets import widgets, Layout, Label, Button, VBox, HBox
|
|
8 |
from IPython.display import display, HTML, Javascript, clear_output
|
9 |
|
10 |
|
11 |
-
#
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
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 ====================
|
|
|
8 |
from IPython.display import display, HTML, Javascript, clear_output
|
9 |
|
10 |
|
11 |
+
# Setup Env
|
12 |
+
env = os.environ.get('ENV_NAME')
|
13 |
+
root_path = os.environ.get('ROOT_PATH')
|
14 |
+
webui_path = os.environ.get('WEBUI_PATH')
|
15 |
+
free_plan = os.environ.get('FREE_PLAN')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
|
18 |
# ==================== CSS JS ====================
|
files_cells/python/ru/auto_cleaner_ru.py
CHANGED
@@ -7,19 +7,11 @@ from ipywidgets import Label, Button, VBox, HBox
|
|
7 |
from IPython.display import display, HTML
|
8 |
|
9 |
|
10 |
-
#
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
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 ====================
|
|
|
7 |
from IPython.display import display, HTML
|
8 |
|
9 |
|
10 |
+
# Setup Env
|
11 |
+
env = os.environ.get('ENV_NAME')
|
12 |
+
root_path = os.environ.get('ROOT_PATH')
|
13 |
+
webui_path = os.environ.get('WEBUI_PATH')
|
14 |
+
free_plan = os.environ.get('FREE_PLAN')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
|
17 |
# ==================== CSS ====================
|
files_cells/python/ru/downloading_ru.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
##~ DOWNLOADING CODE | BY: ANXETY ~##
|
2 |
|
|
|
|
|
3 |
import os
|
4 |
import re
|
5 |
import time
|
@@ -15,19 +17,11 @@ from IPython.display import clear_output
|
|
15 |
from urllib.parse import urlparse, parse_qs
|
16 |
|
17 |
|
18 |
-
#
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
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 ================
|
@@ -197,112 +191,9 @@ if commit_hash:
|
|
197 |
|
198 |
## Downloading model and stuff | oh~ Hey! If you're freaked out by that code too, don't worry, me too!
|
199 |
print("📦 Скачивание моделей и прочего...", end='')
|
200 |
-
model_list = {
|
201 |
-
"1.Anime (by XpucT) + INP": [
|
202 |
-
{"url": "https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2.safetensors", "name": "Anime_V2.safetensors"},
|
203 |
-
{"url": "https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2-inpainting.safetensors", "name": "Anime_V2-inpainting.safetensors"}
|
204 |
-
],
|
205 |
-
"2.BluMix [Anime] [V7] + INP": [
|
206 |
-
{"url": "https://civitai.com/api/download/models/361779", "name": "BluMix_V7.safetensors"},
|
207 |
-
{"url": "https://civitai.com/api/download/models/363850", "name": "BluMix_V7-inpainting.safetensors"}
|
208 |
-
],
|
209 |
-
"3.Cetus-Mix [Anime] [V4] + INP": [
|
210 |
-
{"url": "https://civitai.com/api/download/models/130298", "name": "CetusMix_V4.safetensors"},
|
211 |
-
{"url": "https://civitai.com/api/download/models/139882", "name": "CetusMix_V4-inpainting.safetensors"}
|
212 |
-
],
|
213 |
-
"4.Counterfeit [Anime] [V3] + INP": [
|
214 |
-
{"url": "https://huggingface.co/gsdf/Counterfeit-V3.0/resolve/main/Counterfeit-V3.0_fix_fp16.safetensors", "name": "Counterfeit_V3.safetensors"},
|
215 |
-
{"url": "https://civitai.com/api/download/models/137911", "name": "Counterfeit_V3-inpainting.safetensors"}
|
216 |
-
],
|
217 |
-
"5.CuteColor [Anime] [V3]": [
|
218 |
-
{"url": "https://civitai.com/api/download/models/138754", "name": "CuteColor_V3.safetensors"}
|
219 |
-
],
|
220 |
-
"6.Dark-Sushi-Mix [Anime]": [
|
221 |
-
{"url": "https://civitai.com/api/download/models/101640", "name": "DarkSushiMix_2_5D.safetensors"},
|
222 |
-
{"url": "https://civitai.com/api/download/models/56071", "name": "DarkSushiMix_colorful.safetensors"}
|
223 |
-
],
|
224 |
-
"7.Deliberate [Realism] [V6] + INP": [
|
225 |
-
{"url": "https://huggingface.co/XpucT/Deliberate/resolve/main/Deliberate_v6.safetensors", "name": "Deliberate_V6.safetensors"},
|
226 |
-
{"url": "https://huggingface.co/XpucT/Deliberate/resolve/main/Deliberate_v6-inpainting.safetensors", "name": "Deliberate_V6-inpainting.safetensors"}
|
227 |
-
],
|
228 |
-
"8.Meina-Mix [Anime] [V11] + INP": [
|
229 |
-
{"url": "https://civitai.com/api/download/models/119057", "name": "MeinaMix_V11.safetensors"},
|
230 |
-
{"url": "https://civitai.com/api/download/models/120702", "name": "MeinaMix_V11-inpainting.safetensors"}
|
231 |
-
],
|
232 |
-
"9.Mix-Pro [Anime] [V4] + INP": [
|
233 |
-
{"url": "https://civitai.com/api/download/models/125668", "name": "MixPro_V4.safetensors"},
|
234 |
-
{"url": "https://civitai.com/api/download/models/139878", "name": "MixPro_V4-inpainting.safetensors"}
|
235 |
-
]
|
236 |
-
}
|
237 |
-
|
238 |
-
vae_list = {
|
239 |
-
"1.Anime.vae": [{"url": "https://civitai.com/api/download/models/311162", "name": "Anime.vae.safetensors"}],
|
240 |
-
"2.Anything.vae": [{"url": "https://huggingface.co/NoCrypt/resources/resolve/main/VAE/any.vae.safetensors", "name": "Anything.vae.safetensors"}],
|
241 |
-
"3.Blessed2.vae": [{"url": "https://huggingface.co/NoCrypt/resources/resolve/main/VAE/blessed2.vae.safetensors", "name": "Blessed2.vae.safetensors"}],
|
242 |
-
"4.ClearVae.vae": [{"url": "https://civitai.com/api/download/models/88156", "name": "ClearVae_23.vae.safetensors"}],
|
243 |
-
"5.WD.vae": [{"url": "https://huggingface.co/NoCrypt/resources/resolve/main/VAE/wd.vae.safetensors", "name": "WD.vae.safetensors"}]
|
244 |
-
}
|
245 |
-
|
246 |
-
controlnet_list = {
|
247 |
-
"1.canny": [
|
248 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny_fp16.safetensors", "name": "control_v11p_sd15_canny_fp16.safetensors"},
|
249 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_canny_fp16.yaml", "name": "control_v11p_sd15_canny_fp16.yaml"}
|
250 |
-
],
|
251 |
-
"2.openpose": [
|
252 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose_fp16.safetensors", "name": "control_v11p_sd15_openpose_fp16.safetensors"},
|
253 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_openpose_fp16.yaml", "name": "control_v11p_sd15_openpose_fp16.yaml"}
|
254 |
-
],
|
255 |
-
"3.depth": [
|
256 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth_fp16.safetensors", "name": "control_v11f1p_sd15_depth_fp16.safetensors"},
|
257 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1p_sd15_depth_fp16.yaml", "name": "control_v11f1p_sd15_depth_fp16.yaml"},
|
258 |
-
{"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"}
|
259 |
-
],
|
260 |
-
"4.normal_map": [
|
261 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_normalbae_fp16.safetensors", "name": "control_v11p_sd15_normalbae_fp16.safetensors"},
|
262 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_normalbae_fp16.yaml", "name": "control_v11p_sd15_normalbae_fp16.yaml"}
|
263 |
-
],
|
264 |
-
"5.mlsd": [
|
265 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_mlsd_fp16.safetensors", "name": "control_v11p_sd15_mlsd_fp16.safetensors"},
|
266 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_mlsd_fp16.yaml", "name": "control_v11p_sd15_mlsd_fp16.yaml"}
|
267 |
-
],
|
268 |
-
"6.lineart": [
|
269 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart_fp16.safetensors", "name": "control_v11p_sd15_lineart_fp16.safetensors"},
|
270 |
-
{"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"},
|
271 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_lineart_fp16.yaml", "name": "control_v11p_sd15_lineart_fp16.yaml"},
|
272 |
-
{"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"}
|
273 |
-
],
|
274 |
-
"7.soft_edge": [
|
275 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge_fp16.safetensors", "name": "control_v11p_sd15_softedge_fp16.safetensors"},
|
276 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_softedge_fp16.yaml", "name": "control_v11p_sd15_softedge_fp16.yaml"}
|
277 |
-
],
|
278 |
-
"8.scribble": [
|
279 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble_fp16.safetensors", "name": "control_v11p_sd15_scribble_fp16.safetensors"},
|
280 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_scribble_fp16.yaml", "name": "control_v11p_sd15_scribble_fp16.yaml"}
|
281 |
-
],
|
282 |
-
"9.segmentation": [
|
283 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg_fp16.safetensors", "name": "control_v11p_sd15_seg_fp16.safetensors"},
|
284 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_seg_fp16.yaml", "name": "control_v11p_sd15_seg_fp16.yaml"}
|
285 |
-
],
|
286 |
-
"10.shuffle": [
|
287 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle_fp16.safetensors", "name": "control_v11e_sd15_shuffle_fp16.safetensors"},
|
288 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_shuffle_fp16.yaml", "name": "control_v11e_sd15_shuffle_fp16.yaml"}
|
289 |
-
],
|
290 |
-
"11.tile": [
|
291 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile_fp16.safetensors", "name": "control_v11f1e_sd15_tile_fp16.safetensors"},
|
292 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1e_sd15_tile_fp16.yaml", "name": "control_v11f1e_sd15_tile_fp16.yaml"}
|
293 |
-
],
|
294 |
-
"12.inpaint": [
|
295 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_inpaint_fp16.safetensors", "name": "control_v11p_sd15_inpaint_fp16.safetensors"},
|
296 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_inpaint_fp16.yaml", "name": "control_v11p_sd15_inpaint_fp16.yaml"}
|
297 |
-
],
|
298 |
-
"13.instruct_p2p": [
|
299 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p_fp16.safetensors", "name": "control_v11e_sd15_ip2p_fp16.safetensors"},
|
300 |
-
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_ip2p_fp16.yaml", "name": "control_v11e_sd15_ip2p_fp16.yaml"}
|
301 |
-
]
|
302 |
-
}
|
303 |
|
304 |
url = ""
|
305 |
-
|
306 |
"model": models_dir,
|
307 |
"vae": vaes_dir,
|
308 |
"lora": loras_dir,
|
@@ -314,7 +205,7 @@ prefixes = {
|
|
314 |
}
|
315 |
|
316 |
extension_repo = []
|
317 |
-
directories = [value for key, value in
|
318 |
get_ipython().system('mkdir -p {" ".join(directories)}')
|
319 |
|
320 |
hf_token = huggingface_token if huggingface_token else "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"
|
@@ -325,137 +216,123 @@ user_header = f"\"Authorization: Bearer {hf_token}\""
|
|
325 |
from math import floor
|
326 |
|
327 |
def center_text(text, terminal_width=45):
|
328 |
-
|
329 |
-
|
330 |
-
right_padding = terminal_width - text_length - left_padding
|
331 |
-
return f"\033[1m\033[36m{' ' * left_padding}{text}{' ' * right_padding}\033[0m\033[32m"
|
332 |
|
333 |
def format_output(url, dst_dir, file_name):
|
334 |
-
info = f"[{file_name.split('.')[0]}]"
|
335 |
-
|
336 |
|
337 |
-
print(f"\n
|
338 |
print(f"\033[33mURL: \033[34m{url}")
|
339 |
print(f"\033[33mSAVE DIR: \033[34m{dst_dir}")
|
340 |
print(f"\033[33mFILE NAME: \033[34m{file_name}\033[0m")
|
341 |
|
342 |
''' GET CivitAi API - DATA '''
|
343 |
|
344 |
-
def strip_(url, file_name=None):
|
345 |
-
if 'github.com' in url:
|
346 |
-
if '/blob/' in url:
|
347 |
-
url = url.replace('/blob/', '/raw/')
|
348 |
-
|
349 |
-
elif "civitai.com" in url:
|
350 |
-
return CivitAi_API(url, file_name)
|
351 |
-
|
352 |
-
elif "huggingface.co" in url:
|
353 |
-
if '/blob/' in url:
|
354 |
-
url = url.replace('/blob/', '/resolve/')
|
355 |
-
if '?' in url:
|
356 |
-
url = url.split('?')[0]
|
357 |
-
|
358 |
-
return url
|
359 |
-
|
360 |
def CivitAi_API(url, file_name=None):
|
361 |
-
|
362 |
-
|
363 |
|
364 |
-
if '?token=' in url
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
response = requests.get(f"https://civitai.com/api/v1/model-versions/{version_id}")
|
376 |
-
# print(f"end - https://civitai.com/api/v1/model-versions/{version_id}")
|
377 |
else:
|
378 |
-
|
379 |
-
|
380 |
-
# print(f"end - https://civitai.com/api/v1/models/{model_id}")
|
381 |
-
else:
|
382 |
-
version_id = url.split('/models/')[1].split('/')[0]
|
383 |
-
response = requests.get(f"https://civitai.com/api/v1/model-versions/{version_id}")
|
384 |
-
# print(f"end - https://civitai.com/api/v1/model-versions/{version_id}")
|
385 |
|
386 |
-
data =
|
387 |
|
388 |
-
if
|
389 |
return None, None, None, None, None, None, None
|
390 |
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
396 |
else:
|
397 |
-
model_type = data['type']
|
398 |
-
model_name = data['modelVersions'][0]['files'][0]['name']
|
399 |
-
elif 'type=' in url:
|
400 |
-
model_type = parse_qs(urlparse(url).query).get('type', [''])[0]
|
401 |
-
if 'model' in model_type.lower():
|
402 |
model_name = data['files'][0]['name']
|
403 |
-
|
404 |
-
model_name = data['files'][1]['name']
|
405 |
-
else:
|
406 |
-
model_type = data['model']['type']
|
407 |
-
model_name = data['files'][0]['name']
|
408 |
|
|
|
409 |
model_name = file_name or model_name
|
410 |
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
|
|
|
|
420 |
else:
|
421 |
-
|
422 |
-
else:
|
423 |
-
download_url = data.get('downloadUrl')
|
424 |
|
425 |
-
|
|
|
426 |
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
|
|
|
|
|
|
438 |
|
439 |
-
|
440 |
-
image_name = f"{model_name.split('.')[0]}.preview.{image_url.split('.')[-1]}" if image_url else None
|
441 |
|
442 |
-
return f"{download_url}{'&' if '?' in download_url else '?'}token={
|
443 |
|
444 |
''' Main Download Code '''
|
445 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
446 |
def download(url):
|
447 |
links_and_paths = [link_or_path.strip() for link_or_path in url.split(',') if link_or_path.strip()]
|
448 |
|
449 |
for link_or_path in links_and_paths:
|
450 |
-
if any(link_or_path.lower().startswith(prefix) for prefix in
|
451 |
handle_manual(link_or_path)
|
452 |
else:
|
453 |
url, dst_dir, file_name = link_or_path.split()
|
454 |
manual_download(url, dst_dir, file_name)
|
455 |
|
456 |
-
|
457 |
-
|
458 |
-
def unpack_zip_files():
|
459 |
for directory in directories:
|
460 |
for root, _, files in os.walk(directory):
|
461 |
for file in files:
|
@@ -475,8 +352,8 @@ def handle_manual(url):
|
|
475 |
if file_name:
|
476 |
path = re.sub(r'\[.*?\]', '', path)
|
477 |
|
478 |
-
if prefix in
|
479 |
-
dir =
|
480 |
if prefix != "extension":
|
481 |
try:
|
482 |
manual_download(path, dir, file_name=file_name)
|
@@ -490,60 +367,52 @@ def manual_download(url, dst_dir, file_name):
|
|
490 |
aria2c_header = "--header='User-Agent: Mozilla/5.0' --allow-overwrite=true"
|
491 |
aria2_args = "--optimize-concurrent-downloads --console-log-level=error --summary-interval=10 --stderr=true -c -x16 -s16 -k1M -j5"
|
492 |
|
493 |
-
|
494 |
-
url = strip_(url)
|
495 |
-
|
496 |
-
# -- CivitAi APi+ V2 --
|
497 |
-
elif 'civitai' in url:
|
498 |
-
url, clean_url, model_type, file_name, image_url, image_name, data = strip_(url, file_name)
|
499 |
|
|
|
|
|
500 |
if image_url and image_name:
|
501 |
-
|
502 |
-
|
503 |
-
del cap
|
504 |
|
505 |
-
elif "huggingface.co" in url:
|
506 |
-
|
507 |
-
basename = clean_url.split("/")[-1] if file_name is None else file_name
|
508 |
|
509 |
""" Formatted info output """
|
510 |
-
model_name_or_basename = file_name if
|
511 |
format_output(clean_url or url, dst_dir, model_name_or_basename)
|
512 |
|
513 |
-
# ## -- for my tests --
|
514 |
# print(url, dst_dir, model_name_or_basename)
|
515 |
-
|
516 |
-
|
517 |
-
|
|
|
|
|
|
|
518 |
# =====================
|
|
|
|
|
|
|
519 |
|
520 |
-
# --
|
521 |
-
if '
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
elif 'drive.google' in url:
|
526 |
-
try:
|
527 |
-
have_drive_link
|
528 |
-
except:
|
529 |
-
get_ipython().system('pip install -q gdown==5.2.0 > /dev/null')
|
530 |
-
have_drive_link = True
|
531 |
|
532 |
if 'folders' in url:
|
533 |
-
|
534 |
else:
|
535 |
-
if file_name
|
536 |
-
|
537 |
-
else:
|
538 |
-
get_ipython().system('gdown "{url}" -O {dst_dir} --fuzzy -c')
|
539 |
|
540 |
-
# -- Hugging Face --
|
541 |
-
elif 'huggingface' in url:
|
542 |
-
|
543 |
|
544 |
-
# -- Other --
|
545 |
elif 'http' in url:
|
546 |
-
|
547 |
|
548 |
''' SubModels - Added URLs '''
|
549 |
|
@@ -583,7 +452,7 @@ url = handle_submodels(controlnet, controlnet_num, controlnet_list, control_dir,
|
|
583 |
|
584 |
''' file.txt - added urls '''
|
585 |
|
586 |
-
def process_file_download(file_url,
|
587 |
files_urls = ""
|
588 |
|
589 |
if file_url.startswith("http"):
|
@@ -598,8 +467,8 @@ def process_file_download(file_url, prefixes, unique_urls):
|
|
598 |
current_tag = None
|
599 |
for line in lines:
|
600 |
line = line.strip()
|
601 |
-
if any(f'# {tag}' in line.lower() for tag in
|
602 |
-
current_tag = next((tag for tag in
|
603 |
|
604 |
urls = [url.split('#')[0].strip() for url in line.split(',')] # filter urls
|
605 |
for url in urls:
|
@@ -623,13 +492,13 @@ if custom_file_urls:
|
|
623 |
custom_file_url = f'{root_path}/{custom_file_url}'
|
624 |
|
625 |
try:
|
626 |
-
file_urls += process_file_download(custom_file_url,
|
627 |
except FileNotFoundError:
|
628 |
pass
|
629 |
|
630 |
# url prefixing
|
631 |
urls = (Model_url, Vae_url, LoRA_url, Embedding_url, Extensions_url)
|
632 |
-
prefixed_urls = (f"{prefix}:{url}" for prefix, url in zip(
|
633 |
url += ", ".join(prefixed_urls) + ", " + file_urls
|
634 |
|
635 |
if detailed_download == "on":
|
|
|
1 |
##~ DOWNLOADING CODE | BY: ANXETY ~##
|
2 |
|
3 |
+
from models_data import model_list, vae_list, controlnet_list
|
4 |
+
|
5 |
import os
|
6 |
import re
|
7 |
import time
|
|
|
17 |
from urllib.parse import urlparse, parse_qs
|
18 |
|
19 |
|
20 |
+
# Setup Env
|
21 |
+
env = os.environ.get('ENV_NAME')
|
22 |
+
root_path = os.environ.get('ROOT_PATH')
|
23 |
+
webui_path = os.environ.get('WEBUI_PATH')
|
24 |
+
free_plan = os.environ.get('FREE_PLAN')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
|
27 |
# ================ LIBRARIES V2 ================
|
|
|
191 |
|
192 |
## Downloading model and stuff | oh~ Hey! If you're freaked out by that code too, don't worry, me too!
|
193 |
print("📦 Скачивание моделей и прочего...", end='')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
194 |
|
195 |
url = ""
|
196 |
+
PREFIXES = {
|
197 |
"model": models_dir,
|
198 |
"vae": vaes_dir,
|
199 |
"lora": loras_dir,
|
|
|
205 |
}
|
206 |
|
207 |
extension_repo = []
|
208 |
+
directories = [value for key, value in PREFIXES.items()] # for unpucking zip files
|
209 |
get_ipython().system('mkdir -p {" ".join(directories)}')
|
210 |
|
211 |
hf_token = huggingface_token if huggingface_token else "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"
|
|
|
216 |
from math import floor
|
217 |
|
218 |
def center_text(text, terminal_width=45):
|
219 |
+
padding = (terminal_width - len(text)) // 2
|
220 |
+
return f"\033[1m\033[36m{' ' * padding}{text}{' ' * padding}\033[0m\033[32m"
|
|
|
|
|
221 |
|
222 |
def format_output(url, dst_dir, file_name):
|
223 |
+
info = center_text(f"[{file_name.split('.')[0]}]")
|
224 |
+
separation_line = '\033[32m' + '---' * 20
|
225 |
|
226 |
+
print(f"\n{separation_line}{info}{separation_line}")
|
227 |
print(f"\033[33mURL: \033[34m{url}")
|
228 |
print(f"\033[33mSAVE DIR: \033[34m{dst_dir}")
|
229 |
print(f"\033[33mFILE NAME: \033[34m{file_name}\033[0m")
|
230 |
|
231 |
''' GET CivitAi API - DATA '''
|
232 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
233 |
def CivitAi_API(url, file_name=None):
|
234 |
+
SUPPORT_TYPES = ('Checkpoint', 'Model', 'TextualInversion', 'LORA')
|
235 |
+
CIVITAI_TOKEN = "62c0c5956b2f9defbd844d754000180b"
|
236 |
|
237 |
+
url = url.split('?token=')[0] if '?token=' in url else url
|
238 |
+
url = url.replace('?type=', f'?token={CIVITAI_TOKEN}&type=') if '?type=' in url else f"{url}?token={CIVITAI_TOKEN}"
|
239 |
+
|
240 |
+
def get_model_data(url):
|
241 |
+
if "civitai.com/models/" in url:
|
242 |
+
if '?modelVersionId=' in url:
|
243 |
+
version_id = url.split('?modelVersionId=')[1]
|
244 |
+
return requests.get(f"https://civitai.com/api/v1/model-versions/{version_id}").json()
|
245 |
+
else:
|
246 |
+
model_id = url.split('/models/')[1].split('/')[0]
|
247 |
+
return requests.get(f"https://civitai.com/api/v1/models/{model_id}").json()
|
|
|
|
|
248 |
else:
|
249 |
+
version_id = url.split('/models/')[1].split('/')[0]
|
250 |
+
return requests.get(f"https://civitai.com/api/v1/model-versions/{version_id}").json()
|
|
|
|
|
|
|
|
|
|
|
251 |
|
252 |
+
data = get_model_data(url)
|
253 |
|
254 |
+
if not data:
|
255 |
return None, None, None, None, None, None, None
|
256 |
|
257 |
+
def extract_model_info(url, data):
|
258 |
+
if "civitai.com/models/" in url:
|
259 |
+
if '?modelVersionId=' in url:
|
260 |
+
model_type = data['model']['type']
|
261 |
+
model_name = data['files'][0]['name']
|
262 |
+
else:
|
263 |
+
model_type = data['type']
|
264 |
+
model_name = data['modelVersions'][0]['files'][0]['name']
|
265 |
+
elif 'type=' in url:
|
266 |
+
model_type = parse_qs(urlparse(url).query).get('type', [''])[0]
|
267 |
+
if 'model' in model_type.lower():
|
268 |
+
model_name = data['files'][0]['name']
|
269 |
+
else:
|
270 |
+
model_name = data['files'][1]['name']
|
271 |
else:
|
272 |
+
model_type = data['model']['type']
|
|
|
|
|
|
|
|
|
273 |
model_name = data['files'][0]['name']
|
274 |
+
return model_type, model_name
|
|
|
|
|
|
|
|
|
275 |
|
276 |
+
model_type, model_name = extract_model_info(url, data)
|
277 |
model_name = file_name or model_name
|
278 |
|
279 |
+
def get_download_url(url, data, model_type):
|
280 |
+
if "civitai.com/models/" in url:
|
281 |
+
if '?modelVersionId=' in url:
|
282 |
+
return data.get('downloadUrl')
|
283 |
+
else:
|
284 |
+
return data["modelVersions"][0].get("downloadUrl", "")
|
285 |
+
elif 'type=' in url:
|
286 |
+
if any(t.lower() in model_type.lower() for t in SUPPORT_TYPES):
|
287 |
+
return data['files'][0]['downloadUrl']
|
288 |
+
else:
|
289 |
+
return data['files'][1]['downloadUrl']
|
290 |
else:
|
291 |
+
return data.get('downloadUrl')
|
|
|
|
|
292 |
|
293 |
+
download_url = get_download_url(url, data, model_type)
|
294 |
+
clean_url = re.sub(r'[?&]token=[^&]*', '', download_url)
|
295 |
|
296 |
+
def get_image_info(data, model_type, model_name):
|
297 |
+
image_url, image_name = None, None
|
298 |
+
if any(t in model_type for t in SUPPORT_TYPES):
|
299 |
+
try:
|
300 |
+
images = data.get('images') or data['modelVersions'][0].get('images', [])
|
301 |
+
if env == 'Kaggle':
|
302 |
+
image_url = next((image['url'] for image in images if image['nsfwLevel'] < 4), None)
|
303 |
+
else:
|
304 |
+
image_url = images[0]['url'] if images else None
|
305 |
+
except KeyError:
|
306 |
+
pass
|
307 |
+
|
308 |
+
image_name = f"{model_name.split('.')[0]}.preview.{image_url.split('.')[-1]}" if image_url else None
|
309 |
+
return image_url, image_name
|
310 |
|
311 |
+
image_url, image_name = get_image_info(data, model_type, model_name)
|
|
|
312 |
|
313 |
+
return f"{download_url}{'&' if '?' in download_url else '?'}token={CIVITAI_TOKEN}", clean_url, model_type, model_name, image_url, image_name, data
|
314 |
|
315 |
''' Main Download Code '''
|
316 |
|
317 |
+
def strip_(url):
|
318 |
+
if 'github.com' in url:
|
319 |
+
return url.replace('/blob/', '/raw/')
|
320 |
+
elif "huggingface.co" in url:
|
321 |
+
url = url.replace('/blob/', '/resolve/')
|
322 |
+
return url.split('?')[0] if '?' in url else url
|
323 |
+
return url
|
324 |
+
|
325 |
def download(url):
|
326 |
links_and_paths = [link_or_path.strip() for link_or_path in url.split(',') if link_or_path.strip()]
|
327 |
|
328 |
for link_or_path in links_and_paths:
|
329 |
+
if any(link_or_path.lower().startswith(prefix) for prefix in PREFIXES):
|
330 |
handle_manual(link_or_path)
|
331 |
else:
|
332 |
url, dst_dir, file_name = link_or_path.split()
|
333 |
manual_download(url, dst_dir, file_name)
|
334 |
|
335 |
+
# Unpuck ZIPs Files
|
|
|
|
|
336 |
for directory in directories:
|
337 |
for root, _, files in os.walk(directory):
|
338 |
for file in files:
|
|
|
352 |
if file_name:
|
353 |
path = re.sub(r'\[.*?\]', '', path)
|
354 |
|
355 |
+
if prefix in PREFIXES:
|
356 |
+
dir = PREFIXES[prefix]
|
357 |
if prefix != "extension":
|
358 |
try:
|
359 |
manual_download(path, dir, file_name=file_name)
|
|
|
367 |
aria2c_header = "--header='User-Agent: Mozilla/5.0' --allow-overwrite=true"
|
368 |
aria2_args = "--optimize-concurrent-downloads --console-log-level=error --summary-interval=10 --stderr=true -c -x16 -s16 -k1M -j5"
|
369 |
|
370 |
+
clean_url = strip_(url)
|
|
|
|
|
|
|
|
|
|
|
371 |
|
372 |
+
if 'civitai' in url:
|
373 |
+
url, clean_url, model_type, file_name, image_url, image_name, data = CivitAi_API(url, file_name)
|
374 |
if image_url and image_name:
|
375 |
+
command = ["aria2c"] + aria2_args.split() + ["-d", dst_dir, "-o", image_name, image_url]
|
376 |
+
subprocess.run(command, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
|
377 |
|
378 |
+
elif 'github' in url or "huggingface.co" in url:
|
379 |
+
basename = url.split("/")[-1] if file_name is None else file_name
|
|
|
380 |
|
381 |
""" Formatted info output """
|
382 |
+
model_name_or_basename = file_name if file_name else basename
|
383 |
format_output(clean_url or url, dst_dir, model_name_or_basename)
|
384 |
|
|
|
385 |
# print(url, dst_dir, model_name_or_basename)
|
386 |
+
if 'civitai' in url:
|
387 |
+
if not data:
|
388 |
+
print("\033[31m[Data Info]:\033[0m Failed to retrieve data from the API.\n")
|
389 |
+
if data and image_name:
|
390 |
+
print(f"\033[32m[Preview DL]:\033[0m {image_name} - {image_url}\n")
|
391 |
+
|
392 |
# =====================
|
393 |
+
def run_aria2c(url, dst_dir, file_name=None, args="", header=""):
|
394 |
+
out = f"-o '{file_name}'" if file_name else ""
|
395 |
+
get_ipython().system("aria2c {header} {args} -d {dst_dir} {out} '{url}'")
|
396 |
|
397 |
+
# -- Google Drive --
|
398 |
+
if 'drive.google' in url:
|
399 |
+
if not globals().get('have_drive_link', False):
|
400 |
+
os.system("pip install -U gdown > /dev/null")
|
401 |
+
globals()['have_drive_link'] = True
|
|
|
|
|
|
|
|
|
|
|
|
|
402 |
|
403 |
if 'folders' in url:
|
404 |
+
os.system(f"gdown --folder \"{url}\" -O {dst_dir} --fuzzy -c")
|
405 |
else:
|
406 |
+
out_path = f"{dst_dir}/{file_name}" if file_name else dst_dir
|
407 |
+
os.system(f"gdown \"{url}\" -O {out_path} --fuzzy -c")
|
|
|
|
|
408 |
|
409 |
+
# -- GitHub or Hugging Face --
|
410 |
+
elif 'github' in url or 'huggingface' in url:
|
411 |
+
run_aria2c(clean_url, dst_dir, basename, aria2_args, header_option if 'huggingface' in url else '')
|
412 |
|
413 |
+
# -- Other HTTP/Sources --
|
414 |
elif 'http' in url:
|
415 |
+
run_aria2c(url, dst_dir, file_name, aria2_args, aria2c_header)
|
416 |
|
417 |
''' SubModels - Added URLs '''
|
418 |
|
|
|
452 |
|
453 |
''' file.txt - added urls '''
|
454 |
|
455 |
+
def process_file_download(file_url, PREFIXES, unique_urls):
|
456 |
files_urls = ""
|
457 |
|
458 |
if file_url.startswith("http"):
|
|
|
467 |
current_tag = None
|
468 |
for line in lines:
|
469 |
line = line.strip()
|
470 |
+
if any(f'# {tag}' in line.lower() for tag in PREFIXES):
|
471 |
+
current_tag = next((tag for tag in PREFIXES if tag in line.lower()))
|
472 |
|
473 |
urls = [url.split('#')[0].strip() for url in line.split(',')] # filter urls
|
474 |
for url in urls:
|
|
|
492 |
custom_file_url = f'{root_path}/{custom_file_url}'
|
493 |
|
494 |
try:
|
495 |
+
file_urls += process_file_download(custom_file_url, PREFIXES, unique_urls)
|
496 |
except FileNotFoundError:
|
497 |
pass
|
498 |
|
499 |
# url prefixing
|
500 |
urls = (Model_url, Vae_url, LoRA_url, Embedding_url, Extensions_url)
|
501 |
+
prefixed_urls = (f"{prefix}:{url}" for prefix, url in zip(PREFIXES.keys(), urls) if url for url in url.replace(',', '').split())
|
502 |
url += ", ".join(prefixed_urls) + ", " + file_urls
|
503 |
|
504 |
if detailed_download == "on":
|
files_cells/python/ru/launch_ru.py
CHANGED
@@ -9,21 +9,13 @@ 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 |
-
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'
|
@@ -38,6 +30,7 @@ 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 |
|
@@ -71,6 +64,7 @@ if zrok_token:
|
|
71 |
|
72 |
clear_output()
|
73 |
|
|
|
74 |
# =============== Automatic Fixing Path V3 ===============
|
75 |
paths_to_check = {
|
76 |
"tagger_hf_cache_dir": f"{webui_path}/models/interrogators/",
|
|
|
9 |
from datetime import timedelta
|
10 |
from IPython.display import clear_output
|
11 |
|
12 |
+
|
13 |
+
# Setup Env
|
14 |
+
env = os.environ.get('ENV_NAME')
|
15 |
+
root_path = os.environ.get('ROOT_PATH')
|
16 |
+
webui_path = os.environ.get('WEBUI_PATH')
|
17 |
+
free_plan = os.environ.get('FREE_PLAN')
|
18 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
def load_settings():
|
21 |
SETTINGS_FILE = f'{root_path}/settings.json'
|
|
|
30 |
commandline_arguments = settings.get('commandline_arguments', "")
|
31 |
change_webui = settings.get('change_webui', "")
|
32 |
|
33 |
+
|
34 |
# ======================== TUNNEL V2 ========================
|
35 |
print('Please Wait...')
|
36 |
|
|
|
64 |
|
65 |
clear_output()
|
66 |
|
67 |
+
|
68 |
# =============== Automatic Fixing Path V3 ===============
|
69 |
paths_to_check = {
|
70 |
"tagger_hf_cache_dir": f"{webui_path}/models/interrogators/",
|
files_cells/python/ru/widgets_ru.py
CHANGED
@@ -8,20 +8,11 @@ from ipywidgets import widgets, Layout, Label, Button, VBox, HBox
|
|
8 |
from IPython.display import display, HTML, Javascript, clear_output
|
9 |
|
10 |
|
11 |
-
#
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
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 ====================
|
|
|
8 |
from IPython.display import display, HTML, Javascript, clear_output
|
9 |
|
10 |
|
11 |
+
# Setup Env
|
12 |
+
env = os.environ.get('ENV_NAME')
|
13 |
+
root_path = os.environ.get('ROOT_PATH')
|
14 |
+
webui_path = os.environ.get('WEBUI_PATH')
|
15 |
+
free_plan = os.environ.get('FREE_PLAN')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
|
18 |
# ==================== CSS JS ====================
|
modules/models_data.py
ADDED
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
model_list = {
|
2 |
+
"1.Anime (by XpucT) + INP": [
|
3 |
+
{"url": "https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2.safetensors", "name": "Anime_V2.safetensors"},
|
4 |
+
{"url": "https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2-inpainting.safetensors", "name": "Anime_V2-inpainting.safetensors"}
|
5 |
+
],
|
6 |
+
"2.BluMix [Anime] [V7] + INP": [
|
7 |
+
{"url": "https://civitai.com/api/download/models/361779", "name": "BluMix_V7.safetensors"},
|
8 |
+
{"url": "https://civitai.com/api/download/models/363850", "name": "BluMix_V7-inpainting.safetensors"}
|
9 |
+
],
|
10 |
+
"3.Cetus-Mix [Anime] [V4] + INP": [
|
11 |
+
{"url": "https://civitai.com/api/download/models/130298", "name": "CetusMix_V4.safetensors"},
|
12 |
+
{"url": "https://civitai.com/api/download/models/139882", "name": "CetusMix_V4-inpainting.safetensors"}
|
13 |
+
],
|
14 |
+
"4.Counterfeit [Anime] [V3] + INP": [
|
15 |
+
{"url": "https://huggingface.co/gsdf/Counterfeit-V3.0/resolve/main/Counterfeit-V3.0_fix_fp16.safetensors", "name": "Counterfeit_V3.safetensors"},
|
16 |
+
{"url": "https://civitai.com/api/download/models/137911", "name": "Counterfeit_V3-inpainting.safetensors"}
|
17 |
+
],
|
18 |
+
"5.CuteColor [Anime] [V3]": [
|
19 |
+
{"url": "https://civitai.com/api/download/models/138754", "name": "CuteColor_V3.safetensors"}
|
20 |
+
],
|
21 |
+
"6.Dark-Sushi-Mix [Anime]": [
|
22 |
+
{"url": "https://civitai.com/api/download/models/101640", "name": "DarkSushiMix_2_5D.safetensors"},
|
23 |
+
{"url": "https://civitai.com/api/download/models/56071", "name": "DarkSushiMix_colorful.safetensors"}
|
24 |
+
],
|
25 |
+
"7.Deliberate [Realism] [V6] + INP": [
|
26 |
+
{"url": "https://huggingface.co/XpucT/Deliberate/resolve/main/Deliberate_v6.safetensors", "name": "Deliberate_V6.safetensors"},
|
27 |
+
{"url": "https://huggingface.co/XpucT/Deliberate/resolve/main/Deliberate_v6-inpainting.safetensors", "name": "Deliberate_V6-inpainting.safetensors"}
|
28 |
+
],
|
29 |
+
"8.Meina-Mix [Anime] [V11] + INP": [
|
30 |
+
{"url": "https://civitai.com/api/download/models/119057", "name": "MeinaMix_V11.safetensors"},
|
31 |
+
{"url": "https://civitai.com/api/download/models/120702", "name": "MeinaMix_V11-inpainting.safetensors"}
|
32 |
+
],
|
33 |
+
"9.Mix-Pro [Anime] [V4] + INP": [
|
34 |
+
{"url": "https://civitai.com/api/download/models/125668", "name": "MixPro_V4.safetensors"},
|
35 |
+
{"url": "https://civitai.com/api/download/models/139878", "name": "MixPro_V4-inpainting.safetensors"}
|
36 |
+
]
|
37 |
+
}
|
38 |
+
|
39 |
+
vae_list = {
|
40 |
+
"1.Anime.vae": [{"url": "https://civitai.com/api/download/models/311162", "name": "Anime.vae.safetensors"}],
|
41 |
+
"2.Anything.vae": [{"url": "https://huggingface.co/NoCrypt/resources/resolve/main/VAE/any.vae.safetensors", "name": "Anything.vae.safetensors"}],
|
42 |
+
"3.Blessed2.vae": [{"url": "https://huggingface.co/NoCrypt/resources/resolve/main/VAE/blessed2.vae.safetensors", "name": "Blessed2.vae.safetensors"}],
|
43 |
+
"4.ClearVae.vae": [{"url": "https://civitai.com/api/download/models/88156", "name": "ClearVae_23.vae.safetensors"}],
|
44 |
+
"5.WD.vae": [{"url": "https://huggingface.co/NoCrypt/resources/resolve/main/VAE/wd.vae.safetensors", "name": "WD.vae.safetensors"}]
|
45 |
+
}
|
46 |
+
|
47 |
+
controlnet_list = {
|
48 |
+
"1.canny": [
|
49 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny_fp16.safetensors", "name": "control_v11p_sd15_canny_fp16.safetensors"},
|
50 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_canny_fp16.yaml", "name": "control_v11p_sd15_canny_fp16.yaml"}
|
51 |
+
],
|
52 |
+
"2.openpose": [
|
53 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose_fp16.safetensors", "name": "control_v11p_sd15_openpose_fp16.safetensors"},
|
54 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_openpose_fp16.yaml", "name": "control_v11p_sd15_openpose_fp16.yaml"}
|
55 |
+
],
|
56 |
+
"3.depth": [
|
57 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth_fp16.safetensors", "name": "control_v11f1p_sd15_depth_fp16.safetensors"},
|
58 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1p_sd15_depth_fp16.yaml", "name": "control_v11f1p_sd15_depth_fp16.yaml"},
|
59 |
+
{"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"}
|
60 |
+
],
|
61 |
+
"4.normal_map": [
|
62 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_normalbae_fp16.safetensors", "name": "control_v11p_sd15_normalbae_fp16.safetensors"},
|
63 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_normalbae_fp16.yaml", "name": "control_v11p_sd15_normalbae_fp16.yaml"}
|
64 |
+
],
|
65 |
+
"5.mlsd": [
|
66 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_mlsd_fp16.safetensors", "name": "control_v11p_sd15_mlsd_fp16.safetensors"},
|
67 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_mlsd_fp16.yaml", "name": "control_v11p_sd15_mlsd_fp16.yaml"}
|
68 |
+
],
|
69 |
+
"6.lineart": [
|
70 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart_fp16.safetensors", "name": "control_v11p_sd15_lineart_fp16.safetensors"},
|
71 |
+
{"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"},
|
72 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_lineart_fp16.yaml", "name": "control_v11p_sd15_lineart_fp16.yaml"},
|
73 |
+
{"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"}
|
74 |
+
],
|
75 |
+
"7.soft_edge": [
|
76 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge_fp16.safetensors", "name": "control_v11p_sd15_softedge_fp16.safetensors"},
|
77 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_softedge_fp16.yaml", "name": "control_v11p_sd15_softedge_fp16.yaml"}
|
78 |
+
],
|
79 |
+
"8.scribble": [
|
80 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble_fp16.safetensors", "name": "control_v11p_sd15_scribble_fp16.safetensors"},
|
81 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_scribble_fp16.yaml", "name": "control_v11p_sd15_scribble_fp16.yaml"}
|
82 |
+
],
|
83 |
+
"9.segmentation": [
|
84 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg_fp16.safetensors", "name": "control_v11p_sd15_seg_fp16.safetensors"},
|
85 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_seg_fp16.yaml", "name": "control_v11p_sd15_seg_fp16.yaml"}
|
86 |
+
],
|
87 |
+
"10.shuffle": [
|
88 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle_fp16.safetensors", "name": "control_v11e_sd15_shuffle_fp16.safetensors"},
|
89 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_shuffle_fp16.yaml", "name": "control_v11e_sd15_shuffle_fp16.yaml"}
|
90 |
+
],
|
91 |
+
"11.tile": [
|
92 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile_fp16.safetensors", "name": "control_v11f1e_sd15_tile_fp16.safetensors"},
|
93 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1e_sd15_tile_fp16.yaml", "name": "control_v11f1e_sd15_tile_fp16.yaml"}
|
94 |
+
],
|
95 |
+
"12.inpaint": [
|
96 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_inpaint_fp16.safetensors", "name": "control_v11p_sd15_inpaint_fp16.safetensors"},
|
97 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_inpaint_fp16.yaml", "name": "control_v11p_sd15_inpaint_fp16.yaml"}
|
98 |
+
],
|
99 |
+
"13.instruct_p2p": [
|
100 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p_fp16.safetensors", "name": "control_v11e_sd15_ip2p_fp16.safetensors"},
|
101 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_ip2p_fp16.yaml", "name": "control_v11e_sd15_ip2p_fp16.yaml"}
|
102 |
+
]
|
103 |
+
}
|
modules/setup_en.py
ADDED
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import sys
|
3 |
+
import shutil
|
4 |
+
import argparse
|
5 |
+
import importlib
|
6 |
+
import subprocess
|
7 |
+
|
8 |
+
def parse_args():
|
9 |
+
parser = argparse.ArgumentParser(description='Script configuration')
|
10 |
+
parser.add_argument('--lang', type=str, default='en', help='Код языка, по умолчанию "en"')
|
11 |
+
parser.add_argument('--repo', type=str, required=True, help='Repository Name')
|
12 |
+
return parser.parse_args()
|
13 |
+
|
14 |
+
def detect_environment():
|
15 |
+
free_plan = (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024 ** 3) <= 20)
|
16 |
+
environments = {
|
17 |
+
'COLAB_GPU': ('Google Colab', "/root" if free_plan else "/content"),
|
18 |
+
'KAGGLE_URL_BASE': ('Kaggle', "/kaggle/working/content")
|
19 |
+
}
|
20 |
+
for env_var, (environment, path) in environments.items():
|
21 |
+
if env_var in os.environ:
|
22 |
+
return environment, path, free_plan
|
23 |
+
print("\033[31mError: an unsupported runtime environment was detected.\n\033[34mSupported environments:\033[0m Google Colab, Kaggle")
|
24 |
+
return None, None, None
|
25 |
+
|
26 |
+
def setup_module_folder(root_path):
|
27 |
+
modules_folder = os.path.join(root_path, "modules")
|
28 |
+
os.makedirs(modules_folder, exist_ok=True)
|
29 |
+
if modules_folder not in sys.path:
|
30 |
+
sys.path.append(modules_folder)
|
31 |
+
|
32 |
+
def clear_module_cache(modules_folder):
|
33 |
+
for module_name in list(sys.modules.keys()):
|
34 |
+
module = sys.modules[module_name]
|
35 |
+
if hasattr(module, '__file__') and module.__file__ and module.__file__.startswith(modules_folder):
|
36 |
+
del sys.modules[module_name]
|
37 |
+
|
38 |
+
importlib.invalidate_caches()
|
39 |
+
|
40 |
+
def download_files(root_path, lang, repo):
|
41 |
+
print("Please wait for the files to download... 👀", end='', flush=True)
|
42 |
+
files_dict = {
|
43 |
+
'CSS': {'CSS': ['main_widgets.css', 'auto_cleaner.css']},
|
44 |
+
'file_cell': {f'files_cells/python/{lang}': [f'widgets_{lang}.py', f'downloading_{lang}.py', f'launch_{lang}.py', f'auto_cleaner_{lang}.py']},
|
45 |
+
'file_cell/special': {f'special': ['dl_display_results.py']},
|
46 |
+
'modules': {f'modules': ['models_data.py']}
|
47 |
+
}
|
48 |
+
for folder, contents in files_dict.items():
|
49 |
+
folder_path = os.path.join(root_path, folder)
|
50 |
+
if os.path.exists(folder_path):
|
51 |
+
shutil.rmtree(folder_path)
|
52 |
+
os.makedirs(folder_path)
|
53 |
+
for path_url, files in contents.items():
|
54 |
+
for file in files:
|
55 |
+
file_url = f"https://huggingface.co/NagisaNao/{repo}/resolve/main/{path_url}/{file}"
|
56 |
+
file_path = os.path.join(folder_path, file)
|
57 |
+
os.system(f'wget -q {file_url} -O {file_path}')
|
58 |
+
print("\rDone! Now you can run the cells below. ☄️" + " "*30)
|
59 |
+
|
60 |
+
def main():
|
61 |
+
args = parse_args()
|
62 |
+
lang = args.lang
|
63 |
+
repo = args.repo
|
64 |
+
|
65 |
+
env, root_path, free_plan = detect_environment()
|
66 |
+
|
67 |
+
if env and root_path:
|
68 |
+
webui_path = f"{root_path}/sdw"
|
69 |
+
download_files(root_path, lang, repo)
|
70 |
+
clear_module_cache(os.path.join(root_path, "modules"))
|
71 |
+
setup_module_folder(root_path)
|
72 |
+
|
73 |
+
# Set global environment variable
|
74 |
+
os.environ['ENV_NAME'] = env
|
75 |
+
os.environ['ROOT_PATH'] = root_path
|
76 |
+
os.environ['WEBUI_PATH'] = webui_path
|
77 |
+
os.environ['FREE_PLAN'] = 'True' if free_plan else 'False'
|
78 |
+
|
79 |
+
print(f"Runtime environment: \033[33m{env}\033[0m")
|
80 |
+
if env == "Google Colab":
|
81 |
+
print(f"Colab Pro subscription: \033[34m{not free_plan}\033[0m")
|
82 |
+
print(f"File location: \033[32m{root_path}\033[0m")
|
83 |
+
|
84 |
+
if repo != 'fast_repo':
|
85 |
+
print('\n\033[31mWARNING: Test mode is used, there may be errors in use!\033[0m')
|
86 |
+
|
87 |
+
if __name__ == "__main__":
|
88 |
+
main()
|
modules/setup_ru.py
ADDED
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import sys
|
3 |
+
import shutil
|
4 |
+
import argparse
|
5 |
+
import importlib
|
6 |
+
import subprocess
|
7 |
+
|
8 |
+
def parse_args():
|
9 |
+
parser = argparse.ArgumentParser(description='Script configuration')
|
10 |
+
parser.add_argument('--lang', type=str, default='en', help='Код языка, по умолчанию "en"')
|
11 |
+
parser.add_argument('--repo', type=str, required=True, help='Название репозитория')
|
12 |
+
return parser.parse_args()
|
13 |
+
|
14 |
+
def detect_environment():
|
15 |
+
free_plan = (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024 ** 3) <= 20)
|
16 |
+
environments = {
|
17 |
+
'COLAB_GPU': ('Google Colab', "/root" if free_plan else "/content"),
|
18 |
+
'KAGGLE_URL_BASE': ('Kaggle', "/kaggle/working/content")
|
19 |
+
}
|
20 |
+
for env_var, (environment, path) in environments.items():
|
21 |
+
if env_var in os.environ:
|
22 |
+
return environment, path, free_plan
|
23 |
+
print("\033[31mОшибка: обнаружена неизвестная среда выполнения.\n\033[34mПоддерживаемые среды:\033[0m Google Colab, Kaggle.")
|
24 |
+
return None, None, None
|
25 |
+
|
26 |
+
def setup_module_folder(root_path):
|
27 |
+
modules_folder = os.path.join(root_path, "modules")
|
28 |
+
os.makedirs(modules_folder, exist_ok=True)
|
29 |
+
if modules_folder not in sys.path:
|
30 |
+
sys.path.append(modules_folder)
|
31 |
+
|
32 |
+
def clear_module_cache(modules_folder):
|
33 |
+
for module_name in list(sys.modules.keys()):
|
34 |
+
module = sys.modules[module_name]
|
35 |
+
if hasattr(module, '__file__') and module.__file__ and module.__file__.startswith(modules_folder):
|
36 |
+
del sys.modules[module_name]
|
37 |
+
|
38 |
+
importlib.invalidate_caches()
|
39 |
+
|
40 |
+
def download_files(root_path, lang, repo):
|
41 |
+
print("Пожалуйста, дождитесь загрузки файлов... 👀", end='', flush=True)
|
42 |
+
files_dict = {
|
43 |
+
'CSS': {'CSS': ['main_widgets.css', 'auto_cleaner.css']},
|
44 |
+
'file_cell': {f'files_cells/python/{lang}': [f'widgets_{lang}.py', f'downloading_{lang}.py', f'launch_{lang}.py', f'auto_cleaner_{lang}.py']},
|
45 |
+
'file_cell/special': {f'special': ['dl_display_results.py']},
|
46 |
+
'modules': {f'modules': ['models_data.py']}
|
47 |
+
}
|
48 |
+
for folder, contents in files_dict.items():
|
49 |
+
folder_path = os.path.join(root_path, folder)
|
50 |
+
if os.path.exists(folder_path):
|
51 |
+
shutil.rmtree(folder_path)
|
52 |
+
os.makedirs(folder_path)
|
53 |
+
for path_url, files in contents.items():
|
54 |
+
for file in files:
|
55 |
+
file_url = f"https://huggingface.co/NagisaNao/{repo}/resolve/main/{path_url}/{file}"
|
56 |
+
file_path = os.path.join(folder_path, file)
|
57 |
+
os.system(f'wget -q {file_url} -O {file_path}')
|
58 |
+
print(f"\rГотово! Теперь вы можете запустить ячейки ниже. ☄️" + " "*30)
|
59 |
+
|
60 |
+
def main():
|
61 |
+
args = parse_args()
|
62 |
+
lang = args.lang
|
63 |
+
repo = args.repo
|
64 |
+
|
65 |
+
env, root_path, free_plan = detect_environment()
|
66 |
+
|
67 |
+
if env and root_path:
|
68 |
+
webui_path = f"{root_path}/sdw"
|
69 |
+
download_files(root_path, lang, repo)
|
70 |
+
clear_module_cache(os.path.join(root_path, "modules"))
|
71 |
+
setup_module_folder(root_path)
|
72 |
+
|
73 |
+
# Set global environment variable
|
74 |
+
os.environ['ENV_NAME'] = env
|
75 |
+
os.environ['ROOT_PATH'] = root_path
|
76 |
+
os.environ['WEBUI_PATH'] = webui_path
|
77 |
+
os.environ['FREE_PLAN'] = 'True' if free_plan else 'False'
|
78 |
+
|
79 |
+
print(f"Среда выполнения: \033[33m{env}\033[0m")
|
80 |
+
if env == "Google Colab":
|
81 |
+
print(f"Подписка Colab Pro: \033[34m{not free_plan}\033[0m")
|
82 |
+
print(f"Расположение файлов: \033[32m{root_path}\033[0m")
|
83 |
+
|
84 |
+
if repo != 'fast_repo':
|
85 |
+
print('\n\033[31mВНИМАНИЕ: Используется тестовый режим, возможны ошибки при использовании!\033[0m')
|
86 |
+
|
87 |
+
if __name__ == "__main__":
|
88 |
+
main()
|