dl prew img for models
Browse files
files_cells/notebooks/en/downloading_en.ipynb
CHANGED
@@ -344,12 +344,42 @@
|
|
344 |
" \"adetailer\": adetailer_dir\n",
|
345 |
"}\n",
|
346 |
"\n",
|
347 |
-
"!mkdir -p {models_dir} {vaes_dir} {loras_dir} {embeddings_dir} {extensions_dir} {control_dir} {adetailer_dir}\n",
|
|
|
|
|
348 |
"\n",
|
349 |
"url = \"\"\n",
|
350 |
"hf_token = optional_huggingface_token if optional_huggingface_token else \"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\"\n",
|
351 |
"user_header = f\"\\\"Authorization: Bearer {hf_token}\\\"\"\n",
|
352 |
"\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
353 |
"''' main download code '''\n",
|
354 |
"\n",
|
355 |
"def handle_manual(url):\n",
|
@@ -368,17 +398,32 @@
|
|
368 |
" extension_repo.append((url, file_name))\n",
|
369 |
"\n",
|
370 |
"def manual_download(url, dst_dir, file_name):\n",
|
371 |
-
" basename = url.split(\"/\")[-1] if file_name is None else file_name\n",
|
372 |
" header_option = f\"--header={user_header}\"\n",
|
|
|
|
|
373 |
"\n",
|
374 |
" print(\"\\033[32m---\"*45 + f\"\\n\\033[33mURL: \\033[34m{url}\\n\\033[33mSAVE DIR: \\033[34m{dst_dir}\\n\\033[33mFILE NAME: \\033[34m{file_name}\\033[32m\\n~~~\\033[0m\")\n",
|
375 |
" # print(url, dst_dir, file_name)\n",
|
376 |
"\n",
|
377 |
-
" #
|
378 |
" civitai_token = \"62c0c5956b2f9defbd844d754000180b\"\n",
|
379 |
" if 'civitai' in url and civitai_token:\n",
|
|
|
|
|
380 |
" url = f\"{url}?token={civitai_token}\"\n",
|
381 |
"\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
382 |
" # -- GDrive --\n",
|
383 |
" if 'drive.google' in url:\n",
|
384 |
" if 'folders' in url:\n",
|
@@ -388,22 +433,24 @@
|
|
388 |
" !gdown \"{url}\" -O {dst_dir}/{file_name} --fuzzy -c\n",
|
389 |
" else:\n",
|
390 |
" !gdown \"{url}\" -O {dst_dir} --fuzzy -c\n",
|
391 |
-
"
|
|
|
392 |
" elif 'huggingface' in url:\n",
|
393 |
" if '/blob/' in url:\n",
|
394 |
" url = url.replace('/blob/', '/resolve/')\n",
|
395 |
" if file_name:\n",
|
396 |
-
" !aria2c {header_option}
|
397 |
" else:\n",
|
398 |
" parsed_link = f'\\n{url}\\n\\tout={unquote(url.split(\"/\")[-1])}'\n",
|
399 |
-
" !echo -e \"{parsed_link}\" | aria2c {header_option}
|
|
|
400 |
" # -- Other --\n",
|
401 |
" elif 'http' in url or 'magnet' in url:\n",
|
402 |
" if file_name:\n",
|
403 |
-
" !aria2c
|
404 |
" else:\n",
|
405 |
" parsed_link = '\"{}\"'.format(url)\n",
|
406 |
-
" !aria2c
|
407 |
"\n",
|
408 |
"def download(url):\n",
|
409 |
" links_and_paths = url.split(',')\n",
|
@@ -423,8 +470,7 @@
|
|
423 |
"\n",
|
424 |
"## unpucking zip files\n",
|
425 |
"def unpucking_zip_files():\n",
|
426 |
-
" directories = [models_dir, vaes_dir, embeddings_dir, loras_dir , extensions_dir, control_dir , adetailer_dir]\n",
|
427 |
-
"\n",
|
428 |
" for directory in directories:\n",
|
429 |
" for root, dirs, files in os.walk(directory):\n",
|
430 |
" for file in files:\n",
|
@@ -561,21 +607,21 @@
|
|
561 |
"else:\n",
|
562 |
" if any(not file.endswith('.txt') for file in os.listdir(models_dir)):\n",
|
563 |
" print(\"\\n\\033[33m➤ Models\\033[0m\")\n",
|
564 |
-
"
|
565 |
" if any(not file.endswith('.txt') for file in os.listdir(vaes_dir)):\n",
|
566 |
" print(\"\\n\\033[33m➤ VAEs\\033[0m\")\n",
|
567 |
-
"
|
568 |
" if any(not file.endswith('.txt') and not os.path.isdir(os.path.join(embeddings_dir, file)) for file in os.listdir(embeddings_dir)):\n",
|
569 |
" print(\"\\n\\033[33m➤ Embeddings\\033[0m\")\n",
|
570 |
-
"
|
571 |
" if any(not file.endswith('.txt') for file in os.listdir(loras_dir)):\n",
|
572 |
" print(\"\\n\\033[33m➤ LoRAs\\033[0m\")\n",
|
573 |
-
"
|
574 |
" print(f\"\\n\\033[33m➤ Extensions\\033[0m\")\n",
|
575 |
-
"
|
576 |
" if any(not file.endswith(('.txt', '.yaml')) for file in os.listdir(control_dir)):\n",
|
577 |
" print(\"\\n\\033[33m➤ ControlNet\\033[0m\")\n",
|
578 |
-
"
|
579 |
"\n",
|
580 |
"\n",
|
581 |
"# === OTHER ===\n",
|
|
|
344 |
" \"adetailer\": adetailer_dir\n",
|
345 |
"}\n",
|
346 |
"\n",
|
347 |
+
"# !mkdir -p {models_dir} {vaes_dir} {loras_dir} {embeddings_dir} {extensions_dir} {control_dir} {adetailer_dir}\n",
|
348 |
+
"directories = [value for key, value in prefixes.items()] # for unpucking zip files\n",
|
349 |
+
"!mkdir -p {\" \".join(directories)}\n",
|
350 |
"\n",
|
351 |
"url = \"\"\n",
|
352 |
"hf_token = optional_huggingface_token if optional_huggingface_token else \"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\"\n",
|
353 |
"user_header = f\"\\\"Authorization: Bearer {hf_token}\\\"\"\n",
|
354 |
"\n",
|
355 |
+
"''' Get Image Preview | CivitAi '''\n",
|
356 |
+
"\n",
|
357 |
+
"def get_data_from_api(model_id): # get model data\n",
|
358 |
+
" base_url = f\"https://civitai.com/api/v1/model-versions/{model_id}\"\n",
|
359 |
+
" headers = {\"Content-Type\": \"application/json\"}\n",
|
360 |
+
" try:\n",
|
361 |
+
" response = requests.get(base_url, headers=headers)\n",
|
362 |
+
" if response.status_code == 200:\n",
|
363 |
+
" return response.json()\n",
|
364 |
+
" else:\n",
|
365 |
+
" print(f\"Failed to retrieve data. Status code: {response.status_code}\")\n",
|
366 |
+
" return None\n",
|
367 |
+
" except requests.exceptions.RequestException as e:\n",
|
368 |
+
" print(f\"An error occurred: {e}\")\n",
|
369 |
+
" return None\n",
|
370 |
+
"\n",
|
371 |
+
"def extract_file_and_image_info(data):\n",
|
372 |
+
" files = data.get('files', [{}])\n",
|
373 |
+
" model_name = files[0].get('name', None) # get original file name\n",
|
374 |
+
" images = data.get('images', [{}])\n",
|
375 |
+
" image_url = images[0].get('url', None) # get preview: first image\n",
|
376 |
+
" return model_name, image_url\n",
|
377 |
+
"\n",
|
378 |
+
"def generate_preview_filename(model_name, image_url):\n",
|
379 |
+
" file_parts = model_name.split('.')\n",
|
380 |
+
" image_format = image_url.split('.')[-1].split('?')[0]\n",
|
381 |
+
" return f\"{file_parts[0]}.preview.{image_format}\" # assigning the original image format\n",
|
382 |
+
"\n",
|
383 |
"''' main download code '''\n",
|
384 |
"\n",
|
385 |
"def handle_manual(url):\n",
|
|
|
398 |
" extension_repo.append((url, file_name))\n",
|
399 |
"\n",
|
400 |
"def manual_download(url, dst_dir, file_name):\n",
|
|
|
401 |
" header_option = f\"--header={user_header}\"\n",
|
402 |
+
" basename = url.split(\"/\")[-1] if file_name is None else file_name\n",
|
403 |
+
" aria2_args = '--optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c'\n",
|
404 |
"\n",
|
405 |
" print(\"\\033[32m---\"*45 + f\"\\n\\033[33mURL: \\033[34m{url}\\n\\033[33mSAVE DIR: \\033[34m{dst_dir}\\n\\033[33mFILE NAME: \\033[34m{file_name}\\033[32m\\n~~~\\033[0m\")\n",
|
406 |
" # print(url, dst_dir, file_name)\n",
|
407 |
"\n",
|
408 |
+
" # === CivitAi API ===\n",
|
409 |
" civitai_token = \"62c0c5956b2f9defbd844d754000180b\"\n",
|
410 |
" if 'civitai' in url and civitai_token:\n",
|
411 |
+
" model_id = url.split('/')[-1]\n",
|
412 |
+
" data = get_data_from_api(model_id)\n",
|
413 |
" url = f\"{url}?token={civitai_token}\"\n",
|
414 |
"\n",
|
415 |
+
" if data:\n",
|
416 |
+
" model_name, image_url = extract_file_and_image_info(data)\n",
|
417 |
+
" if model_name and image_url:\n",
|
418 |
+
" image_file_name = generate_preview_filename(model_name if not file_name else file_name, image_url)\n",
|
419 |
+
" with capture.capture_output() as cap: # clear shit\n",
|
420 |
+
" !aria2c {aria2_args} -d {dst_dir} -o {image_file_name} {image_url}\n",
|
421 |
+
" del cap\n",
|
422 |
+
" else:\n",
|
423 |
+
" print(\"File name or image URL missing.\")\n",
|
424 |
+
" else:\n",
|
425 |
+
" print(\"Failed to retrieve data from the API.\")\n",
|
426 |
+
"\n",
|
427 |
" # -- GDrive --\n",
|
428 |
" if 'drive.google' in url:\n",
|
429 |
" if 'folders' in url:\n",
|
|
|
433 |
" !gdown \"{url}\" -O {dst_dir}/{file_name} --fuzzy -c\n",
|
434 |
" else:\n",
|
435 |
" !gdown \"{url}\" -O {dst_dir} --fuzzy -c\n",
|
436 |
+
"\n",
|
437 |
+
" # -- Hugging Face --\n",
|
438 |
" elif 'huggingface' in url:\n",
|
439 |
" if '/blob/' in url:\n",
|
440 |
" url = url.replace('/blob/', '/resolve/')\n",
|
441 |
" if file_name:\n",
|
442 |
+
" !aria2c {header_option} {aria2_args} {dst_dir} -o {basename} {url}\n",
|
443 |
" else:\n",
|
444 |
" parsed_link = f'\\n{url}\\n\\tout={unquote(url.split(\"/\")[-1])}'\n",
|
445 |
+
" !echo -e \"{parsed_link}\" | aria2c {header_option} {aria2_args} -d \"{dst_dir}\" -o {basename}\n",
|
446 |
+
"\n",
|
447 |
" # -- Other --\n",
|
448 |
" elif 'http' in url or 'magnet' in url:\n",
|
449 |
" if file_name:\n",
|
450 |
+
" !aria2c {aria2_args} -d {dst_dir} -o {file_name} {url}\n",
|
451 |
" else:\n",
|
452 |
" parsed_link = '\"{}\"'.format(url)\n",
|
453 |
+
" !aria2c {aria2_args} -d {dst_dir} -Z {parsed_link}\n",
|
454 |
"\n",
|
455 |
"def download(url):\n",
|
456 |
" links_and_paths = url.split(',')\n",
|
|
|
470 |
"\n",
|
471 |
"## unpucking zip files\n",
|
472 |
"def unpucking_zip_files():\n",
|
473 |
+
" # directories = [models_dir, vaes_dir, embeddings_dir, loras_dir , extensions_dir, control_dir , adetailer_dir]\n",
|
|
|
474 |
" for directory in directories:\n",
|
475 |
" for root, dirs, files in os.walk(directory):\n",
|
476 |
" for file in files:\n",
|
|
|
607 |
"else:\n",
|
608 |
" if any(not file.endswith('.txt') for file in os.listdir(models_dir)):\n",
|
609 |
" print(\"\\n\\033[33m➤ Models\\033[0m\")\n",
|
610 |
+
" !find {models_dir}/ -mindepth 1 -name '*.safetensors' -printf '%f\\n'\n",
|
611 |
" if any(not file.endswith('.txt') for file in os.listdir(vaes_dir)):\n",
|
612 |
" print(\"\\n\\033[33m➤ VAEs\\033[0m\")\n",
|
613 |
+
" !find {vaes_dir}/ -mindepth 1 -name '*.safetensors' -printf '%f\\n'\n",
|
614 |
" if any(not file.endswith('.txt') and not os.path.isdir(os.path.join(embeddings_dir, file)) for file in os.listdir(embeddings_dir)):\n",
|
615 |
" print(\"\\n\\033[33m➤ Embeddings\\033[0m\")\n",
|
616 |
+
" !find {embeddings_dir}/ -mindepth 1 -maxdepth 1 \\( -name '*.pt' -or -name '*.safetensors' \\) -printf '%f\\n'\n",
|
617 |
" if any(not file.endswith('.txt') for file in os.listdir(loras_dir)):\n",
|
618 |
" print(\"\\n\\033[33m➤ LoRAs\\033[0m\")\n",
|
619 |
+
" !find {loras_dir}/ -mindepth 1 -name '*.safetensors' -printf '%f\\n'\n",
|
620 |
" print(f\"\\n\\033[33m➤ Extensions\\033[0m\")\n",
|
621 |
+
" !find {extensions_dir}/ -mindepth 1 -maxdepth 1 ! -name '*.txt' -printf '%f\\n'\n",
|
622 |
" if any(not file.endswith(('.txt', '.yaml')) for file in os.listdir(control_dir)):\n",
|
623 |
" print(\"\\n\\033[33m➤ ControlNet\\033[0m\")\n",
|
624 |
+
" !find {control_dir}/ -mindepth 1 ! -name '*.yaml' -printf '%f\\n' | sed 's/^[^_]*_[^_]*_[^_]*_\\([^_]*\\)_fp16\\.safetensors$/\\1/'\n",
|
625 |
"\n",
|
626 |
"\n",
|
627 |
"# === OTHER ===\n",
|
files_cells/notebooks/ru/downloading_ru.ipynb
CHANGED
@@ -344,12 +344,42 @@
|
|
344 |
" \"adetailer\": adetailer_dir\n",
|
345 |
"}\n",
|
346 |
"\n",
|
347 |
-
"!mkdir -p {models_dir} {vaes_dir} {loras_dir} {embeddings_dir} {extensions_dir} {control_dir} {adetailer_dir}\n",
|
|
|
|
|
348 |
"\n",
|
349 |
"url = \"\"\n",
|
350 |
"hf_token = optional_huggingface_token if optional_huggingface_token else \"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\"\n",
|
351 |
"user_header = f\"\\\"Authorization: Bearer {hf_token}\\\"\"\n",
|
352 |
"\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
353 |
"''' main download code '''\n",
|
354 |
"\n",
|
355 |
"def handle_manual(url):\n",
|
@@ -368,17 +398,32 @@
|
|
368 |
" extension_repo.append((url, file_name))\n",
|
369 |
"\n",
|
370 |
"def manual_download(url, dst_dir, file_name):\n",
|
371 |
-
" basename = url.split(\"/\")[-1] if file_name is None else file_name\n",
|
372 |
" header_option = f\"--header={user_header}\"\n",
|
|
|
|
|
373 |
"\n",
|
374 |
" print(\"\\033[32m---\"*45 + f\"\\n\\033[33mURL: \\033[34m{url}\\n\\033[33mSAVE DIR: \\033[34m{dst_dir}\\n\\033[33mFILE NAME: \\033[34m{file_name}\\033[32m\\n~~~\\033[0m\")\n",
|
375 |
" # print(url, dst_dir, file_name)\n",
|
376 |
"\n",
|
377 |
-
" #
|
378 |
" civitai_token = \"62c0c5956b2f9defbd844d754000180b\"\n",
|
379 |
" if 'civitai' in url and civitai_token:\n",
|
|
|
|
|
380 |
" url = f\"{url}?token={civitai_token}\"\n",
|
381 |
"\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
382 |
" # -- GDrive --\n",
|
383 |
" if 'drive.google' in url:\n",
|
384 |
" if 'folders' in url:\n",
|
@@ -388,22 +433,24 @@
|
|
388 |
" !gdown \"{url}\" -O {dst_dir}/{file_name} --fuzzy -c\n",
|
389 |
" else:\n",
|
390 |
" !gdown \"{url}\" -O {dst_dir} --fuzzy -c\n",
|
391 |
-
"
|
|
|
392 |
" elif 'huggingface' in url:\n",
|
393 |
" if '/blob/' in url:\n",
|
394 |
" url = url.replace('/blob/', '/resolve/')\n",
|
395 |
" if file_name:\n",
|
396 |
-
" !aria2c {header_option}
|
397 |
" else:\n",
|
398 |
" parsed_link = f'\\n{url}\\n\\tout={unquote(url.split(\"/\")[-1])}'\n",
|
399 |
-
" !echo -e \"{parsed_link}\" | aria2c {header_option}
|
|
|
400 |
" # -- Other --\n",
|
401 |
" elif 'http' in url or 'magnet' in url:\n",
|
402 |
" if file_name:\n",
|
403 |
-
" !aria2c
|
404 |
" else:\n",
|
405 |
" parsed_link = '\"{}\"'.format(url)\n",
|
406 |
-
" !aria2c
|
407 |
"\n",
|
408 |
"def download(url):\n",
|
409 |
" links_and_paths = url.split(',')\n",
|
@@ -423,8 +470,7 @@
|
|
423 |
"\n",
|
424 |
"## unpucking zip files\n",
|
425 |
"def unpucking_zip_files():\n",
|
426 |
-
" directories = [models_dir, vaes_dir, embeddings_dir, loras_dir , extensions_dir, control_dir , adetailer_dir]\n",
|
427 |
-
"\n",
|
428 |
" for directory in directories:\n",
|
429 |
" for root, dirs, files in os.walk(directory):\n",
|
430 |
" for file in files:\n",
|
@@ -561,21 +607,21 @@
|
|
561 |
"else:\n",
|
562 |
" if any(not file.endswith('.txt') for file in os.listdir(models_dir)):\n",
|
563 |
" print(\"\\n\\033[33m➤ Models\\033[0m\")\n",
|
564 |
-
"
|
565 |
" if any(not file.endswith('.txt') for file in os.listdir(vaes_dir)):\n",
|
566 |
" print(\"\\n\\033[33m➤ VAEs\\033[0m\")\n",
|
567 |
-
"
|
568 |
" if any(not file.endswith('.txt') and not os.path.isdir(os.path.join(embeddings_dir, file)) for file in os.listdir(embeddings_dir)):\n",
|
569 |
" print(\"\\n\\033[33m➤ Embeddings\\033[0m\")\n",
|
570 |
-
"
|
571 |
" if any(not file.endswith('.txt') for file in os.listdir(loras_dir)):\n",
|
572 |
" print(\"\\n\\033[33m➤ LoRAs\\033[0m\")\n",
|
573 |
-
"
|
574 |
" print(f\"\\n\\033[33m➤ Extensions\\033[0m\")\n",
|
575 |
-
"
|
576 |
" if any(not file.endswith(('.txt', '.yaml')) for file in os.listdir(control_dir)):\n",
|
577 |
" print(\"\\n\\033[33m➤ ControlNet\\033[0m\")\n",
|
578 |
-
"
|
579 |
"\n",
|
580 |
"\n",
|
581 |
"# === OTHER ===\n",
|
|
|
344 |
" \"adetailer\": adetailer_dir\n",
|
345 |
"}\n",
|
346 |
"\n",
|
347 |
+
"# !mkdir -p {models_dir} {vaes_dir} {loras_dir} {embeddings_dir} {extensions_dir} {control_dir} {adetailer_dir}\n",
|
348 |
+
"directories = [value for key, value in prefixes.items()] # for unpucking zip files\n",
|
349 |
+
"!mkdir -p {\" \".join(directories)}\n",
|
350 |
"\n",
|
351 |
"url = \"\"\n",
|
352 |
"hf_token = optional_huggingface_token if optional_huggingface_token else \"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\"\n",
|
353 |
"user_header = f\"\\\"Authorization: Bearer {hf_token}\\\"\"\n",
|
354 |
"\n",
|
355 |
+
"''' Get Image Preview | CivitAi '''\n",
|
356 |
+
"\n",
|
357 |
+
"def get_data_from_api(model_id): # get model data\n",
|
358 |
+
" base_url = f\"https://civitai.com/api/v1/model-versions/{model_id}\"\n",
|
359 |
+
" headers = {\"Content-Type\": \"application/json\"}\n",
|
360 |
+
" try:\n",
|
361 |
+
" response = requests.get(base_url, headers=headers)\n",
|
362 |
+
" if response.status_code == 200:\n",
|
363 |
+
" return response.json()\n",
|
364 |
+
" else:\n",
|
365 |
+
" print(f\"Failed to retrieve data. Status code: {response.status_code}\")\n",
|
366 |
+
" return None\n",
|
367 |
+
" except requests.exceptions.RequestException as e:\n",
|
368 |
+
" print(f\"An error occurred: {e}\")\n",
|
369 |
+
" return None\n",
|
370 |
+
"\n",
|
371 |
+
"def extract_file_and_image_info(data):\n",
|
372 |
+
" files = data.get('files', [{}])\n",
|
373 |
+
" model_name = files[0].get('name', None) # get original file name\n",
|
374 |
+
" images = data.get('images', [{}])\n",
|
375 |
+
" image_url = images[0].get('url', None) # get preview: first image\n",
|
376 |
+
" return model_name, image_url\n",
|
377 |
+
"\n",
|
378 |
+
"def generate_preview_filename(model_name, image_url):\n",
|
379 |
+
" file_parts = model_name.split('.')\n",
|
380 |
+
" image_format = image_url.split('.')[-1].split('?')[0]\n",
|
381 |
+
" return f\"{file_parts[0]}.preview.{image_format}\" # assigning the original image format\n",
|
382 |
+
"\n",
|
383 |
"''' main download code '''\n",
|
384 |
"\n",
|
385 |
"def handle_manual(url):\n",
|
|
|
398 |
" extension_repo.append((url, file_name))\n",
|
399 |
"\n",
|
400 |
"def manual_download(url, dst_dir, file_name):\n",
|
|
|
401 |
" header_option = f\"--header={user_header}\"\n",
|
402 |
+
" basename = url.split(\"/\")[-1] if file_name is None else file_name\n",
|
403 |
+
" aria2_args = '--optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c'\n",
|
404 |
"\n",
|
405 |
" print(\"\\033[32m---\"*45 + f\"\\n\\033[33mURL: \\033[34m{url}\\n\\033[33mSAVE DIR: \\033[34m{dst_dir}\\n\\033[33mFILE NAME: \\033[34m{file_name}\\033[32m\\n~~~\\033[0m\")\n",
|
406 |
" # print(url, dst_dir, file_name)\n",
|
407 |
"\n",
|
408 |
+
" # === CivitAi API ===\n",
|
409 |
" civitai_token = \"62c0c5956b2f9defbd844d754000180b\"\n",
|
410 |
" if 'civitai' in url and civitai_token:\n",
|
411 |
+
" model_id = url.split('/')[-1]\n",
|
412 |
+
" data = get_data_from_api(model_id)\n",
|
413 |
" url = f\"{url}?token={civitai_token}\"\n",
|
414 |
"\n",
|
415 |
+
" if data:\n",
|
416 |
+
" model_name, image_url = extract_file_and_image_info(data)\n",
|
417 |
+
" if model_name and image_url:\n",
|
418 |
+
" image_file_name = generate_preview_filename(model_name if not file_name else file_name, image_url)\n",
|
419 |
+
" with capture.capture_output() as cap: # clear shit\n",
|
420 |
+
" !aria2c {aria2_args} -d {dst_dir} -o {image_file_name} {image_url}\n",
|
421 |
+
" del cap\n",
|
422 |
+
" else:\n",
|
423 |
+
" print(\"File name or image URL missing.\")\n",
|
424 |
+
" else:\n",
|
425 |
+
" print(\"Failed to retrieve data from the API.\")\n",
|
426 |
+
"\n",
|
427 |
" # -- GDrive --\n",
|
428 |
" if 'drive.google' in url:\n",
|
429 |
" if 'folders' in url:\n",
|
|
|
433 |
" !gdown \"{url}\" -O {dst_dir}/{file_name} --fuzzy -c\n",
|
434 |
" else:\n",
|
435 |
" !gdown \"{url}\" -O {dst_dir} --fuzzy -c\n",
|
436 |
+
"\n",
|
437 |
+
" # -- Hugging Face --\n",
|
438 |
" elif 'huggingface' in url:\n",
|
439 |
" if '/blob/' in url:\n",
|
440 |
" url = url.replace('/blob/', '/resolve/')\n",
|
441 |
" if file_name:\n",
|
442 |
+
" !aria2c {header_option} {aria2_args} {dst_dir} -o {basename} {url}\n",
|
443 |
" else:\n",
|
444 |
" parsed_link = f'\\n{url}\\n\\tout={unquote(url.split(\"/\")[-1])}'\n",
|
445 |
+
" !echo -e \"{parsed_link}\" | aria2c {header_option} {aria2_args} -d \"{dst_dir}\" -o {basename}\n",
|
446 |
+
"\n",
|
447 |
" # -- Other --\n",
|
448 |
" elif 'http' in url or 'magnet' in url:\n",
|
449 |
" if file_name:\n",
|
450 |
+
" !aria2c {aria2_args} -d {dst_dir} -o {file_name} {url}\n",
|
451 |
" else:\n",
|
452 |
" parsed_link = '\"{}\"'.format(url)\n",
|
453 |
+
" !aria2c {aria2_args} -d {dst_dir} -Z {parsed_link}\n",
|
454 |
"\n",
|
455 |
"def download(url):\n",
|
456 |
" links_and_paths = url.split(',')\n",
|
|
|
470 |
"\n",
|
471 |
"## unpucking zip files\n",
|
472 |
"def unpucking_zip_files():\n",
|
473 |
+
" # directories = [models_dir, vaes_dir, embeddings_dir, loras_dir , extensions_dir, control_dir , adetailer_dir]\n",
|
|
|
474 |
" for directory in directories:\n",
|
475 |
" for root, dirs, files in os.walk(directory):\n",
|
476 |
" for file in files:\n",
|
|
|
607 |
"else:\n",
|
608 |
" if any(not file.endswith('.txt') for file in os.listdir(models_dir)):\n",
|
609 |
" print(\"\\n\\033[33m➤ Models\\033[0m\")\n",
|
610 |
+
" !find {models_dir}/ -mindepth 1 -name '*.safetensors' -printf '%f\\n'\n",
|
611 |
" if any(not file.endswith('.txt') for file in os.listdir(vaes_dir)):\n",
|
612 |
" print(\"\\n\\033[33m➤ VAEs\\033[0m\")\n",
|
613 |
+
" !find {vaes_dir}/ -mindepth 1 -name '*.safetensors' -printf '%f\\n'\n",
|
614 |
" if any(not file.endswith('.txt') and not os.path.isdir(os.path.join(embeddings_dir, file)) for file in os.listdir(embeddings_dir)):\n",
|
615 |
" print(\"\\n\\033[33m➤ Embeddings\\033[0m\")\n",
|
616 |
+
" !find {embeddings_dir}/ -mindepth 1 -maxdepth 1 \\( -name '*.pt' -or -name '*.safetensors' \\) -printf '%f\\n'\n",
|
617 |
" if any(not file.endswith('.txt') for file in os.listdir(loras_dir)):\n",
|
618 |
" print(\"\\n\\033[33m➤ LoRAs\\033[0m\")\n",
|
619 |
+
" !find {loras_dir}/ -mindepth 1 -name '*.safetensors' -printf '%f\\n'\n",
|
620 |
" print(f\"\\n\\033[33m➤ Extensions\\033[0m\")\n",
|
621 |
+
" !find {extensions_dir}/ -mindepth 1 -maxdepth 1 ! -name '*.txt' -printf '%f\\n'\n",
|
622 |
" if any(not file.endswith(('.txt', '.yaml')) for file in os.listdir(control_dir)):\n",
|
623 |
" print(\"\\n\\033[33m➤ ControlNet\\033[0m\")\n",
|
624 |
+
" !find {control_dir}/ -mindepth 1 ! -name '*.yaml' -printf '%f\\n' | sed 's/^[^_]*_[^_]*_[^_]*_\\([^_]*\\)_fp16\\.safetensors$/\\1/'\n",
|
625 |
"\n",
|
626 |
"\n",
|
627 |
"# === OTHER ===\n",
|
files_cells/python/en/downloading_en.py
CHANGED
@@ -325,12 +325,42 @@ prefixes = {
|
|
325 |
"adetailer": adetailer_dir
|
326 |
}
|
327 |
|
328 |
-
|
|
|
|
|
329 |
|
330 |
url = ""
|
331 |
hf_token = optional_huggingface_token if optional_huggingface_token else "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"
|
332 |
user_header = f"\"Authorization: Bearer {hf_token}\""
|
333 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
334 |
''' main download code '''
|
335 |
|
336 |
def handle_manual(url):
|
@@ -349,17 +379,32 @@ def handle_manual(url):
|
|
349 |
extension_repo.append((url, file_name))
|
350 |
|
351 |
def manual_download(url, dst_dir, file_name):
|
352 |
-
basename = url.split("/")[-1] if file_name is None else file_name
|
353 |
header_option = f"--header={user_header}"
|
|
|
|
|
354 |
|
355 |
print("\033[32m---"*45 + f"\n\033[33mURL: \033[34m{url}\n\033[33mSAVE DIR: \033[34m{dst_dir}\n\033[33mFILE NAME: \033[34m{file_name}\033[32m\n~~~\033[0m")
|
356 |
# print(url, dst_dir, file_name)
|
357 |
|
358 |
-
#
|
359 |
civitai_token = "62c0c5956b2f9defbd844d754000180b"
|
360 |
if 'civitai' in url and civitai_token:
|
|
|
|
|
361 |
url = f"{url}?token={civitai_token}"
|
362 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
363 |
# -- GDrive --
|
364 |
if 'drive.google' in url:
|
365 |
if 'folders' in url:
|
@@ -369,22 +414,24 @@ def manual_download(url, dst_dir, file_name):
|
|
369 |
get_ipython().system('gdown "{url}" -O {dst_dir}/{file_name} --fuzzy -c')
|
370 |
else:
|
371 |
get_ipython().system('gdown "{url}" -O {dst_dir} --fuzzy -c')
|
372 |
-
|
|
|
373 |
elif 'huggingface' in url:
|
374 |
if '/blob/' in url:
|
375 |
url = url.replace('/blob/', '/resolve/')
|
376 |
if file_name:
|
377 |
-
get_ipython().system('aria2c {header_option}
|
378 |
else:
|
379 |
parsed_link = f'\n{url}\n\tout={unquote(url.split("/")[-1])}'
|
380 |
-
get_ipython().system('echo -e "{parsed_link}" | aria2c {header_option}
|
|
|
381 |
# -- Other --
|
382 |
elif 'http' in url or 'magnet' in url:
|
383 |
if file_name:
|
384 |
-
get_ipython().system('aria2c
|
385 |
else:
|
386 |
parsed_link = '"{}"'.format(url)
|
387 |
-
get_ipython().system('aria2c
|
388 |
|
389 |
def download(url):
|
390 |
links_and_paths = url.split(',')
|
@@ -404,8 +451,7 @@ def download(url):
|
|
404 |
|
405 |
## unpucking zip files
|
406 |
def unpucking_zip_files():
|
407 |
-
directories = [models_dir, vaes_dir, embeddings_dir, loras_dir , extensions_dir, control_dir , adetailer_dir]
|
408 |
-
|
409 |
for directory in directories:
|
410 |
for root, dirs, files in os.walk(directory):
|
411 |
for file in files:
|
@@ -539,21 +585,21 @@ if detailed_download == "off":
|
|
539 |
else:
|
540 |
if any(not file.endswith('.txt') for file in os.listdir(models_dir)):
|
541 |
print("\n\033[33m➤ Models\033[0m")
|
542 |
-
get_ipython().system("find {models_dir}/ -mindepth 1
|
543 |
if any(not file.endswith('.txt') for file in os.listdir(vaes_dir)):
|
544 |
print("\n\033[33m➤ VAEs\033[0m")
|
545 |
-
get_ipython().system("find {vaes_dir}/ -mindepth 1
|
546 |
if any(not file.endswith('.txt') and not os.path.isdir(os.path.join(embeddings_dir, file)) for file in os.listdir(embeddings_dir)):
|
547 |
print("\n\033[33m➤ Embeddings\033[0m")
|
548 |
get_ipython().system("find {embeddings_dir}/ -mindepth 1 -maxdepth 1 \\( -name '*.pt' -or -name '*.safetensors' \\) -printf '%f\\n'")
|
549 |
if any(not file.endswith('.txt') for file in os.listdir(loras_dir)):
|
550 |
print("\n\033[33m➤ LoRAs\033[0m")
|
551 |
-
get_ipython().system("find {loras_dir}/ -mindepth 1
|
552 |
print(f"\n\033[33m➤ Extensions\033[0m")
|
553 |
get_ipython().system("find {extensions_dir}/ -mindepth 1 -maxdepth 1 ! -name '*.txt' -printf '%f\\n'")
|
554 |
if any(not file.endswith(('.txt', '.yaml')) for file in os.listdir(control_dir)):
|
555 |
print("\n\033[33m➤ ControlNet\033[0m")
|
556 |
-
get_ipython().system("find {control_dir}/ -mindepth 1 ! -name '*.yaml' -printf '%f\\n' | sed 's/^[^_]*_[^_]*_[^_]*_\\(
|
557 |
|
558 |
|
559 |
# === OTHER ===
|
|
|
325 |
"adetailer": adetailer_dir
|
326 |
}
|
327 |
|
328 |
+
# !mkdir -p {models_dir} {vaes_dir} {loras_dir} {embeddings_dir} {extensions_dir} {control_dir} {adetailer_dir}
|
329 |
+
directories = [value for key, value in prefixes.items()] # for unpucking zip files
|
330 |
+
get_ipython().system('mkdir -p {" ".join(directories)}')
|
331 |
|
332 |
url = ""
|
333 |
hf_token = optional_huggingface_token if optional_huggingface_token else "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"
|
334 |
user_header = f"\"Authorization: Bearer {hf_token}\""
|
335 |
|
336 |
+
''' Get Image Preview | CivitAi '''
|
337 |
+
|
338 |
+
def get_data_from_api(model_id): # get model data
|
339 |
+
base_url = f"https://civitai.com/api/v1/model-versions/{model_id}"
|
340 |
+
headers = {"Content-Type": "application/json"}
|
341 |
+
try:
|
342 |
+
response = requests.get(base_url, headers=headers)
|
343 |
+
if response.status_code == 200:
|
344 |
+
return response.json()
|
345 |
+
else:
|
346 |
+
print(f"Failed to retrieve data. Status code: {response.status_code}")
|
347 |
+
return None
|
348 |
+
except requests.exceptions.RequestException as e:
|
349 |
+
print(f"An error occurred: {e}")
|
350 |
+
return None
|
351 |
+
|
352 |
+
def extract_file_and_image_info(data):
|
353 |
+
files = data.get('files', [{}])
|
354 |
+
model_name = files[0].get('name', None) # get original file name
|
355 |
+
images = data.get('images', [{}])
|
356 |
+
image_url = images[0].get('url', None) # get preview: first image
|
357 |
+
return model_name, image_url
|
358 |
+
|
359 |
+
def generate_preview_filename(model_name, image_url):
|
360 |
+
file_parts = model_name.split('.')
|
361 |
+
image_format = image_url.split('.')[-1].split('?')[0]
|
362 |
+
return f"{file_parts[0]}.preview.{image_format}" # assigning the original image format
|
363 |
+
|
364 |
''' main download code '''
|
365 |
|
366 |
def handle_manual(url):
|
|
|
379 |
extension_repo.append((url, file_name))
|
380 |
|
381 |
def manual_download(url, dst_dir, file_name):
|
|
|
382 |
header_option = f"--header={user_header}"
|
383 |
+
basename = url.split("/")[-1] if file_name is None else file_name
|
384 |
+
aria2_args = '--optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c'
|
385 |
|
386 |
print("\033[32m---"*45 + f"\n\033[33mURL: \033[34m{url}\n\033[33mSAVE DIR: \033[34m{dst_dir}\n\033[33mFILE NAME: \033[34m{file_name}\033[32m\n~~~\033[0m")
|
387 |
# print(url, dst_dir, file_name)
|
388 |
|
389 |
+
# === CivitAi API ===
|
390 |
civitai_token = "62c0c5956b2f9defbd844d754000180b"
|
391 |
if 'civitai' in url and civitai_token:
|
392 |
+
model_id = url.split('/')[-1]
|
393 |
+
data = get_data_from_api(model_id)
|
394 |
url = f"{url}?token={civitai_token}"
|
395 |
|
396 |
+
if data:
|
397 |
+
model_name, image_url = extract_file_and_image_info(data)
|
398 |
+
if model_name and image_url:
|
399 |
+
image_file_name = generate_preview_filename(model_name if not file_name else file_name, image_url)
|
400 |
+
with capture.capture_output() as cap: # clear shit
|
401 |
+
get_ipython().system('aria2c {aria2_args} -d {dst_dir} -o {image_file_name} {image_url}')
|
402 |
+
del cap
|
403 |
+
else:
|
404 |
+
print("File name or image URL missing.")
|
405 |
+
else:
|
406 |
+
print("Failed to retrieve data from the API.")
|
407 |
+
|
408 |
# -- GDrive --
|
409 |
if 'drive.google' in url:
|
410 |
if 'folders' in url:
|
|
|
414 |
get_ipython().system('gdown "{url}" -O {dst_dir}/{file_name} --fuzzy -c')
|
415 |
else:
|
416 |
get_ipython().system('gdown "{url}" -O {dst_dir} --fuzzy -c')
|
417 |
+
|
418 |
+
# -- Hugging Face --
|
419 |
elif 'huggingface' in url:
|
420 |
if '/blob/' in url:
|
421 |
url = url.replace('/blob/', '/resolve/')
|
422 |
if file_name:
|
423 |
+
get_ipython().system('aria2c {header_option} {aria2_args} {dst_dir} -o {basename} {url}')
|
424 |
else:
|
425 |
parsed_link = f'\n{url}\n\tout={unquote(url.split("/")[-1])}'
|
426 |
+
get_ipython().system('echo -e "{parsed_link}" | aria2c {header_option} {aria2_args} -d "{dst_dir}" -o {basename}')
|
427 |
+
|
428 |
# -- Other --
|
429 |
elif 'http' in url or 'magnet' in url:
|
430 |
if file_name:
|
431 |
+
get_ipython().system('aria2c {aria2_args} -d {dst_dir} -o {file_name} {url}')
|
432 |
else:
|
433 |
parsed_link = '"{}"'.format(url)
|
434 |
+
get_ipython().system('aria2c {aria2_args} -d {dst_dir} -Z {parsed_link}')
|
435 |
|
436 |
def download(url):
|
437 |
links_and_paths = url.split(',')
|
|
|
451 |
|
452 |
## unpucking zip files
|
453 |
def unpucking_zip_files():
|
454 |
+
# directories = [models_dir, vaes_dir, embeddings_dir, loras_dir , extensions_dir, control_dir , adetailer_dir]
|
|
|
455 |
for directory in directories:
|
456 |
for root, dirs, files in os.walk(directory):
|
457 |
for file in files:
|
|
|
585 |
else:
|
586 |
if any(not file.endswith('.txt') for file in os.listdir(models_dir)):
|
587 |
print("\n\033[33m➤ Models\033[0m")
|
588 |
+
get_ipython().system("find {models_dir}/ -mindepth 1 -name '*.safetensors' -printf '%f\\n'")
|
589 |
if any(not file.endswith('.txt') for file in os.listdir(vaes_dir)):
|
590 |
print("\n\033[33m➤ VAEs\033[0m")
|
591 |
+
get_ipython().system("find {vaes_dir}/ -mindepth 1 -name '*.safetensors' -printf '%f\\n'")
|
592 |
if any(not file.endswith('.txt') and not os.path.isdir(os.path.join(embeddings_dir, file)) for file in os.listdir(embeddings_dir)):
|
593 |
print("\n\033[33m➤ Embeddings\033[0m")
|
594 |
get_ipython().system("find {embeddings_dir}/ -mindepth 1 -maxdepth 1 \\( -name '*.pt' -or -name '*.safetensors' \\) -printf '%f\\n'")
|
595 |
if any(not file.endswith('.txt') for file in os.listdir(loras_dir)):
|
596 |
print("\n\033[33m➤ LoRAs\033[0m")
|
597 |
+
get_ipython().system("find {loras_dir}/ -mindepth 1 -name '*.safetensors' -printf '%f\\n'")
|
598 |
print(f"\n\033[33m➤ Extensions\033[0m")
|
599 |
get_ipython().system("find {extensions_dir}/ -mindepth 1 -maxdepth 1 ! -name '*.txt' -printf '%f\\n'")
|
600 |
if any(not file.endswith(('.txt', '.yaml')) for file in os.listdir(control_dir)):
|
601 |
print("\n\033[33m➤ ControlNet\033[0m")
|
602 |
+
get_ipython().system("find {control_dir}/ -mindepth 1 ! -name '*.yaml' -printf '%f\\n' | sed 's/^[^_]*_[^_]*_[^_]*_\\([^_]*\\)_fp16\\.safetensors$/\\1/'")
|
603 |
|
604 |
|
605 |
# === OTHER ===
|
files_cells/python/ru/downloading_ru.py
CHANGED
@@ -325,12 +325,42 @@ prefixes = {
|
|
325 |
"adetailer": adetailer_dir
|
326 |
}
|
327 |
|
328 |
-
|
|
|
|
|
329 |
|
330 |
url = ""
|
331 |
hf_token = optional_huggingface_token if optional_huggingface_token else "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"
|
332 |
user_header = f"\"Authorization: Bearer {hf_token}\""
|
333 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
334 |
''' main download code '''
|
335 |
|
336 |
def handle_manual(url):
|
@@ -349,17 +379,32 @@ def handle_manual(url):
|
|
349 |
extension_repo.append((url, file_name))
|
350 |
|
351 |
def manual_download(url, dst_dir, file_name):
|
352 |
-
basename = url.split("/")[-1] if file_name is None else file_name
|
353 |
header_option = f"--header={user_header}"
|
|
|
|
|
354 |
|
355 |
print("\033[32m---"*45 + f"\n\033[33mURL: \033[34m{url}\n\033[33mSAVE DIR: \033[34m{dst_dir}\n\033[33mFILE NAME: \033[34m{file_name}\033[32m\n~~~\033[0m")
|
356 |
# print(url, dst_dir, file_name)
|
357 |
|
358 |
-
#
|
359 |
civitai_token = "62c0c5956b2f9defbd844d754000180b"
|
360 |
if 'civitai' in url and civitai_token:
|
|
|
|
|
361 |
url = f"{url}?token={civitai_token}"
|
362 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
363 |
# -- GDrive --
|
364 |
if 'drive.google' in url:
|
365 |
if 'folders' in url:
|
@@ -369,22 +414,24 @@ def manual_download(url, dst_dir, file_name):
|
|
369 |
get_ipython().system('gdown "{url}" -O {dst_dir}/{file_name} --fuzzy -c')
|
370 |
else:
|
371 |
get_ipython().system('gdown "{url}" -O {dst_dir} --fuzzy -c')
|
372 |
-
|
|
|
373 |
elif 'huggingface' in url:
|
374 |
if '/blob/' in url:
|
375 |
url = url.replace('/blob/', '/resolve/')
|
376 |
if file_name:
|
377 |
-
get_ipython().system('aria2c {header_option}
|
378 |
else:
|
379 |
parsed_link = f'\n{url}\n\tout={unquote(url.split("/")[-1])}'
|
380 |
-
get_ipython().system('echo -e "{parsed_link}" | aria2c {header_option}
|
|
|
381 |
# -- Other --
|
382 |
elif 'http' in url or 'magnet' in url:
|
383 |
if file_name:
|
384 |
-
get_ipython().system('aria2c
|
385 |
else:
|
386 |
parsed_link = '"{}"'.format(url)
|
387 |
-
get_ipython().system('aria2c
|
388 |
|
389 |
def download(url):
|
390 |
links_and_paths = url.split(',')
|
@@ -404,8 +451,7 @@ def download(url):
|
|
404 |
|
405 |
## unpucking zip files
|
406 |
def unpucking_zip_files():
|
407 |
-
directories = [models_dir, vaes_dir, embeddings_dir, loras_dir , extensions_dir, control_dir , adetailer_dir]
|
408 |
-
|
409 |
for directory in directories:
|
410 |
for root, dirs, files in os.walk(directory):
|
411 |
for file in files:
|
@@ -539,21 +585,21 @@ if detailed_download == "off":
|
|
539 |
else:
|
540 |
if any(not file.endswith('.txt') for file in os.listdir(models_dir)):
|
541 |
print("\n\033[33m➤ Models\033[0m")
|
542 |
-
get_ipython().system("find {models_dir}/ -mindepth 1
|
543 |
if any(not file.endswith('.txt') for file in os.listdir(vaes_dir)):
|
544 |
print("\n\033[33m➤ VAEs\033[0m")
|
545 |
-
get_ipython().system("find {vaes_dir}/ -mindepth 1
|
546 |
if any(not file.endswith('.txt') and not os.path.isdir(os.path.join(embeddings_dir, file)) for file in os.listdir(embeddings_dir)):
|
547 |
print("\n\033[33m➤ Embeddings\033[0m")
|
548 |
get_ipython().system("find {embeddings_dir}/ -mindepth 1 -maxdepth 1 \\( -name '*.pt' -or -name '*.safetensors' \\) -printf '%f\\n'")
|
549 |
if any(not file.endswith('.txt') for file in os.listdir(loras_dir)):
|
550 |
print("\n\033[33m➤ LoRAs\033[0m")
|
551 |
-
get_ipython().system("find {loras_dir}/ -mindepth 1
|
552 |
print(f"\n\033[33m➤ Extensions\033[0m")
|
553 |
get_ipython().system("find {extensions_dir}/ -mindepth 1 -maxdepth 1 ! -name '*.txt' -printf '%f\\n'")
|
554 |
if any(not file.endswith(('.txt', '.yaml')) for file in os.listdir(control_dir)):
|
555 |
print("\n\033[33m➤ ControlNet\033[0m")
|
556 |
-
get_ipython().system("find {control_dir}/ -mindepth 1 ! -name '*.yaml' -printf '%f\\n' | sed 's/^[^_]*_[^_]*_[^_]*_\\(
|
557 |
|
558 |
|
559 |
# === OTHER ===
|
|
|
325 |
"adetailer": adetailer_dir
|
326 |
}
|
327 |
|
328 |
+
# !mkdir -p {models_dir} {vaes_dir} {loras_dir} {embeddings_dir} {extensions_dir} {control_dir} {adetailer_dir}
|
329 |
+
directories = [value for key, value in prefixes.items()] # for unpucking zip files
|
330 |
+
get_ipython().system('mkdir -p {" ".join(directories)}')
|
331 |
|
332 |
url = ""
|
333 |
hf_token = optional_huggingface_token if optional_huggingface_token else "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"
|
334 |
user_header = f"\"Authorization: Bearer {hf_token}\""
|
335 |
|
336 |
+
''' Get Image Preview | CivitAi '''
|
337 |
+
|
338 |
+
def get_data_from_api(model_id): # get model data
|
339 |
+
base_url = f"https://civitai.com/api/v1/model-versions/{model_id}"
|
340 |
+
headers = {"Content-Type": "application/json"}
|
341 |
+
try:
|
342 |
+
response = requests.get(base_url, headers=headers)
|
343 |
+
if response.status_code == 200:
|
344 |
+
return response.json()
|
345 |
+
else:
|
346 |
+
print(f"Failed to retrieve data. Status code: {response.status_code}")
|
347 |
+
return None
|
348 |
+
except requests.exceptions.RequestException as e:
|
349 |
+
print(f"An error occurred: {e}")
|
350 |
+
return None
|
351 |
+
|
352 |
+
def extract_file_and_image_info(data):
|
353 |
+
files = data.get('files', [{}])
|
354 |
+
model_name = files[0].get('name', None) # get original file name
|
355 |
+
images = data.get('images', [{}])
|
356 |
+
image_url = images[0].get('url', None) # get preview: first image
|
357 |
+
return model_name, image_url
|
358 |
+
|
359 |
+
def generate_preview_filename(model_name, image_url):
|
360 |
+
file_parts = model_name.split('.')
|
361 |
+
image_format = image_url.split('.')[-1].split('?')[0]
|
362 |
+
return f"{file_parts[0]}.preview.{image_format}" # assigning the original image format
|
363 |
+
|
364 |
''' main download code '''
|
365 |
|
366 |
def handle_manual(url):
|
|
|
379 |
extension_repo.append((url, file_name))
|
380 |
|
381 |
def manual_download(url, dst_dir, file_name):
|
|
|
382 |
header_option = f"--header={user_header}"
|
383 |
+
basename = url.split("/")[-1] if file_name is None else file_name
|
384 |
+
aria2_args = '--optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c'
|
385 |
|
386 |
print("\033[32m---"*45 + f"\n\033[33mURL: \033[34m{url}\n\033[33mSAVE DIR: \033[34m{dst_dir}\n\033[33mFILE NAME: \033[34m{file_name}\033[32m\n~~~\033[0m")
|
387 |
# print(url, dst_dir, file_name)
|
388 |
|
389 |
+
# === CivitAi API ===
|
390 |
civitai_token = "62c0c5956b2f9defbd844d754000180b"
|
391 |
if 'civitai' in url and civitai_token:
|
392 |
+
model_id = url.split('/')[-1]
|
393 |
+
data = get_data_from_api(model_id)
|
394 |
url = f"{url}?token={civitai_token}"
|
395 |
|
396 |
+
if data:
|
397 |
+
model_name, image_url = extract_file_and_image_info(data)
|
398 |
+
if model_name and image_url:
|
399 |
+
image_file_name = generate_preview_filename(model_name if not file_name else file_name, image_url)
|
400 |
+
with capture.capture_output() as cap: # clear shit
|
401 |
+
get_ipython().system('aria2c {aria2_args} -d {dst_dir} -o {image_file_name} {image_url}')
|
402 |
+
del cap
|
403 |
+
else:
|
404 |
+
print("File name or image URL missing.")
|
405 |
+
else:
|
406 |
+
print("Failed to retrieve data from the API.")
|
407 |
+
|
408 |
# -- GDrive --
|
409 |
if 'drive.google' in url:
|
410 |
if 'folders' in url:
|
|
|
414 |
get_ipython().system('gdown "{url}" -O {dst_dir}/{file_name} --fuzzy -c')
|
415 |
else:
|
416 |
get_ipython().system('gdown "{url}" -O {dst_dir} --fuzzy -c')
|
417 |
+
|
418 |
+
# -- Hugging Face --
|
419 |
elif 'huggingface' in url:
|
420 |
if '/blob/' in url:
|
421 |
url = url.replace('/blob/', '/resolve/')
|
422 |
if file_name:
|
423 |
+
get_ipython().system('aria2c {header_option} {aria2_args} {dst_dir} -o {basename} {url}')
|
424 |
else:
|
425 |
parsed_link = f'\n{url}\n\tout={unquote(url.split("/")[-1])}'
|
426 |
+
get_ipython().system('echo -e "{parsed_link}" | aria2c {header_option} {aria2_args} -d "{dst_dir}" -o {basename}')
|
427 |
+
|
428 |
# -- Other --
|
429 |
elif 'http' in url or 'magnet' in url:
|
430 |
if file_name:
|
431 |
+
get_ipython().system('aria2c {aria2_args} -d {dst_dir} -o {file_name} {url}')
|
432 |
else:
|
433 |
parsed_link = '"{}"'.format(url)
|
434 |
+
get_ipython().system('aria2c {aria2_args} -d {dst_dir} -Z {parsed_link}')
|
435 |
|
436 |
def download(url):
|
437 |
links_and_paths = url.split(',')
|
|
|
451 |
|
452 |
## unpucking zip files
|
453 |
def unpucking_zip_files():
|
454 |
+
# directories = [models_dir, vaes_dir, embeddings_dir, loras_dir , extensions_dir, control_dir , adetailer_dir]
|
|
|
455 |
for directory in directories:
|
456 |
for root, dirs, files in os.walk(directory):
|
457 |
for file in files:
|
|
|
585 |
else:
|
586 |
if any(not file.endswith('.txt') for file in os.listdir(models_dir)):
|
587 |
print("\n\033[33m➤ Models\033[0m")
|
588 |
+
get_ipython().system("find {models_dir}/ -mindepth 1 -name '*.safetensors' -printf '%f\\n'")
|
589 |
if any(not file.endswith('.txt') for file in os.listdir(vaes_dir)):
|
590 |
print("\n\033[33m➤ VAEs\033[0m")
|
591 |
+
get_ipython().system("find {vaes_dir}/ -mindepth 1 -name '*.safetensors' -printf '%f\\n'")
|
592 |
if any(not file.endswith('.txt') and not os.path.isdir(os.path.join(embeddings_dir, file)) for file in os.listdir(embeddings_dir)):
|
593 |
print("\n\033[33m➤ Embeddings\033[0m")
|
594 |
get_ipython().system("find {embeddings_dir}/ -mindepth 1 -maxdepth 1 \\( -name '*.pt' -or -name '*.safetensors' \\) -printf '%f\\n'")
|
595 |
if any(not file.endswith('.txt') for file in os.listdir(loras_dir)):
|
596 |
print("\n\033[33m➤ LoRAs\033[0m")
|
597 |
+
get_ipython().system("find {loras_dir}/ -mindepth 1 -name '*.safetensors' -printf '%f\\n'")
|
598 |
print(f"\n\033[33m➤ Extensions\033[0m")
|
599 |
get_ipython().system("find {extensions_dir}/ -mindepth 1 -maxdepth 1 ! -name '*.txt' -printf '%f\\n'")
|
600 |
if any(not file.endswith(('.txt', '.yaml')) for file in os.listdir(control_dir)):
|
601 |
print("\n\033[33m➤ ControlNet\033[0m")
|
602 |
+
get_ipython().system("find {control_dir}/ -mindepth 1 ! -name '*.yaml' -printf '%f\\n' | sed 's/^[^_]*_[^_]*_[^_]*_\\([^_]*\\)_fp16\\.safetensors$/\\1/'")
|
603 |
|
604 |
|
605 |
# === OTHER ===
|