Spaces:
Running on Zero
Running on Zero
Commit ·
e54b04d
1
Parent(s): 40da61b
Fix runtime dependency and model placement
Browse files- app.py +41 -10
- requirements.txt +1 -1
app.py
CHANGED
|
@@ -100,6 +100,15 @@ _comfy_ready = False
|
|
| 100 |
_nodes_ready = False
|
| 101 |
|
| 102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
def _run(cmd: list[str], cwd: pathlib.Path | None = None, check: bool = True) -> subprocess.CompletedProcess:
|
| 104 |
print("[setup]", " ".join(cmd), flush=True)
|
| 105 |
return subprocess.run(cmd, cwd=str(cwd) if cwd else None, check=check)
|
|
@@ -178,6 +187,36 @@ def _link_or_copy(src: pathlib.Path, dest: pathlib.Path) -> None:
|
|
| 178 |
shutil.copy2(src, dest)
|
| 179 |
|
| 180 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
def _ensure_models(progress: gr.Progress | None = None) -> None:
|
| 182 |
token = os.environ.get("HF_TOKEN") or os.environ.get("HUGGINGFACE_HUB_TOKEN")
|
| 183 |
for index, item in enumerate(DOWNLOADS):
|
|
@@ -187,15 +226,7 @@ def _ensure_models(progress: gr.Progress | None = None) -> None:
|
|
| 187 |
continue
|
| 188 |
if progress:
|
| 189 |
progress(index / len(DOWNLOADS), desc=f"downloading {item['label']}")
|
| 190 |
-
|
| 191 |
-
subfolder = str(pathlib.Path(item["file"]).parent)
|
| 192 |
-
cached = hf_hub_download(
|
| 193 |
-
repo_id=item["repo"],
|
| 194 |
-
filename=filename,
|
| 195 |
-
subfolder=None if subfolder == "." else subfolder,
|
| 196 |
-
token=token,
|
| 197 |
-
)
|
| 198 |
-
_link_or_copy(pathlib.Path(cached), dest)
|
| 199 |
|
| 200 |
|
| 201 |
def _init_comfy_nodes() -> None:
|
|
@@ -492,7 +523,7 @@ def generate(
|
|
| 492 |
out_path = out_dir / "output.mp4"
|
| 493 |
rc = subprocess.run(
|
| 494 |
[
|
| 495 |
-
|
| 496 |
"-y",
|
| 497 |
"-i",
|
| 498 |
result,
|
|
|
|
| 100 |
_nodes_ready = False
|
| 101 |
|
| 102 |
|
| 103 |
+
def _ffmpeg_exe() -> str:
|
| 104 |
+
exe = shutil.which("ffmpeg")
|
| 105 |
+
if exe:
|
| 106 |
+
return exe
|
| 107 |
+
import imageio_ffmpeg
|
| 108 |
+
|
| 109 |
+
return imageio_ffmpeg.get_ffmpeg_exe()
|
| 110 |
+
|
| 111 |
+
|
| 112 |
def _run(cmd: list[str], cwd: pathlib.Path | None = None, check: bool = True) -> subprocess.CompletedProcess:
|
| 113 |
print("[setup]", " ".join(cmd), flush=True)
|
| 114 |
return subprocess.run(cmd, cwd=str(cwd) if cwd else None, check=check)
|
|
|
|
| 187 |
shutil.copy2(src, dest)
|
| 188 |
|
| 189 |
|
| 190 |
+
def _download_to_dest(repo: str, file_path: str, dest: pathlib.Path, token: str | None) -> None:
|
| 191 |
+
dest.parent.mkdir(parents=True, exist_ok=True)
|
| 192 |
+
if dest.exists() and not dest.is_symlink():
|
| 193 |
+
return
|
| 194 |
+
if dest.is_symlink():
|
| 195 |
+
dest.unlink()
|
| 196 |
+
|
| 197 |
+
filename = pathlib.Path(file_path).name
|
| 198 |
+
subfolder = str(pathlib.Path(file_path).parent)
|
| 199 |
+
downloaded = pathlib.Path(
|
| 200 |
+
hf_hub_download(
|
| 201 |
+
repo_id=repo,
|
| 202 |
+
filename=filename,
|
| 203 |
+
subfolder=None if subfolder == "." else subfolder,
|
| 204 |
+
local_dir=str(dest.parent),
|
| 205 |
+
token=token,
|
| 206 |
+
)
|
| 207 |
+
)
|
| 208 |
+
|
| 209 |
+
if downloaded.resolve() == dest.resolve():
|
| 210 |
+
return
|
| 211 |
+
if dest.exists() or dest.is_symlink():
|
| 212 |
+
dest.unlink()
|
| 213 |
+
dest.parent.mkdir(parents=True, exist_ok=True)
|
| 214 |
+
try:
|
| 215 |
+
os.replace(downloaded, dest)
|
| 216 |
+
except OSError:
|
| 217 |
+
_link_or_copy(downloaded, dest)
|
| 218 |
+
|
| 219 |
+
|
| 220 |
def _ensure_models(progress: gr.Progress | None = None) -> None:
|
| 221 |
token = os.environ.get("HF_TOKEN") or os.environ.get("HUGGINGFACE_HUB_TOKEN")
|
| 222 |
for index, item in enumerate(DOWNLOADS):
|
|
|
|
| 226 |
continue
|
| 227 |
if progress:
|
| 228 |
progress(index / len(DOWNLOADS), desc=f"downloading {item['label']}")
|
| 229 |
+
_download_to_dest(item["repo"], item["file"], dest, token)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 230 |
|
| 231 |
|
| 232 |
def _init_comfy_nodes() -> None:
|
|
|
|
| 523 |
out_path = out_dir / "output.mp4"
|
| 524 |
rc = subprocess.run(
|
| 525 |
[
|
| 526 |
+
_ffmpeg_exe(),
|
| 527 |
"-y",
|
| 528 |
"-i",
|
| 529 |
result,
|
requirements.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
--extra-index-url https://download.pytorch.org/whl/
|
| 2 |
torch==2.8.0
|
| 3 |
torchvision==0.23.0
|
| 4 |
torchaudio==2.8.0
|
|
|
|
| 1 |
+
--extra-index-url https://download.pytorch.org/whl/cu128
|
| 2 |
torch==2.8.0
|
| 3 |
torchvision==0.23.0
|
| 4 |
torchaudio==2.8.0
|