File size: 3,574 Bytes
c076b60
 
 
 
 
3a580c7
 
 
 
c076b60
3a580c7
 
 
 
 
c076b60
 
 
 
3a580c7
c076b60
 
3a580c7
c076b60
 
3a580c7
c076b60
 
3a580c7
c076b60
 
3a580c7
c076b60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3a580c7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import os
import subprocess
import requests
from huggingface_hub import hf_hub_download

# Use writable directories
BASE_DIR = "/tmp"
MODELS_DIR = f"{BASE_DIR}/comfyui_models"

# Create directories
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)

# List of models to download
models = [
    # SDXL Checkpoint
    {"repo_id": "Lykon/DreamShaper-XL-Turbo", "filename": "dreamshaperXL_turboDpmppSDEKarras.safetensors", "local_path": f"{MODELS_DIR}/checkpoints/dreamshaperXL_turboDpmppSDEKarras.safetensors"},
    
    # ControlNet model
    {"repo_id": "thibaud/controlnet-openpose-sdxl-1.0", "filename": "diffusion_pytorch_model.safetensors", "local_path": f"{MODELS_DIR}/controlnet/thibaud_xl_openpose.safetensors"},
    
    # IP-Adapter
    {"repo_id": "h94/IP-Adapter", "filename": "ip-adapter_sdxl.safetensors", "local_path": f"{MODELS_DIR}/ipadapter/ip-adapter_sdxl.safetensors"},
    
    # PuLID model
    {"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"},
    
    # CLIP Vision
    {"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"}
]

# Download each model
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']}...")
        
        # Get token from environment variable if available
        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
        )
        
        # Rename if necessary
        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)}")

# Create symbolic links for standard ComfyUI paths
print("Creating symbolic links to models directory...")
try:
    # Link from ComfyUI's default directories to our writable directory
    for model_type in ["checkpoints", "controlnet", "ipadapter", "pulid", "clip_vision"]:
        # Make the original directory if it doesn't exist
        os.makedirs(f"/app/ComfyUI/models/{model_type}", exist_ok=True)
        
        # Create symbolic links for each file
        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.")