Upload download_models.py with huggingface_hub
Browse files- download_models.py +56 -0
download_models.py
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import subprocess
|
3 |
+
import requests
|
4 |
+
from huggingface_hub import hf_hub_download
|
5 |
+
|
6 |
+
# Create directories
|
7 |
+
os.makedirs("/app/ComfyUI/models/checkpoints", exist_ok=True)
|
8 |
+
os.makedirs("/app/ComfyUI/models/controlnet", exist_ok=True)
|
9 |
+
os.makedirs("/app/ComfyUI/models/ipadapter", exist_ok=True)
|
10 |
+
os.makedirs("/app/ComfyUI/models/pulid", exist_ok=True)
|
11 |
+
os.makedirs("/app/ComfyUI/models/clip_vision", exist_ok=True)
|
12 |
+
|
13 |
+
# List of models to download
|
14 |
+
models = [
|
15 |
+
# SDXL Checkpoint
|
16 |
+
{"repo_id": "Lykon/DreamShaper-XL-Turbo", "filename": "dreamshaperXL_turboDpmppSDEKarras.safetensors", "local_path": "/app/ComfyUI/models/checkpoints/sdxl/dreamshaperXL_turboDpmppSDEKarras.safetensors"},
|
17 |
+
|
18 |
+
# ControlNet model
|
19 |
+
{"repo_id": "thibaud/controlnet-openpose-sdxl-1.0", "filename": "diffusion_pytorch_model.safetensors", "local_path": "/app/ComfyUI/models/controlnet/sdxl/thibaud_xl_openpose.safetensors"},
|
20 |
+
|
21 |
+
# IP-Adapter
|
22 |
+
{"repo_id": "h94/IP-Adapter", "filename": "ip-adapter_sdxl.safetensors", "local_path": "/app/ComfyUI/models/ipadapter/sdxl/ip-adapter_sdxl.safetensors"},
|
23 |
+
|
24 |
+
# PuLID model
|
25 |
+
{"repo_id": "l7dev/ip-adapter-pulid-sdxl", "filename": "ip-adapter_pulid_sdxl_fp16.safetensors", "local_path": "/app/ComfyUI/models/pulid/ip-adapter_pulid_sdxl_fp16.safetensors"},
|
26 |
+
|
27 |
+
# CLIP Vision
|
28 |
+
{"repo_id": "h94/IP-Adapter", "filename": "CLIP-ViT-bigG-14-laion2B-39B-b160k.safetensors", "local_path": "/app/ComfyUI/models/clip_vision/CLIP-ViT-bigG-14-laion2B-39B-b160k.safetensors"}
|
29 |
+
]
|
30 |
+
|
31 |
+
# Download each model
|
32 |
+
for model in models:
|
33 |
+
try:
|
34 |
+
os.makedirs(os.path.dirname(model["local_path"]), exist_ok=True)
|
35 |
+
|
36 |
+
print(f"Downloading {model['filename']} from {model['repo_id']}...")
|
37 |
+
|
38 |
+
# Get token from environment variable if available
|
39 |
+
token = os.environ.get("HF_TOKEN", None)
|
40 |
+
|
41 |
+
hf_hub_download(
|
42 |
+
repo_id=model["repo_id"],
|
43 |
+
filename=model["filename"],
|
44 |
+
local_dir=os.path.dirname(model["local_path"]),
|
45 |
+
local_dir_use_symlinks=False,
|
46 |
+
token=token
|
47 |
+
)
|
48 |
+
|
49 |
+
# Rename if necessary
|
50 |
+
downloaded_path = os.path.join(os.path.dirname(model["local_path"]), model["filename"])
|
51 |
+
if downloaded_path != model["local_path"]:
|
52 |
+
os.rename(downloaded_path, model["local_path"])
|
53 |
+
|
54 |
+
print(f"Successfully downloaded {model['filename']}")
|
55 |
+
except Exception as e:
|
56 |
+
print(f"Error downloading {model['filename']}: {str(e)}")
|