...
Browse files- files_cells/notebooks/en/downloading_en.ipynb +65 -62
- files_cells/notebooks/en/launch_en.ipynb +16 -4
- files_cells/notebooks/en/widgets_en.ipynb +20 -2
- files_cells/notebooks/ru/downloading_ru.ipynb +65 -62
- files_cells/notebooks/ru/launch_ru.ipynb +16 -4
- files_cells/notebooks/ru/widgets_ru.ipynb +20 -2
- files_cells/python/en/downloading_en.py +65 -62
- files_cells/python/en/launch_en.py +16 -4
- files_cells/python/en/widgets_en.py +20 -2
- files_cells/python/ru/downloading_ru.py +65 -62
- files_cells/python/ru/launch_ru.py +16 -4
- files_cells/python/ru/widgets_ru.py +20 -2
files_cells/notebooks/en/downloading_en.ipynb
CHANGED
@@ -34,6 +34,9 @@
|
|
34 |
"webui_path = os.getenv('WEBUI_PATH')\n",
|
35 |
"free_plan = os.getenv('FREE_PLAN')\n",
|
36 |
"\n",
|
|
|
|
|
|
|
37 |
"\n",
|
38 |
"# ================ LIBRARIES V2 ================\n",
|
39 |
"flag_file = f\"{root_path}/libraries_installed.txt\"\n",
|
@@ -115,6 +118,18 @@
|
|
115 |
"\n",
|
116 |
"\n",
|
117 |
"# ================= MAIN CODE =================\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
"if not os.path.exists(webui_path):\n",
|
119 |
" start_install = int(time.time())\n",
|
120 |
" print(\"⌚ Unpacking Stable Diffusion...\" if change_webui != 'Forge' else \"⌚ Unpacking Stable Diffusion (Forge)...\", end='')\n",
|
@@ -221,7 +236,7 @@
|
|
221 |
" padding = (terminal_width - len(text)) // 2\n",
|
222 |
" return f\"\\033[1m\\033[36m{' ' * padding}{text}{' ' * padding}\\033[0m\\033[32m\"\n",
|
223 |
"\n",
|
224 |
-
"def format_output(url, dst_dir, file_name):\n",
|
225 |
" info = center_text(f\"[{file_name.split('.')[0]}]\")\n",
|
226 |
" separation_line = '\\033[32m' + '---' * 20\n",
|
227 |
"\n",
|
@@ -230,89 +245,81 @@
|
|
230 |
" print(f\"\\033[33mSAVE DIR: \\033[34m{dst_dir}\")\n",
|
231 |
" print(f\"\\033[33mFILE NAME: \\033[34m{file_name}\\033[0m\")\n",
|
232 |
"\n",
|
|
|
|
|
|
|
233 |
"''' GET CivitAi API - DATA '''\n",
|
234 |
"\n",
|
235 |
"def CivitAi_API(url, file_name=None):\n",
|
236 |
-
" SUPPORT_TYPES = ('Checkpoint', '
|
237 |
" CIVITAI_TOKEN = \"62c0c5956b2f9defbd844d754000180b\"\n",
|
238 |
"\n",
|
239 |
" url = url.split('?token=')[0] if '?token=' in url else url\n",
|
240 |
" url = url.replace('?type=', f'?token={CIVITAI_TOKEN}&type=') if '?type=' in url else f\"{url}?token={CIVITAI_TOKEN}\"\n",
|
241 |
"\n",
|
242 |
" def get_model_data(url):\n",
|
243 |
-
"
|
244 |
-
"
|
245 |
-
"
|
246 |
-
"
|
|
|
|
|
|
|
|
|
|
|
247 |
" else:\n",
|
248 |
-
"
|
249 |
-
"
|
250 |
-
"
|
251 |
-
"
|
252 |
-
" return
|
253 |
"\n",
|
254 |
" data = get_model_data(url)\n",
|
255 |
"\n",
|
256 |
" if not data:\n",
|
257 |
-
"
|
|
|
258 |
"\n",
|
259 |
" def extract_model_info(url, data):\n",
|
260 |
-
"
|
261 |
-
"
|
262 |
-
"
|
263 |
-
"
|
264 |
-
"
|
265 |
-
"
|
266 |
-
"
|
267 |
-
" elif 'type=' in url:\n",
|
268 |
-
" model_type = parse_qs(urlparse(url).query).get('type', [''])[0]\n",
|
269 |
-
" if 'model' in model_type.lower():\n",
|
270 |
-
" model_name = data['files'][0]['name']\n",
|
271 |
-
" else:\n",
|
272 |
" model_name = data['files'][1]['name']\n",
|
273 |
-
"
|
274 |
-
" model_type = data['model']['type']\n",
|
275 |
-
" model_name = data['files'][0]['name']\n",
|
276 |
" return model_type, model_name\n",
|
277 |
"\n",
|
278 |
" model_type, model_name = extract_model_info(url, data)\n",
|
279 |
" model_name = file_name or model_name\n",
|
280 |
"\n",
|
281 |
-
" def get_download_url(
|
282 |
-
" if
|
283 |
-
"
|
284 |
-
" return data.get('downloadUrl')\n",
|
285 |
-
" else:\n",
|
286 |
-
" return data[\"modelVersions\"][0].get(\"downloadUrl\", \"\")\n",
|
287 |
-
" elif 'type=' in url:\n",
|
288 |
-
" if any(t.lower() in model_type.lower() for t in SUPPORT_TYPES):\n",
|
289 |
-
" return data['files'][0]['downloadUrl']\n",
|
290 |
-
" else:\n",
|
291 |
-
" return data['files'][1]['downloadUrl']\n",
|
292 |
" else:\n",
|
293 |
-
" return data
|
294 |
"\n",
|
295 |
-
" download_url = get_download_url(
|
296 |
-
" clean_url = re.sub(r'[?&]token=[^&]*', '', download_url)\n",
|
297 |
"\n",
|
298 |
" def get_image_info(data, model_type, model_name):\n",
|
299 |
-
"
|
300 |
-
"
|
301 |
-
"
|
302 |
-
"
|
303 |
-
"
|
304 |
-
"
|
305 |
-
"
|
306 |
-
"
|
307 |
-
"
|
308 |
-
"
|
309 |
"\n",
|
310 |
-
"
|
311 |
-
" return image_url, image_name\n",
|
312 |
"\n",
|
313 |
" image_url, image_name = get_image_info(data, model_type, model_name)\n",
|
314 |
"\n",
|
315 |
-
" return f\"{download_url}{'&' if '?' in download_url else '?'}token={CIVITAI_TOKEN}\",
|
316 |
"\n",
|
317 |
"''' Main Download Code '''\n",
|
318 |
"\n",
|
@@ -382,14 +389,10 @@
|
|
382 |
"\n",
|
383 |
" \"\"\" Formatted info output \"\"\"\n",
|
384 |
" model_name_or_basename = file_name if file_name else basename\n",
|
385 |
-
"
|
386 |
-
"\n",
|
387 |
-
"
|
388 |
-
"
|
389 |
-
" if not data:\n",
|
390 |
-
" print(\"\\033[31m[Data Info]:\\033[0m Failed to retrieve data from the API.\\n\")\n",
|
391 |
-
" if data and image_name:\n",
|
392 |
-
" print(f\"\\033[32m[Preview DL]:\\033[0m {image_name} - {image_url}\\n\")\n",
|
393 |
"\n",
|
394 |
" # =====================\n",
|
395 |
" def run_aria2c(url, dst_dir, file_name=None, args=\"\", header=\"\"):\n",
|
|
|
34 |
"webui_path = os.getenv('WEBUI_PATH')\n",
|
35 |
"free_plan = os.getenv('FREE_PLAN')\n",
|
36 |
"\n",
|
37 |
+
"OLD_UI = os.getenv('SDW_OLD_UI')\n",
|
38 |
+
"UI = os.getenv('SDW_UI')\n",
|
39 |
+
"\n",
|
40 |
"\n",
|
41 |
"# ================ LIBRARIES V2 ================\n",
|
42 |
"flag_file = f\"{root_path}/libraries_installed.txt\"\n",
|
|
|
118 |
"\n",
|
119 |
"\n",
|
120 |
"# ================= MAIN CODE =================\n",
|
121 |
+
"# WebUI switch\n",
|
122 |
+
"if os.path.exists(webui_path):\n",
|
123 |
+
" if UI != OLD_UI:\n",
|
124 |
+
" print(f'Switching the WebUI from \\033[33m{OLD_UI}\\033[0m to \\033[33m{UI}\\033[0m...', end='')\n",
|
125 |
+
" shutil.rmtree(webui_path)\n",
|
126 |
+
" # Updating the environment variable after a change\n",
|
127 |
+
" os.environ['SDW_OLD_UI'] = UI\n",
|
128 |
+
" print('\\rDone!')\n",
|
129 |
+
" time.sleep(2)\n",
|
130 |
+
" clear_output()\n",
|
131 |
+
"\n",
|
132 |
+
"# Unpacking the WebUI\n",
|
133 |
"if not os.path.exists(webui_path):\n",
|
134 |
" start_install = int(time.time())\n",
|
135 |
" print(\"⌚ Unpacking Stable Diffusion...\" if change_webui != 'Forge' else \"⌚ Unpacking Stable Diffusion (Forge)...\", end='')\n",
|
|
|
236 |
" padding = (terminal_width - len(text)) // 2\n",
|
237 |
" return f\"\\033[1m\\033[36m{' ' * padding}{text}{' ' * padding}\\033[0m\\033[32m\"\n",
|
238 |
"\n",
|
239 |
+
"def format_output(url, dst_dir, file_name, image_name=None, image_url=None):\n",
|
240 |
" info = center_text(f\"[{file_name.split('.')[0]}]\")\n",
|
241 |
" separation_line = '\\033[32m' + '---' * 20\n",
|
242 |
"\n",
|
|
|
245 |
" print(f\"\\033[33mSAVE DIR: \\033[34m{dst_dir}\")\n",
|
246 |
" print(f\"\\033[33mFILE NAME: \\033[34m{file_name}\\033[0m\")\n",
|
247 |
"\n",
|
248 |
+
" if 'civitai' in url and image_url:\n",
|
249 |
+
" print(f\"\\033[32m[Preview DL]:\\033[0m {image_name} - {image_url}\\n\")\n",
|
250 |
+
"\n",
|
251 |
"''' GET CivitAi API - DATA '''\n",
|
252 |
"\n",
|
253 |
"def CivitAi_API(url, file_name=None):\n",
|
254 |
+
" SUPPORT_TYPES = ('Checkpoint', 'TextualInversion', 'LORA')\n",
|
255 |
" CIVITAI_TOKEN = \"62c0c5956b2f9defbd844d754000180b\"\n",
|
256 |
"\n",
|
257 |
" url = url.split('?token=')[0] if '?token=' in url else url\n",
|
258 |
" url = url.replace('?type=', f'?token={CIVITAI_TOKEN}&type=') if '?type=' in url else f\"{url}?token={CIVITAI_TOKEN}\"\n",
|
259 |
"\n",
|
260 |
" def get_model_data(url):\n",
|
261 |
+
" base_url = \"https://civitai.com/api/v1\"\n",
|
262 |
+
" try:\n",
|
263 |
+
" if \"civitai.com/models/\" in url:\n",
|
264 |
+
" if '?modelVersionId=' in url:\n",
|
265 |
+
" version_id = url.split('?modelVersionId=')[1]\n",
|
266 |
+
" else:\n",
|
267 |
+
" model_id = url.split('/models/')[1].split('/')[0]\n",
|
268 |
+
" model_data = requests.get(f\"{base_url}/models/{model_id}\").json()\n",
|
269 |
+
" version_id = model_data['modelVersions'][0].get('id')\n",
|
270 |
" else:\n",
|
271 |
+
" version_id = url.split('/models/')[1].split('/')[0]\n",
|
272 |
+
"\n",
|
273 |
+
" return requests.get(f\"{base_url}/model-versions/{version_id}\").json()\n",
|
274 |
+
" except (KeyError, IndexError, requests.RequestException) as e:\n",
|
275 |
+
" return None\n",
|
276 |
"\n",
|
277 |
" data = get_model_data(url)\n",
|
278 |
"\n",
|
279 |
" if not data:\n",
|
280 |
+
" print(\"\\033[31m[Data Info]:\\033[0m Failed to retrieve data from the API.\\n\")\n",
|
281 |
+
" return 'None', None, None, None, None, None, None\n",
|
282 |
"\n",
|
283 |
" def extract_model_info(url, data):\n",
|
284 |
+
" model_type = data['model']['type']\n",
|
285 |
+
" model_name = data['files'][0]['name']\n",
|
286 |
+
"\n",
|
287 |
+
" if 'type=' in url:\n",
|
288 |
+
" url_model_type = parse_qs(urlparse(url).query).get('type', [''])[0].lower()\n",
|
289 |
+
" if 'vae' in url_model_type:\n",
|
290 |
+
" model_type = data['files'][1]['type']\n",
|
|
|
|
|
|
|
|
|
|
|
291 |
" model_name = data['files'][1]['name']\n",
|
292 |
+
"\n",
|
|
|
|
|
293 |
" return model_type, model_name\n",
|
294 |
"\n",
|
295 |
" model_type, model_name = extract_model_info(url, data)\n",
|
296 |
" model_name = file_name or model_name\n",
|
297 |
"\n",
|
298 |
+
" def get_download_url(data, model_type):\n",
|
299 |
+
" if any(t.lower() in model_type.lower() for t in SUPPORT_TYPES):\n",
|
300 |
+
" return data['files'][0]['downloadUrl']\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
301 |
" else:\n",
|
302 |
+
" return data['files'][1]['downloadUrl']\n",
|
303 |
"\n",
|
304 |
+
" download_url = get_download_url(data, model_type)\n",
|
|
|
305 |
"\n",
|
306 |
" def get_image_info(data, model_type, model_name):\n",
|
307 |
+
" if not any(t in model_type for t in SUPPORT_TYPES):\n",
|
308 |
+
" return None, None\n",
|
309 |
+
"\n",
|
310 |
+
" for image in data.get('images', []):\n",
|
311 |
+
" if image['nsfwLevel'] >= 4 and env == 'Kaggle': # Filter NSFW images for Kaggle\n",
|
312 |
+
" continue\n",
|
313 |
+
" image_url = image['url']\n",
|
314 |
+
" image_extension = image_url.split('.')[-1]\n",
|
315 |
+
" image_name = f\"{model_name.split('.')[0]}.preview.{image_extension}\" if image_url else None\n",
|
316 |
+
" return image_url, image_name\n",
|
317 |
"\n",
|
318 |
+
" return None, None\n",
|
|
|
319 |
"\n",
|
320 |
" image_url, image_name = get_image_info(data, model_type, model_name)\n",
|
321 |
"\n",
|
322 |
+
" return f\"{download_url}{'&' if '?' in download_url else '?'}token={CIVITAI_TOKEN}\", download_url, model_type, model_name, image_url, image_name, data\n",
|
323 |
"\n",
|
324 |
"''' Main Download Code '''\n",
|
325 |
"\n",
|
|
|
389 |
"\n",
|
390 |
" \"\"\" Formatted info output \"\"\"\n",
|
391 |
" model_name_or_basename = file_name if file_name else basename\n",
|
392 |
+
" try:\n",
|
393 |
+
" format_output(clean_url or url, dst_dir, model_name_or_basename, image_url, image_name)\n",
|
394 |
+
" except UnboundLocalError:\n",
|
395 |
+
" format_output(clean_url or url, dst_dir, model_name_or_basename, None, None)\n",
|
|
|
|
|
|
|
|
|
396 |
"\n",
|
397 |
" # =====================\n",
|
398 |
" def run_aria2c(url, dst_dir, file_name=None, args=\"\", header=\"\"):\n",
|
files_cells/notebooks/en/launch_en.ipynb
CHANGED
@@ -29,6 +29,7 @@
|
|
29 |
"import time\n",
|
30 |
"import json\n",
|
31 |
"import requests\n",
|
|
|
32 |
"import cloudpickle as pickle\n",
|
33 |
"from datetime import timedelta\n",
|
34 |
"from IPython.display import clear_output\n",
|
@@ -55,6 +56,17 @@
|
|
55 |
"change_webui = settings.get('change_webui', \"\")\n",
|
56 |
"\n",
|
57 |
"\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
"# ======================== TUNNEL V2 ========================\n",
|
59 |
"print('Please Wait...')\n",
|
60 |
"\n",
|
@@ -80,7 +92,9 @@
|
|
80 |
"tunnel_port = 1834\n",
|
81 |
"tunnel = tunnel_class(tunnel_port)\n",
|
82 |
"tunnel.add_tunnel(command=\"cl tunnel --url localhost:{port}\", name=\"cl\", pattern=re.compile(r\"[\\w-]+\\.trycloudflare\\.com\"))\n",
|
83 |
-
"
|
|
|
|
|
84 |
"\n",
|
85 |
"if zrok_token:\n",
|
86 |
" !zrok enable {zrok_token} &> /dev/null\n",
|
@@ -89,7 +103,7 @@
|
|
89 |
"clear_output()\n",
|
90 |
"\n",
|
91 |
"\n",
|
92 |
-
"#
|
93 |
"paths_to_check = {\n",
|
94 |
" \"tagger_hf_cache_dir\": f\"{webui_path}/models/interrogators/\",\n",
|
95 |
" \"additional_networks_extra_lora_path\": f\"{webui_path}/models/Lora/\",\n",
|
@@ -110,8 +124,6 @@
|
|
110 |
" sed_command = f\"sed -i 's|\\\"{key}\\\": \\\".*\\\"|\\\"{key}\\\": \\\"{value}\\\"|' {config_path}\"\n",
|
111 |
" os.system(sed_command)\n",
|
112 |
"\n",
|
113 |
-
" if env == 'Kaggle':\n",
|
114 |
-
" !sed -i 's/\"civitai_interface\\/NSFW content\\/visible\": true,/\"civitai_interface\\/NSFW content\\/visible\": false,/' {webui_path}/ui-config.json\n",
|
115 |
"\n",
|
116 |
"with tunnel:\n",
|
117 |
" %cd {webui_path}\n",
|
|
|
29 |
"import time\n",
|
30 |
"import json\n",
|
31 |
"import requests\n",
|
32 |
+
"import subprocess\n",
|
33 |
"import cloudpickle as pickle\n",
|
34 |
"from datetime import timedelta\n",
|
35 |
"from IPython.display import clear_output\n",
|
|
|
56 |
"change_webui = settings.get('change_webui', \"\")\n",
|
57 |
"\n",
|
58 |
"\n",
|
59 |
+
"# ========================== OTHER ==========================\n",
|
60 |
+
"def is_package_installed(package_name):\n",
|
61 |
+
" try:\n",
|
62 |
+
" subprocess.run([\"npm\", \"ls\", \"-g\", package_name], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n",
|
63 |
+
" return True\n",
|
64 |
+
" except subprocess.CalledProcessError:\n",
|
65 |
+
" return False\n",
|
66 |
+
"\n",
|
67 |
+
"lt_tunnel = is_package_installed('localtunnel')\n",
|
68 |
+
"\n",
|
69 |
+
"\n",
|
70 |
"# ======================== TUNNEL V2 ========================\n",
|
71 |
"print('Please Wait...')\n",
|
72 |
"\n",
|
|
|
92 |
"tunnel_port = 1834\n",
|
93 |
"tunnel = tunnel_class(tunnel_port)\n",
|
94 |
"tunnel.add_tunnel(command=\"cl tunnel --url localhost:{port}\", name=\"cl\", pattern=re.compile(r\"[\\w-]+\\.trycloudflare\\.com\"))\n",
|
95 |
+
"\n",
|
96 |
+
"if lt_tunnel:\n",
|
97 |
+
" tunnel.add_tunnel(command=\"lt --port {port}\", name=\"lt\", pattern=re.compile(r\"[\\w-]+\\.loca\\.lt\"), note=\"Password : \" + \"\\033[32m\" + public_ipv4 + \"\\033[0m\" + \" rerun cell if 404 error.\")\n",
|
98 |
"\n",
|
99 |
"if zrok_token:\n",
|
100 |
" !zrok enable {zrok_token} &> /dev/null\n",
|
|
|
103 |
"clear_output()\n",
|
104 |
"\n",
|
105 |
"\n",
|
106 |
+
"# ================= Automatic Fixing Path V3 ================\n",
|
107 |
"paths_to_check = {\n",
|
108 |
" \"tagger_hf_cache_dir\": f\"{webui_path}/models/interrogators/\",\n",
|
109 |
" \"additional_networks_extra_lora_path\": f\"{webui_path}/models/Lora/\",\n",
|
|
|
124 |
" sed_command = f\"sed -i 's|\\\"{key}\\\": \\\".*\\\"|\\\"{key}\\\": \\\"{value}\\\"|' {config_path}\"\n",
|
125 |
" os.system(sed_command)\n",
|
126 |
"\n",
|
|
|
|
|
127 |
"\n",
|
128 |
"with tunnel:\n",
|
129 |
" %cd {webui_path}\n",
|
files_cells/notebooks/en/widgets_en.ipynb
CHANGED
@@ -116,6 +116,7 @@
|
|
116 |
"'''\n",
|
117 |
"display(HTML(JS))\n",
|
118 |
"\n",
|
|
|
119 |
"# ==================== WIDGETS V2 ====================\n",
|
120 |
"HR = widgets.HTML('<hr>')\n",
|
121 |
"\n",
|
@@ -245,8 +246,6 @@
|
|
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",
|
@@ -296,6 +295,24 @@
|
|
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",
|
@@ -329,6 +346,7 @@
|
|
329 |
" widgets.Widget.close_all()\n",
|
330 |
"\n",
|
331 |
"def save_data(button):\n",
|
|
|
332 |
" save_settings()\n",
|
333 |
" hide_widgets()\n",
|
334 |
"\n",
|
|
|
116 |
"'''\n",
|
117 |
"display(HTML(JS))\n",
|
118 |
"\n",
|
119 |
+
"\n",
|
120 |
"# ==================== WIDGETS V2 ====================\n",
|
121 |
"HR = widgets.HTML('<hr>')\n",
|
122 |
"\n",
|
|
|
246 |
"\n",
|
247 |
"if free_plan and env == \"Google Colab\": # remove ngrok from colab\n",
|
248 |
" additional_widget_list.remove(ngrok_widget)\n",
|
|
|
|
|
249 |
"\n",
|
250 |
"all_additional_box = factory.create_vbox(additional_widget_list, class_names=[\"container\", \"image_3\"])\n",
|
251 |
"factory.display(all_additional_box)\n",
|
|
|
295 |
"factory.display(save_button)\n",
|
296 |
"\n",
|
297 |
"\n",
|
298 |
+
"# ==================== OTHER FUNC ====================\n",
|
299 |
+
"# Setup UI\n",
|
300 |
+
"def setup_webui(change_webui_widget):\n",
|
301 |
+
" if 'SDW_UI' in os.environ:\n",
|
302 |
+
" UI = os.environ['SDW_UI']\n",
|
303 |
+
" else:\n",
|
304 |
+
" os.environ['SDW_UI'] = change_webui_widget\n",
|
305 |
+
" os.environ['SDW_OLD_UI'] = change_webui_widget\n",
|
306 |
+
"\n",
|
307 |
+
" UI = os.getenv('SDW_UI')\n",
|
308 |
+
" OLD_UI = os.getenv('SDW_OLD_UI')\n",
|
309 |
+
"\n",
|
310 |
+
" if UI != change_webui_widget:\n",
|
311 |
+
" os.environ['SDW_UI'] = change_webui_widget\n",
|
312 |
+
"\n",
|
313 |
+
" # print(f'Current UI: {os.getenv(\"SDW_UI\")}, Old UI: {os.getenv(\"SDW_OLD_UI\")}')\n",
|
314 |
+
"\n",
|
315 |
+
"\n",
|
316 |
"# ============ Load / Save - Settings V2 ============\n",
|
317 |
"SETTINGS_FILE = f'{root_path}/settings.json'\n",
|
318 |
"\n",
|
|
|
346 |
" widgets.Widget.close_all()\n",
|
347 |
"\n",
|
348 |
"def save_data(button):\n",
|
349 |
+
" setup_webui(change_webui_widget.value)\n",
|
350 |
" save_settings()\n",
|
351 |
" hide_widgets()\n",
|
352 |
"\n",
|
files_cells/notebooks/ru/downloading_ru.ipynb
CHANGED
@@ -34,6 +34,9 @@
|
|
34 |
"webui_path = os.getenv('WEBUI_PATH')\n",
|
35 |
"free_plan = os.getenv('FREE_PLAN')\n",
|
36 |
"\n",
|
|
|
|
|
|
|
37 |
"\n",
|
38 |
"# ================ LIBRARIES V2 ================\n",
|
39 |
"flag_file = f\"{root_path}/libraries_installed.txt\"\n",
|
@@ -115,6 +118,18 @@
|
|
115 |
"\n",
|
116 |
"\n",
|
117 |
"# ================= MAIN CODE =================\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
"if not os.path.exists(webui_path):\n",
|
119 |
" start_install = int(time.time())\n",
|
120 |
" print(\"⌚ Распаковка Stable Diffusion...\" if change_webui != 'Forge' else \"⌚ Распаковка Stable Diffusion (Forge)...\", end='')\n",
|
@@ -221,7 +236,7 @@
|
|
221 |
" padding = (terminal_width - len(text)) // 2\n",
|
222 |
" return f\"\\033[1m\\033[36m{' ' * padding}{text}{' ' * padding}\\033[0m\\033[32m\"\n",
|
223 |
"\n",
|
224 |
-
"def format_output(url, dst_dir, file_name):\n",
|
225 |
" info = center_text(f\"[{file_name.split('.')[0]}]\")\n",
|
226 |
" separation_line = '\\033[32m' + '---' * 20\n",
|
227 |
"\n",
|
@@ -230,89 +245,81 @@
|
|
230 |
" print(f\"\\033[33mSAVE DIR: \\033[34m{dst_dir}\")\n",
|
231 |
" print(f\"\\033[33mFILE NAME: \\033[34m{file_name}\\033[0m\")\n",
|
232 |
"\n",
|
|
|
|
|
|
|
233 |
"''' GET CivitAi API - DATA '''\n",
|
234 |
"\n",
|
235 |
"def CivitAi_API(url, file_name=None):\n",
|
236 |
-
" SUPPORT_TYPES = ('Checkpoint', '
|
237 |
" CIVITAI_TOKEN = \"62c0c5956b2f9defbd844d754000180b\"\n",
|
238 |
"\n",
|
239 |
" url = url.split('?token=')[0] if '?token=' in url else url\n",
|
240 |
" url = url.replace('?type=', f'?token={CIVITAI_TOKEN}&type=') if '?type=' in url else f\"{url}?token={CIVITAI_TOKEN}\"\n",
|
241 |
"\n",
|
242 |
" def get_model_data(url):\n",
|
243 |
-
"
|
244 |
-
"
|
245 |
-
"
|
246 |
-
"
|
|
|
|
|
|
|
|
|
|
|
247 |
" else:\n",
|
248 |
-
"
|
249 |
-
"
|
250 |
-
"
|
251 |
-
"
|
252 |
-
" return
|
253 |
"\n",
|
254 |
" data = get_model_data(url)\n",
|
255 |
"\n",
|
256 |
" if not data:\n",
|
257 |
-
"
|
|
|
258 |
"\n",
|
259 |
" def extract_model_info(url, data):\n",
|
260 |
-
"
|
261 |
-
"
|
262 |
-
"
|
263 |
-
"
|
264 |
-
"
|
265 |
-
"
|
266 |
-
"
|
267 |
-
" elif 'type=' in url:\n",
|
268 |
-
" model_type = parse_qs(urlparse(url).query).get('type', [''])[0]\n",
|
269 |
-
" if 'model' in model_type.lower():\n",
|
270 |
-
" model_name = data['files'][0]['name']\n",
|
271 |
-
" else:\n",
|
272 |
" model_name = data['files'][1]['name']\n",
|
273 |
-
"
|
274 |
-
" model_type = data['model']['type']\n",
|
275 |
-
" model_name = data['files'][0]['name']\n",
|
276 |
" return model_type, model_name\n",
|
277 |
"\n",
|
278 |
" model_type, model_name = extract_model_info(url, data)\n",
|
279 |
" model_name = file_name or model_name\n",
|
280 |
"\n",
|
281 |
-
" def get_download_url(
|
282 |
-
" if
|
283 |
-
"
|
284 |
-
" return data.get('downloadUrl')\n",
|
285 |
-
" else:\n",
|
286 |
-
" return data[\"modelVersions\"][0].get(\"downloadUrl\", \"\")\n",
|
287 |
-
" elif 'type=' in url:\n",
|
288 |
-
" if any(t.lower() in model_type.lower() for t in SUPPORT_TYPES):\n",
|
289 |
-
" return data['files'][0]['downloadUrl']\n",
|
290 |
-
" else:\n",
|
291 |
-
" return data['files'][1]['downloadUrl']\n",
|
292 |
" else:\n",
|
293 |
-
" return data
|
294 |
"\n",
|
295 |
-
" download_url = get_download_url(
|
296 |
-
" clean_url = re.sub(r'[?&]token=[^&]*', '', download_url)\n",
|
297 |
"\n",
|
298 |
" def get_image_info(data, model_type, model_name):\n",
|
299 |
-
"
|
300 |
-
"
|
301 |
-
"
|
302 |
-
"
|
303 |
-
"
|
304 |
-
"
|
305 |
-
"
|
306 |
-
"
|
307 |
-
"
|
308 |
-
"
|
309 |
"\n",
|
310 |
-
"
|
311 |
-
" return image_url, image_name\n",
|
312 |
"\n",
|
313 |
" image_url, image_name = get_image_info(data, model_type, model_name)\n",
|
314 |
"\n",
|
315 |
-
" return f\"{download_url}{'&' if '?' in download_url else '?'}token={CIVITAI_TOKEN}\",
|
316 |
"\n",
|
317 |
"''' Main Download Code '''\n",
|
318 |
"\n",
|
@@ -382,14 +389,10 @@
|
|
382 |
"\n",
|
383 |
" \"\"\" Formatted info output \"\"\"\n",
|
384 |
" model_name_or_basename = file_name if file_name else basename\n",
|
385 |
-
"
|
386 |
-
"\n",
|
387 |
-
"
|
388 |
-
"
|
389 |
-
" if not data:\n",
|
390 |
-
" print(\"\\033[31m[Data Info]:\\033[0m Failed to retrieve data from the API.\\n\")\n",
|
391 |
-
" if data and image_name:\n",
|
392 |
-
" print(f\"\\033[32m[Preview DL]:\\033[0m {image_name} - {image_url}\\n\")\n",
|
393 |
"\n",
|
394 |
" # =====================\n",
|
395 |
" def run_aria2c(url, dst_dir, file_name=None, args=\"\", header=\"\"):\n",
|
|
|
34 |
"webui_path = os.getenv('WEBUI_PATH')\n",
|
35 |
"free_plan = os.getenv('FREE_PLAN')\n",
|
36 |
"\n",
|
37 |
+
"OLD_UI = os.getenv('SDW_OLD_UI')\n",
|
38 |
+
"UI = os.getenv('SDW_UI')\n",
|
39 |
+
"\n",
|
40 |
"\n",
|
41 |
"# ================ LIBRARIES V2 ================\n",
|
42 |
"flag_file = f\"{root_path}/libraries_installed.txt\"\n",
|
|
|
118 |
"\n",
|
119 |
"\n",
|
120 |
"# ================= MAIN CODE =================\n",
|
121 |
+
"# WebUI switch\n",
|
122 |
+
"if os.path.exists(webui_path):\n",
|
123 |
+
" if UI != OLD_UI:\n",
|
124 |
+
" print(f'Переключение веб-интерфейса с \\033[33m{OLD_UI}\\033[0m на \\033[33m{UI}\\033[0m...', end='')\n",
|
125 |
+
" shutil.rmtree(webui_path)\n",
|
126 |
+
" # Updating the environment variable after a change\n",
|
127 |
+
" os.environ['SDW_OLD_UI'] = UI\n",
|
128 |
+
" print('\\rГотово!')\n",
|
129 |
+
" time.sleep(2)\n",
|
130 |
+
" clear_output()\n",
|
131 |
+
"\n",
|
132 |
+
"# Unpacking the WebUI\n",
|
133 |
"if not os.path.exists(webui_path):\n",
|
134 |
" start_install = int(time.time())\n",
|
135 |
" print(\"⌚ Распаковка Stable Diffusion...\" if change_webui != 'Forge' else \"⌚ Распаковка Stable Diffusion (Forge)...\", end='')\n",
|
|
|
236 |
" padding = (terminal_width - len(text)) // 2\n",
|
237 |
" return f\"\\033[1m\\033[36m{' ' * padding}{text}{' ' * padding}\\033[0m\\033[32m\"\n",
|
238 |
"\n",
|
239 |
+
"def format_output(url, dst_dir, file_name, image_name=None, image_url=None):\n",
|
240 |
" info = center_text(f\"[{file_name.split('.')[0]}]\")\n",
|
241 |
" separation_line = '\\033[32m' + '---' * 20\n",
|
242 |
"\n",
|
|
|
245 |
" print(f\"\\033[33mSAVE DIR: \\033[34m{dst_dir}\")\n",
|
246 |
" print(f\"\\033[33mFILE NAME: \\033[34m{file_name}\\033[0m\")\n",
|
247 |
"\n",
|
248 |
+
" if 'civitai' in url and image_url:\n",
|
249 |
+
" print(f\"\\033[32m[Preview DL]:\\033[0m {image_name} - {image_url}\\n\")\n",
|
250 |
+
"\n",
|
251 |
"''' GET CivitAi API - DATA '''\n",
|
252 |
"\n",
|
253 |
"def CivitAi_API(url, file_name=None):\n",
|
254 |
+
" SUPPORT_TYPES = ('Checkpoint', 'TextualInversion', 'LORA')\n",
|
255 |
" CIVITAI_TOKEN = \"62c0c5956b2f9defbd844d754000180b\"\n",
|
256 |
"\n",
|
257 |
" url = url.split('?token=')[0] if '?token=' in url else url\n",
|
258 |
" url = url.replace('?type=', f'?token={CIVITAI_TOKEN}&type=') if '?type=' in url else f\"{url}?token={CIVITAI_TOKEN}\"\n",
|
259 |
"\n",
|
260 |
" def get_model_data(url):\n",
|
261 |
+
" base_url = \"https://civitai.com/api/v1\"\n",
|
262 |
+
" try:\n",
|
263 |
+
" if \"civitai.com/models/\" in url:\n",
|
264 |
+
" if '?modelVersionId=' in url:\n",
|
265 |
+
" version_id = url.split('?modelVersionId=')[1]\n",
|
266 |
+
" else:\n",
|
267 |
+
" model_id = url.split('/models/')[1].split('/')[0]\n",
|
268 |
+
" model_data = requests.get(f\"{base_url}/models/{model_id}\").json()\n",
|
269 |
+
" version_id = model_data['modelVersions'][0].get('id')\n",
|
270 |
" else:\n",
|
271 |
+
" version_id = url.split('/models/')[1].split('/')[0]\n",
|
272 |
+
"\n",
|
273 |
+
" return requests.get(f\"{base_url}/model-versions/{version_id}\").json()\n",
|
274 |
+
" except (KeyError, IndexError, requests.RequestException) as e:\n",
|
275 |
+
" return None\n",
|
276 |
"\n",
|
277 |
" data = get_model_data(url)\n",
|
278 |
"\n",
|
279 |
" if not data:\n",
|
280 |
+
" print(\"\\033[31m[Data Info]:\\033[0m Failed to retrieve data from the API.\\n\")\n",
|
281 |
+
" return 'None', None, None, None, None, None, None\n",
|
282 |
"\n",
|
283 |
" def extract_model_info(url, data):\n",
|
284 |
+
" model_type = data['model']['type']\n",
|
285 |
+
" model_name = data['files'][0]['name']\n",
|
286 |
+
"\n",
|
287 |
+
" if 'type=' in url:\n",
|
288 |
+
" url_model_type = parse_qs(urlparse(url).query).get('type', [''])[0].lower()\n",
|
289 |
+
" if 'vae' in url_model_type:\n",
|
290 |
+
" model_type = data['files'][1]['type']\n",
|
|
|
|
|
|
|
|
|
|
|
291 |
" model_name = data['files'][1]['name']\n",
|
292 |
+
"\n",
|
|
|
|
|
293 |
" return model_type, model_name\n",
|
294 |
"\n",
|
295 |
" model_type, model_name = extract_model_info(url, data)\n",
|
296 |
" model_name = file_name or model_name\n",
|
297 |
"\n",
|
298 |
+
" def get_download_url(data, model_type):\n",
|
299 |
+
" if any(t.lower() in model_type.lower() for t in SUPPORT_TYPES):\n",
|
300 |
+
" return data['files'][0]['downloadUrl']\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
301 |
" else:\n",
|
302 |
+
" return data['files'][1]['downloadUrl']\n",
|
303 |
"\n",
|
304 |
+
" download_url = get_download_url(data, model_type)\n",
|
|
|
305 |
"\n",
|
306 |
" def get_image_info(data, model_type, model_name):\n",
|
307 |
+
" if not any(t in model_type for t in SUPPORT_TYPES):\n",
|
308 |
+
" return None, None\n",
|
309 |
+
"\n",
|
310 |
+
" for image in data.get('images', []):\n",
|
311 |
+
" if image['nsfwLevel'] >= 4 and env == 'Kaggle': # Filter NSFW images for Kaggle\n",
|
312 |
+
" continue\n",
|
313 |
+
" image_url = image['url']\n",
|
314 |
+
" image_extension = image_url.split('.')[-1]\n",
|
315 |
+
" image_name = f\"{model_name.split('.')[0]}.preview.{image_extension}\" if image_url else None\n",
|
316 |
+
" return image_url, image_name\n",
|
317 |
"\n",
|
318 |
+
" return None, None\n",
|
|
|
319 |
"\n",
|
320 |
" image_url, image_name = get_image_info(data, model_type, model_name)\n",
|
321 |
"\n",
|
322 |
+
" return f\"{download_url}{'&' if '?' in download_url else '?'}token={CIVITAI_TOKEN}\", download_url, model_type, model_name, image_url, image_name, data\n",
|
323 |
"\n",
|
324 |
"''' Main Download Code '''\n",
|
325 |
"\n",
|
|
|
389 |
"\n",
|
390 |
" \"\"\" Formatted info output \"\"\"\n",
|
391 |
" model_name_or_basename = file_name if file_name else basename\n",
|
392 |
+
" try:\n",
|
393 |
+
" format_output(clean_url or url, dst_dir, model_name_or_basename, image_url, image_name)\n",
|
394 |
+
" except UnboundLocalError:\n",
|
395 |
+
" format_output(clean_url or url, dst_dir, model_name_or_basename, None, None)\n",
|
|
|
|
|
|
|
|
|
396 |
"\n",
|
397 |
" # =====================\n",
|
398 |
" def run_aria2c(url, dst_dir, file_name=None, args=\"\", header=\"\"):\n",
|
files_cells/notebooks/ru/launch_ru.ipynb
CHANGED
@@ -29,6 +29,7 @@
|
|
29 |
"import time\n",
|
30 |
"import json\n",
|
31 |
"import requests\n",
|
|
|
32 |
"import cloudpickle as pickle\n",
|
33 |
"from datetime import timedelta\n",
|
34 |
"from IPython.display import clear_output\n",
|
@@ -55,6 +56,17 @@
|
|
55 |
"change_webui = settings.get('change_webui', \"\")\n",
|
56 |
"\n",
|
57 |
"\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
"# ======================== TUNNEL V2 ========================\n",
|
59 |
"print('Please Wait...')\n",
|
60 |
"\n",
|
@@ -80,7 +92,9 @@
|
|
80 |
"tunnel_port = 1834\n",
|
81 |
"tunnel = tunnel_class(tunnel_port)\n",
|
82 |
"tunnel.add_tunnel(command=\"cl tunnel --url localhost:{port}\", name=\"cl\", pattern=re.compile(r\"[\\w-]+\\.trycloudflare\\.com\"))\n",
|
83 |
-
"
|
|
|
|
|
84 |
"\n",
|
85 |
"if zrok_token:\n",
|
86 |
" !zrok enable {zrok_token} &> /dev/null\n",
|
@@ -89,7 +103,7 @@
|
|
89 |
"clear_output()\n",
|
90 |
"\n",
|
91 |
"\n",
|
92 |
-
"#
|
93 |
"paths_to_check = {\n",
|
94 |
" \"tagger_hf_cache_dir\": f\"{webui_path}/models/interrogators/\",\n",
|
95 |
" \"additional_networks_extra_lora_path\": f\"{webui_path}/models/Lora/\",\n",
|
@@ -110,8 +124,6 @@
|
|
110 |
" sed_command = f\"sed -i 's|\\\"{key}\\\": \\\".*\\\"|\\\"{key}\\\": \\\"{value}\\\"|' {config_path}\"\n",
|
111 |
" os.system(sed_command)\n",
|
112 |
"\n",
|
113 |
-
" if env == 'Kaggle':\n",
|
114 |
-
" !sed -i 's/\"civitai_interface\\/NSFW content\\/visible\": true,/\"civitai_interface\\/NSFW content\\/visible\": false,/' {webui_path}/ui-config.json\n",
|
115 |
"\n",
|
116 |
"with tunnel:\n",
|
117 |
" %cd {webui_path}\n",
|
|
|
29 |
"import time\n",
|
30 |
"import json\n",
|
31 |
"import requests\n",
|
32 |
+
"import subprocess\n",
|
33 |
"import cloudpickle as pickle\n",
|
34 |
"from datetime import timedelta\n",
|
35 |
"from IPython.display import clear_output\n",
|
|
|
56 |
"change_webui = settings.get('change_webui', \"\")\n",
|
57 |
"\n",
|
58 |
"\n",
|
59 |
+
"# ========================== OTHER ==========================\n",
|
60 |
+
"def is_package_installed(package_name):\n",
|
61 |
+
" try:\n",
|
62 |
+
" subprocess.run([\"npm\", \"ls\", \"-g\", package_name], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n",
|
63 |
+
" return True\n",
|
64 |
+
" except subprocess.CalledProcessError:\n",
|
65 |
+
" return False\n",
|
66 |
+
"\n",
|
67 |
+
"lt_tunnel = is_package_installed('localtunnel')\n",
|
68 |
+
"\n",
|
69 |
+
"\n",
|
70 |
"# ======================== TUNNEL V2 ========================\n",
|
71 |
"print('Please Wait...')\n",
|
72 |
"\n",
|
|
|
92 |
"tunnel_port = 1834\n",
|
93 |
"tunnel = tunnel_class(tunnel_port)\n",
|
94 |
"tunnel.add_tunnel(command=\"cl tunnel --url localhost:{port}\", name=\"cl\", pattern=re.compile(r\"[\\w-]+\\.trycloudflare\\.com\"))\n",
|
95 |
+
"\n",
|
96 |
+
"if lt_tunnel:\n",
|
97 |
+
" tunnel.add_tunnel(command=\"lt --port {port}\", name=\"lt\", pattern=re.compile(r\"[\\w-]+\\.loca\\.lt\"), note=\"Password : \" + \"\\033[32m\" + public_ipv4 + \"\\033[0m\" + \" rerun cell if 404 error.\")\n",
|
98 |
"\n",
|
99 |
"if zrok_token:\n",
|
100 |
" !zrok enable {zrok_token} &> /dev/null\n",
|
|
|
103 |
"clear_output()\n",
|
104 |
"\n",
|
105 |
"\n",
|
106 |
+
"# ================= Automatic Fixing Path V3 ================\n",
|
107 |
"paths_to_check = {\n",
|
108 |
" \"tagger_hf_cache_dir\": f\"{webui_path}/models/interrogators/\",\n",
|
109 |
" \"additional_networks_extra_lora_path\": f\"{webui_path}/models/Lora/\",\n",
|
|
|
124 |
" sed_command = f\"sed -i 's|\\\"{key}\\\": \\\".*\\\"|\\\"{key}\\\": \\\"{value}\\\"|' {config_path}\"\n",
|
125 |
" os.system(sed_command)\n",
|
126 |
"\n",
|
|
|
|
|
127 |
"\n",
|
128 |
"with tunnel:\n",
|
129 |
" %cd {webui_path}\n",
|
files_cells/notebooks/ru/widgets_ru.ipynb
CHANGED
@@ -116,6 +116,7 @@
|
|
116 |
"'''\n",
|
117 |
"display(HTML(JS))\n",
|
118 |
"\n",
|
|
|
119 |
"# ==================== WIDGETS V2 ====================\n",
|
120 |
"HR = widgets.HTML('<hr>')\n",
|
121 |
"\n",
|
@@ -245,8 +246,6 @@
|
|
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",
|
@@ -296,6 +295,24 @@
|
|
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",
|
@@ -329,6 +346,7 @@
|
|
329 |
" widgets.Widget.close_all()\n",
|
330 |
"\n",
|
331 |
"def save_data(button):\n",
|
|
|
332 |
" save_settings()\n",
|
333 |
" hide_widgets()\n",
|
334 |
"\n",
|
|
|
116 |
"'''\n",
|
117 |
"display(HTML(JS))\n",
|
118 |
"\n",
|
119 |
+
"\n",
|
120 |
"# ==================== WIDGETS V2 ====================\n",
|
121 |
"HR = widgets.HTML('<hr>')\n",
|
122 |
"\n",
|
|
|
246 |
"\n",
|
247 |
"if free_plan and env == \"Google Colab\": # remove ngrok from colab\n",
|
248 |
" additional_widget_list.remove(ngrok_widget)\n",
|
|
|
|
|
249 |
"\n",
|
250 |
"all_additional_box = factory.create_vbox(additional_widget_list, class_names=[\"container\", \"image_3\"])\n",
|
251 |
"factory.display(all_additional_box)\n",
|
|
|
295 |
"factory.display(save_button)\n",
|
296 |
"\n",
|
297 |
"\n",
|
298 |
+
"# ==================== OTHER FUNC ====================\n",
|
299 |
+
"# Setup UI\n",
|
300 |
+
"def setup_webui(change_webui_widget):\n",
|
301 |
+
" if 'SDW_UI' in os.environ:\n",
|
302 |
+
" UI = os.environ['SDW_UI']\n",
|
303 |
+
" else:\n",
|
304 |
+
" os.environ['SDW_UI'] = change_webui_widget\n",
|
305 |
+
" os.environ['SDW_OLD_UI'] = change_webui_widget\n",
|
306 |
+
"\n",
|
307 |
+
" UI = os.getenv('SDW_UI')\n",
|
308 |
+
" OLD_UI = os.getenv('SDW_OLD_UI')\n",
|
309 |
+
"\n",
|
310 |
+
" if UI != change_webui_widget:\n",
|
311 |
+
" os.environ['SDW_UI'] = change_webui_widget\n",
|
312 |
+
"\n",
|
313 |
+
" # print(f'Current UI: {os.getenv(\"SDW_UI\")}, Old UI: {os.getenv(\"SDW_OLD_UI\")}')\n",
|
314 |
+
"\n",
|
315 |
+
"\n",
|
316 |
"# ============ Load / Save - Settings V2 ============\n",
|
317 |
"SETTINGS_FILE = f'{root_path}/settings.json'\n",
|
318 |
"\n",
|
|
|
346 |
" widgets.Widget.close_all()\n",
|
347 |
"\n",
|
348 |
"def save_data(button):\n",
|
349 |
+
" setup_webui(change_webui_widget.value)\n",
|
350 |
" save_settings()\n",
|
351 |
" hide_widgets()\n",
|
352 |
"\n",
|
files_cells/python/en/downloading_en.py
CHANGED
@@ -24,6 +24,9 @@ root_path = os.getenv('ROOT_PATH')
|
|
24 |
webui_path = os.getenv('WEBUI_PATH')
|
25 |
free_plan = os.getenv('FREE_PLAN')
|
26 |
|
|
|
|
|
|
|
27 |
|
28 |
# ================ LIBRARIES V2 ================
|
29 |
flag_file = f"{root_path}/libraries_installed.txt"
|
@@ -105,6 +108,18 @@ except:
|
|
105 |
|
106 |
|
107 |
# ================= MAIN CODE =================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
if not os.path.exists(webui_path):
|
109 |
start_install = int(time.time())
|
110 |
print("⌚ Unpacking Stable Diffusion..." if change_webui != 'Forge' else "⌚ Unpacking Stable Diffusion (Forge)...", end='')
|
@@ -211,7 +226,7 @@ def center_text(text, terminal_width=45):
|
|
211 |
padding = (terminal_width - len(text)) // 2
|
212 |
return f"\033[1m\033[36m{' ' * padding}{text}{' ' * padding}\033[0m\033[32m"
|
213 |
|
214 |
-
def format_output(url, dst_dir, file_name):
|
215 |
info = center_text(f"[{file_name.split('.')[0]}]")
|
216 |
separation_line = '\033[32m' + '---' * 20
|
217 |
|
@@ -220,89 +235,81 @@ def format_output(url, dst_dir, file_name):
|
|
220 |
print(f"\033[33mSAVE DIR: \033[34m{dst_dir}")
|
221 |
print(f"\033[33mFILE NAME: \033[34m{file_name}\033[0m")
|
222 |
|
|
|
|
|
|
|
223 |
''' GET CivitAi API - DATA '''
|
224 |
|
225 |
def CivitAi_API(url, file_name=None):
|
226 |
-
SUPPORT_TYPES = ('Checkpoint', '
|
227 |
CIVITAI_TOKEN = "62c0c5956b2f9defbd844d754000180b"
|
228 |
|
229 |
url = url.split('?token=')[0] if '?token=' in url else url
|
230 |
url = url.replace('?type=', f'?token={CIVITAI_TOKEN}&type=') if '?type=' in url else f"{url}?token={CIVITAI_TOKEN}"
|
231 |
|
232 |
def get_model_data(url):
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
|
|
|
|
|
|
|
|
|
|
237 |
else:
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
return
|
243 |
|
244 |
data = get_model_data(url)
|
245 |
|
246 |
if not data:
|
247 |
-
|
|
|
248 |
|
249 |
def extract_model_info(url, data):
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
elif 'type=' in url:
|
258 |
-
model_type = parse_qs(urlparse(url).query).get('type', [''])[0]
|
259 |
-
if 'model' in model_type.lower():
|
260 |
-
model_name = data['files'][0]['name']
|
261 |
-
else:
|
262 |
model_name = data['files'][1]['name']
|
263 |
-
|
264 |
-
model_type = data['model']['type']
|
265 |
-
model_name = data['files'][0]['name']
|
266 |
return model_type, model_name
|
267 |
|
268 |
model_type, model_name = extract_model_info(url, data)
|
269 |
model_name = file_name or model_name
|
270 |
|
271 |
-
def get_download_url(
|
272 |
-
if
|
273 |
-
|
274 |
-
return data.get('downloadUrl')
|
275 |
-
else:
|
276 |
-
return data["modelVersions"][0].get("downloadUrl", "")
|
277 |
-
elif 'type=' in url:
|
278 |
-
if any(t.lower() in model_type.lower() for t in SUPPORT_TYPES):
|
279 |
-
return data['files'][0]['downloadUrl']
|
280 |
-
else:
|
281 |
-
return data['files'][1]['downloadUrl']
|
282 |
else:
|
283 |
-
return data
|
284 |
|
285 |
-
download_url = get_download_url(
|
286 |
-
clean_url = re.sub(r'[?&]token=[^&]*', '', download_url)
|
287 |
|
288 |
def get_image_info(data, model_type, model_name):
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
|
300 |
-
|
301 |
-
return image_url, image_name
|
302 |
|
303 |
image_url, image_name = get_image_info(data, model_type, model_name)
|
304 |
|
305 |
-
return f"{download_url}{'&' if '?' in download_url else '?'}token={CIVITAI_TOKEN}",
|
306 |
|
307 |
''' Main Download Code '''
|
308 |
|
@@ -372,14 +379,10 @@ def manual_download(url, dst_dir, file_name):
|
|
372 |
|
373 |
""" Formatted info output """
|
374 |
model_name_or_basename = file_name if file_name else basename
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
if not data:
|
380 |
-
print("\033[31m[Data Info]:\033[0m Failed to retrieve data from the API.\n")
|
381 |
-
if data and image_name:
|
382 |
-
print(f"\033[32m[Preview DL]:\033[0m {image_name} - {image_url}\n")
|
383 |
|
384 |
# =====================
|
385 |
def run_aria2c(url, dst_dir, file_name=None, args="", header=""):
|
|
|
24 |
webui_path = os.getenv('WEBUI_PATH')
|
25 |
free_plan = os.getenv('FREE_PLAN')
|
26 |
|
27 |
+
OLD_UI = os.getenv('SDW_OLD_UI')
|
28 |
+
UI = os.getenv('SDW_UI')
|
29 |
+
|
30 |
|
31 |
# ================ LIBRARIES V2 ================
|
32 |
flag_file = f"{root_path}/libraries_installed.txt"
|
|
|
108 |
|
109 |
|
110 |
# ================= MAIN CODE =================
|
111 |
+
# WebUI switch
|
112 |
+
if os.path.exists(webui_path):
|
113 |
+
if UI != OLD_UI:
|
114 |
+
print(f'Switching the WebUI from \033[33m{OLD_UI}\033[0m to \033[33m{UI}\033[0m...', end='')
|
115 |
+
shutil.rmtree(webui_path)
|
116 |
+
# Updating the environment variable after a change
|
117 |
+
os.environ['SDW_OLD_UI'] = UI
|
118 |
+
print('\rDone!')
|
119 |
+
time.sleep(2)
|
120 |
+
clear_output()
|
121 |
+
|
122 |
+
# Unpacking the WebUI
|
123 |
if not os.path.exists(webui_path):
|
124 |
start_install = int(time.time())
|
125 |
print("⌚ Unpacking Stable Diffusion..." if change_webui != 'Forge' else "⌚ Unpacking Stable Diffusion (Forge)...", end='')
|
|
|
226 |
padding = (terminal_width - len(text)) // 2
|
227 |
return f"\033[1m\033[36m{' ' * padding}{text}{' ' * padding}\033[0m\033[32m"
|
228 |
|
229 |
+
def format_output(url, dst_dir, file_name, image_name=None, image_url=None):
|
230 |
info = center_text(f"[{file_name.split('.')[0]}]")
|
231 |
separation_line = '\033[32m' + '---' * 20
|
232 |
|
|
|
235 |
print(f"\033[33mSAVE DIR: \033[34m{dst_dir}")
|
236 |
print(f"\033[33mFILE NAME: \033[34m{file_name}\033[0m")
|
237 |
|
238 |
+
if 'civitai' in url and image_url:
|
239 |
+
print(f"\033[32m[Preview DL]:\033[0m {image_name} - {image_url}\n")
|
240 |
+
|
241 |
''' GET CivitAi API - DATA '''
|
242 |
|
243 |
def CivitAi_API(url, file_name=None):
|
244 |
+
SUPPORT_TYPES = ('Checkpoint', 'TextualInversion', 'LORA')
|
245 |
CIVITAI_TOKEN = "62c0c5956b2f9defbd844d754000180b"
|
246 |
|
247 |
url = url.split('?token=')[0] if '?token=' in url else url
|
248 |
url = url.replace('?type=', f'?token={CIVITAI_TOKEN}&type=') if '?type=' in url else f"{url}?token={CIVITAI_TOKEN}"
|
249 |
|
250 |
def get_model_data(url):
|
251 |
+
base_url = "https://civitai.com/api/v1"
|
252 |
+
try:
|
253 |
+
if "civitai.com/models/" in url:
|
254 |
+
if '?modelVersionId=' in url:
|
255 |
+
version_id = url.split('?modelVersionId=')[1]
|
256 |
+
else:
|
257 |
+
model_id = url.split('/models/')[1].split('/')[0]
|
258 |
+
model_data = requests.get(f"{base_url}/models/{model_id}").json()
|
259 |
+
version_id = model_data['modelVersions'][0].get('id')
|
260 |
else:
|
261 |
+
version_id = url.split('/models/')[1].split('/')[0]
|
262 |
+
|
263 |
+
return requests.get(f"{base_url}/model-versions/{version_id}").json()
|
264 |
+
except (KeyError, IndexError, requests.RequestException) as e:
|
265 |
+
return None
|
266 |
|
267 |
data = get_model_data(url)
|
268 |
|
269 |
if not data:
|
270 |
+
print("\033[31m[Data Info]:\033[0m Failed to retrieve data from the API.\n")
|
271 |
+
return 'None', None, None, None, None, None, None
|
272 |
|
273 |
def extract_model_info(url, data):
|
274 |
+
model_type = data['model']['type']
|
275 |
+
model_name = data['files'][0]['name']
|
276 |
+
|
277 |
+
if 'type=' in url:
|
278 |
+
url_model_type = parse_qs(urlparse(url).query).get('type', [''])[0].lower()
|
279 |
+
if 'vae' in url_model_type:
|
280 |
+
model_type = data['files'][1]['type']
|
|
|
|
|
|
|
|
|
|
|
281 |
model_name = data['files'][1]['name']
|
282 |
+
|
|
|
|
|
283 |
return model_type, model_name
|
284 |
|
285 |
model_type, model_name = extract_model_info(url, data)
|
286 |
model_name = file_name or model_name
|
287 |
|
288 |
+
def get_download_url(data, model_type):
|
289 |
+
if any(t.lower() in model_type.lower() for t in SUPPORT_TYPES):
|
290 |
+
return data['files'][0]['downloadUrl']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
291 |
else:
|
292 |
+
return data['files'][1]['downloadUrl']
|
293 |
|
294 |
+
download_url = get_download_url(data, model_type)
|
|
|
295 |
|
296 |
def get_image_info(data, model_type, model_name):
|
297 |
+
if not any(t in model_type for t in SUPPORT_TYPES):
|
298 |
+
return None, None
|
299 |
+
|
300 |
+
for image in data.get('images', []):
|
301 |
+
if image['nsfwLevel'] >= 4 and env == 'Kaggle': # Filter NSFW images for Kaggle
|
302 |
+
continue
|
303 |
+
image_url = image['url']
|
304 |
+
image_extension = image_url.split('.')[-1]
|
305 |
+
image_name = f"{model_name.split('.')[0]}.preview.{image_extension}" if image_url else None
|
306 |
+
return image_url, image_name
|
307 |
|
308 |
+
return None, None
|
|
|
309 |
|
310 |
image_url, image_name = get_image_info(data, model_type, model_name)
|
311 |
|
312 |
+
return f"{download_url}{'&' if '?' in download_url else '?'}token={CIVITAI_TOKEN}", download_url, model_type, model_name, image_url, image_name, data
|
313 |
|
314 |
''' Main Download Code '''
|
315 |
|
|
|
379 |
|
380 |
""" Formatted info output """
|
381 |
model_name_or_basename = file_name if file_name else basename
|
382 |
+
try:
|
383 |
+
format_output(clean_url or url, dst_dir, model_name_or_basename, image_url, image_name)
|
384 |
+
except UnboundLocalError:
|
385 |
+
format_output(clean_url or url, dst_dir, model_name_or_basename, None, None)
|
|
|
|
|
|
|
|
|
386 |
|
387 |
# =====================
|
388 |
def run_aria2c(url, dst_dir, file_name=None, args="", header=""):
|
files_cells/python/en/launch_en.py
CHANGED
@@ -5,6 +5,7 @@ import re
|
|
5 |
import time
|
6 |
import json
|
7 |
import requests
|
|
|
8 |
import cloudpickle as pickle
|
9 |
from datetime import timedelta
|
10 |
from IPython.display import clear_output
|
@@ -31,6 +32,17 @@ commandline_arguments = settings.get('commandline_arguments', "")
|
|
31 |
change_webui = settings.get('change_webui', "")
|
32 |
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
# ======================== TUNNEL V2 ========================
|
35 |
print('Please Wait...')
|
36 |
|
@@ -56,7 +68,9 @@ tunnel_class = pickle.load(open(f"{root_path}/new_tunnel", "rb"), encoding="utf-
|
|
56 |
tunnel_port = 1834
|
57 |
tunnel = tunnel_class(tunnel_port)
|
58 |
tunnel.add_tunnel(command="cl tunnel --url localhost:{port}", name="cl", pattern=re.compile(r"[\w-]+\.trycloudflare\.com"))
|
59 |
-
|
|
|
|
|
60 |
|
61 |
if zrok_token:
|
62 |
get_ipython().system('zrok enable {zrok_token} &> /dev/null')
|
@@ -65,7 +79,7 @@ if zrok_token:
|
|
65 |
clear_output()
|
66 |
|
67 |
|
68 |
-
#
|
69 |
paths_to_check = {
|
70 |
"tagger_hf_cache_dir": f"{webui_path}/models/interrogators/",
|
71 |
"additional_networks_extra_lora_path": f"{webui_path}/models/Lora/",
|
@@ -86,8 +100,6 @@ if os.path.exists(config_path):
|
|
86 |
sed_command = f"sed -i 's|\"{key}\": \".*\"|\"{key}\": \"{value}\"|' {config_path}"
|
87 |
os.system(sed_command)
|
88 |
|
89 |
-
if env == 'Kaggle':
|
90 |
-
get_ipython().system('sed -i \'s/"civitai_interface\\/NSFW content\\/visible": true,/"civitai_interface\\/NSFW content\\/visible": false,/\' {webui_path}/ui-config.json')
|
91 |
|
92 |
with tunnel:
|
93 |
get_ipython().run_line_magic('cd', '{webui_path}')
|
|
|
5 |
import time
|
6 |
import json
|
7 |
import requests
|
8 |
+
import subprocess
|
9 |
import cloudpickle as pickle
|
10 |
from datetime import timedelta
|
11 |
from IPython.display import clear_output
|
|
|
32 |
change_webui = settings.get('change_webui', "")
|
33 |
|
34 |
|
35 |
+
# ========================== OTHER ==========================
|
36 |
+
def is_package_installed(package_name):
|
37 |
+
try:
|
38 |
+
subprocess.run(["npm", "ls", "-g", package_name], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
39 |
+
return True
|
40 |
+
except subprocess.CalledProcessError:
|
41 |
+
return False
|
42 |
+
|
43 |
+
lt_tunnel = is_package_installed('localtunnel')
|
44 |
+
|
45 |
+
|
46 |
# ======================== TUNNEL V2 ========================
|
47 |
print('Please Wait...')
|
48 |
|
|
|
68 |
tunnel_port = 1834
|
69 |
tunnel = tunnel_class(tunnel_port)
|
70 |
tunnel.add_tunnel(command="cl tunnel --url localhost:{port}", name="cl", pattern=re.compile(r"[\w-]+\.trycloudflare\.com"))
|
71 |
+
|
72 |
+
if lt_tunnel:
|
73 |
+
tunnel.add_tunnel(command="lt --port {port}", name="lt", pattern=re.compile(r"[\w-]+\.loca\.lt"), note="Password : " + "\033[32m" + public_ipv4 + "\033[0m" + " rerun cell if 404 error.")
|
74 |
|
75 |
if zrok_token:
|
76 |
get_ipython().system('zrok enable {zrok_token} &> /dev/null')
|
|
|
79 |
clear_output()
|
80 |
|
81 |
|
82 |
+
# ================= Automatic Fixing Path V3 ================
|
83 |
paths_to_check = {
|
84 |
"tagger_hf_cache_dir": f"{webui_path}/models/interrogators/",
|
85 |
"additional_networks_extra_lora_path": f"{webui_path}/models/Lora/",
|
|
|
100 |
sed_command = f"sed -i 's|\"{key}\": \".*\"|\"{key}\": \"{value}\"|' {config_path}"
|
101 |
os.system(sed_command)
|
102 |
|
|
|
|
|
103 |
|
104 |
with tunnel:
|
105 |
get_ipython().run_line_magic('cd', '{webui_path}')
|
files_cells/python/en/widgets_en.py
CHANGED
@@ -92,6 +92,7 @@ function toggleContainer() {
|
|
92 |
'''
|
93 |
display(HTML(JS))
|
94 |
|
|
|
95 |
# ==================== WIDGETS V2 ====================
|
96 |
HR = widgets.HTML('<hr>')
|
97 |
|
@@ -221,8 +222,6 @@ additional_widget_list = [additional_header,
|
|
221 |
|
222 |
if free_plan and env == "Google Colab": # remove ngrok from colab
|
223 |
additional_widget_list.remove(ngrok_widget)
|
224 |
-
if os.path.exists(webui_path): # remove selection after selection ;3
|
225 |
-
choose_changes_widget.children = [widget for widget in choose_changes_widget.children if widget != change_webui_widget]
|
226 |
|
227 |
all_additional_box = factory.create_vbox(additional_widget_list, class_names=["container", "image_3"])
|
228 |
factory.display(all_additional_box)
|
@@ -272,6 +271,24 @@ save_button = factory.create_button('Save', class_name="button_save")
|
|
272 |
factory.display(save_button)
|
273 |
|
274 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
275 |
# ============ Load / Save - Settings V2 ============
|
276 |
SETTINGS_FILE = f'{root_path}/settings.json'
|
277 |
|
@@ -305,6 +322,7 @@ def hide_widgets():
|
|
305 |
widgets.Widget.close_all()
|
306 |
|
307 |
def save_data(button):
|
|
|
308 |
save_settings()
|
309 |
hide_widgets()
|
310 |
|
|
|
92 |
'''
|
93 |
display(HTML(JS))
|
94 |
|
95 |
+
|
96 |
# ==================== WIDGETS V2 ====================
|
97 |
HR = widgets.HTML('<hr>')
|
98 |
|
|
|
222 |
|
223 |
if free_plan and env == "Google Colab": # remove ngrok from colab
|
224 |
additional_widget_list.remove(ngrok_widget)
|
|
|
|
|
225 |
|
226 |
all_additional_box = factory.create_vbox(additional_widget_list, class_names=["container", "image_3"])
|
227 |
factory.display(all_additional_box)
|
|
|
271 |
factory.display(save_button)
|
272 |
|
273 |
|
274 |
+
# ==================== OTHER FUNC ====================
|
275 |
+
# Setup UI
|
276 |
+
def setup_webui(change_webui_widget):
|
277 |
+
if 'SDW_UI' in os.environ:
|
278 |
+
UI = os.environ['SDW_UI']
|
279 |
+
else:
|
280 |
+
os.environ['SDW_UI'] = change_webui_widget
|
281 |
+
os.environ['SDW_OLD_UI'] = change_webui_widget
|
282 |
+
|
283 |
+
UI = os.getenv('SDW_UI')
|
284 |
+
OLD_UI = os.getenv('SDW_OLD_UI')
|
285 |
+
|
286 |
+
if UI != change_webui_widget:
|
287 |
+
os.environ['SDW_UI'] = change_webui_widget
|
288 |
+
|
289 |
+
# print(f'Current UI: {os.getenv("SDW_UI")}, Old UI: {os.getenv("SDW_OLD_UI")}')
|
290 |
+
|
291 |
+
|
292 |
# ============ Load / Save - Settings V2 ============
|
293 |
SETTINGS_FILE = f'{root_path}/settings.json'
|
294 |
|
|
|
322 |
widgets.Widget.close_all()
|
323 |
|
324 |
def save_data(button):
|
325 |
+
setup_webui(change_webui_widget.value)
|
326 |
save_settings()
|
327 |
hide_widgets()
|
328 |
|
files_cells/python/ru/downloading_ru.py
CHANGED
@@ -24,6 +24,9 @@ root_path = os.getenv('ROOT_PATH')
|
|
24 |
webui_path = os.getenv('WEBUI_PATH')
|
25 |
free_plan = os.getenv('FREE_PLAN')
|
26 |
|
|
|
|
|
|
|
27 |
|
28 |
# ================ LIBRARIES V2 ================
|
29 |
flag_file = f"{root_path}/libraries_installed.txt"
|
@@ -105,6 +108,18 @@ except:
|
|
105 |
|
106 |
|
107 |
# ================= MAIN CODE =================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
if not os.path.exists(webui_path):
|
109 |
start_install = int(time.time())
|
110 |
print("⌚ Распаковка Stable Diffusion..." if change_webui != 'Forge' else "⌚ Распаковка Stable Diffusion (Forge)...", end='')
|
@@ -211,7 +226,7 @@ def center_text(text, terminal_width=45):
|
|
211 |
padding = (terminal_width - len(text)) // 2
|
212 |
return f"\033[1m\033[36m{' ' * padding}{text}{' ' * padding}\033[0m\033[32m"
|
213 |
|
214 |
-
def format_output(url, dst_dir, file_name):
|
215 |
info = center_text(f"[{file_name.split('.')[0]}]")
|
216 |
separation_line = '\033[32m' + '---' * 20
|
217 |
|
@@ -220,89 +235,81 @@ def format_output(url, dst_dir, file_name):
|
|
220 |
print(f"\033[33mSAVE DIR: \033[34m{dst_dir}")
|
221 |
print(f"\033[33mFILE NAME: \033[34m{file_name}\033[0m")
|
222 |
|
|
|
|
|
|
|
223 |
''' GET CivitAi API - DATA '''
|
224 |
|
225 |
def CivitAi_API(url, file_name=None):
|
226 |
-
SUPPORT_TYPES = ('Checkpoint', '
|
227 |
CIVITAI_TOKEN = "62c0c5956b2f9defbd844d754000180b"
|
228 |
|
229 |
url = url.split('?token=')[0] if '?token=' in url else url
|
230 |
url = url.replace('?type=', f'?token={CIVITAI_TOKEN}&type=') if '?type=' in url else f"{url}?token={CIVITAI_TOKEN}"
|
231 |
|
232 |
def get_model_data(url):
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
|
|
|
|
|
|
|
|
|
|
237 |
else:
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
return
|
243 |
|
244 |
data = get_model_data(url)
|
245 |
|
246 |
if not data:
|
247 |
-
|
|
|
248 |
|
249 |
def extract_model_info(url, data):
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
elif 'type=' in url:
|
258 |
-
model_type = parse_qs(urlparse(url).query).get('type', [''])[0]
|
259 |
-
if 'model' in model_type.lower():
|
260 |
-
model_name = data['files'][0]['name']
|
261 |
-
else:
|
262 |
model_name = data['files'][1]['name']
|
263 |
-
|
264 |
-
model_type = data['model']['type']
|
265 |
-
model_name = data['files'][0]['name']
|
266 |
return model_type, model_name
|
267 |
|
268 |
model_type, model_name = extract_model_info(url, data)
|
269 |
model_name = file_name or model_name
|
270 |
|
271 |
-
def get_download_url(
|
272 |
-
if
|
273 |
-
|
274 |
-
return data.get('downloadUrl')
|
275 |
-
else:
|
276 |
-
return data["modelVersions"][0].get("downloadUrl", "")
|
277 |
-
elif 'type=' in url:
|
278 |
-
if any(t.lower() in model_type.lower() for t in SUPPORT_TYPES):
|
279 |
-
return data['files'][0]['downloadUrl']
|
280 |
-
else:
|
281 |
-
return data['files'][1]['downloadUrl']
|
282 |
else:
|
283 |
-
return data
|
284 |
|
285 |
-
download_url = get_download_url(
|
286 |
-
clean_url = re.sub(r'[?&]token=[^&]*', '', download_url)
|
287 |
|
288 |
def get_image_info(data, model_type, model_name):
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
|
300 |
-
|
301 |
-
return image_url, image_name
|
302 |
|
303 |
image_url, image_name = get_image_info(data, model_type, model_name)
|
304 |
|
305 |
-
return f"{download_url}{'&' if '?' in download_url else '?'}token={CIVITAI_TOKEN}",
|
306 |
|
307 |
''' Main Download Code '''
|
308 |
|
@@ -372,14 +379,10 @@ def manual_download(url, dst_dir, file_name):
|
|
372 |
|
373 |
""" Formatted info output """
|
374 |
model_name_or_basename = file_name if file_name else basename
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
if not data:
|
380 |
-
print("\033[31m[Data Info]:\033[0m Failed to retrieve data from the API.\n")
|
381 |
-
if data and image_name:
|
382 |
-
print(f"\033[32m[Preview DL]:\033[0m {image_name} - {image_url}\n")
|
383 |
|
384 |
# =====================
|
385 |
def run_aria2c(url, dst_dir, file_name=None, args="", header=""):
|
|
|
24 |
webui_path = os.getenv('WEBUI_PATH')
|
25 |
free_plan = os.getenv('FREE_PLAN')
|
26 |
|
27 |
+
OLD_UI = os.getenv('SDW_OLD_UI')
|
28 |
+
UI = os.getenv('SDW_UI')
|
29 |
+
|
30 |
|
31 |
# ================ LIBRARIES V2 ================
|
32 |
flag_file = f"{root_path}/libraries_installed.txt"
|
|
|
108 |
|
109 |
|
110 |
# ================= MAIN CODE =================
|
111 |
+
# WebUI switch
|
112 |
+
if os.path.exists(webui_path):
|
113 |
+
if UI != OLD_UI:
|
114 |
+
print(f'Переключение веб-интерфейса с \033[33m{OLD_UI}\033[0m на \033[33m{UI}\033[0m...', end='')
|
115 |
+
shutil.rmtree(webui_path)
|
116 |
+
# Updating the environment variable after a change
|
117 |
+
os.environ['SDW_OLD_UI'] = UI
|
118 |
+
print('\rГотово!')
|
119 |
+
time.sleep(2)
|
120 |
+
clear_output()
|
121 |
+
|
122 |
+
# Unpacking the WebUI
|
123 |
if not os.path.exists(webui_path):
|
124 |
start_install = int(time.time())
|
125 |
print("⌚ Распаковка Stable Diffusion..." if change_webui != 'Forge' else "⌚ Распаковка Stable Diffusion (Forge)...", end='')
|
|
|
226 |
padding = (terminal_width - len(text)) // 2
|
227 |
return f"\033[1m\033[36m{' ' * padding}{text}{' ' * padding}\033[0m\033[32m"
|
228 |
|
229 |
+
def format_output(url, dst_dir, file_name, image_name=None, image_url=None):
|
230 |
info = center_text(f"[{file_name.split('.')[0]}]")
|
231 |
separation_line = '\033[32m' + '---' * 20
|
232 |
|
|
|
235 |
print(f"\033[33mSAVE DIR: \033[34m{dst_dir}")
|
236 |
print(f"\033[33mFILE NAME: \033[34m{file_name}\033[0m")
|
237 |
|
238 |
+
if 'civitai' in url and image_url:
|
239 |
+
print(f"\033[32m[Preview DL]:\033[0m {image_name} - {image_url}\n")
|
240 |
+
|
241 |
''' GET CivitAi API - DATA '''
|
242 |
|
243 |
def CivitAi_API(url, file_name=None):
|
244 |
+
SUPPORT_TYPES = ('Checkpoint', 'TextualInversion', 'LORA')
|
245 |
CIVITAI_TOKEN = "62c0c5956b2f9defbd844d754000180b"
|
246 |
|
247 |
url = url.split('?token=')[0] if '?token=' in url else url
|
248 |
url = url.replace('?type=', f'?token={CIVITAI_TOKEN}&type=') if '?type=' in url else f"{url}?token={CIVITAI_TOKEN}"
|
249 |
|
250 |
def get_model_data(url):
|
251 |
+
base_url = "https://civitai.com/api/v1"
|
252 |
+
try:
|
253 |
+
if "civitai.com/models/" in url:
|
254 |
+
if '?modelVersionId=' in url:
|
255 |
+
version_id = url.split('?modelVersionId=')[1]
|
256 |
+
else:
|
257 |
+
model_id = url.split('/models/')[1].split('/')[0]
|
258 |
+
model_data = requests.get(f"{base_url}/models/{model_id}").json()
|
259 |
+
version_id = model_data['modelVersions'][0].get('id')
|
260 |
else:
|
261 |
+
version_id = url.split('/models/')[1].split('/')[0]
|
262 |
+
|
263 |
+
return requests.get(f"{base_url}/model-versions/{version_id}").json()
|
264 |
+
except (KeyError, IndexError, requests.RequestException) as e:
|
265 |
+
return None
|
266 |
|
267 |
data = get_model_data(url)
|
268 |
|
269 |
if not data:
|
270 |
+
print("\033[31m[Data Info]:\033[0m Failed to retrieve data from the API.\n")
|
271 |
+
return 'None', None, None, None, None, None, None
|
272 |
|
273 |
def extract_model_info(url, data):
|
274 |
+
model_type = data['model']['type']
|
275 |
+
model_name = data['files'][0]['name']
|
276 |
+
|
277 |
+
if 'type=' in url:
|
278 |
+
url_model_type = parse_qs(urlparse(url).query).get('type', [''])[0].lower()
|
279 |
+
if 'vae' in url_model_type:
|
280 |
+
model_type = data['files'][1]['type']
|
|
|
|
|
|
|
|
|
|
|
281 |
model_name = data['files'][1]['name']
|
282 |
+
|
|
|
|
|
283 |
return model_type, model_name
|
284 |
|
285 |
model_type, model_name = extract_model_info(url, data)
|
286 |
model_name = file_name or model_name
|
287 |
|
288 |
+
def get_download_url(data, model_type):
|
289 |
+
if any(t.lower() in model_type.lower() for t in SUPPORT_TYPES):
|
290 |
+
return data['files'][0]['downloadUrl']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
291 |
else:
|
292 |
+
return data['files'][1]['downloadUrl']
|
293 |
|
294 |
+
download_url = get_download_url(data, model_type)
|
|
|
295 |
|
296 |
def get_image_info(data, model_type, model_name):
|
297 |
+
if not any(t in model_type for t in SUPPORT_TYPES):
|
298 |
+
return None, None
|
299 |
+
|
300 |
+
for image in data.get('images', []):
|
301 |
+
if image['nsfwLevel'] >= 4 and env == 'Kaggle': # Filter NSFW images for Kaggle
|
302 |
+
continue
|
303 |
+
image_url = image['url']
|
304 |
+
image_extension = image_url.split('.')[-1]
|
305 |
+
image_name = f"{model_name.split('.')[0]}.preview.{image_extension}" if image_url else None
|
306 |
+
return image_url, image_name
|
307 |
|
308 |
+
return None, None
|
|
|
309 |
|
310 |
image_url, image_name = get_image_info(data, model_type, model_name)
|
311 |
|
312 |
+
return f"{download_url}{'&' if '?' in download_url else '?'}token={CIVITAI_TOKEN}", download_url, model_type, model_name, image_url, image_name, data
|
313 |
|
314 |
''' Main Download Code '''
|
315 |
|
|
|
379 |
|
380 |
""" Formatted info output """
|
381 |
model_name_or_basename = file_name if file_name else basename
|
382 |
+
try:
|
383 |
+
format_output(clean_url or url, dst_dir, model_name_or_basename, image_url, image_name)
|
384 |
+
except UnboundLocalError:
|
385 |
+
format_output(clean_url or url, dst_dir, model_name_or_basename, None, None)
|
|
|
|
|
|
|
|
|
386 |
|
387 |
# =====================
|
388 |
def run_aria2c(url, dst_dir, file_name=None, args="", header=""):
|
files_cells/python/ru/launch_ru.py
CHANGED
@@ -5,6 +5,7 @@ import re
|
|
5 |
import time
|
6 |
import json
|
7 |
import requests
|
|
|
8 |
import cloudpickle as pickle
|
9 |
from datetime import timedelta
|
10 |
from IPython.display import clear_output
|
@@ -31,6 +32,17 @@ commandline_arguments = settings.get('commandline_arguments', "")
|
|
31 |
change_webui = settings.get('change_webui', "")
|
32 |
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
# ======================== TUNNEL V2 ========================
|
35 |
print('Please Wait...')
|
36 |
|
@@ -56,7 +68,9 @@ tunnel_class = pickle.load(open(f"{root_path}/new_tunnel", "rb"), encoding="utf-
|
|
56 |
tunnel_port = 1834
|
57 |
tunnel = tunnel_class(tunnel_port)
|
58 |
tunnel.add_tunnel(command="cl tunnel --url localhost:{port}", name="cl", pattern=re.compile(r"[\w-]+\.trycloudflare\.com"))
|
59 |
-
|
|
|
|
|
60 |
|
61 |
if zrok_token:
|
62 |
get_ipython().system('zrok enable {zrok_token} &> /dev/null')
|
@@ -65,7 +79,7 @@ if zrok_token:
|
|
65 |
clear_output()
|
66 |
|
67 |
|
68 |
-
#
|
69 |
paths_to_check = {
|
70 |
"tagger_hf_cache_dir": f"{webui_path}/models/interrogators/",
|
71 |
"additional_networks_extra_lora_path": f"{webui_path}/models/Lora/",
|
@@ -86,8 +100,6 @@ if os.path.exists(config_path):
|
|
86 |
sed_command = f"sed -i 's|\"{key}\": \".*\"|\"{key}\": \"{value}\"|' {config_path}"
|
87 |
os.system(sed_command)
|
88 |
|
89 |
-
if env == 'Kaggle':
|
90 |
-
get_ipython().system('sed -i \'s/"civitai_interface\\/NSFW content\\/visible": true,/"civitai_interface\\/NSFW content\\/visible": false,/\' {webui_path}/ui-config.json')
|
91 |
|
92 |
with tunnel:
|
93 |
get_ipython().run_line_magic('cd', '{webui_path}')
|
|
|
5 |
import time
|
6 |
import json
|
7 |
import requests
|
8 |
+
import subprocess
|
9 |
import cloudpickle as pickle
|
10 |
from datetime import timedelta
|
11 |
from IPython.display import clear_output
|
|
|
32 |
change_webui = settings.get('change_webui', "")
|
33 |
|
34 |
|
35 |
+
# ========================== OTHER ==========================
|
36 |
+
def is_package_installed(package_name):
|
37 |
+
try:
|
38 |
+
subprocess.run(["npm", "ls", "-g", package_name], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
39 |
+
return True
|
40 |
+
except subprocess.CalledProcessError:
|
41 |
+
return False
|
42 |
+
|
43 |
+
lt_tunnel = is_package_installed('localtunnel')
|
44 |
+
|
45 |
+
|
46 |
# ======================== TUNNEL V2 ========================
|
47 |
print('Please Wait...')
|
48 |
|
|
|
68 |
tunnel_port = 1834
|
69 |
tunnel = tunnel_class(tunnel_port)
|
70 |
tunnel.add_tunnel(command="cl tunnel --url localhost:{port}", name="cl", pattern=re.compile(r"[\w-]+\.trycloudflare\.com"))
|
71 |
+
|
72 |
+
if lt_tunnel:
|
73 |
+
tunnel.add_tunnel(command="lt --port {port}", name="lt", pattern=re.compile(r"[\w-]+\.loca\.lt"), note="Password : " + "\033[32m" + public_ipv4 + "\033[0m" + " rerun cell if 404 error.")
|
74 |
|
75 |
if zrok_token:
|
76 |
get_ipython().system('zrok enable {zrok_token} &> /dev/null')
|
|
|
79 |
clear_output()
|
80 |
|
81 |
|
82 |
+
# ================= Automatic Fixing Path V3 ================
|
83 |
paths_to_check = {
|
84 |
"tagger_hf_cache_dir": f"{webui_path}/models/interrogators/",
|
85 |
"additional_networks_extra_lora_path": f"{webui_path}/models/Lora/",
|
|
|
100 |
sed_command = f"sed -i 's|\"{key}\": \".*\"|\"{key}\": \"{value}\"|' {config_path}"
|
101 |
os.system(sed_command)
|
102 |
|
|
|
|
|
103 |
|
104 |
with tunnel:
|
105 |
get_ipython().run_line_magic('cd', '{webui_path}')
|
files_cells/python/ru/widgets_ru.py
CHANGED
@@ -92,6 +92,7 @@ function toggleContainer() {
|
|
92 |
'''
|
93 |
display(HTML(JS))
|
94 |
|
|
|
95 |
# ==================== WIDGETS V2 ====================
|
96 |
HR = widgets.HTML('<hr>')
|
97 |
|
@@ -221,8 +222,6 @@ additional_widget_list = [additional_header,
|
|
221 |
|
222 |
if free_plan and env == "Google Colab": # remove ngrok from colab
|
223 |
additional_widget_list.remove(ngrok_widget)
|
224 |
-
if os.path.exists(webui_path): # remove selection after selection ;3
|
225 |
-
choose_changes_widget.children = [widget for widget in choose_changes_widget.children if widget != change_webui_widget]
|
226 |
|
227 |
all_additional_box = factory.create_vbox(additional_widget_list, class_names=["container", "image_3"])
|
228 |
factory.display(all_additional_box)
|
@@ -272,6 +271,24 @@ save_button = factory.create_button('Сохранить', class_name="button_sav
|
|
272 |
factory.display(save_button)
|
273 |
|
274 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
275 |
# ============ Load / Save - Settings V2 ============
|
276 |
SETTINGS_FILE = f'{root_path}/settings.json'
|
277 |
|
@@ -305,6 +322,7 @@ def hide_widgets():
|
|
305 |
widgets.Widget.close_all()
|
306 |
|
307 |
def save_data(button):
|
|
|
308 |
save_settings()
|
309 |
hide_widgets()
|
310 |
|
|
|
92 |
'''
|
93 |
display(HTML(JS))
|
94 |
|
95 |
+
|
96 |
# ==================== WIDGETS V2 ====================
|
97 |
HR = widgets.HTML('<hr>')
|
98 |
|
|
|
222 |
|
223 |
if free_plan and env == "Google Colab": # remove ngrok from colab
|
224 |
additional_widget_list.remove(ngrok_widget)
|
|
|
|
|
225 |
|
226 |
all_additional_box = factory.create_vbox(additional_widget_list, class_names=["container", "image_3"])
|
227 |
factory.display(all_additional_box)
|
|
|
271 |
factory.display(save_button)
|
272 |
|
273 |
|
274 |
+
# ==================== OTHER FUNC ====================
|
275 |
+
# Setup UI
|
276 |
+
def setup_webui(change_webui_widget):
|
277 |
+
if 'SDW_UI' in os.environ:
|
278 |
+
UI = os.environ['SDW_UI']
|
279 |
+
else:
|
280 |
+
os.environ['SDW_UI'] = change_webui_widget
|
281 |
+
os.environ['SDW_OLD_UI'] = change_webui_widget
|
282 |
+
|
283 |
+
UI = os.getenv('SDW_UI')
|
284 |
+
OLD_UI = os.getenv('SDW_OLD_UI')
|
285 |
+
|
286 |
+
if UI != change_webui_widget:
|
287 |
+
os.environ['SDW_UI'] = change_webui_widget
|
288 |
+
|
289 |
+
# print(f'Current UI: {os.getenv("SDW_UI")}, Old UI: {os.getenv("SDW_OLD_UI")}')
|
290 |
+
|
291 |
+
|
292 |
# ============ Load / Save - Settings V2 ============
|
293 |
SETTINGS_FILE = f'{root_path}/settings.json'
|
294 |
|
|
|
322 |
widgets.Widget.close_all()
|
323 |
|
324 |
def save_data(button):
|
325 |
+
setup_webui(change_webui_widget.value)
|
326 |
save_settings()
|
327 |
hide_widgets()
|
328 |
|