Spaces:
Running on Zero
Running on Zero
Pre-download T5, CLIP, VAE at startup (no GPU needed)
Browse files
app.py
CHANGED
|
@@ -107,11 +107,12 @@ _is_optimized = False
|
|
| 107 |
# ============================================================
|
| 108 |
def preload_model_files():
|
| 109 |
"""Pre-download model files to cache at startup (no GPU needed)"""
|
| 110 |
-
from huggingface_hub import snapshot_download
|
| 111 |
|
| 112 |
hf_token = os.environ.get("HF_TOKEN", None)
|
| 113 |
print("Pre-downloading model files to cache...")
|
| 114 |
|
|
|
|
| 115 |
try:
|
| 116 |
local_dir = snapshot_download(
|
| 117 |
repo_id="TSXu/Unicalli_Pro",
|
|
@@ -124,11 +125,33 @@ def preload_model_files():
|
|
| 124 |
ignore_patterns=["*.bin"],
|
| 125 |
token=hf_token
|
| 126 |
)
|
| 127 |
-
print(f"✓
|
| 128 |
-
return local_dir
|
| 129 |
except Exception as e:
|
| 130 |
-
print(f"Warning: Could not pre-download
|
| 131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
|
| 133 |
print("="*50)
|
| 134 |
print("Starting model pre-download...")
|
|
|
|
| 107 |
# ============================================================
|
| 108 |
def preload_model_files():
|
| 109 |
"""Pre-download model files to cache at startup (no GPU needed)"""
|
| 110 |
+
from huggingface_hub import snapshot_download, hf_hub_download
|
| 111 |
|
| 112 |
hf_token = os.environ.get("HF_TOKEN", None)
|
| 113 |
print("Pre-downloading model files to cache...")
|
| 114 |
|
| 115 |
+
# 1. Main model (Unicalli_Pro)
|
| 116 |
try:
|
| 117 |
local_dir = snapshot_download(
|
| 118 |
repo_id="TSXu/Unicalli_Pro",
|
|
|
|
| 125 |
ignore_patterns=["*.bin"],
|
| 126 |
token=hf_token
|
| 127 |
)
|
| 128 |
+
print(f"✓ Unicalli_Pro cached at: {local_dir}")
|
|
|
|
| 129 |
except Exception as e:
|
| 130 |
+
print(f"Warning: Could not pre-download Unicalli_Pro: {e}")
|
| 131 |
+
local_dir = None
|
| 132 |
+
|
| 133 |
+
# 2. T5 text encoder
|
| 134 |
+
try:
|
| 135 |
+
snapshot_download("xlabs-ai/xflux_text_encoders", token=hf_token)
|
| 136 |
+
print("✓ T5 text encoder cached")
|
| 137 |
+
except Exception as e:
|
| 138 |
+
print(f"Warning: Could not pre-download T5: {e}")
|
| 139 |
+
|
| 140 |
+
# 3. CLIP text encoder
|
| 141 |
+
try:
|
| 142 |
+
snapshot_download("openai/clip-vit-large-patch14", token=hf_token)
|
| 143 |
+
print("✓ CLIP text encoder cached")
|
| 144 |
+
except Exception as e:
|
| 145 |
+
print(f"Warning: Could not pre-download CLIP: {e}")
|
| 146 |
+
|
| 147 |
+
# 4. VAE (ae.safetensors from FLUX.1-dev)
|
| 148 |
+
try:
|
| 149 |
+
hf_hub_download("black-forest-labs/FLUX.1-dev", "ae.safetensors", token=hf_token)
|
| 150 |
+
print("✓ VAE cached")
|
| 151 |
+
except Exception as e:
|
| 152 |
+
print(f"Warning: Could not pre-download VAE: {e}")
|
| 153 |
+
|
| 154 |
+
return local_dir
|
| 155 |
|
| 156 |
print("="*50)
|
| 157 |
print("Starting model pre-download...")
|