get nsfwLevel | for kaggle
Browse filesMaybe this will prevent a ban for images of a sensitive nature... (I'm not sure about that!)
files_cells/notebooks/en/downloading_en.ipynb
CHANGED
|
@@ -50,7 +50,7 @@
|
|
| 50 |
" install_lib = {\n",
|
| 51 |
" \"aria2\": \"apt -y install aria2\",\n",
|
| 52 |
" \"localtunnel\": \"npm install -g localtunnel\",\n",
|
| 53 |
-
" \"insightface\": \"pip install insightface\"
|
| 54 |
" }\n",
|
| 55 |
"\n",
|
| 56 |
" additional_libs = {\n",
|
|
@@ -207,7 +207,7 @@
|
|
| 207 |
" print(f\"\\r⌛️ The time machine has been activated! Current commit: \\033[34m{commit_hash}\\033[0m\")\n",
|
| 208 |
"\n",
|
| 209 |
"\n",
|
| 210 |
-
"## Downloading model and stuff | oh
|
| 211 |
"print(\"📦 Downloading models and stuff...\", end='')\n",
|
| 212 |
"model_list = {\n",
|
| 213 |
" \"1.Anime (by XpucT) + INP\": [\n",
|
|
@@ -338,7 +338,7 @@
|
|
| 338 |
"''' Get Image Preview | CivitAi '''\n",
|
| 339 |
"\n",
|
| 340 |
"def get_data_from_api(model_id, api_key): # get model data\n",
|
| 341 |
-
" base_url = f\"https://civitai.com/api/v1/model-versions/{model_id}\"
|
| 342 |
" headers = {\"Content-Type\": \"application/json\"}\n",
|
| 343 |
" try:\n",
|
| 344 |
" response = requests.get(base_url, headers=headers)\n",
|
|
@@ -349,17 +349,18 @@
|
|
| 349 |
" return None\n",
|
| 350 |
"\n",
|
| 351 |
"def extract_model_info(data, url):\n",
|
| 352 |
-
" # Get 'Type, Name and
|
|
|
|
| 353 |
" if 'type=' in url:\n",
|
| 354 |
" model_type = data['files'][1]['type']\n",
|
| 355 |
" model_name = data['files'][1]['name']\n",
|
| 356 |
-
" image_url =
|
| 357 |
" else:\n",
|
| 358 |
" model_type = data['model']['type']\n",
|
| 359 |
" model_name = data['files'][0]['name']\n",
|
| 360 |
" image_url = data['images'][0]['url']\n",
|
| 361 |
"\n",
|
| 362 |
-
" return model_type, model_name, image_url\n",
|
| 363 |
"\n",
|
| 364 |
"def gen_preview_filename(model_name, image_url):\n",
|
| 365 |
" name = model_name.split('.')\n",
|
|
@@ -391,8 +392,6 @@
|
|
| 391 |
" # === CivitAi API ===\n",
|
| 392 |
" supported_types = ('Checkpoint', 'TextualInversion', 'LORA') # for dl preview image\n",
|
| 393 |
" civitai_token = \"62c0c5956b2f9defbd844d754000180b\"\n",
|
| 394 |
-
" image_file_name = None\n",
|
| 395 |
-
" model_type = None\n",
|
| 396 |
"\n",
|
| 397 |
" if 'civitai' in url:\n",
|
| 398 |
" url = f\"{url}{'&' if '?' in url else '?'}token={civitai_token}\" # some authors are pussies and they need API token...\n",
|
|
@@ -401,20 +400,20 @@
|
|
| 401 |
"\n",
|
| 402 |
" data = get_data_from_api(model_id, civitai_token)\n",
|
| 403 |
" if data:\n",
|
| 404 |
-
" model_type, model_name, image_url = extract_model_info(data, url)\n",
|
| 405 |
" if model_name and image_url:\n",
|
| 406 |
-
"
|
| 407 |
-
"
|
| 408 |
-
"
|
| 409 |
-
"
|
| 410 |
-
"
|
|
|
|
| 411 |
" file_name = file_name or model_name # assigns the original file name if not specified initially\n",
|
| 412 |
"\n",
|
| 413 |
" \"\"\" information output \"\"\"\n",
|
| 414 |
-
" #
|
| 415 |
-
" print(f\"\\n\\033[32m{'---'*45}\\n\\033[33mURL: \\033[34m{clean_url if 'civitai' in url else url}\\n\\033[33mSAVE DIR: \\033[34m{dst_dir}\\n\\033[33mFILE NAME: \\033[34m{file_name if not 'huggingface' in url else basename}\\033[0m\")
|
| 416 |
-
" print(
|
| 417 |
-
" print(\"\\033[31m[Data Info]\\033[0m: Failed to retrieve data from the API.\\n\") if 'civitai' in url and not data else None # DATA: ERROR\n",
|
| 418 |
" # ===================\n",
|
| 419 |
"\n",
|
| 420 |
" # -- GDrive --\n",
|
|
@@ -643,4 +642,4 @@
|
|
| 643 |
},
|
| 644 |
"nbformat": 4,
|
| 645 |
"nbformat_minor": 0
|
| 646 |
-
}
|
|
|
|
| 50 |
" install_lib = {\n",
|
| 51 |
" \"aria2\": \"apt -y install aria2\",\n",
|
| 52 |
" \"localtunnel\": \"npm install -g localtunnel\",\n",
|
| 53 |
+
" \"insightface\": \"pip install insightface\"\n",
|
| 54 |
" }\n",
|
| 55 |
"\n",
|
| 56 |
" additional_libs = {\n",
|
|
|
|
| 207 |
" print(f\"\\r⌛️ The time machine has been activated! Current commit: \\033[34m{commit_hash}\\033[0m\")\n",
|
| 208 |
"\n",
|
| 209 |
"\n",
|
| 210 |
+
"## Downloading model and stuff | oh~ Hey! If you're freaked out by that code too, don't worry, me too!\n",
|
| 211 |
"print(\"📦 Downloading models and stuff...\", end='')\n",
|
| 212 |
"model_list = {\n",
|
| 213 |
" \"1.Anime (by XpucT) + INP\": [\n",
|
|
|
|
| 338 |
"''' Get Image Preview | CivitAi '''\n",
|
| 339 |
"\n",
|
| 340 |
"def get_data_from_api(model_id, api_key): # get model data\n",
|
| 341 |
+
" base_url = f\"https://civitai.com/api/v1/model-versions/{model_id}\"\n",
|
| 342 |
" headers = {\"Content-Type\": \"application/json\"}\n",
|
| 343 |
" try:\n",
|
| 344 |
" response = requests.get(base_url, headers=headers)\n",
|
|
|
|
| 349 |
" return None\n",
|
| 350 |
"\n",
|
| 351 |
"def extract_model_info(data, url):\n",
|
| 352 |
+
" # Get 'Type, Name, imgURL and nsfwLevel' current model\n",
|
| 353 |
+
" nsfwLevel = data['images'][0]['nsfwLevel']\n",
|
| 354 |
" if 'type=' in url:\n",
|
| 355 |
" model_type = data['files'][1]['type']\n",
|
| 356 |
" model_name = data['files'][1]['name']\n",
|
| 357 |
+
" image_url = None\n",
|
| 358 |
" else:\n",
|
| 359 |
" model_type = data['model']['type']\n",
|
| 360 |
" model_name = data['files'][0]['name']\n",
|
| 361 |
" image_url = data['images'][0]['url']\n",
|
| 362 |
"\n",
|
| 363 |
+
" return model_type, model_name, image_url, nsfwLevel\n",
|
| 364 |
"\n",
|
| 365 |
"def gen_preview_filename(model_name, image_url):\n",
|
| 366 |
" name = model_name.split('.')\n",
|
|
|
|
| 392 |
" # === CivitAi API ===\n",
|
| 393 |
" supported_types = ('Checkpoint', 'TextualInversion', 'LORA') # for dl preview image\n",
|
| 394 |
" civitai_token = \"62c0c5956b2f9defbd844d754000180b\"\n",
|
|
|
|
|
|
|
| 395 |
"\n",
|
| 396 |
" if 'civitai' in url:\n",
|
| 397 |
" url = f\"{url}{'&' if '?' in url else '?'}token={civitai_token}\" # some authors are pussies and they need API token...\n",
|
|
|
|
| 400 |
"\n",
|
| 401 |
" data = get_data_from_api(model_id, civitai_token)\n",
|
| 402 |
" if data:\n",
|
| 403 |
+
" model_type, model_name, image_url, nsfwLevel = extract_model_info(data, url)\n",
|
| 404 |
" if model_name and image_url:\n",
|
| 405 |
+
" if env != 'Kaggle' or (env == 'Kaggle' and nsfwLevel <= 4): # 4 seems like a relatively safe level, but it's still a risk!\n",
|
| 406 |
+
" image_file_name = gen_preview_filename(model_name if not file_name else file_name, image_url)\n",
|
| 407 |
+
" if model_type in supported_types:\n",
|
| 408 |
+
" with capture.capture_output() as cap: # clear shit\n",
|
| 409 |
+
" !aria2c {aria2_args} -d {dst_dir} -o {image_file_name} {image_url}\n",
|
| 410 |
+
" del cap\n",
|
| 411 |
" file_name = file_name or model_name # assigns the original file name if not specified initially\n",
|
| 412 |
"\n",
|
| 413 |
" \"\"\" information output \"\"\"\n",
|
| 414 |
+
" # -- wrold's best print info --\n",
|
| 415 |
+
" print(f\"\\n\\033[32m{'---'*45}\\n\\033[33mURL: \\033[34m{clean_url if 'civitai' in url else url}\\n\\033[33mSAVE DIR: \\033[34m{dst_dir}\\n\\033[33mFILE NAME: \\033[34m{file_name if not 'huggingface' in url else basename}\\033[0m\")\n",
|
| 416 |
+
" print(\"\\033[31m[Data Info]\\033[0m: Failed to retrieve data from the API.\") if 'civitai' in url and not data else None # DATA: ERROR\n",
|
|
|
|
| 417 |
" # ===================\n",
|
| 418 |
"\n",
|
| 419 |
" # -- GDrive --\n",
|
|
|
|
| 642 |
},
|
| 643 |
"nbformat": 4,
|
| 644 |
"nbformat_minor": 0
|
| 645 |
+
}
|
files_cells/notebooks/ru/downloading_ru.ipynb
CHANGED
|
@@ -50,7 +50,7 @@
|
|
| 50 |
" install_lib = {\n",
|
| 51 |
" \"aria2\": \"apt -y install aria2\",\n",
|
| 52 |
" \"localtunnel\": \"npm install -g localtunnel\",\n",
|
| 53 |
-
" \"insightface\": \"pip install insightface\"
|
| 54 |
" }\n",
|
| 55 |
"\n",
|
| 56 |
" additional_libs = {\n",
|
|
@@ -207,7 +207,7 @@
|
|
| 207 |
" print(f\"\\r⌛️ Машина времени активированна! Текущий коммит: \\033[34m{commit_hash}\\033[0m\")\n",
|
| 208 |
"\n",
|
| 209 |
"\n",
|
| 210 |
-
"## Downloading model and stuff | oh
|
| 211 |
"print(\"📦 Скачивание моделей и прочего...\", end='')\n",
|
| 212 |
"model_list = {\n",
|
| 213 |
" \"1.Anime (by XpucT) + INP\": [\n",
|
|
@@ -338,7 +338,7 @@
|
|
| 338 |
"''' Get Image Preview | CivitAi '''\n",
|
| 339 |
"\n",
|
| 340 |
"def get_data_from_api(model_id, api_key): # get model data\n",
|
| 341 |
-
" base_url = f\"https://civitai.com/api/v1/model-versions/{model_id}\"
|
| 342 |
" headers = {\"Content-Type\": \"application/json\"}\n",
|
| 343 |
" try:\n",
|
| 344 |
" response = requests.get(base_url, headers=headers)\n",
|
|
@@ -349,17 +349,18 @@
|
|
| 349 |
" return None\n",
|
| 350 |
"\n",
|
| 351 |
"def extract_model_info(data, url):\n",
|
| 352 |
-
" # Get 'Type, Name and
|
|
|
|
| 353 |
" if 'type=' in url:\n",
|
| 354 |
" model_type = data['files'][1]['type']\n",
|
| 355 |
" model_name = data['files'][1]['name']\n",
|
| 356 |
-
" image_url =
|
| 357 |
" else:\n",
|
| 358 |
" model_type = data['model']['type']\n",
|
| 359 |
" model_name = data['files'][0]['name']\n",
|
| 360 |
" image_url = data['images'][0]['url']\n",
|
| 361 |
"\n",
|
| 362 |
-
" return model_type, model_name, image_url\n",
|
| 363 |
"\n",
|
| 364 |
"def gen_preview_filename(model_name, image_url):\n",
|
| 365 |
" name = model_name.split('.')\n",
|
|
@@ -391,8 +392,6 @@
|
|
| 391 |
" # === CivitAi API ===\n",
|
| 392 |
" supported_types = ('Checkpoint', 'TextualInversion', 'LORA') # for dl preview image\n",
|
| 393 |
" civitai_token = \"62c0c5956b2f9defbd844d754000180b\"\n",
|
| 394 |
-
" image_file_name = None\n",
|
| 395 |
-
" model_type = None\n",
|
| 396 |
"\n",
|
| 397 |
" if 'civitai' in url:\n",
|
| 398 |
" url = f\"{url}{'&' if '?' in url else '?'}token={civitai_token}\" # some authors are pussies and they need API token...\n",
|
|
@@ -401,20 +400,20 @@
|
|
| 401 |
"\n",
|
| 402 |
" data = get_data_from_api(model_id, civitai_token)\n",
|
| 403 |
" if data:\n",
|
| 404 |
-
" model_type, model_name, image_url = extract_model_info(data, url)\n",
|
| 405 |
" if model_name and image_url:\n",
|
| 406 |
-
"
|
| 407 |
-
"
|
| 408 |
-
"
|
| 409 |
-
"
|
| 410 |
-
"
|
|
|
|
| 411 |
" file_name = file_name or model_name # assigns the original file name if not specified initially\n",
|
| 412 |
"\n",
|
| 413 |
" \"\"\" information output \"\"\"\n",
|
| 414 |
-
" #
|
| 415 |
-
" print(f\"\\n\\033[32m{'---'*45}\\n\\033[33mURL: \\033[34m{clean_url if 'civitai' in url else url}\\n\\033[33mSAVE DIR: \\033[34m{dst_dir}\\n\\033[33mFILE NAME: \\033[34m{file_name if not 'huggingface' in url else basename}\\033[0m\")
|
| 416 |
-
" print(
|
| 417 |
-
" print(\"\\033[31m[Data Info]\\033[0m: Failed to retrieve data from the API.\\n\") if 'civitai' in url and not data else None # DATA: ERROR\n",
|
| 418 |
" # ===================\n",
|
| 419 |
"\n",
|
| 420 |
" # -- GDrive --\n",
|
|
@@ -643,4 +642,4 @@
|
|
| 643 |
},
|
| 644 |
"nbformat": 4,
|
| 645 |
"nbformat_minor": 0
|
| 646 |
-
}
|
|
|
|
| 50 |
" install_lib = {\n",
|
| 51 |
" \"aria2\": \"apt -y install aria2\",\n",
|
| 52 |
" \"localtunnel\": \"npm install -g localtunnel\",\n",
|
| 53 |
+
" \"insightface\": \"pip install insightface\"\n",
|
| 54 |
" }\n",
|
| 55 |
"\n",
|
| 56 |
" additional_libs = {\n",
|
|
|
|
| 207 |
" print(f\"\\r⌛️ Машина времени активированна! Текущий коммит: \\033[34m{commit_hash}\\033[0m\")\n",
|
| 208 |
"\n",
|
| 209 |
"\n",
|
| 210 |
+
"## Downloading model and stuff | oh~ Hey! If you're freaked out by that code too, don't worry, me too!\n",
|
| 211 |
"print(\"📦 Скачивание моделей и прочего...\", end='')\n",
|
| 212 |
"model_list = {\n",
|
| 213 |
" \"1.Anime (by XpucT) + INP\": [\n",
|
|
|
|
| 338 |
"''' Get Image Preview | CivitAi '''\n",
|
| 339 |
"\n",
|
| 340 |
"def get_data_from_api(model_id, api_key): # get model data\n",
|
| 341 |
+
" base_url = f\"https://civitai.com/api/v1/model-versions/{model_id}\"\n",
|
| 342 |
" headers = {\"Content-Type\": \"application/json\"}\n",
|
| 343 |
" try:\n",
|
| 344 |
" response = requests.get(base_url, headers=headers)\n",
|
|
|
|
| 349 |
" return None\n",
|
| 350 |
"\n",
|
| 351 |
"def extract_model_info(data, url):\n",
|
| 352 |
+
" # Get 'Type, Name, imgURL and nsfwLevel' current model\n",
|
| 353 |
+
" nsfwLevel = data['images'][0]['nsfwLevel']\n",
|
| 354 |
" if 'type=' in url:\n",
|
| 355 |
" model_type = data['files'][1]['type']\n",
|
| 356 |
" model_name = data['files'][1]['name']\n",
|
| 357 |
+
" image_url = None\n",
|
| 358 |
" else:\n",
|
| 359 |
" model_type = data['model']['type']\n",
|
| 360 |
" model_name = data['files'][0]['name']\n",
|
| 361 |
" image_url = data['images'][0]['url']\n",
|
| 362 |
"\n",
|
| 363 |
+
" return model_type, model_name, image_url, nsfwLevel\n",
|
| 364 |
"\n",
|
| 365 |
"def gen_preview_filename(model_name, image_url):\n",
|
| 366 |
" name = model_name.split('.')\n",
|
|
|
|
| 392 |
" # === CivitAi API ===\n",
|
| 393 |
" supported_types = ('Checkpoint', 'TextualInversion', 'LORA') # for dl preview image\n",
|
| 394 |
" civitai_token = \"62c0c5956b2f9defbd844d754000180b\"\n",
|
|
|
|
|
|
|
| 395 |
"\n",
|
| 396 |
" if 'civitai' in url:\n",
|
| 397 |
" url = f\"{url}{'&' if '?' in url else '?'}token={civitai_token}\" # some authors are pussies and they need API token...\n",
|
|
|
|
| 400 |
"\n",
|
| 401 |
" data = get_data_from_api(model_id, civitai_token)\n",
|
| 402 |
" if data:\n",
|
| 403 |
+
" model_type, model_name, image_url, nsfwLevel = extract_model_info(data, url)\n",
|
| 404 |
" if model_name and image_url:\n",
|
| 405 |
+
" if env != 'Kaggle' or (env == 'Kaggle' and nsfwLevel <= 4): # 4 seems like a relatively safe level, but it's still a risk!\n",
|
| 406 |
+
" image_file_name = gen_preview_filename(model_name if not file_name else file_name, image_url)\n",
|
| 407 |
+
" if model_type in supported_types:\n",
|
| 408 |
+
" with capture.capture_output() as cap: # clear shit\n",
|
| 409 |
+
" !aria2c {aria2_args} -d {dst_dir} -o {image_file_name} {image_url}\n",
|
| 410 |
+
" del cap\n",
|
| 411 |
" file_name = file_name or model_name # assigns the original file name if not specified initially\n",
|
| 412 |
"\n",
|
| 413 |
" \"\"\" information output \"\"\"\n",
|
| 414 |
+
" # -- wrold's best print info --\n",
|
| 415 |
+
" print(f\"\\n\\033[32m{'---'*45}\\n\\033[33mURL: \\033[34m{clean_url if 'civitai' in url else url}\\n\\033[33mSAVE DIR: \\033[34m{dst_dir}\\n\\033[33mFILE NAME: \\033[34m{file_name if not 'huggingface' in url else basename}\\033[0m\")\n",
|
| 416 |
+
" print(\"\\033[31m[Data Info]\\033[0m: Failed to retrieve data from the API.\") if 'civitai' in url and not data else None # DATA: ERROR\n",
|
|
|
|
| 417 |
" # ===================\n",
|
| 418 |
"\n",
|
| 419 |
" # -- GDrive --\n",
|
|
|
|
| 642 |
},
|
| 643 |
"nbformat": 4,
|
| 644 |
"nbformat_minor": 0
|
| 645 |
+
}
|
files_cells/python/en/downloading_en.py
CHANGED
|
@@ -40,7 +40,7 @@ if not os.path.exists(flag_file):
|
|
| 40 |
install_lib = {
|
| 41 |
"aria2": "apt -y install aria2",
|
| 42 |
"localtunnel": "npm install -g localtunnel",
|
| 43 |
-
"insightface": "pip install insightface"
|
| 44 |
}
|
| 45 |
|
| 46 |
additional_libs = {
|
|
@@ -197,7 +197,7 @@ if commit_hash:
|
|
| 197 |
print(f"\r⌛️ The time machine has been activated! Current commit: \033[34m{commit_hash}\033[0m")
|
| 198 |
|
| 199 |
|
| 200 |
-
## Downloading model and stuff | oh
|
| 201 |
print("📦 Downloading models and stuff...", end='')
|
| 202 |
model_list = {
|
| 203 |
"1.Anime (by XpucT) + INP": [
|
|
@@ -328,7 +328,7 @@ user_header = f"\"Authorization: Bearer {hf_token}\""
|
|
| 328 |
''' Get Image Preview | CivitAi '''
|
| 329 |
|
| 330 |
def get_data_from_api(model_id, api_key): # get model data
|
| 331 |
-
base_url = f"https://civitai.com/api/v1/model-versions/{model_id}"
|
| 332 |
headers = {"Content-Type": "application/json"}
|
| 333 |
try:
|
| 334 |
response = requests.get(base_url, headers=headers)
|
|
@@ -339,17 +339,18 @@ def get_data_from_api(model_id, api_key): # get model data
|
|
| 339 |
return None
|
| 340 |
|
| 341 |
def extract_model_info(data, url):
|
| 342 |
-
# Get 'Type, Name and
|
|
|
|
| 343 |
if 'type=' in url:
|
| 344 |
model_type = data['files'][1]['type']
|
| 345 |
model_name = data['files'][1]['name']
|
| 346 |
-
image_url =
|
| 347 |
else:
|
| 348 |
model_type = data['model']['type']
|
| 349 |
model_name = data['files'][0]['name']
|
| 350 |
image_url = data['images'][0]['url']
|
| 351 |
|
| 352 |
-
return model_type, model_name, image_url
|
| 353 |
|
| 354 |
def gen_preview_filename(model_name, image_url):
|
| 355 |
name = model_name.split('.')
|
|
@@ -381,8 +382,6 @@ def manual_download(url, dst_dir, file_name):
|
|
| 381 |
# === CivitAi API ===
|
| 382 |
supported_types = ('Checkpoint', 'TextualInversion', 'LORA') # for dl preview image
|
| 383 |
civitai_token = "62c0c5956b2f9defbd844d754000180b"
|
| 384 |
-
image_file_name = None
|
| 385 |
-
model_type = None
|
| 386 |
|
| 387 |
if 'civitai' in url:
|
| 388 |
url = f"{url}{'&' if '?' in url else '?'}token={civitai_token}" # some authors are pussies and they need API token...
|
|
@@ -391,21 +390,20 @@ def manual_download(url, dst_dir, file_name):
|
|
| 391 |
|
| 392 |
data = get_data_from_api(model_id, civitai_token)
|
| 393 |
if data:
|
| 394 |
-
model_type, model_name, image_url = extract_model_info(data, url)
|
| 395 |
if model_name and image_url:
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
file_name = file_name or model_name # assigns the original file name if not specified initially
|
| 403 |
|
| 404 |
""" information output """
|
| 405 |
-
#
|
| 406 |
-
print(f"\n\033[32m{'---'*45}\n\033[33mURL: \033[34m{clean_url if 'civitai' in url else url}\n\033[33mSAVE DIR: \033[34m{dst_dir}\n\033[33mFILE NAME: \033[34m{file_name if not 'huggingface' in url else basename}\033[0m")
|
| 407 |
-
print(
|
| 408 |
-
print("\033[31m[Data Info]\033[0m: Failed to retrieve data from the API.\n") if 'civitai' in url and not data else None # DATA: ERROR
|
| 409 |
# ===================
|
| 410 |
|
| 411 |
# -- GDrive --
|
|
|
|
| 40 |
install_lib = {
|
| 41 |
"aria2": "apt -y install aria2",
|
| 42 |
"localtunnel": "npm install -g localtunnel",
|
| 43 |
+
"insightface": "pip install insightface"
|
| 44 |
}
|
| 45 |
|
| 46 |
additional_libs = {
|
|
|
|
| 197 |
print(f"\r⌛️ The time machine has been activated! Current commit: \033[34m{commit_hash}\033[0m")
|
| 198 |
|
| 199 |
|
| 200 |
+
## Downloading model and stuff | oh~ Hey! If you're freaked out by that code too, don't worry, me too!
|
| 201 |
print("📦 Downloading models and stuff...", end='')
|
| 202 |
model_list = {
|
| 203 |
"1.Anime (by XpucT) + INP": [
|
|
|
|
| 328 |
''' Get Image Preview | CivitAi '''
|
| 329 |
|
| 330 |
def get_data_from_api(model_id, api_key): # get model data
|
| 331 |
+
base_url = f"https://civitai.com/api/v1/model-versions/{model_id}"
|
| 332 |
headers = {"Content-Type": "application/json"}
|
| 333 |
try:
|
| 334 |
response = requests.get(base_url, headers=headers)
|
|
|
|
| 339 |
return None
|
| 340 |
|
| 341 |
def extract_model_info(data, url):
|
| 342 |
+
# Get 'Type, Name, imgURL and nsfwLevel' current model
|
| 343 |
+
nsfwLevel = data['images'][0]['nsfwLevel']
|
| 344 |
if 'type=' in url:
|
| 345 |
model_type = data['files'][1]['type']
|
| 346 |
model_name = data['files'][1]['name']
|
| 347 |
+
image_url = None
|
| 348 |
else:
|
| 349 |
model_type = data['model']['type']
|
| 350 |
model_name = data['files'][0]['name']
|
| 351 |
image_url = data['images'][0]['url']
|
| 352 |
|
| 353 |
+
return model_type, model_name, image_url, nsfwLevel
|
| 354 |
|
| 355 |
def gen_preview_filename(model_name, image_url):
|
| 356 |
name = model_name.split('.')
|
|
|
|
| 382 |
# === CivitAi API ===
|
| 383 |
supported_types = ('Checkpoint', 'TextualInversion', 'LORA') # for dl preview image
|
| 384 |
civitai_token = "62c0c5956b2f9defbd844d754000180b"
|
|
|
|
|
|
|
| 385 |
|
| 386 |
if 'civitai' in url:
|
| 387 |
url = f"{url}{'&' if '?' in url else '?'}token={civitai_token}" # some authors are pussies and they need API token...
|
|
|
|
| 390 |
|
| 391 |
data = get_data_from_api(model_id, civitai_token)
|
| 392 |
if data:
|
| 393 |
+
model_type, model_name, image_url, nsfwLevel = extract_model_info(data, url)
|
| 394 |
if model_name and image_url:
|
| 395 |
+
if env != 'Kaggle' or (env == 'Kaggle' and nsfwLevel <= 4): # 4 seems like a relatively safe level, but it's still a risk!
|
| 396 |
+
image_file_name = gen_preview_filename(model_name if not file_name else file_name, image_url)
|
| 397 |
+
if model_type in supported_types:
|
| 398 |
+
with capture.capture_output() as cap: # clear shit
|
| 399 |
+
get_ipython().system('aria2c {aria2_args} -d {dst_dir} -o {image_file_name} {image_url}')
|
| 400 |
+
del cap
|
| 401 |
file_name = file_name or model_name # assigns the original file name if not specified initially
|
| 402 |
|
| 403 |
""" information output """
|
| 404 |
+
# -- wrold's best print info --
|
| 405 |
+
print(f"\n\033[32m{'---'*45}\n\033[33mURL: \033[34m{clean_url if 'civitai' in url else url}\n\033[33mSAVE DIR: \033[34m{dst_dir}\n\033[33mFILE NAME: \033[34m{file_name if not 'huggingface' in url else basename}\033[0m")
|
| 406 |
+
print("\033[31m[Data Info]\033[0m: Failed to retrieve data from the API.") if 'civitai' in url and not data else None # DATA: ERROR
|
|
|
|
| 407 |
# ===================
|
| 408 |
|
| 409 |
# -- GDrive --
|
files_cells/python/ru/downloading_ru.py
CHANGED
|
@@ -40,7 +40,7 @@ if not os.path.exists(flag_file):
|
|
| 40 |
install_lib = {
|
| 41 |
"aria2": "apt -y install aria2",
|
| 42 |
"localtunnel": "npm install -g localtunnel",
|
| 43 |
-
"insightface": "pip install insightface"
|
| 44 |
}
|
| 45 |
|
| 46 |
additional_libs = {
|
|
@@ -197,7 +197,7 @@ if commit_hash:
|
|
| 197 |
print(f"\r⌛️ Машина времени активированна! Текущий коммит: \033[34m{commit_hash}\033[0m")
|
| 198 |
|
| 199 |
|
| 200 |
-
## Downloading model and stuff | oh
|
| 201 |
print("📦 Скачивание моделей и прочего...", end='')
|
| 202 |
model_list = {
|
| 203 |
"1.Anime (by XpucT) + INP": [
|
|
@@ -328,7 +328,7 @@ user_header = f"\"Authorization: Bearer {hf_token}\""
|
|
| 328 |
''' Get Image Preview | CivitAi '''
|
| 329 |
|
| 330 |
def get_data_from_api(model_id, api_key): # get model data
|
| 331 |
-
base_url = f"https://civitai.com/api/v1/model-versions/{model_id}"
|
| 332 |
headers = {"Content-Type": "application/json"}
|
| 333 |
try:
|
| 334 |
response = requests.get(base_url, headers=headers)
|
|
@@ -339,17 +339,18 @@ def get_data_from_api(model_id, api_key): # get model data
|
|
| 339 |
return None
|
| 340 |
|
| 341 |
def extract_model_info(data, url):
|
| 342 |
-
# Get 'Type, Name and
|
|
|
|
| 343 |
if 'type=' in url:
|
| 344 |
model_type = data['files'][1]['type']
|
| 345 |
model_name = data['files'][1]['name']
|
| 346 |
-
image_url =
|
| 347 |
else:
|
| 348 |
model_type = data['model']['type']
|
| 349 |
model_name = data['files'][0]['name']
|
| 350 |
image_url = data['images'][0]['url']
|
| 351 |
|
| 352 |
-
return model_type, model_name, image_url
|
| 353 |
|
| 354 |
def gen_preview_filename(model_name, image_url):
|
| 355 |
name = model_name.split('.')
|
|
@@ -381,8 +382,6 @@ def manual_download(url, dst_dir, file_name):
|
|
| 381 |
# === CivitAi API ===
|
| 382 |
supported_types = ('Checkpoint', 'TextualInversion', 'LORA') # for dl preview image
|
| 383 |
civitai_token = "62c0c5956b2f9defbd844d754000180b"
|
| 384 |
-
image_file_name = None
|
| 385 |
-
model_type = None
|
| 386 |
|
| 387 |
if 'civitai' in url:
|
| 388 |
url = f"{url}{'&' if '?' in url else '?'}token={civitai_token}" # some authors are pussies and they need API token...
|
|
@@ -391,21 +390,20 @@ def manual_download(url, dst_dir, file_name):
|
|
| 391 |
|
| 392 |
data = get_data_from_api(model_id, civitai_token)
|
| 393 |
if data:
|
| 394 |
-
model_type, model_name, image_url = extract_model_info(data, url)
|
| 395 |
if model_name and image_url:
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
file_name = file_name or model_name # assigns the original file name if not specified initially
|
| 403 |
|
| 404 |
""" information output """
|
| 405 |
-
#
|
| 406 |
-
print(f"\n\033[32m{'---'*45}\n\033[33mURL: \033[34m{clean_url if 'civitai' in url else url}\n\033[33mSAVE DIR: \033[34m{dst_dir}\n\033[33mFILE NAME: \033[34m{file_name if not 'huggingface' in url else basename}\033[0m")
|
| 407 |
-
print(
|
| 408 |
-
print("\033[31m[Data Info]\033[0m: Failed to retrieve data from the API.\n") if 'civitai' in url and not data else None # DATA: ERROR
|
| 409 |
# ===================
|
| 410 |
|
| 411 |
# -- GDrive --
|
|
|
|
| 40 |
install_lib = {
|
| 41 |
"aria2": "apt -y install aria2",
|
| 42 |
"localtunnel": "npm install -g localtunnel",
|
| 43 |
+
"insightface": "pip install insightface"
|
| 44 |
}
|
| 45 |
|
| 46 |
additional_libs = {
|
|
|
|
| 197 |
print(f"\r⌛️ Машина времени активированна! Текущий коммит: \033[34m{commit_hash}\033[0m")
|
| 198 |
|
| 199 |
|
| 200 |
+
## Downloading model and stuff | oh~ Hey! If you're freaked out by that code too, don't worry, me too!
|
| 201 |
print("📦 Скачивание моделей и прочего...", end='')
|
| 202 |
model_list = {
|
| 203 |
"1.Anime (by XpucT) + INP": [
|
|
|
|
| 328 |
''' Get Image Preview | CivitAi '''
|
| 329 |
|
| 330 |
def get_data_from_api(model_id, api_key): # get model data
|
| 331 |
+
base_url = f"https://civitai.com/api/v1/model-versions/{model_id}"
|
| 332 |
headers = {"Content-Type": "application/json"}
|
| 333 |
try:
|
| 334 |
response = requests.get(base_url, headers=headers)
|
|
|
|
| 339 |
return None
|
| 340 |
|
| 341 |
def extract_model_info(data, url):
|
| 342 |
+
# Get 'Type, Name, imgURL and nsfwLevel' current model
|
| 343 |
+
nsfwLevel = data['images'][0]['nsfwLevel']
|
| 344 |
if 'type=' in url:
|
| 345 |
model_type = data['files'][1]['type']
|
| 346 |
model_name = data['files'][1]['name']
|
| 347 |
+
image_url = None
|
| 348 |
else:
|
| 349 |
model_type = data['model']['type']
|
| 350 |
model_name = data['files'][0]['name']
|
| 351 |
image_url = data['images'][0]['url']
|
| 352 |
|
| 353 |
+
return model_type, model_name, image_url, nsfwLevel
|
| 354 |
|
| 355 |
def gen_preview_filename(model_name, image_url):
|
| 356 |
name = model_name.split('.')
|
|
|
|
| 382 |
# === CivitAi API ===
|
| 383 |
supported_types = ('Checkpoint', 'TextualInversion', 'LORA') # for dl preview image
|
| 384 |
civitai_token = "62c0c5956b2f9defbd844d754000180b"
|
|
|
|
|
|
|
| 385 |
|
| 386 |
if 'civitai' in url:
|
| 387 |
url = f"{url}{'&' if '?' in url else '?'}token={civitai_token}" # some authors are pussies and they need API token...
|
|
|
|
| 390 |
|
| 391 |
data = get_data_from_api(model_id, civitai_token)
|
| 392 |
if data:
|
| 393 |
+
model_type, model_name, image_url, nsfwLevel = extract_model_info(data, url)
|
| 394 |
if model_name and image_url:
|
| 395 |
+
if env != 'Kaggle' or (env == 'Kaggle' and nsfwLevel <= 4): # 4 seems like a relatively safe level, but it's still a risk!
|
| 396 |
+
image_file_name = gen_preview_filename(model_name if not file_name else file_name, image_url)
|
| 397 |
+
if model_type in supported_types:
|
| 398 |
+
with capture.capture_output() as cap: # clear shit
|
| 399 |
+
get_ipython().system('aria2c {aria2_args} -d {dst_dir} -o {image_file_name} {image_url}')
|
| 400 |
+
del cap
|
| 401 |
file_name = file_name or model_name # assigns the original file name if not specified initially
|
| 402 |
|
| 403 |
""" information output """
|
| 404 |
+
# -- wrold's best print info --
|
| 405 |
+
print(f"\n\033[32m{'---'*45}\n\033[33mURL: \033[34m{clean_url if 'civitai' in url else url}\n\033[33mSAVE DIR: \033[34m{dst_dir}\n\033[33mFILE NAME: \033[34m{file_name if not 'huggingface' in url else basename}\033[0m")
|
| 406 |
+
print("\033[31m[Data Info]\033[0m: Failed to retrieve data from the API.") if 'civitai' in url and not data else None # DATA: ERROR
|
|
|
|
| 407 |
# ===================
|
| 408 |
|
| 409 |
# -- GDrive --
|