Spaces:
Paused
Paused
Rishi Desai
commited on
Commit
Β·
64967ea
1
Parent(s):
5fb47d3
noncache for HF
Browse files- demo.py +1 -1
- install.py +25 -13
demo.py
CHANGED
|
@@ -5,7 +5,7 @@ if "HF_DEMO" in os.environ:
|
|
| 5 |
# Global variable to track if install() has been run; only for deploying on HF space
|
| 6 |
INSTALLED = False
|
| 7 |
if not INSTALLED:
|
| 8 |
-
install(is_hf_space=True)
|
| 9 |
INSTALLED = True
|
| 10 |
|
| 11 |
import gradio as gr
|
|
|
|
| 5 |
# Global variable to track if install() has been run; only for deploying on HF space
|
| 6 |
INSTALLED = False
|
| 7 |
if not INSTALLED:
|
| 8 |
+
install(is_hf_space=True, cache_models=False)
|
| 9 |
INSTALLED = True
|
| 10 |
|
| 11 |
import gradio as gr
|
install.py
CHANGED
|
@@ -58,8 +58,8 @@ def install_comfyui():
|
|
| 58 |
)
|
| 59 |
|
| 60 |
|
| 61 |
-
def download_huggingface_models():
|
| 62 |
-
"""Download required models from Hugging Face
|
| 63 |
from huggingface_hub import hf_hub_download
|
| 64 |
hf_models = [
|
| 65 |
{"repo_id": "black-forest-labs/FLUX.1-dev", "filename": "flux1-dev.safetensors", "folder": "unet"},
|
|
@@ -79,13 +79,6 @@ def download_huggingface_models():
|
|
| 79 |
|
| 80 |
for model in hf_models:
|
| 81 |
try:
|
| 82 |
-
model_path = hf_hub_download(
|
| 83 |
-
repo_id=model["repo_id"],
|
| 84 |
-
filename=model["filename"],
|
| 85 |
-
cache_dir=os.getenv('HF_HOME'),
|
| 86 |
-
repo_type=model.get("repo_type", "model"),
|
| 87 |
-
token=os.getenv('HUGGINGFACE_TOKEN')
|
| 88 |
-
)
|
| 89 |
target_dir = os.path.join(COMFYUI_PATH, "models", model["folder"])
|
| 90 |
os.makedirs(target_dir, exist_ok=True)
|
| 91 |
|
|
@@ -93,11 +86,30 @@ def download_huggingface_models():
|
|
| 93 |
file_name_only = filename_mappings.get(model["repo_id"], os.path.basename(model["filename"]))
|
| 94 |
target_path = os.path.join(target_dir, file_name_only)
|
| 95 |
|
| 96 |
-
if
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
os.symlink(model_path, target_path)
|
| 98 |
print(f"β
Linked: {model_path} to {target_path}")
|
| 99 |
else:
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
except Exception as e:
|
| 102 |
print(f"β Failed to download {model['filename']}: {e}")
|
| 103 |
|
|
@@ -209,14 +221,14 @@ def install_hfdemo_dependencies():
|
|
| 209 |
os.makedirs(HF_CACHE, exist_ok=True)
|
| 210 |
|
| 211 |
|
| 212 |
-
def install(is_hf_space=False):
|
| 213 |
install_lfs_files()
|
| 214 |
install_comfyui()
|
| 215 |
install_custom_nodes()
|
| 216 |
if is_hf_space:
|
| 217 |
print("π Installing HF spaces dependencies...")
|
| 218 |
install_hfdemo_dependencies()
|
| 219 |
-
download_huggingface_models()
|
| 220 |
download_and_extract_antelopev2()
|
| 221 |
print("π Setup Complete!")
|
| 222 |
|
|
|
|
| 58 |
)
|
| 59 |
|
| 60 |
|
| 61 |
+
def download_huggingface_models(cache_models=True):
|
| 62 |
+
"""Download required models from Hugging Face."""
|
| 63 |
from huggingface_hub import hf_hub_download
|
| 64 |
hf_models = [
|
| 65 |
{"repo_id": "black-forest-labs/FLUX.1-dev", "filename": "flux1-dev.safetensors", "folder": "unet"},
|
|
|
|
| 79 |
|
| 80 |
for model in hf_models:
|
| 81 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
target_dir = os.path.join(COMFYUI_PATH, "models", model["folder"])
|
| 83 |
os.makedirs(target_dir, exist_ok=True)
|
| 84 |
|
|
|
|
| 86 |
file_name_only = filename_mappings.get(model["repo_id"], os.path.basename(model["filename"]))
|
| 87 |
target_path = os.path.join(target_dir, file_name_only)
|
| 88 |
|
| 89 |
+
if os.path.exists(target_path):
|
| 90 |
+
print(f"β
Already exists: {file_name_only}")
|
| 91 |
+
continue
|
| 92 |
+
|
| 93 |
+
if cache_models:
|
| 94 |
+
# Download to HF_HOME cache and create symlink
|
| 95 |
+
model_path = hf_hub_download(
|
| 96 |
+
repo_id=model["repo_id"],
|
| 97 |
+
filename=model["filename"],
|
| 98 |
+
cache_dir=os.getenv('HF_HOME'),
|
| 99 |
+
repo_type=model.get("repo_type", "model"),
|
| 100 |
+
token=os.getenv('HUGGINGFACE_TOKEN')
|
| 101 |
+
)
|
| 102 |
os.symlink(model_path, target_path)
|
| 103 |
print(f"β
Linked: {model_path} to {target_path}")
|
| 104 |
else:
|
| 105 |
+
hf_hub_download(
|
| 106 |
+
repo_id=model["repo_id"],
|
| 107 |
+
filename=model["filename"],
|
| 108 |
+
local_dir=target_dir,
|
| 109 |
+
repo_type=model.get("repo_type", "model"),
|
| 110 |
+
token=os.getenv('HUGGINGFACE_TOKEN')
|
| 111 |
+
)
|
| 112 |
+
print(f"β
Downloaded: {file_name_only} directly to {target_dir}")
|
| 113 |
except Exception as e:
|
| 114 |
print(f"β Failed to download {model['filename']}: {e}")
|
| 115 |
|
|
|
|
| 221 |
os.makedirs(HF_CACHE, exist_ok=True)
|
| 222 |
|
| 223 |
|
| 224 |
+
def install(is_hf_space=False, cache_models=True):
|
| 225 |
install_lfs_files()
|
| 226 |
install_comfyui()
|
| 227 |
install_custom_nodes()
|
| 228 |
if is_hf_space:
|
| 229 |
print("π Installing HF spaces dependencies...")
|
| 230 |
install_hfdemo_dependencies()
|
| 231 |
+
download_huggingface_models(cache_models)
|
| 232 |
download_and_extract_antelopev2()
|
| 233 |
print("π Setup Complete!")
|
| 234 |
|