|
import os |
|
import subprocess |
|
import requests |
|
from huggingface_hub import hf_hub_download |
|
|
|
|
|
BASE_DIR = "/tmp" |
|
MODELS_DIR = f"{BASE_DIR}/comfyui_models" |
|
|
|
|
|
os.makedirs(f"{MODELS_DIR}/checkpoints", exist_ok=True) |
|
os.makedirs(f"{MODELS_DIR}/controlnet", exist_ok=True) |
|
os.makedirs(f"{MODELS_DIR}/ipadapter", exist_ok=True) |
|
os.makedirs(f"{MODELS_DIR}/pulid", exist_ok=True) |
|
os.makedirs(f"{MODELS_DIR}/clip_vision", exist_ok=True) |
|
|
|
|
|
models = [ |
|
|
|
{"repo_id": "Lykon/DreamShaper-XL-Turbo", "filename": "dreamshaperXL_turboDpmppSDEKarras.safetensors", "local_path": f"{MODELS_DIR}/checkpoints/dreamshaperXL_turboDpmppSDEKarras.safetensors"}, |
|
|
|
|
|
{"repo_id": "thibaud/controlnet-openpose-sdxl-1.0", "filename": "diffusion_pytorch_model.safetensors", "local_path": f"{MODELS_DIR}/controlnet/thibaud_xl_openpose.safetensors"}, |
|
|
|
|
|
{"repo_id": "h94/IP-Adapter", "filename": "ip-adapter_sdxl.safetensors", "local_path": f"{MODELS_DIR}/ipadapter/ip-adapter_sdxl.safetensors"}, |
|
|
|
|
|
{"repo_id": "l7dev/ip-adapter-pulid-sdxl", "filename": "ip-adapter_pulid_sdxl_fp16.safetensors", "local_path": f"{MODELS_DIR}/pulid/ip-adapter_pulid_sdxl_fp16.safetensors"}, |
|
|
|
|
|
{"repo_id": "h94/IP-Adapter", "filename": "CLIP-ViT-bigG-14-laion2B-39B-b160k.safetensors", "local_path": f"{MODELS_DIR}/clip_vision/CLIP-ViT-bigG-14-laion2B-39B-b160k.safetensors"} |
|
] |
|
|
|
|
|
for model in models: |
|
try: |
|
os.makedirs(os.path.dirname(model["local_path"]), exist_ok=True) |
|
|
|
print(f"Downloading {model['filename']} from {model['repo_id']}...") |
|
|
|
|
|
token = os.environ.get("HF_TOKEN", None) |
|
|
|
hf_hub_download( |
|
repo_id=model["repo_id"], |
|
filename=model["filename"], |
|
local_dir=os.path.dirname(model["local_path"]), |
|
local_dir_use_symlinks=False, |
|
token=token |
|
) |
|
|
|
|
|
downloaded_path = os.path.join(os.path.dirname(model["local_path"]), model["filename"]) |
|
if downloaded_path != model["local_path"]: |
|
os.rename(downloaded_path, model["local_path"]) |
|
|
|
print(f"Successfully downloaded {model['filename']}") |
|
except Exception as e: |
|
print(f"Error downloading {model['filename']}: {str(e)}") |
|
|
|
|
|
print("Creating symbolic links to models directory...") |
|
try: |
|
|
|
for model_type in ["checkpoints", "controlnet", "ipadapter", "pulid", "clip_vision"]: |
|
|
|
os.makedirs(f"/app/ComfyUI/models/{model_type}", exist_ok=True) |
|
|
|
|
|
for filename in os.listdir(f"{MODELS_DIR}/{model_type}"): |
|
source = f"{MODELS_DIR}/{model_type}/{filename}" |
|
target = f"/app/ComfyUI/models/{model_type}/{filename}" |
|
|
|
if not os.path.exists(target): |
|
try: |
|
os.symlink(source, target) |
|
print(f"Created symlink: {target} -> {source}") |
|
except Exception as e: |
|
print(f"Error creating symlink {target}: {e}") |
|
except Exception as e: |
|
print(f"Error setting up symbolic links: {e}") |
|
|
|
print("Model download completed.") |
|
|