- files_cells/notebooks/en/auto_cleaner_en.ipynb +1 -2
- files_cells/notebooks/en/downloading_en.ipynb +19 -34
- files_cells/notebooks/ru/auto_cleaner_ru.ipynb +1 -2
- files_cells/notebooks/ru/downloading_ru.ipynb +42 -52
- files_cells/python/en/auto_cleaner_en.py +1 -2
- files_cells/python/en/downloading_en.py +19 -34
- files_cells/python/ru/auto_cleaner_ru.py +1 -2
- files_cells/python/ru/downloading_ru.py +42 -52
files_cells/notebooks/en/auto_cleaner_en.ipynb
CHANGED
@@ -55,7 +55,6 @@
|
|
55 |
"\"\"\" functions \"\"\"\n",
|
56 |
"def clean_directory(directory):\n",
|
57 |
" deleted_files = 0\n",
|
58 |
-
" image_dir = directories['Images']\n",
|
59 |
"\n",
|
60 |
" for root, dirs, files in os.walk(directory):\n",
|
61 |
" for file in files:\n",
|
@@ -63,7 +62,7 @@
|
|
63 |
"\n",
|
64 |
" if file.endswith(\".txt\"):\n",
|
65 |
" continue\n",
|
66 |
-
" if file.endswith((\".safetensors\", \".pt\"
|
67 |
" deleted_files += 1\n",
|
68 |
"\n",
|
69 |
" os.remove(file_path)\n",
|
|
|
55 |
"\"\"\" functions \"\"\"\n",
|
56 |
"def clean_directory(directory):\n",
|
57 |
" deleted_files = 0\n",
|
|
|
58 |
"\n",
|
59 |
" for root, dirs, files in os.walk(directory):\n",
|
60 |
" for file in files:\n",
|
|
|
62 |
"\n",
|
63 |
" if file.endswith(\".txt\"):\n",
|
64 |
" continue\n",
|
65 |
+
" if file.endswith((\".safetensors\", \".pt\", \".png\", \".jpg\", \".jpeg\")):\n",
|
66 |
" deleted_files += 1\n",
|
67 |
"\n",
|
68 |
" os.remove(file_path)\n",
|
files_cells/notebooks/en/downloading_en.ipynb
CHANGED
@@ -254,7 +254,7 @@
|
|
254 |
"## Downloading model and stuff | oh~ Hey! If you're freaked out by that code too, don't worry, me too!\n",
|
255 |
"print(\"📦 Downloading models and stuff...\", end='')\n",
|
256 |
"\n",
|
257 |
-
"
|
258 |
"PREFIXES = {\n",
|
259 |
" \"model\": models_dir,\n",
|
260 |
" \"vae\": vaes_dir,\n",
|
@@ -265,33 +265,24 @@
|
|
265 |
" \"adetailer\": adetailer_dir,\n",
|
266 |
" \"config\": webui_path\n",
|
267 |
"}\n",
|
268 |
-
"\n",
|
269 |
-
"extension_repo = []\n",
|
270 |
-
"directories = [value for key, value in PREFIXES.items()] # for unpucking zip files\n",
|
271 |
-
"!mkdir -p {\" \".join(directories)}\n",
|
272 |
-
"\n",
|
273 |
-
"hf_token = huggingface_token if huggingface_token else \"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\"\n",
|
274 |
-
"user_header = f\"\\\"Authorization: Bearer {hf_token}\\\"\"\n",
|
275 |
"\n",
|
276 |
"''' Formatted Info Output '''\n",
|
277 |
"\n",
|
278 |
-
"from math import floor\n",
|
279 |
-
"\n",
|
280 |
"def center_text(text, terminal_width=45):\n",
|
281 |
" padding = (terminal_width - len(text)) // 2\n",
|
282 |
-
" return f\"
|
283 |
"\n",
|
284 |
"def format_output(url, dst_dir, file_name, image_name=None, image_url=None):\n",
|
285 |
" info = center_text(f\"[{file_name.split('.')[0]}]\")\n",
|
286 |
-
"
|
287 |
"\n",
|
288 |
-
" print(f\"\\n{
|
289 |
-
" print(f\"\\033[33mURL:
|
290 |
" print(f\"\\033[33mSAVE DIR: \\033[34m{dst_dir}\")\n",
|
291 |
" print(f\"\\033[33mFILE NAME: \\033[34m{file_name}\\033[0m\")\n",
|
292 |
-
"\n",
|
293 |
" if 'civitai' in url and image_url:\n",
|
294 |
-
" print(f\"\\033[32m[Preview
|
295 |
"\n",
|
296 |
"''' GET CivitAi API - DATA '''\n",
|
297 |
"\n",
|
@@ -325,7 +316,7 @@
|
|
325 |
" print(\"\\033[31m[Data Info]:\\033[0m Failed to retrieve data from the API.\\n\")\n",
|
326 |
" return 'None', None, None, None, None, None, None\n",
|
327 |
"\n",
|
328 |
-
" def
|
329 |
" model_type = data['model']['type']\n",
|
330 |
" model_name = data['files'][0]['name']\n",
|
331 |
"\n",
|
@@ -337,17 +328,12 @@
|
|
337 |
"\n",
|
338 |
" return model_type, model_name\n",
|
339 |
"\n",
|
340 |
-
" model_type, model_name = extract_model_info(url, data)\n",
|
341 |
-
" model_name = file_name or model_name\n",
|
342 |
-
"\n",
|
343 |
" def get_download_url(data, model_type):\n",
|
344 |
" if any(t.lower() in model_type.lower() for t in SUPPORT_TYPES):\n",
|
345 |
" return data['files'][0]['downloadUrl']\n",
|
346 |
"\n",
|
347 |
" return data['files'][1]['downloadUrl'] if 'type' in url else data['files'][0]['downloadUrl']\n",
|
348 |
"\n",
|
349 |
-
" download_url = get_download_url(data, model_type)\n",
|
350 |
-
"\n",
|
351 |
" def get_image_info(data, model_type, model_name):\n",
|
352 |
" if not any(t in model_type for t in SUPPORT_TYPES):\n",
|
353 |
" return None, None\n",
|
@@ -359,9 +345,11 @@
|
|
359 |
" image_extension = image_url.split('.')[-1]\n",
|
360 |
" image_name = f\"{model_name.split('.')[0]}.preview.{image_extension}\" if image_url else None\n",
|
361 |
" return image_url, image_name\n",
|
362 |
-
"\n",
|
363 |
" return None, None\n",
|
364 |
"\n",
|
|
|
|
|
|
|
365 |
" image_url, image_name = get_image_info(data, model_type, model_name)\n",
|
366 |
"\n",
|
367 |
" return f\"{download_url}{'&' if '?' in download_url else '?'}token={CIVITAI_TOKEN}\", download_url, model_type, model_name, image_url, image_name, data\n",
|
@@ -387,7 +375,7 @@
|
|
387 |
" manual_download(url, dst_dir, file_name)\n",
|
388 |
"\n",
|
389 |
" # Unpuck ZIPs Files\n",
|
390 |
-
" for directory in
|
391 |
" for root, _, files in os.walk(directory):\n",
|
392 |
" for file in files:\n",
|
393 |
" if file.endswith(\".zip\"):\n",
|
@@ -417,7 +405,7 @@
|
|
417 |
" extension_repo.append((path, file_name))\n",
|
418 |
"\n",
|
419 |
"def manual_download(url, dst_dir, file_name, prefix=None):\n",
|
420 |
-
"
|
421 |
" aria2c_header = \"--header='User-Agent: Mozilla/5.0' --allow-overwrite=true\"\n",
|
422 |
" aria2_args = \"--optimize-concurrent-downloads --console-log-level=error --summary-interval=10 --stderr=true -c -x16 -s16 -k1M -j5\"\n",
|
423 |
"\n",
|
@@ -430,14 +418,13 @@
|
|
430 |
" subprocess.run(command, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)\n",
|
431 |
"\n",
|
432 |
" elif 'github' in url or \"huggingface.co\" in url:\n",
|
433 |
-
"
|
434 |
"\n",
|
435 |
" \"\"\" Formatted info output \"\"\"\n",
|
436 |
-
" model_name_or_basename = file_name if file_name else basename\n",
|
437 |
" try:\n",
|
438 |
-
" format_output(clean_url, dst_dir,
|
439 |
" except UnboundLocalError:\n",
|
440 |
-
" format_output(clean_url, dst_dir,
|
441 |
"\n",
|
442 |
" # =====================\n",
|
443 |
" def run_aria2c(url, dst_dir, file_name=None, args=\"\", header=\"\"):\n",
|
@@ -462,7 +449,7 @@
|
|
462 |
"\n",
|
463 |
" # -- GitHub or Hugging Face --\n",
|
464 |
" elif 'github' in url or 'huggingface' in url:\n",
|
465 |
-
" run_aria2c(clean_url, dst_dir,
|
466 |
"\n",
|
467 |
" # -- Other HTTP/Sources --\n",
|
468 |
" elif 'http' in url:\n",
|
@@ -521,15 +508,13 @@
|
|
521 |
"\n",
|
522 |
"def handle_submodels(selection, num_selection, model_dict, dst_dir, url):\n",
|
523 |
" submodels = add_submodels(selection, num_selection, model_dict, dst_dir)\n",
|
524 |
-
" urls = []\n",
|
525 |
" for submodel in submodels:\n",
|
526 |
" if not inpainting_model and \"inpainting\" in submodel['name']:\n",
|
527 |
" continue\n",
|
528 |
-
"
|
529 |
-
"\n",
|
530 |
-
" url += \", \".join(urls) + ', '\n",
|
531 |
" return url\n",
|
532 |
"\n",
|
|
|
533 |
"url = handle_submodels(model, model_num, model_list, models_dir, url)\n",
|
534 |
"url = handle_submodels(vae, vae_num, vae_list, vaes_dir, url)\n",
|
535 |
"url = handle_submodels(controlnet, controlnet_num, controlnet_list, control_dir, url)\n",
|
|
|
254 |
"## Downloading model and stuff | oh~ Hey! If you're freaked out by that code too, don't worry, me too!\n",
|
255 |
"print(\"📦 Downloading models and stuff...\", end='')\n",
|
256 |
"\n",
|
257 |
+
"extension_repo = []\n",
|
258 |
"PREFIXES = {\n",
|
259 |
" \"model\": models_dir,\n",
|
260 |
" \"vae\": vaes_dir,\n",
|
|
|
265 |
" \"adetailer\": adetailer_dir,\n",
|
266 |
" \"config\": webui_path\n",
|
267 |
"}\n",
|
268 |
+
"!mkdir -p {\" \".join(PREFIXES.values())}\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
269 |
"\n",
|
270 |
"''' Formatted Info Output '''\n",
|
271 |
"\n",
|
|
|
|
|
272 |
"def center_text(text, terminal_width=45):\n",
|
273 |
" padding = (terminal_width - len(text)) // 2\n",
|
274 |
+
" return f\"{' ' * padding}{text}{' ' * padding}\"\n",
|
275 |
"\n",
|
276 |
"def format_output(url, dst_dir, file_name, image_name=None, image_url=None):\n",
|
277 |
" info = center_text(f\"[{file_name.split('.')[0]}]\")\n",
|
278 |
+
" sep_line = '---' * 20\n",
|
279 |
"\n",
|
280 |
+
" print(f\"\\n\\033[32m{sep_line}\\033[36;1m{info}\\033[32m{sep_line}\\033[0m\")\n",
|
281 |
+
" print(f\"\\033[33mURL: {url}\")\n",
|
282 |
" print(f\"\\033[33mSAVE DIR: \\033[34m{dst_dir}\")\n",
|
283 |
" print(f\"\\033[33mFILE NAME: \\033[34m{file_name}\\033[0m\")\n",
|
|
|
284 |
" if 'civitai' in url and image_url:\n",
|
285 |
+
" print(f\"\\033[32m[Preview DL]:\\033[0m {image_name} - {image_url}\\n\")\n",
|
286 |
"\n",
|
287 |
"''' GET CivitAi API - DATA '''\n",
|
288 |
"\n",
|
|
|
316 |
" print(\"\\033[31m[Data Info]:\\033[0m Failed to retrieve data from the API.\\n\")\n",
|
317 |
" return 'None', None, None, None, None, None, None\n",
|
318 |
"\n",
|
319 |
+
" def get_model_info(url, data):\n",
|
320 |
" model_type = data['model']['type']\n",
|
321 |
" model_name = data['files'][0]['name']\n",
|
322 |
"\n",
|
|
|
328 |
"\n",
|
329 |
" return model_type, model_name\n",
|
330 |
"\n",
|
|
|
|
|
|
|
331 |
" def get_download_url(data, model_type):\n",
|
332 |
" if any(t.lower() in model_type.lower() for t in SUPPORT_TYPES):\n",
|
333 |
" return data['files'][0]['downloadUrl']\n",
|
334 |
"\n",
|
335 |
" return data['files'][1]['downloadUrl'] if 'type' in url else data['files'][0]['downloadUrl']\n",
|
336 |
"\n",
|
|
|
|
|
337 |
" def get_image_info(data, model_type, model_name):\n",
|
338 |
" if not any(t in model_type for t in SUPPORT_TYPES):\n",
|
339 |
" return None, None\n",
|
|
|
345 |
" image_extension = image_url.split('.')[-1]\n",
|
346 |
" image_name = f\"{model_name.split('.')[0]}.preview.{image_extension}\" if image_url else None\n",
|
347 |
" return image_url, image_name\n",
|
|
|
348 |
" return None, None\n",
|
349 |
"\n",
|
350 |
+
" model_type, model_name = get_model_info(url, data)\n",
|
351 |
+
" model_name = file_name or model_name\n",
|
352 |
+
" download_url = get_download_url(data, model_type)\n",
|
353 |
" image_url, image_name = get_image_info(data, model_type, model_name)\n",
|
354 |
"\n",
|
355 |
" return f\"{download_url}{'&' if '?' in download_url else '?'}token={CIVITAI_TOKEN}\", download_url, model_type, model_name, image_url, image_name, data\n",
|
|
|
375 |
" manual_download(url, dst_dir, file_name)\n",
|
376 |
"\n",
|
377 |
" # Unpuck ZIPs Files\n",
|
378 |
+
" for directory in PREFIXES.values():\n",
|
379 |
" for root, _, files in os.walk(directory):\n",
|
380 |
" for file in files:\n",
|
381 |
" if file.endswith(\".zip\"):\n",
|
|
|
405 |
" extension_repo.append((path, file_name))\n",
|
406 |
"\n",
|
407 |
"def manual_download(url, dst_dir, file_name, prefix=None):\n",
|
408 |
+
" hf_header = f\"--header='Authorization: Bearer {huggingface_token}'\" if huggingface_token else \"\"\n",
|
409 |
" aria2c_header = \"--header='User-Agent: Mozilla/5.0' --allow-overwrite=true\"\n",
|
410 |
" aria2_args = \"--optimize-concurrent-downloads --console-log-level=error --summary-interval=10 --stderr=true -c -x16 -s16 -k1M -j5\"\n",
|
411 |
"\n",
|
|
|
418 |
" subprocess.run(command, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)\n",
|
419 |
"\n",
|
420 |
" elif 'github' in url or \"huggingface.co\" in url:\n",
|
421 |
+
" file_name = clean_url.split(\"/\")[-1] if file_name is None else file_name\n",
|
422 |
"\n",
|
423 |
" \"\"\" Formatted info output \"\"\"\n",
|
|
|
424 |
" try:\n",
|
425 |
+
" format_output(clean_url, dst_dir, file_name, image_name, image_url)\n",
|
426 |
" except UnboundLocalError:\n",
|
427 |
+
" format_output(clean_url, dst_dir, file_name, None, None)\n",
|
428 |
"\n",
|
429 |
" # =====================\n",
|
430 |
" def run_aria2c(url, dst_dir, file_name=None, args=\"\", header=\"\"):\n",
|
|
|
449 |
"\n",
|
450 |
" # -- GitHub or Hugging Face --\n",
|
451 |
" elif 'github' in url or 'huggingface' in url:\n",
|
452 |
+
" run_aria2c(clean_url, dst_dir, file_name, aria2_args, hf_header if 'huggingface' in url else '')\n",
|
453 |
"\n",
|
454 |
" # -- Other HTTP/Sources --\n",
|
455 |
" elif 'http' in url:\n",
|
|
|
508 |
"\n",
|
509 |
"def handle_submodels(selection, num_selection, model_dict, dst_dir, url):\n",
|
510 |
" submodels = add_submodels(selection, num_selection, model_dict, dst_dir)\n",
|
|
|
511 |
" for submodel in submodels:\n",
|
512 |
" if not inpainting_model and \"inpainting\" in submodel['name']:\n",
|
513 |
" continue\n",
|
514 |
+
" url += f\"{submodel['url']} {submodel['dst_dir']} {submodel['name']}, \"\n",
|
|
|
|
|
515 |
" return url\n",
|
516 |
"\n",
|
517 |
+
"url = \"\"\n",
|
518 |
"url = handle_submodels(model, model_num, model_list, models_dir, url)\n",
|
519 |
"url = handle_submodels(vae, vae_num, vae_list, vaes_dir, url)\n",
|
520 |
"url = handle_submodels(controlnet, controlnet_num, controlnet_list, control_dir, url)\n",
|
files_cells/notebooks/ru/auto_cleaner_ru.ipynb
CHANGED
@@ -60,7 +60,6 @@
|
|
60 |
"\"\"\" functions \"\"\"\n",
|
61 |
"def clean_directory(directory):\n",
|
62 |
" deleted_files = 0\n",
|
63 |
-
" image_dir = directories['Изображения']\n",
|
64 |
"\n",
|
65 |
" for root, dirs, files in os.walk(directory):\n",
|
66 |
" for file in files:\n",
|
@@ -68,7 +67,7 @@
|
|
68 |
"\n",
|
69 |
" if file.endswith(\".txt\"):\n",
|
70 |
" continue\n",
|
71 |
-
" if file.endswith((\".safetensors\", \".pt\"
|
72 |
" deleted_files += 1\n",
|
73 |
"\n",
|
74 |
" os.remove(file_path)\n",
|
|
|
60 |
"\"\"\" functions \"\"\"\n",
|
61 |
"def clean_directory(directory):\n",
|
62 |
" deleted_files = 0\n",
|
|
|
63 |
"\n",
|
64 |
" for root, dirs, files in os.walk(directory):\n",
|
65 |
" for file in files:\n",
|
|
|
67 |
"\n",
|
68 |
" if file.endswith(\".txt\"):\n",
|
69 |
" continue\n",
|
70 |
+
" if file.endswith((\".safetensors\", \".pt\", \".png\", \".jpg\", \".jpeg\")):\n",
|
71 |
" deleted_files += 1\n",
|
72 |
"\n",
|
73 |
" os.remove(file_path)\n",
|
files_cells/notebooks/ru/downloading_ru.ipynb
CHANGED
@@ -254,7 +254,7 @@
|
|
254 |
"## Downloading model and stuff | oh~ Hey! If you're freaked out by that code too, don't worry, me too!\n",
|
255 |
"print(\"📦 Скачивание моделей и прочего...\", end='')\n",
|
256 |
"\n",
|
257 |
-
"
|
258 |
"PREFIXES = {\n",
|
259 |
" \"model\": models_dir,\n",
|
260 |
" \"vae\": vaes_dir,\n",
|
@@ -265,33 +265,24 @@
|
|
265 |
" \"adetailer\": adetailer_dir,\n",
|
266 |
" \"config\": webui_path\n",
|
267 |
"}\n",
|
268 |
-
"\n",
|
269 |
-
"extension_repo = []\n",
|
270 |
-
"directories = [value for key, value in PREFIXES.items()] # for unpucking zip files\n",
|
271 |
-
"!mkdir -p {\" \".join(directories)}\n",
|
272 |
-
"\n",
|
273 |
-
"hf_token = huggingface_token if huggingface_token else \"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\"\n",
|
274 |
-
"user_header = f\"\\\"Authorization: Bearer {hf_token}\\\"\"\n",
|
275 |
"\n",
|
276 |
"''' Formatted Info Output '''\n",
|
277 |
"\n",
|
278 |
-
"from math import floor\n",
|
279 |
-
"\n",
|
280 |
"def center_text(text, terminal_width=45):\n",
|
281 |
" padding = (terminal_width - len(text)) // 2\n",
|
282 |
-
" return f\"
|
283 |
"\n",
|
284 |
"def format_output(url, dst_dir, file_name, image_name=None, image_url=None):\n",
|
285 |
" info = center_text(f\"[{file_name.split('.')[0]}]\")\n",
|
286 |
-
"
|
287 |
"\n",
|
288 |
-
" print(f\"\\n{
|
289 |
-
" print(f\"\\033[33mURL:
|
290 |
" print(f\"\\033[33mSAVE DIR: \\033[34m{dst_dir}\")\n",
|
291 |
" print(f\"\\033[33mFILE NAME: \\033[34m{file_name}\\033[0m\")\n",
|
292 |
-
"\n",
|
293 |
" if 'civitai' in url and image_url:\n",
|
294 |
-
" print(f\"\\033[32m[Preview
|
295 |
"\n",
|
296 |
"''' GET CivitAi API - DATA '''\n",
|
297 |
"\n",
|
@@ -325,7 +316,7 @@
|
|
325 |
" print(\"\\033[31m[Data Info]:\\033[0m Failed to retrieve data from the API.\\n\")\n",
|
326 |
" return 'None', None, None, None, None, None, None\n",
|
327 |
"\n",
|
328 |
-
" def
|
329 |
" model_type = data['model']['type']\n",
|
330 |
" model_name = data['files'][0]['name']\n",
|
331 |
"\n",
|
@@ -337,17 +328,12 @@
|
|
337 |
"\n",
|
338 |
" return model_type, model_name\n",
|
339 |
"\n",
|
340 |
-
" model_type, model_name = extract_model_info(url, data)\n",
|
341 |
-
" model_name = file_name or model_name\n",
|
342 |
-
"\n",
|
343 |
" def get_download_url(data, model_type):\n",
|
344 |
" if any(t.lower() in model_type.lower() for t in SUPPORT_TYPES):\n",
|
345 |
" return data['files'][0]['downloadUrl']\n",
|
346 |
"\n",
|
347 |
" return data['files'][1]['downloadUrl'] if 'type' in url else data['files'][0]['downloadUrl']\n",
|
348 |
"\n",
|
349 |
-
" download_url = get_download_url(data, model_type)\n",
|
350 |
-
"\n",
|
351 |
" def get_image_info(data, model_type, model_name):\n",
|
352 |
" if not any(t in model_type for t in SUPPORT_TYPES):\n",
|
353 |
" return None, None\n",
|
@@ -359,9 +345,11 @@
|
|
359 |
" image_extension = image_url.split('.')[-1]\n",
|
360 |
" image_name = f\"{model_name.split('.')[0]}.preview.{image_extension}\" if image_url else None\n",
|
361 |
" return image_url, image_name\n",
|
362 |
-
"\n",
|
363 |
" return None, None\n",
|
364 |
"\n",
|
|
|
|
|
|
|
365 |
" image_url, image_name = get_image_info(data, model_type, model_name)\n",
|
366 |
"\n",
|
367 |
" return f\"{download_url}{'&' if '?' in download_url else '?'}token={CIVITAI_TOKEN}\", download_url, model_type, model_name, image_url, image_name, data\n",
|
@@ -387,7 +375,7 @@
|
|
387 |
" manual_download(url, dst_dir, file_name)\n",
|
388 |
"\n",
|
389 |
" # Unpuck ZIPs Files\n",
|
390 |
-
" for directory in
|
391 |
" for root, _, files in os.walk(directory):\n",
|
392 |
" for file in files:\n",
|
393 |
" if file.endswith(\".zip\"):\n",
|
@@ -417,7 +405,7 @@
|
|
417 |
" extension_repo.append((path, file_name))\n",
|
418 |
"\n",
|
419 |
"def manual_download(url, dst_dir, file_name, prefix=None):\n",
|
420 |
-
"
|
421 |
" aria2c_header = \"--header='User-Agent: Mozilla/5.0' --allow-overwrite=true\"\n",
|
422 |
" aria2_args = \"--optimize-concurrent-downloads --console-log-level=error --summary-interval=10 --stderr=true -c -x16 -s16 -k1M -j5\"\n",
|
423 |
"\n",
|
@@ -430,14 +418,13 @@
|
|
430 |
" subprocess.run(command, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)\n",
|
431 |
"\n",
|
432 |
" elif 'github' in url or \"huggingface.co\" in url:\n",
|
433 |
-
"
|
434 |
"\n",
|
435 |
" \"\"\" Formatted info output \"\"\"\n",
|
436 |
-
" model_name_or_basename = file_name if file_name else basename\n",
|
437 |
" try:\n",
|
438 |
-
" format_output(clean_url, dst_dir,
|
439 |
" except UnboundLocalError:\n",
|
440 |
-
" format_output(clean_url, dst_dir,
|
441 |
"\n",
|
442 |
" # =====================\n",
|
443 |
" def run_aria2c(url, dst_dir, file_name=None, args=\"\", header=\"\"):\n",
|
@@ -462,7 +449,7 @@
|
|
462 |
"\n",
|
463 |
" # -- GitHub or Hugging Face --\n",
|
464 |
" elif 'github' in url or 'huggingface' in url:\n",
|
465 |
-
" run_aria2c(clean_url, dst_dir,
|
466 |
"\n",
|
467 |
" # -- Other HTTP/Sources --\n",
|
468 |
" elif 'http' in url:\n",
|
@@ -472,50 +459,52 @@
|
|
472 |
"\n",
|
473 |
"# Separation of merged numbers\n",
|
474 |
"def split_numbers(num_str, max_num):\n",
|
475 |
-
"
|
476 |
-
"
|
477 |
-
"
|
|
|
478 |
" for length in range(2, 0, -1):\n",
|
479 |
-
" if len(
|
480 |
-
" part = int(
|
481 |
" if part <= max_num:\n",
|
482 |
-
" result
|
483 |
-
"
|
484 |
-
"
|
485 |
-
"
|
486 |
-
"
|
|
|
|
|
487 |
"\n",
|
488 |
"def add_submodels(selection, num_selection, model_dict, dst_dir):\n",
|
489 |
-
" selected_models = []\n",
|
490 |
" if selection == \"none\":\n",
|
491 |
-
" return
|
|
|
|
|
492 |
" if selection == \"ALL\":\n",
|
493 |
-
"
|
494 |
-
" selected_models.extend(models)\n",
|
495 |
" else:\n",
|
496 |
" if selection in model_dict:\n",
|
497 |
" selected_models.extend(model_dict[selection])\n",
|
|
|
498 |
" nums = num_selection.replace(',', ' ').split()\n",
|
499 |
" max_num = len(model_dict)\n",
|
500 |
-
"
|
501 |
"\n",
|
502 |
" for num_part in nums:\n",
|
503 |
" split_nums = split_numbers(num_part, max_num)\n",
|
504 |
-
"
|
505 |
-
" selected_nums.extend(split_nums)\n",
|
506 |
-
"\n",
|
507 |
-
" unique_nums = list(set(selected_nums))\n",
|
508 |
"\n",
|
509 |
" for num in unique_nums:\n",
|
510 |
" if 1 <= num <= max_num:\n",
|
511 |
-
" name = list(model_dict)[num - 1]\n",
|
512 |
" selected_models.extend(model_dict[name])\n",
|
513 |
"\n",
|
514 |
-
" unique_models =
|
|
|
515 |
" for model in unique_models:\n",
|
516 |
" model['dst_dir'] = dst_dir\n",
|
517 |
"\n",
|
518 |
-
" return unique_models\n",
|
519 |
"\n",
|
520 |
"def handle_submodels(selection, num_selection, model_dict, dst_dir, url):\n",
|
521 |
" submodels = add_submodels(selection, num_selection, model_dict, dst_dir)\n",
|
@@ -525,6 +514,7 @@
|
|
525 |
" url += f\"{submodel['url']} {submodel['dst_dir']} {submodel['name']}, \"\n",
|
526 |
" return url\n",
|
527 |
"\n",
|
|
|
528 |
"url = handle_submodels(model, model_num, model_list, models_dir, url)\n",
|
529 |
"url = handle_submodels(vae, vae_num, vae_list, vaes_dir, url)\n",
|
530 |
"url = handle_submodels(controlnet, controlnet_num, controlnet_list, control_dir, url)\n",
|
|
|
254 |
"## Downloading model and stuff | oh~ Hey! If you're freaked out by that code too, don't worry, me too!\n",
|
255 |
"print(\"📦 Скачивание моделей и прочего...\", end='')\n",
|
256 |
"\n",
|
257 |
+
"extension_repo = []\n",
|
258 |
"PREFIXES = {\n",
|
259 |
" \"model\": models_dir,\n",
|
260 |
" \"vae\": vaes_dir,\n",
|
|
|
265 |
" \"adetailer\": adetailer_dir,\n",
|
266 |
" \"config\": webui_path\n",
|
267 |
"}\n",
|
268 |
+
"!mkdir -p {\" \".join(PREFIXES.values())}\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
269 |
"\n",
|
270 |
"''' Formatted Info Output '''\n",
|
271 |
"\n",
|
|
|
|
|
272 |
"def center_text(text, terminal_width=45):\n",
|
273 |
" padding = (terminal_width - len(text)) // 2\n",
|
274 |
+
" return f\"{' ' * padding}{text}{' ' * padding}\"\n",
|
275 |
"\n",
|
276 |
"def format_output(url, dst_dir, file_name, image_name=None, image_url=None):\n",
|
277 |
" info = center_text(f\"[{file_name.split('.')[0]}]\")\n",
|
278 |
+
" sep_line = '---' * 20\n",
|
279 |
"\n",
|
280 |
+
" print(f\"\\n\\033[32m{sep_line}\\033[36;1m{info}\\033[32m{sep_line}\\033[0m\")\n",
|
281 |
+
" print(f\"\\033[33mURL: {url}\")\n",
|
282 |
" print(f\"\\033[33mSAVE DIR: \\033[34m{dst_dir}\")\n",
|
283 |
" print(f\"\\033[33mFILE NAME: \\033[34m{file_name}\\033[0m\")\n",
|
|
|
284 |
" if 'civitai' in url and image_url:\n",
|
285 |
+
" print(f\"\\033[32m[Preview DL]:\\033[0m {image_name} - {image_url}\\n\")\n",
|
286 |
"\n",
|
287 |
"''' GET CivitAi API - DATA '''\n",
|
288 |
"\n",
|
|
|
316 |
" print(\"\\033[31m[Data Info]:\\033[0m Failed to retrieve data from the API.\\n\")\n",
|
317 |
" return 'None', None, None, None, None, None, None\n",
|
318 |
"\n",
|
319 |
+
" def get_model_info(url, data):\n",
|
320 |
" model_type = data['model']['type']\n",
|
321 |
" model_name = data['files'][0]['name']\n",
|
322 |
"\n",
|
|
|
328 |
"\n",
|
329 |
" return model_type, model_name\n",
|
330 |
"\n",
|
|
|
|
|
|
|
331 |
" def get_download_url(data, model_type):\n",
|
332 |
" if any(t.lower() in model_type.lower() for t in SUPPORT_TYPES):\n",
|
333 |
" return data['files'][0]['downloadUrl']\n",
|
334 |
"\n",
|
335 |
" return data['files'][1]['downloadUrl'] if 'type' in url else data['files'][0]['downloadUrl']\n",
|
336 |
"\n",
|
|
|
|
|
337 |
" def get_image_info(data, model_type, model_name):\n",
|
338 |
" if not any(t in model_type for t in SUPPORT_TYPES):\n",
|
339 |
" return None, None\n",
|
|
|
345 |
" image_extension = image_url.split('.')[-1]\n",
|
346 |
" image_name = f\"{model_name.split('.')[0]}.preview.{image_extension}\" if image_url else None\n",
|
347 |
" return image_url, image_name\n",
|
|
|
348 |
" return None, None\n",
|
349 |
"\n",
|
350 |
+
" model_type, model_name = get_model_info(url, data)\n",
|
351 |
+
" model_name = file_name or model_name\n",
|
352 |
+
" download_url = get_download_url(data, model_type)\n",
|
353 |
" image_url, image_name = get_image_info(data, model_type, model_name)\n",
|
354 |
"\n",
|
355 |
" return f\"{download_url}{'&' if '?' in download_url else '?'}token={CIVITAI_TOKEN}\", download_url, model_type, model_name, image_url, image_name, data\n",
|
|
|
375 |
" manual_download(url, dst_dir, file_name)\n",
|
376 |
"\n",
|
377 |
" # Unpuck ZIPs Files\n",
|
378 |
+
" for directory in PREFIXES.values():\n",
|
379 |
" for root, _, files in os.walk(directory):\n",
|
380 |
" for file in files:\n",
|
381 |
" if file.endswith(\".zip\"):\n",
|
|
|
405 |
" extension_repo.append((path, file_name))\n",
|
406 |
"\n",
|
407 |
"def manual_download(url, dst_dir, file_name, prefix=None):\n",
|
408 |
+
" hf_header = f\"--header='Authorization: Bearer {huggingface_token}'\" if huggingface_token else \"\"\n",
|
409 |
" aria2c_header = \"--header='User-Agent: Mozilla/5.0' --allow-overwrite=true\"\n",
|
410 |
" aria2_args = \"--optimize-concurrent-downloads --console-log-level=error --summary-interval=10 --stderr=true -c -x16 -s16 -k1M -j5\"\n",
|
411 |
"\n",
|
|
|
418 |
" subprocess.run(command, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)\n",
|
419 |
"\n",
|
420 |
" elif 'github' in url or \"huggingface.co\" in url:\n",
|
421 |
+
" file_name = clean_url.split(\"/\")[-1] if file_name is None else file_name\n",
|
422 |
"\n",
|
423 |
" \"\"\" Formatted info output \"\"\"\n",
|
|
|
424 |
" try:\n",
|
425 |
+
" format_output(clean_url, dst_dir, file_name, image_name, image_url)\n",
|
426 |
" except UnboundLocalError:\n",
|
427 |
+
" format_output(clean_url, dst_dir, file_name, None, None)\n",
|
428 |
"\n",
|
429 |
" # =====================\n",
|
430 |
" def run_aria2c(url, dst_dir, file_name=None, args=\"\", header=\"\"):\n",
|
|
|
449 |
"\n",
|
450 |
" # -- GitHub or Hugging Face --\n",
|
451 |
" elif 'github' in url or 'huggingface' in url:\n",
|
452 |
+
" run_aria2c(clean_url, dst_dir, file_name, aria2_args, hf_header if 'huggingface' in url else '')\n",
|
453 |
"\n",
|
454 |
" # -- Other HTTP/Sources --\n",
|
455 |
" elif 'http' in url:\n",
|
|
|
459 |
"\n",
|
460 |
"# Separation of merged numbers\n",
|
461 |
"def split_numbers(num_str, max_num):\n",
|
462 |
+
" result = []\n",
|
463 |
+
" i = 0\n",
|
464 |
+
" while i < len(num_str):\n",
|
465 |
+
" found = False\n",
|
466 |
" for length in range(2, 0, -1):\n",
|
467 |
+
" if i + length <= len(num_str):\n",
|
468 |
+
" part = int(num_str[i:i + length])\n",
|
469 |
" if part <= max_num:\n",
|
470 |
+
" result.append(part)\n",
|
471 |
+
" i += length\n",
|
472 |
+
" found = True\n",
|
473 |
+
" break\n",
|
474 |
+
" if not found:\n",
|
475 |
+
" break\n",
|
476 |
+
" return result\n",
|
477 |
"\n",
|
478 |
"def add_submodels(selection, num_selection, model_dict, dst_dir):\n",
|
|
|
479 |
" if selection == \"none\":\n",
|
480 |
+
" return []\n",
|
481 |
+
" selected_models = []\n",
|
482 |
+
"\n",
|
483 |
" if selection == \"ALL\":\n",
|
484 |
+
" selected_models = sum(model_dict.values(), [])\n",
|
|
|
485 |
" else:\n",
|
486 |
" if selection in model_dict:\n",
|
487 |
" selected_models.extend(model_dict[selection])\n",
|
488 |
+
"\n",
|
489 |
" nums = num_selection.replace(',', ' ').split()\n",
|
490 |
" max_num = len(model_dict)\n",
|
491 |
+
" unique_nums = set()\n",
|
492 |
"\n",
|
493 |
" for num_part in nums:\n",
|
494 |
" split_nums = split_numbers(num_part, max_num)\n",
|
495 |
+
" unique_nums.update(split_nums)\n",
|
|
|
|
|
|
|
496 |
"\n",
|
497 |
" for num in unique_nums:\n",
|
498 |
" if 1 <= num <= max_num:\n",
|
499 |
+
" name = list(model_dict.keys())[num - 1]\n",
|
500 |
" selected_models.extend(model_dict[name])\n",
|
501 |
"\n",
|
502 |
+
" unique_models = {model['name']: model for model in selected_models}.values()\n",
|
503 |
+
"\n",
|
504 |
" for model in unique_models:\n",
|
505 |
" model['dst_dir'] = dst_dir\n",
|
506 |
"\n",
|
507 |
+
" return list(unique_models)\n",
|
508 |
"\n",
|
509 |
"def handle_submodels(selection, num_selection, model_dict, dst_dir, url):\n",
|
510 |
" submodels = add_submodels(selection, num_selection, model_dict, dst_dir)\n",
|
|
|
514 |
" url += f\"{submodel['url']} {submodel['dst_dir']} {submodel['name']}, \"\n",
|
515 |
" return url\n",
|
516 |
"\n",
|
517 |
+
"url = \"\"\n",
|
518 |
"url = handle_submodels(model, model_num, model_list, models_dir, url)\n",
|
519 |
"url = handle_submodels(vae, vae_num, vae_list, vaes_dir, url)\n",
|
520 |
"url = handle_submodels(controlnet, controlnet_num, controlnet_list, control_dir, url)\n",
|
files_cells/python/en/auto_cleaner_en.py
CHANGED
@@ -36,7 +36,6 @@ directories = {
|
|
36 |
""" functions """
|
37 |
def clean_directory(directory):
|
38 |
deleted_files = 0
|
39 |
-
image_dir = directories['Images']
|
40 |
|
41 |
for root, dirs, files in os.walk(directory):
|
42 |
for file in files:
|
@@ -44,7 +43,7 @@ def clean_directory(directory):
|
|
44 |
|
45 |
if file.endswith(".txt"):
|
46 |
continue
|
47 |
-
if file.endswith((".safetensors", ".pt"
|
48 |
deleted_files += 1
|
49 |
|
50 |
os.remove(file_path)
|
|
|
36 |
""" functions """
|
37 |
def clean_directory(directory):
|
38 |
deleted_files = 0
|
|
|
39 |
|
40 |
for root, dirs, files in os.walk(directory):
|
41 |
for file in files:
|
|
|
43 |
|
44 |
if file.endswith(".txt"):
|
45 |
continue
|
46 |
+
if file.endswith((".safetensors", ".pt", ".png", ".jpg", ".jpeg")):
|
47 |
deleted_files += 1
|
48 |
|
49 |
os.remove(file_path)
|
files_cells/python/en/downloading_en.py
CHANGED
@@ -244,7 +244,7 @@ if commit_hash:
|
|
244 |
## Downloading model and stuff | oh~ Hey! If you're freaked out by that code too, don't worry, me too!
|
245 |
print("📦 Downloading models and stuff...", end='')
|
246 |
|
247 |
-
|
248 |
PREFIXES = {
|
249 |
"model": models_dir,
|
250 |
"vae": vaes_dir,
|
@@ -255,33 +255,24 @@ PREFIXES = {
|
|
255 |
"adetailer": adetailer_dir,
|
256 |
"config": webui_path
|
257 |
}
|
258 |
-
|
259 |
-
extension_repo = []
|
260 |
-
directories = [value for key, value in PREFIXES.items()] # for unpucking zip files
|
261 |
-
get_ipython().system('mkdir -p {" ".join(directories)}')
|
262 |
-
|
263 |
-
hf_token = huggingface_token if huggingface_token else "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"
|
264 |
-
user_header = f"\"Authorization: Bearer {hf_token}\""
|
265 |
|
266 |
''' Formatted Info Output '''
|
267 |
|
268 |
-
from math import floor
|
269 |
-
|
270 |
def center_text(text, terminal_width=45):
|
271 |
padding = (terminal_width - len(text)) // 2
|
272 |
-
return f"
|
273 |
|
274 |
def format_output(url, dst_dir, file_name, image_name=None, image_url=None):
|
275 |
info = center_text(f"[{file_name.split('.')[0]}]")
|
276 |
-
|
277 |
|
278 |
-
print(f"\n{
|
279 |
-
print(f"\033[33mURL:
|
280 |
print(f"\033[33mSAVE DIR: \033[34m{dst_dir}")
|
281 |
print(f"\033[33mFILE NAME: \033[34m{file_name}\033[0m")
|
282 |
-
|
283 |
if 'civitai' in url and image_url:
|
284 |
-
print(f"\033[32m[Preview
|
285 |
|
286 |
''' GET CivitAi API - DATA '''
|
287 |
|
@@ -315,7 +306,7 @@ def CivitAi_API(url, file_name=None):
|
|
315 |
print("\033[31m[Data Info]:\033[0m Failed to retrieve data from the API.\n")
|
316 |
return 'None', None, None, None, None, None, None
|
317 |
|
318 |
-
def
|
319 |
model_type = data['model']['type']
|
320 |
model_name = data['files'][0]['name']
|
321 |
|
@@ -327,17 +318,12 @@ def CivitAi_API(url, file_name=None):
|
|
327 |
|
328 |
return model_type, model_name
|
329 |
|
330 |
-
model_type, model_name = extract_model_info(url, data)
|
331 |
-
model_name = file_name or model_name
|
332 |
-
|
333 |
def get_download_url(data, model_type):
|
334 |
if any(t.lower() in model_type.lower() for t in SUPPORT_TYPES):
|
335 |
return data['files'][0]['downloadUrl']
|
336 |
|
337 |
return data['files'][1]['downloadUrl'] if 'type' in url else data['files'][0]['downloadUrl']
|
338 |
|
339 |
-
download_url = get_download_url(data, model_type)
|
340 |
-
|
341 |
def get_image_info(data, model_type, model_name):
|
342 |
if not any(t in model_type for t in SUPPORT_TYPES):
|
343 |
return None, None
|
@@ -349,9 +335,11 @@ def CivitAi_API(url, file_name=None):
|
|
349 |
image_extension = image_url.split('.')[-1]
|
350 |
image_name = f"{model_name.split('.')[0]}.preview.{image_extension}" if image_url else None
|
351 |
return image_url, image_name
|
352 |
-
|
353 |
return None, None
|
354 |
|
|
|
|
|
|
|
355 |
image_url, image_name = get_image_info(data, model_type, model_name)
|
356 |
|
357 |
return f"{download_url}{'&' if '?' in download_url else '?'}token={CIVITAI_TOKEN}", download_url, model_type, model_name, image_url, image_name, data
|
@@ -377,7 +365,7 @@ def download(url):
|
|
377 |
manual_download(url, dst_dir, file_name)
|
378 |
|
379 |
# Unpuck ZIPs Files
|
380 |
-
for directory in
|
381 |
for root, _, files in os.walk(directory):
|
382 |
for file in files:
|
383 |
if file.endswith(".zip"):
|
@@ -407,7 +395,7 @@ def handle_manual(url):
|
|
407 |
extension_repo.append((path, file_name))
|
408 |
|
409 |
def manual_download(url, dst_dir, file_name, prefix=None):
|
410 |
-
|
411 |
aria2c_header = "--header='User-Agent: Mozilla/5.0' --allow-overwrite=true"
|
412 |
aria2_args = "--optimize-concurrent-downloads --console-log-level=error --summary-interval=10 --stderr=true -c -x16 -s16 -k1M -j5"
|
413 |
|
@@ -420,14 +408,13 @@ def manual_download(url, dst_dir, file_name, prefix=None):
|
|
420 |
subprocess.run(command, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
421 |
|
422 |
elif 'github' in url or "huggingface.co" in url:
|
423 |
-
|
424 |
|
425 |
""" Formatted info output """
|
426 |
-
model_name_or_basename = file_name if file_name else basename
|
427 |
try:
|
428 |
-
format_output(clean_url, dst_dir,
|
429 |
except UnboundLocalError:
|
430 |
-
format_output(clean_url, dst_dir,
|
431 |
|
432 |
# =====================
|
433 |
def run_aria2c(url, dst_dir, file_name=None, args="", header=""):
|
@@ -452,7 +439,7 @@ def manual_download(url, dst_dir, file_name, prefix=None):
|
|
452 |
|
453 |
# -- GitHub or Hugging Face --
|
454 |
elif 'github' in url or 'huggingface' in url:
|
455 |
-
run_aria2c(clean_url, dst_dir,
|
456 |
|
457 |
# -- Other HTTP/Sources --
|
458 |
elif 'http' in url:
|
@@ -511,15 +498,13 @@ def add_submodels(selection, num_selection, model_dict, dst_dir):
|
|
511 |
|
512 |
def handle_submodels(selection, num_selection, model_dict, dst_dir, url):
|
513 |
submodels = add_submodels(selection, num_selection, model_dict, dst_dir)
|
514 |
-
urls = []
|
515 |
for submodel in submodels:
|
516 |
if not inpainting_model and "inpainting" in submodel['name']:
|
517 |
continue
|
518 |
-
|
519 |
-
|
520 |
-
url += ", ".join(urls) + ', '
|
521 |
return url
|
522 |
|
|
|
523 |
url = handle_submodels(model, model_num, model_list, models_dir, url)
|
524 |
url = handle_submodels(vae, vae_num, vae_list, vaes_dir, url)
|
525 |
url = handle_submodels(controlnet, controlnet_num, controlnet_list, control_dir, url)
|
|
|
244 |
## Downloading model and stuff | oh~ Hey! If you're freaked out by that code too, don't worry, me too!
|
245 |
print("📦 Downloading models and stuff...", end='')
|
246 |
|
247 |
+
extension_repo = []
|
248 |
PREFIXES = {
|
249 |
"model": models_dir,
|
250 |
"vae": vaes_dir,
|
|
|
255 |
"adetailer": adetailer_dir,
|
256 |
"config": webui_path
|
257 |
}
|
258 |
+
get_ipython().system('mkdir -p {" ".join(PREFIXES.values())}')
|
|
|
|
|
|
|
|
|
|
|
|
|
259 |
|
260 |
''' Formatted Info Output '''
|
261 |
|
|
|
|
|
262 |
def center_text(text, terminal_width=45):
|
263 |
padding = (terminal_width - len(text)) // 2
|
264 |
+
return f"{' ' * padding}{text}{' ' * padding}"
|
265 |
|
266 |
def format_output(url, dst_dir, file_name, image_name=None, image_url=None):
|
267 |
info = center_text(f"[{file_name.split('.')[0]}]")
|
268 |
+
sep_line = '---' * 20
|
269 |
|
270 |
+
print(f"\n\033[32m{sep_line}\033[36;1m{info}\033[32m{sep_line}\033[0m")
|
271 |
+
print(f"\033[33mURL: {url}")
|
272 |
print(f"\033[33mSAVE DIR: \033[34m{dst_dir}")
|
273 |
print(f"\033[33mFILE NAME: \033[34m{file_name}\033[0m")
|
|
|
274 |
if 'civitai' in url and image_url:
|
275 |
+
print(f"\033[32m[Preview DL]:\033[0m {image_name} - {image_url}\n")
|
276 |
|
277 |
''' GET CivitAi API - DATA '''
|
278 |
|
|
|
306 |
print("\033[31m[Data Info]:\033[0m Failed to retrieve data from the API.\n")
|
307 |
return 'None', None, None, None, None, None, None
|
308 |
|
309 |
+
def get_model_info(url, data):
|
310 |
model_type = data['model']['type']
|
311 |
model_name = data['files'][0]['name']
|
312 |
|
|
|
318 |
|
319 |
return model_type, model_name
|
320 |
|
|
|
|
|
|
|
321 |
def get_download_url(data, model_type):
|
322 |
if any(t.lower() in model_type.lower() for t in SUPPORT_TYPES):
|
323 |
return data['files'][0]['downloadUrl']
|
324 |
|
325 |
return data['files'][1]['downloadUrl'] if 'type' in url else data['files'][0]['downloadUrl']
|
326 |
|
|
|
|
|
327 |
def get_image_info(data, model_type, model_name):
|
328 |
if not any(t in model_type for t in SUPPORT_TYPES):
|
329 |
return None, None
|
|
|
335 |
image_extension = image_url.split('.')[-1]
|
336 |
image_name = f"{model_name.split('.')[0]}.preview.{image_extension}" if image_url else None
|
337 |
return image_url, image_name
|
|
|
338 |
return None, None
|
339 |
|
340 |
+
model_type, model_name = get_model_info(url, data)
|
341 |
+
model_name = file_name or model_name
|
342 |
+
download_url = get_download_url(data, model_type)
|
343 |
image_url, image_name = get_image_info(data, model_type, model_name)
|
344 |
|
345 |
return f"{download_url}{'&' if '?' in download_url else '?'}token={CIVITAI_TOKEN}", download_url, model_type, model_name, image_url, image_name, data
|
|
|
365 |
manual_download(url, dst_dir, file_name)
|
366 |
|
367 |
# Unpuck ZIPs Files
|
368 |
+
for directory in PREFIXES.values():
|
369 |
for root, _, files in os.walk(directory):
|
370 |
for file in files:
|
371 |
if file.endswith(".zip"):
|
|
|
395 |
extension_repo.append((path, file_name))
|
396 |
|
397 |
def manual_download(url, dst_dir, file_name, prefix=None):
|
398 |
+
hf_header = f"--header='Authorization: Bearer {huggingface_token}'" if huggingface_token else ""
|
399 |
aria2c_header = "--header='User-Agent: Mozilla/5.0' --allow-overwrite=true"
|
400 |
aria2_args = "--optimize-concurrent-downloads --console-log-level=error --summary-interval=10 --stderr=true -c -x16 -s16 -k1M -j5"
|
401 |
|
|
|
408 |
subprocess.run(command, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
409 |
|
410 |
elif 'github' in url or "huggingface.co" in url:
|
411 |
+
file_name = clean_url.split("/")[-1] if file_name is None else file_name
|
412 |
|
413 |
""" Formatted info output """
|
|
|
414 |
try:
|
415 |
+
format_output(clean_url, dst_dir, file_name, image_name, image_url)
|
416 |
except UnboundLocalError:
|
417 |
+
format_output(clean_url, dst_dir, file_name, None, None)
|
418 |
|
419 |
# =====================
|
420 |
def run_aria2c(url, dst_dir, file_name=None, args="", header=""):
|
|
|
439 |
|
440 |
# -- GitHub or Hugging Face --
|
441 |
elif 'github' in url or 'huggingface' in url:
|
442 |
+
run_aria2c(clean_url, dst_dir, file_name, aria2_args, hf_header if 'huggingface' in url else '')
|
443 |
|
444 |
# -- Other HTTP/Sources --
|
445 |
elif 'http' in url:
|
|
|
498 |
|
499 |
def handle_submodels(selection, num_selection, model_dict, dst_dir, url):
|
500 |
submodels = add_submodels(selection, num_selection, model_dict, dst_dir)
|
|
|
501 |
for submodel in submodels:
|
502 |
if not inpainting_model and "inpainting" in submodel['name']:
|
503 |
continue
|
504 |
+
url += f"{submodel['url']} {submodel['dst_dir']} {submodel['name']}, "
|
|
|
|
|
505 |
return url
|
506 |
|
507 |
+
url = ""
|
508 |
url = handle_submodels(model, model_num, model_list, models_dir, url)
|
509 |
url = handle_submodels(vae, vae_num, vae_list, vaes_dir, url)
|
510 |
url = handle_submodels(controlnet, controlnet_num, controlnet_list, control_dir, url)
|
files_cells/python/ru/auto_cleaner_ru.py
CHANGED
@@ -36,7 +36,6 @@ directories = {
|
|
36 |
""" functions """
|
37 |
def clean_directory(directory):
|
38 |
deleted_files = 0
|
39 |
-
image_dir = directories['Изображения']
|
40 |
|
41 |
for root, dirs, files in os.walk(directory):
|
42 |
for file in files:
|
@@ -44,7 +43,7 @@ def clean_directory(directory):
|
|
44 |
|
45 |
if file.endswith(".txt"):
|
46 |
continue
|
47 |
-
if file.endswith((".safetensors", ".pt"
|
48 |
deleted_files += 1
|
49 |
|
50 |
os.remove(file_path)
|
|
|
36 |
""" functions """
|
37 |
def clean_directory(directory):
|
38 |
deleted_files = 0
|
|
|
39 |
|
40 |
for root, dirs, files in os.walk(directory):
|
41 |
for file in files:
|
|
|
43 |
|
44 |
if file.endswith(".txt"):
|
45 |
continue
|
46 |
+
if file.endswith((".safetensors", ".pt", ".png", ".jpg", ".jpeg")):
|
47 |
deleted_files += 1
|
48 |
|
49 |
os.remove(file_path)
|
files_cells/python/ru/downloading_ru.py
CHANGED
@@ -244,7 +244,7 @@ if commit_hash:
|
|
244 |
## Downloading model and stuff | oh~ Hey! If you're freaked out by that code too, don't worry, me too!
|
245 |
print("📦 Скачивание моделей и прочего...", end='')
|
246 |
|
247 |
-
|
248 |
PREFIXES = {
|
249 |
"model": models_dir,
|
250 |
"vae": vaes_dir,
|
@@ -255,33 +255,24 @@ PREFIXES = {
|
|
255 |
"adetailer": adetailer_dir,
|
256 |
"config": webui_path
|
257 |
}
|
258 |
-
|
259 |
-
extension_repo = []
|
260 |
-
directories = [value for key, value in PREFIXES.items()] # for unpucking zip files
|
261 |
-
get_ipython().system('mkdir -p {" ".join(directories)}')
|
262 |
-
|
263 |
-
hf_token = huggingface_token if huggingface_token else "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"
|
264 |
-
user_header = f"\"Authorization: Bearer {hf_token}\""
|
265 |
|
266 |
''' Formatted Info Output '''
|
267 |
|
268 |
-
from math import floor
|
269 |
-
|
270 |
def center_text(text, terminal_width=45):
|
271 |
padding = (terminal_width - len(text)) // 2
|
272 |
-
return f"
|
273 |
|
274 |
def format_output(url, dst_dir, file_name, image_name=None, image_url=None):
|
275 |
info = center_text(f"[{file_name.split('.')[0]}]")
|
276 |
-
|
277 |
|
278 |
-
print(f"\n{
|
279 |
-
print(f"\033[33mURL:
|
280 |
print(f"\033[33mSAVE DIR: \033[34m{dst_dir}")
|
281 |
print(f"\033[33mFILE NAME: \033[34m{file_name}\033[0m")
|
282 |
-
|
283 |
if 'civitai' in url and image_url:
|
284 |
-
print(f"\033[32m[Preview
|
285 |
|
286 |
''' GET CivitAi API - DATA '''
|
287 |
|
@@ -315,7 +306,7 @@ def CivitAi_API(url, file_name=None):
|
|
315 |
print("\033[31m[Data Info]:\033[0m Failed to retrieve data from the API.\n")
|
316 |
return 'None', None, None, None, None, None, None
|
317 |
|
318 |
-
def
|
319 |
model_type = data['model']['type']
|
320 |
model_name = data['files'][0]['name']
|
321 |
|
@@ -327,17 +318,12 @@ def CivitAi_API(url, file_name=None):
|
|
327 |
|
328 |
return model_type, model_name
|
329 |
|
330 |
-
model_type, model_name = extract_model_info(url, data)
|
331 |
-
model_name = file_name or model_name
|
332 |
-
|
333 |
def get_download_url(data, model_type):
|
334 |
if any(t.lower() in model_type.lower() for t in SUPPORT_TYPES):
|
335 |
return data['files'][0]['downloadUrl']
|
336 |
|
337 |
return data['files'][1]['downloadUrl'] if 'type' in url else data['files'][0]['downloadUrl']
|
338 |
|
339 |
-
download_url = get_download_url(data, model_type)
|
340 |
-
|
341 |
def get_image_info(data, model_type, model_name):
|
342 |
if not any(t in model_type for t in SUPPORT_TYPES):
|
343 |
return None, None
|
@@ -349,9 +335,11 @@ def CivitAi_API(url, file_name=None):
|
|
349 |
image_extension = image_url.split('.')[-1]
|
350 |
image_name = f"{model_name.split('.')[0]}.preview.{image_extension}" if image_url else None
|
351 |
return image_url, image_name
|
352 |
-
|
353 |
return None, None
|
354 |
|
|
|
|
|
|
|
355 |
image_url, image_name = get_image_info(data, model_type, model_name)
|
356 |
|
357 |
return f"{download_url}{'&' if '?' in download_url else '?'}token={CIVITAI_TOKEN}", download_url, model_type, model_name, image_url, image_name, data
|
@@ -377,7 +365,7 @@ def download(url):
|
|
377 |
manual_download(url, dst_dir, file_name)
|
378 |
|
379 |
# Unpuck ZIPs Files
|
380 |
-
for directory in
|
381 |
for root, _, files in os.walk(directory):
|
382 |
for file in files:
|
383 |
if file.endswith(".zip"):
|
@@ -407,7 +395,7 @@ def handle_manual(url):
|
|
407 |
extension_repo.append((path, file_name))
|
408 |
|
409 |
def manual_download(url, dst_dir, file_name, prefix=None):
|
410 |
-
|
411 |
aria2c_header = "--header='User-Agent: Mozilla/5.0' --allow-overwrite=true"
|
412 |
aria2_args = "--optimize-concurrent-downloads --console-log-level=error --summary-interval=10 --stderr=true -c -x16 -s16 -k1M -j5"
|
413 |
|
@@ -420,14 +408,13 @@ def manual_download(url, dst_dir, file_name, prefix=None):
|
|
420 |
subprocess.run(command, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
421 |
|
422 |
elif 'github' in url or "huggingface.co" in url:
|
423 |
-
|
424 |
|
425 |
""" Formatted info output """
|
426 |
-
model_name_or_basename = file_name if file_name else basename
|
427 |
try:
|
428 |
-
format_output(clean_url, dst_dir,
|
429 |
except UnboundLocalError:
|
430 |
-
format_output(clean_url, dst_dir,
|
431 |
|
432 |
# =====================
|
433 |
def run_aria2c(url, dst_dir, file_name=None, args="", header=""):
|
@@ -452,7 +439,7 @@ def manual_download(url, dst_dir, file_name, prefix=None):
|
|
452 |
|
453 |
# -- GitHub or Hugging Face --
|
454 |
elif 'github' in url or 'huggingface' in url:
|
455 |
-
run_aria2c(clean_url, dst_dir,
|
456 |
|
457 |
# -- Other HTTP/Sources --
|
458 |
elif 'http' in url:
|
@@ -462,50 +449,52 @@ def manual_download(url, dst_dir, file_name, prefix=None):
|
|
462 |
|
463 |
# Separation of merged numbers
|
464 |
def split_numbers(num_str, max_num):
|
465 |
-
|
466 |
-
|
467 |
-
|
|
|
468 |
for length in range(2, 0, -1):
|
469 |
-
if len(
|
470 |
-
part = int(
|
471 |
if part <= max_num:
|
472 |
-
result
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
|
|
|
|
477 |
|
478 |
def add_submodels(selection, num_selection, model_dict, dst_dir):
|
479 |
-
selected_models = []
|
480 |
if selection == "none":
|
481 |
-
return
|
|
|
|
|
482 |
if selection == "ALL":
|
483 |
-
|
484 |
-
selected_models.extend(models)
|
485 |
else:
|
486 |
if selection in model_dict:
|
487 |
selected_models.extend(model_dict[selection])
|
|
|
488 |
nums = num_selection.replace(',', ' ').split()
|
489 |
max_num = len(model_dict)
|
490 |
-
|
491 |
|
492 |
for num_part in nums:
|
493 |
split_nums = split_numbers(num_part, max_num)
|
494 |
-
|
495 |
-
selected_nums.extend(split_nums)
|
496 |
-
|
497 |
-
unique_nums = list(set(selected_nums))
|
498 |
|
499 |
for num in unique_nums:
|
500 |
if 1 <= num <= max_num:
|
501 |
-
name = list(model_dict)[num - 1]
|
502 |
selected_models.extend(model_dict[name])
|
503 |
|
504 |
-
unique_models =
|
|
|
505 |
for model in unique_models:
|
506 |
model['dst_dir'] = dst_dir
|
507 |
|
508 |
-
return unique_models
|
509 |
|
510 |
def handle_submodels(selection, num_selection, model_dict, dst_dir, url):
|
511 |
submodels = add_submodels(selection, num_selection, model_dict, dst_dir)
|
@@ -515,6 +504,7 @@ def handle_submodels(selection, num_selection, model_dict, dst_dir, url):
|
|
515 |
url += f"{submodel['url']} {submodel['dst_dir']} {submodel['name']}, "
|
516 |
return url
|
517 |
|
|
|
518 |
url = handle_submodels(model, model_num, model_list, models_dir, url)
|
519 |
url = handle_submodels(vae, vae_num, vae_list, vaes_dir, url)
|
520 |
url = handle_submodels(controlnet, controlnet_num, controlnet_list, control_dir, url)
|
|
|
244 |
## Downloading model and stuff | oh~ Hey! If you're freaked out by that code too, don't worry, me too!
|
245 |
print("📦 Скачивание моделей и прочего...", end='')
|
246 |
|
247 |
+
extension_repo = []
|
248 |
PREFIXES = {
|
249 |
"model": models_dir,
|
250 |
"vae": vaes_dir,
|
|
|
255 |
"adetailer": adetailer_dir,
|
256 |
"config": webui_path
|
257 |
}
|
258 |
+
get_ipython().system('mkdir -p {" ".join(PREFIXES.values())}')
|
|
|
|
|
|
|
|
|
|
|
|
|
259 |
|
260 |
''' Formatted Info Output '''
|
261 |
|
|
|
|
|
262 |
def center_text(text, terminal_width=45):
|
263 |
padding = (terminal_width - len(text)) // 2
|
264 |
+
return f"{' ' * padding}{text}{' ' * padding}"
|
265 |
|
266 |
def format_output(url, dst_dir, file_name, image_name=None, image_url=None):
|
267 |
info = center_text(f"[{file_name.split('.')[0]}]")
|
268 |
+
sep_line = '---' * 20
|
269 |
|
270 |
+
print(f"\n\033[32m{sep_line}\033[36;1m{info}\033[32m{sep_line}\033[0m")
|
271 |
+
print(f"\033[33mURL: {url}")
|
272 |
print(f"\033[33mSAVE DIR: \033[34m{dst_dir}")
|
273 |
print(f"\033[33mFILE NAME: \033[34m{file_name}\033[0m")
|
|
|
274 |
if 'civitai' in url and image_url:
|
275 |
+
print(f"\033[32m[Preview DL]:\033[0m {image_name} - {image_url}\n")
|
276 |
|
277 |
''' GET CivitAi API - DATA '''
|
278 |
|
|
|
306 |
print("\033[31m[Data Info]:\033[0m Failed to retrieve data from the API.\n")
|
307 |
return 'None', None, None, None, None, None, None
|
308 |
|
309 |
+
def get_model_info(url, data):
|
310 |
model_type = data['model']['type']
|
311 |
model_name = data['files'][0]['name']
|
312 |
|
|
|
318 |
|
319 |
return model_type, model_name
|
320 |
|
|
|
|
|
|
|
321 |
def get_download_url(data, model_type):
|
322 |
if any(t.lower() in model_type.lower() for t in SUPPORT_TYPES):
|
323 |
return data['files'][0]['downloadUrl']
|
324 |
|
325 |
return data['files'][1]['downloadUrl'] if 'type' in url else data['files'][0]['downloadUrl']
|
326 |
|
|
|
|
|
327 |
def get_image_info(data, model_type, model_name):
|
328 |
if not any(t in model_type for t in SUPPORT_TYPES):
|
329 |
return None, None
|
|
|
335 |
image_extension = image_url.split('.')[-1]
|
336 |
image_name = f"{model_name.split('.')[0]}.preview.{image_extension}" if image_url else None
|
337 |
return image_url, image_name
|
|
|
338 |
return None, None
|
339 |
|
340 |
+
model_type, model_name = get_model_info(url, data)
|
341 |
+
model_name = file_name or model_name
|
342 |
+
download_url = get_download_url(data, model_type)
|
343 |
image_url, image_name = get_image_info(data, model_type, model_name)
|
344 |
|
345 |
return f"{download_url}{'&' if '?' in download_url else '?'}token={CIVITAI_TOKEN}", download_url, model_type, model_name, image_url, image_name, data
|
|
|
365 |
manual_download(url, dst_dir, file_name)
|
366 |
|
367 |
# Unpuck ZIPs Files
|
368 |
+
for directory in PREFIXES.values():
|
369 |
for root, _, files in os.walk(directory):
|
370 |
for file in files:
|
371 |
if file.endswith(".zip"):
|
|
|
395 |
extension_repo.append((path, file_name))
|
396 |
|
397 |
def manual_download(url, dst_dir, file_name, prefix=None):
|
398 |
+
hf_header = f"--header='Authorization: Bearer {huggingface_token}'" if huggingface_token else ""
|
399 |
aria2c_header = "--header='User-Agent: Mozilla/5.0' --allow-overwrite=true"
|
400 |
aria2_args = "--optimize-concurrent-downloads --console-log-level=error --summary-interval=10 --stderr=true -c -x16 -s16 -k1M -j5"
|
401 |
|
|
|
408 |
subprocess.run(command, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
409 |
|
410 |
elif 'github' in url or "huggingface.co" in url:
|
411 |
+
file_name = clean_url.split("/")[-1] if file_name is None else file_name
|
412 |
|
413 |
""" Formatted info output """
|
|
|
414 |
try:
|
415 |
+
format_output(clean_url, dst_dir, file_name, image_name, image_url)
|
416 |
except UnboundLocalError:
|
417 |
+
format_output(clean_url, dst_dir, file_name, None, None)
|
418 |
|
419 |
# =====================
|
420 |
def run_aria2c(url, dst_dir, file_name=None, args="", header=""):
|
|
|
439 |
|
440 |
# -- GitHub or Hugging Face --
|
441 |
elif 'github' in url or 'huggingface' in url:
|
442 |
+
run_aria2c(clean_url, dst_dir, file_name, aria2_args, hf_header if 'huggingface' in url else '')
|
443 |
|
444 |
# -- Other HTTP/Sources --
|
445 |
elif 'http' in url:
|
|
|
449 |
|
450 |
# Separation of merged numbers
|
451 |
def split_numbers(num_str, max_num):
|
452 |
+
result = []
|
453 |
+
i = 0
|
454 |
+
while i < len(num_str):
|
455 |
+
found = False
|
456 |
for length in range(2, 0, -1):
|
457 |
+
if i + length <= len(num_str):
|
458 |
+
part = int(num_str[i:i + length])
|
459 |
if part <= max_num:
|
460 |
+
result.append(part)
|
461 |
+
i += length
|
462 |
+
found = True
|
463 |
+
break
|
464 |
+
if not found:
|
465 |
+
break
|
466 |
+
return result
|
467 |
|
468 |
def add_submodels(selection, num_selection, model_dict, dst_dir):
|
|
|
469 |
if selection == "none":
|
470 |
+
return []
|
471 |
+
selected_models = []
|
472 |
+
|
473 |
if selection == "ALL":
|
474 |
+
selected_models = sum(model_dict.values(), [])
|
|
|
475 |
else:
|
476 |
if selection in model_dict:
|
477 |
selected_models.extend(model_dict[selection])
|
478 |
+
|
479 |
nums = num_selection.replace(',', ' ').split()
|
480 |
max_num = len(model_dict)
|
481 |
+
unique_nums = set()
|
482 |
|
483 |
for num_part in nums:
|
484 |
split_nums = split_numbers(num_part, max_num)
|
485 |
+
unique_nums.update(split_nums)
|
|
|
|
|
|
|
486 |
|
487 |
for num in unique_nums:
|
488 |
if 1 <= num <= max_num:
|
489 |
+
name = list(model_dict.keys())[num - 1]
|
490 |
selected_models.extend(model_dict[name])
|
491 |
|
492 |
+
unique_models = {model['name']: model for model in selected_models}.values()
|
493 |
+
|
494 |
for model in unique_models:
|
495 |
model['dst_dir'] = dst_dir
|
496 |
|
497 |
+
return list(unique_models)
|
498 |
|
499 |
def handle_submodels(selection, num_selection, model_dict, dst_dir, url):
|
500 |
submodels = add_submodels(selection, num_selection, model_dict, dst_dir)
|
|
|
504 |
url += f"{submodel['url']} {submodel['dst_dir']} {submodel['name']}, "
|
505 |
return url
|
506 |
|
507 |
+
url = ""
|
508 |
url = handle_submodels(model, model_num, model_list, models_dir, url)
|
509 |
url = handle_submodels(vae, vae_num, vae_list, vaes_dir, url)
|
510 |
url = handle_submodels(controlnet, controlnet_num, controlnet_list, control_dir, url)
|