Spaces:
Running on Zero
Running on Zero
fix(spaces): use \$HOME instead of /data (no persistent-storage add-on needed)
Browse filesHF Pro grants ZeroGPU minutes but persistent storage at /data is a
separate paid add-on. Without it /data is unwritable, which crashed the
Space at startup. Switching the Spaces clone target and models dir to
~/comfyui — \$HOME is writable, and ZeroGPU containers freeze on sleep
rather than tear down, so the clone effectively persists across calls
within a single deploy.
- app.py +6 -5
- backend.py +1 -1
- models.py +3 -3
app.py
CHANGED
|
@@ -49,7 +49,11 @@ def _git_clone(url: str, dst: pathlib.Path, ref: str) -> None:
|
|
| 49 |
|
| 50 |
def _bootstrap() -> None:
|
| 51 |
on_spaces = _on_spaces()
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
if on_spaces and not comfy_dir.exists():
|
| 55 |
print(f"[bootstrap] cold start on Spaces; cloning ComfyUI to {comfy_dir}", flush=True)
|
|
@@ -73,10 +77,7 @@ def _bootstrap() -> None:
|
|
| 73 |
|
| 74 |
if str(comfy_dir) not in sys.path:
|
| 75 |
sys.path.insert(0, str(comfy_dir))
|
| 76 |
-
os.environ.setdefault(
|
| 77 |
-
"COMFY_MODELS_DIR",
|
| 78 |
-
str(pathlib.Path("/data/models") if on_spaces else (comfy_dir / "models")),
|
| 79 |
-
)
|
| 80 |
|
| 81 |
# Stage placeholder input files so the workflow's hard-referenced loaders
|
| 82 |
# (LoadImage/VHS_Load*) don't error at runtime even when the active mode
|
|
|
|
| 49 |
|
| 50 |
def _bootstrap() -> None:
|
| 51 |
on_spaces = _on_spaces()
|
| 52 |
+
# /data requires the paid persistent-storage add-on (separate from Pro).
|
| 53 |
+
# Without it, /data is unwritable. $HOME is writable and — because ZeroGPU
|
| 54 |
+
# containers freeze on sleep rather than tear down — the clone persists
|
| 55 |
+
# across calls within a single deploy.
|
| 56 |
+
comfy_dir = (pathlib.Path.home() / "comfyui") if on_spaces else pathlib.Path("comfyui")
|
| 57 |
|
| 58 |
if on_spaces and not comfy_dir.exists():
|
| 59 |
print(f"[bootstrap] cold start on Spaces; cloning ComfyUI to {comfy_dir}", flush=True)
|
|
|
|
| 77 |
|
| 78 |
if str(comfy_dir) not in sys.path:
|
| 79 |
sys.path.insert(0, str(comfy_dir))
|
| 80 |
+
os.environ.setdefault("COMFY_MODELS_DIR", str(comfy_dir / "models"))
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
# Stage placeholder input files so the workflow's hard-referenced loaders
|
| 83 |
# (LoadImage/VHS_Load*) don't error at runtime even when the active mode
|
backend.py
CHANGED
|
@@ -160,7 +160,7 @@ class _StubPromptServerInstance:
|
|
| 160 |
|
| 161 |
def _comfy_dir() -> pathlib.Path:
|
| 162 |
if _on_spaces():
|
| 163 |
-
return pathlib.Path(
|
| 164 |
return pathlib.Path(__file__).parent / "comfyui"
|
| 165 |
|
| 166 |
|
|
|
|
| 160 |
|
| 161 |
def _comfy_dir() -> pathlib.Path:
|
| 162 |
if _on_spaces():
|
| 163 |
+
return pathlib.Path.home() / "comfyui"
|
| 164 |
return pathlib.Path(__file__).parent / "comfyui"
|
| 165 |
|
| 166 |
|
models.py
CHANGED
|
@@ -216,7 +216,7 @@ def _comfy_models_dir() -> pathlib.Path:
|
|
| 216 |
if raw:
|
| 217 |
return pathlib.Path(raw)
|
| 218 |
if _on_spaces():
|
| 219 |
-
return pathlib.Path("/
|
| 220 |
return pathlib.Path(__file__).parent / "comfyui" / "models"
|
| 221 |
|
| 222 |
|
|
@@ -224,8 +224,8 @@ def ensure_models(filenames: set[str]) -> Iterator[DownloadEvent]:
|
|
| 224 |
"""Ensure each requested model is materialized in comfyui/models/<type>/.
|
| 225 |
|
| 226 |
Local mode: hf_hub_download into the user's HF cache; symlink to comfyui/models/.
|
| 227 |
-
Spaces mode: hf_hub_download with cache_dir
|
| 228 |
-
|
| 229 |
|
| 230 |
Files not in MODEL_REGISTRY are skipped (with a warning) — useful when the
|
| 231 |
workflow has been manually customized with non-canonical filenames that the
|
|
|
|
| 216 |
if raw:
|
| 217 |
return pathlib.Path(raw)
|
| 218 |
if _on_spaces():
|
| 219 |
+
return pathlib.Path.home() / "comfyui" / "models"
|
| 220 |
return pathlib.Path(__file__).parent / "comfyui" / "models"
|
| 221 |
|
| 222 |
|
|
|
|
| 224 |
"""Ensure each requested model is materialized in comfyui/models/<type>/.
|
| 225 |
|
| 226 |
Local mode: hf_hub_download into the user's HF cache; symlink to comfyui/models/.
|
| 227 |
+
Spaces mode: hf_hub_download with cache_dir under $HOME (no /data dependency);
|
| 228 |
+
files staged at ~/comfyui/models/<comfy_type>/<filename>.
|
| 229 |
|
| 230 |
Files not in MODEL_REGISTRY are skipped (with a warning) — useful when the
|
| 231 |
workflow has been manually customized with non-canonical filenames that the
|