fix dl files civitai with params | 1
Browse files- files_cells/notebooks/en/downloading_en.ipynb +24 -29
- files_cells/notebooks/en/widgets_en.ipynb +1 -1
- files_cells/notebooks/ru/downloading_ru.ipynb +24 -29
- files_cells/notebooks/ru/widgets_ru.ipynb +4 -4
- files_cells/python/en/downloading_en.py +24 -29
- files_cells/python/en/widgets_en.py +1 -1
- files_cells/python/ru/downloading_ru.py +24 -29
- files_cells/python/ru/widgets_ru.py +4 -4
files_cells/notebooks/en/downloading_en.ipynb
CHANGED
|
@@ -333,7 +333,7 @@
|
|
| 333 |
" ]\n",
|
| 334 |
"}\n",
|
| 335 |
"\n",
|
| 336 |
-
"
|
| 337 |
"prefixes = {\n",
|
| 338 |
" \"model\": models_dir,\n",
|
| 339 |
" \"vae\": vaes_dir,\n",
|
|
@@ -344,11 +344,10 @@
|
|
| 344 |
" \"adetailer\": adetailer_dir\n",
|
| 345 |
"}\n",
|
| 346 |
"\n",
|
| 347 |
-
"
|
| 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",
|
|
@@ -361,23 +360,20 @@
|
|
| 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 |
-
"
|
| 373 |
-
"
|
| 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):\n",
|
| 379 |
-
"
|
| 380 |
-
"
|
|
|
|
|
|
|
| 381 |
"\n",
|
| 382 |
"''' main download code '''\n",
|
| 383 |
"\n",
|
|
@@ -401,27 +397,26 @@
|
|
| 401 |
" basename = url.split(\"/\")[-1] if file_name is None else file_name\n",
|
| 402 |
" aria2_args = '--optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c'\n",
|
| 403 |
"\n",
|
| 404 |
-
" print(\"\\033[32m
|
| 405 |
" # print(url, dst_dir, file_name)\n",
|
| 406 |
"\n",
|
| 407 |
" # === CivitAi API ===\n",
|
| 408 |
" civitai_token = \"62c0c5956b2f9defbd844d754000180b\"\n",
|
| 409 |
-
" if 'civitai' in url
|
| 410 |
" model_id = url.split('/')[-1]\n",
|
| 411 |
-
"
|
| 412 |
-
"
|
| 413 |
-
"\n",
|
| 414 |
-
"
|
| 415 |
-
"
|
| 416 |
-
"
|
| 417 |
-
"
|
| 418 |
-
"
|
| 419 |
-
"
|
| 420 |
-
"
|
|
|
|
| 421 |
" else:\n",
|
| 422 |
-
" print(\"
|
| 423 |
-
" else:\n",
|
| 424 |
-
" print(\"Failed to retrieve data from the API.\")\n",
|
| 425 |
"\n",
|
| 426 |
" # -- GDrive --\n",
|
| 427 |
" if 'drive.google' in url:\n",
|
|
@@ -465,7 +460,7 @@
|
|
| 465 |
"\n",
|
| 466 |
"## unpucking zip files\n",
|
| 467 |
"def unpucking_zip_files():\n",
|
| 468 |
-
" # directories
|
| 469 |
" for directory in directories:\n",
|
| 470 |
" for root, dirs, files in os.walk(directory):\n",
|
| 471 |
" for file in files:\n",
|
|
|
|
| 333 |
" ]\n",
|
| 334 |
"}\n",
|
| 335 |
"\n",
|
| 336 |
+
"url = \"\"\n",
|
| 337 |
"prefixes = {\n",
|
| 338 |
" \"model\": models_dir,\n",
|
| 339 |
" \"vae\": vaes_dir,\n",
|
|
|
|
| 344 |
" \"adetailer\": adetailer_dir\n",
|
| 345 |
"}\n",
|
| 346 |
"\n",
|
| 347 |
+
"extension_repo = []\n",
|
| 348 |
"directories = [value for key, value in prefixes.items()] # for unpucking zip files\n",
|
| 349 |
"!mkdir -p {\" \".join(directories)}\n",
|
| 350 |
"\n",
|
|
|
|
| 351 |
"hf_token = optional_huggingface_token if optional_huggingface_token else \"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\"\n",
|
| 352 |
"user_header = f\"\\\"Authorization: Bearer {hf_token}\\\"\"\n",
|
| 353 |
"\n",
|
|
|
|
| 360 |
" response = requests.get(base_url, headers=headers)\n",
|
| 361 |
" if response.status_code == 200:\n",
|
| 362 |
" return response.json()\n",
|
|
|
|
|
|
|
|
|
|
| 363 |
" except requests.exceptions.RequestException as e:\n",
|
| 364 |
" print(f\"An error occurred: {e}\")\n",
|
| 365 |
" return None\n",
|
| 366 |
"\n",
|
| 367 |
"def extract_file_and_image_info(data):\n",
|
| 368 |
+
" model_name = data['files'][0]['name'] # get original model file name\n",
|
| 369 |
+
" image_url = data['images'][0]['url'] # get preview: first image\n",
|
|
|
|
|
|
|
| 370 |
" return model_name, image_url\n",
|
| 371 |
"\n",
|
| 372 |
+
"def generate_preview_filename(model_name, image_url):\n",
|
| 373 |
+
" name = model_name.split('.')\n",
|
| 374 |
+
" img_ext = image_url.split('.')\n",
|
| 375 |
+
" print(f\"\\n\\033[31m[Preview DL]\\033[0m: {name[0]}.preview.{img_ext[-1]}\")\n",
|
| 376 |
+
" return f\"{name[0]}.preview.{img_ext[-1]}\" # assigning the original image format\n",
|
| 377 |
"\n",
|
| 378 |
"''' main download code '''\n",
|
| 379 |
"\n",
|
|
|
|
| 397 |
" basename = url.split(\"/\")[-1] if file_name is None else file_name\n",
|
| 398 |
" aria2_args = '--optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c'\n",
|
| 399 |
"\n",
|
| 400 |
+
" print(f\"\\n\\033[32m{'---'*45}\\n\\033[33mURL: \\033[34m{url}\\n\\033[33mSAVE DIR: \\033[34m{dst_dir}\\n\\033[33mFILE NAME: \\033[34m{file_name}033[0m\")\n",
|
| 401 |
" # print(url, dst_dir, file_name)\n",
|
| 402 |
"\n",
|
| 403 |
" # === CivitAi API ===\n",
|
| 404 |
" civitai_token = \"62c0c5956b2f9defbd844d754000180b\"\n",
|
| 405 |
+
" if 'civitai' in url:\n",
|
| 406 |
" model_id = url.split('/')[-1]\n",
|
| 407 |
+
" url = f\"{url}&token={civitai_token}\" if '?' in url else f\"{url}?token={civitai_token}\"\n",
|
| 408 |
+
"\n",
|
| 409 |
+
" if dst_dir not in [vaes_dir, control_dir, adetailer_dir]: # filter\n",
|
| 410 |
+
" data = get_data_from_api(model_id, civitai_token)\n",
|
| 411 |
+
" if data:\n",
|
| 412 |
+
" model_name, image_url = extract_file_and_image_info(data)\n",
|
| 413 |
+
" if model_name and image_url:\n",
|
| 414 |
+
" image_file_name = generate_preview_filename(model_name if not file_name else file_name, image_url)\n",
|
| 415 |
+
" with capture.capture_output() as cap: # clear shit\n",
|
| 416 |
+
" !aria2c {aria2_args} -d {dst_dir} -o {image_file_name} {image_url}\n",
|
| 417 |
+
" del cap\n",
|
| 418 |
" else:\n",
|
| 419 |
+
" print(\"\\033[31m[Preview DL]\\033[0m: Failed to retrieve data from the API.\")\n",
|
|
|
|
|
|
|
| 420 |
"\n",
|
| 421 |
" # -- GDrive --\n",
|
| 422 |
" if 'drive.google' in url:\n",
|
|
|
|
| 460 |
"\n",
|
| 461 |
"## unpucking zip files\n",
|
| 462 |
"def unpucking_zip_files():\n",
|
| 463 |
+
" # directories - above\n",
|
| 464 |
" for directory in directories:\n",
|
| 465 |
" for root, dirs, files in os.walk(directory):\n",
|
| 466 |
" for file in files:\n",
|
files_cells/notebooks/en/widgets_en.ipynb
CHANGED
|
@@ -485,7 +485,7 @@
|
|
| 485 |
"display(all_model_box)\n",
|
| 486 |
"\n",
|
| 487 |
"# --- VAE ---\n",
|
| 488 |
-
"vae_header = widgets.HTML('<div class=\"header\"
|
| 489 |
"vae_options = ['none',\n",
|
| 490 |
" '1.Anime.vae',\n",
|
| 491 |
" '2.Anything.vae',\n",
|
|
|
|
| 485 |
"display(all_model_box)\n",
|
| 486 |
"\n",
|
| 487 |
"# --- VAE ---\n",
|
| 488 |
+
"vae_header = widgets.HTML('<div class=\"header\">VAE Selection</div>')\n",
|
| 489 |
"vae_options = ['none',\n",
|
| 490 |
" '1.Anime.vae',\n",
|
| 491 |
" '2.Anything.vae',\n",
|
files_cells/notebooks/ru/downloading_ru.ipynb
CHANGED
|
@@ -333,7 +333,7 @@
|
|
| 333 |
" ]\n",
|
| 334 |
"}\n",
|
| 335 |
"\n",
|
| 336 |
-
"
|
| 337 |
"prefixes = {\n",
|
| 338 |
" \"model\": models_dir,\n",
|
| 339 |
" \"vae\": vaes_dir,\n",
|
|
@@ -344,11 +344,10 @@
|
|
| 344 |
" \"adetailer\": adetailer_dir\n",
|
| 345 |
"}\n",
|
| 346 |
"\n",
|
| 347 |
-
"
|
| 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",
|
|
@@ -361,23 +360,20 @@
|
|
| 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 |
-
"
|
| 373 |
-
"
|
| 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):\n",
|
| 379 |
-
"
|
| 380 |
-
"
|
|
|
|
|
|
|
| 381 |
"\n",
|
| 382 |
"''' main download code '''\n",
|
| 383 |
"\n",
|
|
@@ -401,27 +397,26 @@
|
|
| 401 |
" basename = url.split(\"/\")[-1] if file_name is None else file_name\n",
|
| 402 |
" aria2_args = '--optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c'\n",
|
| 403 |
"\n",
|
| 404 |
-
" print(\"\\033[32m
|
| 405 |
" # print(url, dst_dir, file_name)\n",
|
| 406 |
"\n",
|
| 407 |
" # === CivitAi API ===\n",
|
| 408 |
" civitai_token = \"62c0c5956b2f9defbd844d754000180b\"\n",
|
| 409 |
-
" if 'civitai' in url
|
| 410 |
" model_id = url.split('/')[-1]\n",
|
| 411 |
-
"
|
| 412 |
-
"
|
| 413 |
-
"\n",
|
| 414 |
-
"
|
| 415 |
-
"
|
| 416 |
-
"
|
| 417 |
-
"
|
| 418 |
-
"
|
| 419 |
-
"
|
| 420 |
-
"
|
|
|
|
| 421 |
" else:\n",
|
| 422 |
-
" print(\"
|
| 423 |
-
" else:\n",
|
| 424 |
-
" print(\"Failed to retrieve data from the API.\")\n",
|
| 425 |
"\n",
|
| 426 |
" # -- GDrive --\n",
|
| 427 |
" if 'drive.google' in url:\n",
|
|
@@ -465,7 +460,7 @@
|
|
| 465 |
"\n",
|
| 466 |
"## unpucking zip files\n",
|
| 467 |
"def unpucking_zip_files():\n",
|
| 468 |
-
" # directories
|
| 469 |
" for directory in directories:\n",
|
| 470 |
" for root, dirs, files in os.walk(directory):\n",
|
| 471 |
" for file in files:\n",
|
|
|
|
| 333 |
" ]\n",
|
| 334 |
"}\n",
|
| 335 |
"\n",
|
| 336 |
+
"url = \"\"\n",
|
| 337 |
"prefixes = {\n",
|
| 338 |
" \"model\": models_dir,\n",
|
| 339 |
" \"vae\": vaes_dir,\n",
|
|
|
|
| 344 |
" \"adetailer\": adetailer_dir\n",
|
| 345 |
"}\n",
|
| 346 |
"\n",
|
| 347 |
+
"extension_repo = []\n",
|
| 348 |
"directories = [value for key, value in prefixes.items()] # for unpucking zip files\n",
|
| 349 |
"!mkdir -p {\" \".join(directories)}\n",
|
| 350 |
"\n",
|
|
|
|
| 351 |
"hf_token = optional_huggingface_token if optional_huggingface_token else \"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\"\n",
|
| 352 |
"user_header = f\"\\\"Authorization: Bearer {hf_token}\\\"\"\n",
|
| 353 |
"\n",
|
|
|
|
| 360 |
" response = requests.get(base_url, headers=headers)\n",
|
| 361 |
" if response.status_code == 200:\n",
|
| 362 |
" return response.json()\n",
|
|
|
|
|
|
|
|
|
|
| 363 |
" except requests.exceptions.RequestException as e:\n",
|
| 364 |
" print(f\"An error occurred: {e}\")\n",
|
| 365 |
" return None\n",
|
| 366 |
"\n",
|
| 367 |
"def extract_file_and_image_info(data):\n",
|
| 368 |
+
" model_name = data['files'][0]['name'] # get original model file name\n",
|
| 369 |
+
" image_url = data['images'][0]['url'] # get preview: first image\n",
|
|
|
|
|
|
|
| 370 |
" return model_name, image_url\n",
|
| 371 |
"\n",
|
| 372 |
+
"def generate_preview_filename(model_name, image_url):\n",
|
| 373 |
+
" name = model_name.split('.')\n",
|
| 374 |
+
" img_ext = image_url.split('.')\n",
|
| 375 |
+
" print(f\"\\n\\033[31m[Preview DL]\\033[0m: {name[0]}.preview.{img_ext[-1]}\")\n",
|
| 376 |
+
" return f\"{name[0]}.preview.{img_ext[-1]}\" # assigning the original image format\n",
|
| 377 |
"\n",
|
| 378 |
"''' main download code '''\n",
|
| 379 |
"\n",
|
|
|
|
| 397 |
" basename = url.split(\"/\")[-1] if file_name is None else file_name\n",
|
| 398 |
" aria2_args = '--optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c'\n",
|
| 399 |
"\n",
|
| 400 |
+
" print(f\"\\n\\033[32m{'---'*45}\\n\\033[33mURL: \\033[34m{url}\\n\\033[33mSAVE DIR: \\033[34m{dst_dir}\\n\\033[33mFILE NAME: \\033[34m{file_name}033[0m\")\n",
|
| 401 |
" # print(url, dst_dir, file_name)\n",
|
| 402 |
"\n",
|
| 403 |
" # === CivitAi API ===\n",
|
| 404 |
" civitai_token = \"62c0c5956b2f9defbd844d754000180b\"\n",
|
| 405 |
+
" if 'civitai' in url:\n",
|
| 406 |
" model_id = url.split('/')[-1]\n",
|
| 407 |
+
" url = f\"{url}&token={civitai_token}\" if '?' in url else f\"{url}?token={civitai_token}\"\n",
|
| 408 |
+
"\n",
|
| 409 |
+
" if dst_dir not in [vaes_dir, control_dir, adetailer_dir]: # filter\n",
|
| 410 |
+
" data = get_data_from_api(model_id, civitai_token)\n",
|
| 411 |
+
" if data:\n",
|
| 412 |
+
" model_name, image_url = extract_file_and_image_info(data)\n",
|
| 413 |
+
" if model_name and image_url:\n",
|
| 414 |
+
" image_file_name = generate_preview_filename(model_name if not file_name else file_name, image_url)\n",
|
| 415 |
+
" with capture.capture_output() as cap: # clear shit\n",
|
| 416 |
+
" !aria2c {aria2_args} -d {dst_dir} -o {image_file_name} {image_url}\n",
|
| 417 |
+
" del cap\n",
|
| 418 |
" else:\n",
|
| 419 |
+
" print(\"\\033[31m[Preview DL]\\033[0m: Failed to retrieve data from the API.\")\n",
|
|
|
|
|
|
|
| 420 |
"\n",
|
| 421 |
" # -- GDrive --\n",
|
| 422 |
" if 'drive.google' in url:\n",
|
|
|
|
| 460 |
"\n",
|
| 461 |
"## unpucking zip files\n",
|
| 462 |
"def unpucking_zip_files():\n",
|
| 463 |
+
" # directories - above\n",
|
| 464 |
" for directory in directories:\n",
|
| 465 |
" for root, dirs, files in os.walk(directory):\n",
|
| 466 |
" for file in files:\n",
|
files_cells/notebooks/ru/widgets_ru.ipynb
CHANGED
|
@@ -56,7 +56,7 @@
|
|
| 56 |
"parser.add_argument('-y', type=int, help='Y coordinate for the image in px', metavar='', default=0)\n",
|
| 57 |
"parser.add_argument('-x', type=int, help='X coordinate for the image in px', metavar='', default=0)\n",
|
| 58 |
"parser.add_argument('-s', '--scale', type=int, help='Scale image in %%', metavar='', default=100)\n",
|
| 59 |
-
"parser.add_argument('-m', '--mode',action='store_true', help='Removes repetitive image tiles')\n",
|
| 60 |
"parser.add_argument('-t', '--transparent', action='store_true', help='Makes input/selection fields 35%% more transparent')\n",
|
| 61 |
"parser.add_argument('-bf', '--blur-fields', type=str, help='Background blur level for input/selection fields', metavar='', default=2)\n",
|
| 62 |
"args = parser.parse_args()\n",
|
|
@@ -485,7 +485,7 @@
|
|
| 485 |
"display(all_model_box)\n",
|
| 486 |
"\n",
|
| 487 |
"# --- VAE ---\n",
|
| 488 |
-
"vae_header = widgets.HTML('<div class=\"header\"
|
| 489 |
"vae_options = ['none',\n",
|
| 490 |
" '1.Anime.vae',\n",
|
| 491 |
" '2.Anything.vae',\n",
|
|
@@ -538,7 +538,7 @@
|
|
| 538 |
"# --- CUSTOM DOWNLOAD ---\n",
|
| 539 |
"custom_download_header_popup = widgets.HTML('''\n",
|
| 540 |
"<style>\n",
|
| 541 |
-
"/*
|
| 542 |
".sample_label {color: #dbafff;}\n",
|
| 543 |
".braces {color: #ffff00;}\n",
|
| 544 |
".extension {color: #eb934b;}\n",
|
|
@@ -546,7 +546,7 @@
|
|
| 546 |
"</style>\n",
|
| 547 |
"\n",
|
| 548 |
"<div class=\"header\" style=\"cursor: pointer;\" onclick=\"toggleContainer()\">Кастомная Загрузка</div>\n",
|
| 549 |
-
"<!-- PopUp
|
| 550 |
"<div class=\"info\" id=\"info_dl\">INFO</div>\n",
|
| 551 |
"<div class=\"popup\">\n",
|
| 552 |
" Разделите несколько URL-адресов запятой/пробелом. Для <span class=\"file_name\">пользовательского имени</span> файла/расширения укажите его через <span class=\"braces\">[]</span>\n",
|
|
|
|
| 56 |
"parser.add_argument('-y', type=int, help='Y coordinate for the image in px', metavar='', default=0)\n",
|
| 57 |
"parser.add_argument('-x', type=int, help='X coordinate for the image in px', metavar='', default=0)\n",
|
| 58 |
"parser.add_argument('-s', '--scale', type=int, help='Scale image in %%', metavar='', default=100)\n",
|
| 59 |
+
"parser.add_argument('-m', '--mode', action='store_true', help='Removes repetitive image tiles')\n",
|
| 60 |
"parser.add_argument('-t', '--transparent', action='store_true', help='Makes input/selection fields 35%% more transparent')\n",
|
| 61 |
"parser.add_argument('-bf', '--blur-fields', type=str, help='Background blur level for input/selection fields', metavar='', default=2)\n",
|
| 62 |
"args = parser.parse_args()\n",
|
|
|
|
| 485 |
"display(all_model_box)\n",
|
| 486 |
"\n",
|
| 487 |
"# --- VAE ---\n",
|
| 488 |
+
"vae_header = widgets.HTML('<div class=\"header\">Выбор VAE</div>')\n",
|
| 489 |
"vae_options = ['none',\n",
|
| 490 |
" '1.Anime.vae',\n",
|
| 491 |
" '2.Anything.vae',\n",
|
|
|
|
| 538 |
"# --- CUSTOM DOWNLOAD ---\n",
|
| 539 |
"custom_download_header_popup = widgets.HTML('''\n",
|
| 540 |
"<style>\n",
|
| 541 |
+
"/* Term Colors */\n",
|
| 542 |
".sample_label {color: #dbafff;}\n",
|
| 543 |
".braces {color: #ffff00;}\n",
|
| 544 |
".extension {color: #eb934b;}\n",
|
|
|
|
| 546 |
"</style>\n",
|
| 547 |
"\n",
|
| 548 |
"<div class=\"header\" style=\"cursor: pointer;\" onclick=\"toggleContainer()\">Кастомная Загрузка</div>\n",
|
| 549 |
+
"<!-- PopUp Window -->\n",
|
| 550 |
"<div class=\"info\" id=\"info_dl\">INFO</div>\n",
|
| 551 |
"<div class=\"popup\">\n",
|
| 552 |
" Разделите несколько URL-адресов запятой/пробелом. Для <span class=\"file_name\">пользовательского имени</span> файла/расширения укажите его через <span class=\"braces\">[]</span>\n",
|
files_cells/python/en/downloading_en.py
CHANGED
|
@@ -314,7 +314,7 @@ controlnet_list = {
|
|
| 314 |
]
|
| 315 |
}
|
| 316 |
|
| 317 |
-
|
| 318 |
prefixes = {
|
| 319 |
"model": models_dir,
|
| 320 |
"vae": vaes_dir,
|
|
@@ -325,11 +325,10 @@ prefixes = {
|
|
| 325 |
"adetailer": adetailer_dir
|
| 326 |
}
|
| 327 |
|
| 328 |
-
|
| 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 |
|
|
@@ -342,23 +341,20 @@ def get_data_from_api(model_id, api_key): # get model data
|
|
| 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 |
-
|
| 354 |
-
|
| 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):
|
| 360 |
-
|
| 361 |
-
|
|
|
|
|
|
|
| 362 |
|
| 363 |
''' main download code '''
|
| 364 |
|
|
@@ -382,27 +378,26 @@ def manual_download(url, dst_dir, file_name):
|
|
| 382 |
basename = url.split("/")[-1] if file_name is None else file_name
|
| 383 |
aria2_args = '--optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c'
|
| 384 |
|
| 385 |
-
print("\033[32m---
|
| 386 |
# print(url, dst_dir, file_name)
|
| 387 |
|
| 388 |
# === CivitAi API ===
|
| 389 |
civitai_token = "62c0c5956b2f9defbd844d754000180b"
|
| 390 |
-
if 'civitai' in url
|
| 391 |
model_id = url.split('/')[-1]
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
|
|
|
| 402 |
else:
|
| 403 |
-
print("
|
| 404 |
-
else:
|
| 405 |
-
print("Failed to retrieve data from the API.")
|
| 406 |
|
| 407 |
# -- GDrive --
|
| 408 |
if 'drive.google' in url:
|
|
@@ -446,7 +441,7 @@ def download(url):
|
|
| 446 |
|
| 447 |
## unpucking zip files
|
| 448 |
def unpucking_zip_files():
|
| 449 |
-
# directories
|
| 450 |
for directory in directories:
|
| 451 |
for root, dirs, files in os.walk(directory):
|
| 452 |
for file in files:
|
|
|
|
| 314 |
]
|
| 315 |
}
|
| 316 |
|
| 317 |
+
url = ""
|
| 318 |
prefixes = {
|
| 319 |
"model": models_dir,
|
| 320 |
"vae": vaes_dir,
|
|
|
|
| 325 |
"adetailer": adetailer_dir
|
| 326 |
}
|
| 327 |
|
| 328 |
+
extension_repo = []
|
| 329 |
directories = [value for key, value in prefixes.items()] # for unpucking zip files
|
| 330 |
get_ipython().system('mkdir -p {" ".join(directories)}')
|
| 331 |
|
|
|
|
| 332 |
hf_token = optional_huggingface_token if optional_huggingface_token else "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"
|
| 333 |
user_header = f"\"Authorization: Bearer {hf_token}\""
|
| 334 |
|
|
|
|
| 341 |
response = requests.get(base_url, headers=headers)
|
| 342 |
if response.status_code == 200:
|
| 343 |
return response.json()
|
|
|
|
|
|
|
|
|
|
| 344 |
except requests.exceptions.RequestException as e:
|
| 345 |
print(f"An error occurred: {e}")
|
| 346 |
return None
|
| 347 |
|
| 348 |
def extract_file_and_image_info(data):
|
| 349 |
+
model_name = data['files'][0]['name'] # get original model file name
|
| 350 |
+
image_url = data['images'][0]['url'] # get preview: first image
|
|
|
|
|
|
|
| 351 |
return model_name, image_url
|
| 352 |
|
| 353 |
+
def generate_preview_filename(model_name, image_url):
|
| 354 |
+
name = model_name.split('.')
|
| 355 |
+
img_ext = image_url.split('.')
|
| 356 |
+
print(f"\n\033[31m[Preview DL]\033[0m: {name[0]}.preview.{img_ext[-1]}")
|
| 357 |
+
return f"{name[0]}.preview.{img_ext[-1]}" # assigning the original image format
|
| 358 |
|
| 359 |
''' main download code '''
|
| 360 |
|
|
|
|
| 378 |
basename = url.split("/")[-1] if file_name is None else file_name
|
| 379 |
aria2_args = '--optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c'
|
| 380 |
|
| 381 |
+
print(f"\n\033[32m{'---'*45}\n\033[33mURL: \033[34m{url}\n\033[33mSAVE DIR: \033[34m{dst_dir}\n\033[33mFILE NAME: \033[34m{file_name}033[0m")
|
| 382 |
# print(url, dst_dir, file_name)
|
| 383 |
|
| 384 |
# === CivitAi API ===
|
| 385 |
civitai_token = "62c0c5956b2f9defbd844d754000180b"
|
| 386 |
+
if 'civitai' in url:
|
| 387 |
model_id = url.split('/')[-1]
|
| 388 |
+
url = f"{url}&token={civitai_token}" if '?' in url else f"{url}?token={civitai_token}"
|
| 389 |
+
|
| 390 |
+
if dst_dir not in [vaes_dir, control_dir, adetailer_dir]: # filter
|
| 391 |
+
data = get_data_from_api(model_id, civitai_token)
|
| 392 |
+
if data:
|
| 393 |
+
model_name, image_url = extract_file_and_image_info(data)
|
| 394 |
+
if model_name and image_url:
|
| 395 |
+
image_file_name = generate_preview_filename(model_name if not file_name else file_name, image_url)
|
| 396 |
+
with capture.capture_output() as cap: # clear shit
|
| 397 |
+
get_ipython().system('aria2c {aria2_args} -d {dst_dir} -o {image_file_name} {image_url}')
|
| 398 |
+
del cap
|
| 399 |
else:
|
| 400 |
+
print("\033[31m[Preview DL]\033[0m: Failed to retrieve data from the API.")
|
|
|
|
|
|
|
| 401 |
|
| 402 |
# -- GDrive --
|
| 403 |
if 'drive.google' in url:
|
|
|
|
| 441 |
|
| 442 |
## unpucking zip files
|
| 443 |
def unpucking_zip_files():
|
| 444 |
+
# directories - above
|
| 445 |
for directory in directories:
|
| 446 |
for root, dirs, files in os.walk(directory):
|
| 447 |
for file in files:
|
files_cells/python/en/widgets_en.py
CHANGED
|
@@ -466,7 +466,7 @@ all_model_box = widgets.VBox([model_header, Model_widget, Model_Num_widget, Inpa
|
|
| 466 |
display(all_model_box)
|
| 467 |
|
| 468 |
# --- VAE ---
|
| 469 |
-
vae_header = widgets.HTML('<div class="header"
|
| 470 |
vae_options = ['none',
|
| 471 |
'1.Anime.vae',
|
| 472 |
'2.Anything.vae',
|
|
|
|
| 466 |
display(all_model_box)
|
| 467 |
|
| 468 |
# --- VAE ---
|
| 469 |
+
vae_header = widgets.HTML('<div class="header">VAE Selection</div>')
|
| 470 |
vae_options = ['none',
|
| 471 |
'1.Anime.vae',
|
| 472 |
'2.Anything.vae',
|
files_cells/python/ru/downloading_ru.py
CHANGED
|
@@ -314,7 +314,7 @@ controlnet_list = {
|
|
| 314 |
]
|
| 315 |
}
|
| 316 |
|
| 317 |
-
|
| 318 |
prefixes = {
|
| 319 |
"model": models_dir,
|
| 320 |
"vae": vaes_dir,
|
|
@@ -325,11 +325,10 @@ prefixes = {
|
|
| 325 |
"adetailer": adetailer_dir
|
| 326 |
}
|
| 327 |
|
| 328 |
-
|
| 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 |
|
|
@@ -342,23 +341,20 @@ def get_data_from_api(model_id, api_key): # get model data
|
|
| 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 |
-
|
| 354 |
-
|
| 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):
|
| 360 |
-
|
| 361 |
-
|
|
|
|
|
|
|
| 362 |
|
| 363 |
''' main download code '''
|
| 364 |
|
|
@@ -382,27 +378,26 @@ def manual_download(url, dst_dir, file_name):
|
|
| 382 |
basename = url.split("/")[-1] if file_name is None else file_name
|
| 383 |
aria2_args = '--optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c'
|
| 384 |
|
| 385 |
-
print("\033[32m---
|
| 386 |
# print(url, dst_dir, file_name)
|
| 387 |
|
| 388 |
# === CivitAi API ===
|
| 389 |
civitai_token = "62c0c5956b2f9defbd844d754000180b"
|
| 390 |
-
if 'civitai' in url
|
| 391 |
model_id = url.split('/')[-1]
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
|
|
|
| 402 |
else:
|
| 403 |
-
print("
|
| 404 |
-
else:
|
| 405 |
-
print("Failed to retrieve data from the API.")
|
| 406 |
|
| 407 |
# -- GDrive --
|
| 408 |
if 'drive.google' in url:
|
|
@@ -446,7 +441,7 @@ def download(url):
|
|
| 446 |
|
| 447 |
## unpucking zip files
|
| 448 |
def unpucking_zip_files():
|
| 449 |
-
# directories
|
| 450 |
for directory in directories:
|
| 451 |
for root, dirs, files in os.walk(directory):
|
| 452 |
for file in files:
|
|
|
|
| 314 |
]
|
| 315 |
}
|
| 316 |
|
| 317 |
+
url = ""
|
| 318 |
prefixes = {
|
| 319 |
"model": models_dir,
|
| 320 |
"vae": vaes_dir,
|
|
|
|
| 325 |
"adetailer": adetailer_dir
|
| 326 |
}
|
| 327 |
|
| 328 |
+
extension_repo = []
|
| 329 |
directories = [value for key, value in prefixes.items()] # for unpucking zip files
|
| 330 |
get_ipython().system('mkdir -p {" ".join(directories)}')
|
| 331 |
|
|
|
|
| 332 |
hf_token = optional_huggingface_token if optional_huggingface_token else "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"
|
| 333 |
user_header = f"\"Authorization: Bearer {hf_token}\""
|
| 334 |
|
|
|
|
| 341 |
response = requests.get(base_url, headers=headers)
|
| 342 |
if response.status_code == 200:
|
| 343 |
return response.json()
|
|
|
|
|
|
|
|
|
|
| 344 |
except requests.exceptions.RequestException as e:
|
| 345 |
print(f"An error occurred: {e}")
|
| 346 |
return None
|
| 347 |
|
| 348 |
def extract_file_and_image_info(data):
|
| 349 |
+
model_name = data['files'][0]['name'] # get original model file name
|
| 350 |
+
image_url = data['images'][0]['url'] # get preview: first image
|
|
|
|
|
|
|
| 351 |
return model_name, image_url
|
| 352 |
|
| 353 |
+
def generate_preview_filename(model_name, image_url):
|
| 354 |
+
name = model_name.split('.')
|
| 355 |
+
img_ext = image_url.split('.')
|
| 356 |
+
print(f"\n\033[31m[Preview DL]\033[0m: {name[0]}.preview.{img_ext[-1]}")
|
| 357 |
+
return f"{name[0]}.preview.{img_ext[-1]}" # assigning the original image format
|
| 358 |
|
| 359 |
''' main download code '''
|
| 360 |
|
|
|
|
| 378 |
basename = url.split("/")[-1] if file_name is None else file_name
|
| 379 |
aria2_args = '--optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c'
|
| 380 |
|
| 381 |
+
print(f"\n\033[32m{'---'*45}\n\033[33mURL: \033[34m{url}\n\033[33mSAVE DIR: \033[34m{dst_dir}\n\033[33mFILE NAME: \033[34m{file_name}033[0m")
|
| 382 |
# print(url, dst_dir, file_name)
|
| 383 |
|
| 384 |
# === CivitAi API ===
|
| 385 |
civitai_token = "62c0c5956b2f9defbd844d754000180b"
|
| 386 |
+
if 'civitai' in url:
|
| 387 |
model_id = url.split('/')[-1]
|
| 388 |
+
url = f"{url}&token={civitai_token}" if '?' in url else f"{url}?token={civitai_token}"
|
| 389 |
+
|
| 390 |
+
if dst_dir not in [vaes_dir, control_dir, adetailer_dir]: # filter
|
| 391 |
+
data = get_data_from_api(model_id, civitai_token)
|
| 392 |
+
if data:
|
| 393 |
+
model_name, image_url = extract_file_and_image_info(data)
|
| 394 |
+
if model_name and image_url:
|
| 395 |
+
image_file_name = generate_preview_filename(model_name if not file_name else file_name, image_url)
|
| 396 |
+
with capture.capture_output() as cap: # clear shit
|
| 397 |
+
get_ipython().system('aria2c {aria2_args} -d {dst_dir} -o {image_file_name} {image_url}')
|
| 398 |
+
del cap
|
| 399 |
else:
|
| 400 |
+
print("\033[31m[Preview DL]\033[0m: Failed to retrieve data from the API.")
|
|
|
|
|
|
|
| 401 |
|
| 402 |
# -- GDrive --
|
| 403 |
if 'drive.google' in url:
|
|
|
|
| 441 |
|
| 442 |
## unpucking zip files
|
| 443 |
def unpucking_zip_files():
|
| 444 |
+
# directories - above
|
| 445 |
for directory in directories:
|
| 446 |
for root, dirs, files in os.walk(directory):
|
| 447 |
for file in files:
|
files_cells/python/ru/widgets_ru.py
CHANGED
|
@@ -37,7 +37,7 @@ parser.add_argument('-b', '--blur', type=str, help='Blur level for the image', m
|
|
| 37 |
parser.add_argument('-y', type=int, help='Y coordinate for the image in px', metavar='', default=0)
|
| 38 |
parser.add_argument('-x', type=int, help='X coordinate for the image in px', metavar='', default=0)
|
| 39 |
parser.add_argument('-s', '--scale', type=int, help='Scale image in %%', metavar='', default=100)
|
| 40 |
-
parser.add_argument('-m', '--mode',action='store_true', help='Removes repetitive image tiles')
|
| 41 |
parser.add_argument('-t', '--transparent', action='store_true', help='Makes input/selection fields 35%% more transparent')
|
| 42 |
parser.add_argument('-bf', '--blur-fields', type=str, help='Background blur level for input/selection fields', metavar='', default=2)
|
| 43 |
args = parser.parse_args()
|
|
@@ -466,7 +466,7 @@ all_model_box = widgets.VBox([model_header, Model_widget, Model_Num_widget, Inpa
|
|
| 466 |
display(all_model_box)
|
| 467 |
|
| 468 |
# --- VAE ---
|
| 469 |
-
vae_header = widgets.HTML('<div class="header"
|
| 470 |
vae_options = ['none',
|
| 471 |
'1.Anime.vae',
|
| 472 |
'2.Anything.vae',
|
|
@@ -519,7 +519,7 @@ display(all_additional_box)
|
|
| 519 |
# --- CUSTOM DOWNLOAD ---
|
| 520 |
custom_download_header_popup = widgets.HTML('''
|
| 521 |
<style>
|
| 522 |
-
/*
|
| 523 |
.sample_label {color: #dbafff;}
|
| 524 |
.braces {color: #ffff00;}
|
| 525 |
.extension {color: #eb934b;}
|
|
@@ -527,7 +527,7 @@ custom_download_header_popup = widgets.HTML('''
|
|
| 527 |
</style>
|
| 528 |
|
| 529 |
<div class="header" style="cursor: pointer;" onclick="toggleContainer()">Кастомная Загрузка</div>
|
| 530 |
-
<!-- PopUp
|
| 531 |
<div class="info" id="info_dl">INFO</div>
|
| 532 |
<div class="popup">
|
| 533 |
Разделите несколько URL-адресов запятой/пробелом. Для <span class="file_name">пользовательского имени</span> файла/расширения укажите его через <span class="braces">[]</span>
|
|
|
|
| 37 |
parser.add_argument('-y', type=int, help='Y coordinate for the image in px', metavar='', default=0)
|
| 38 |
parser.add_argument('-x', type=int, help='X coordinate for the image in px', metavar='', default=0)
|
| 39 |
parser.add_argument('-s', '--scale', type=int, help='Scale image in %%', metavar='', default=100)
|
| 40 |
+
parser.add_argument('-m', '--mode', action='store_true', help='Removes repetitive image tiles')
|
| 41 |
parser.add_argument('-t', '--transparent', action='store_true', help='Makes input/selection fields 35%% more transparent')
|
| 42 |
parser.add_argument('-bf', '--blur-fields', type=str, help='Background blur level for input/selection fields', metavar='', default=2)
|
| 43 |
args = parser.parse_args()
|
|
|
|
| 466 |
display(all_model_box)
|
| 467 |
|
| 468 |
# --- VAE ---
|
| 469 |
+
vae_header = widgets.HTML('<div class="header">Выбор VAE</div>')
|
| 470 |
vae_options = ['none',
|
| 471 |
'1.Anime.vae',
|
| 472 |
'2.Anything.vae',
|
|
|
|
| 519 |
# --- CUSTOM DOWNLOAD ---
|
| 520 |
custom_download_header_popup = widgets.HTML('''
|
| 521 |
<style>
|
| 522 |
+
/* Term Colors */
|
| 523 |
.sample_label {color: #dbafff;}
|
| 524 |
.braces {color: #ffff00;}
|
| 525 |
.extension {color: #eb934b;}
|
|
|
|
| 527 |
</style>
|
| 528 |
|
| 529 |
<div class="header" style="cursor: pointer;" onclick="toggleContainer()">Кастомная Загрузка</div>
|
| 530 |
+
<!-- PopUp Window -->
|
| 531 |
<div class="info" id="info_dl">INFO</div>
|
| 532 |
<div class="popup">
|
| 533 |
Разделите несколько URL-адресов запятой/пробелом. Для <span class="file_name">пользовательского имени</span> файла/расширения укажите его через <span class="braces">[]</span>
|