Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,14 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
import json
|
| 3 |
import tempfile
|
| 4 |
import subprocess
|
| 5 |
import shutil
|
| 6 |
from pathlib import Path
|
| 7 |
|
|
|
|
|
|
|
|
|
|
| 8 |
import gradio as gr
|
| 9 |
import spaces
|
| 10 |
import numpy as np
|
|
@@ -39,13 +43,23 @@ def _write_caption_txt(image_path: str, caption: str) -> str:
|
|
| 39 |
|
| 40 |
|
| 41 |
def _run(cmd: list[str], desc: str = "") -> tuple[bool, str]:
|
| 42 |
-
"""Run a
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
print(f"[Lyra] {desc}: {' '.join(cmd)}")
|
| 44 |
result = subprocess.run(
|
| 45 |
cmd,
|
| 46 |
capture_output=True,
|
| 47 |
text=True,
|
| 48 |
-
env=
|
|
|
|
| 49 |
)
|
| 50 |
log = result.stdout + "\n" + result.stderr
|
| 51 |
return result.returncode == 0, log
|
|
@@ -97,8 +111,7 @@ def run_zoomgs(
|
|
| 97 |
if use_dmd:
|
| 98 |
cmd.append("--use_dmd")
|
| 99 |
|
| 100 |
-
ok, log = _run(
|
| 101 |
-
"ZoomGS video generation")
|
| 102 |
|
| 103 |
# Locate output video
|
| 104 |
video_path = output_dir / "0" / "videos" / "0.mp4"
|
|
@@ -130,7 +143,7 @@ def run_zoomgs(
|
|
| 130 |
# Custom trajectory (Option 2)
|
| 131 |
# ββββββββββββββββββββββββββββββββββββββββββββββ
|
| 132 |
|
| 133 |
-
@spaces.GPU(duration=
|
| 134 |
def run_custom_traj(
|
| 135 |
image,
|
| 136 |
trajectory_file,
|
|
@@ -521,4 +534,4 @@ huggingface-cli download nvidia/Lyra-2.0 \\
|
|
| 521 |
|
| 522 |
if __name__ == "__main__":
|
| 523 |
demo = build_app()
|
| 524 |
-
demo.launch(css=CSS
|
|
|
|
| 1 |
import os
|
| 2 |
+
import sys
|
| 3 |
import json
|
| 4 |
import tempfile
|
| 5 |
import subprocess
|
| 6 |
import shutil
|
| 7 |
from pathlib import Path
|
| 8 |
|
| 9 |
+
# Root of the repo β wherever app.py lives
|
| 10 |
+
REPO_ROOT = Path(__file__).parent.resolve()
|
| 11 |
+
|
| 12 |
import gradio as gr
|
| 13 |
import spaces
|
| 14 |
import numpy as np
|
|
|
|
| 43 |
|
| 44 |
|
| 45 |
def _run(cmd: list[str], desc: str = "") -> tuple[bool, str]:
|
| 46 |
+
"""Run a Python -m command using the current interpreter with PYTHONPATH set."""
|
| 47 |
+
# Replace bare "python" / "python3" with the real interpreter path
|
| 48 |
+
if cmd[0] in ("python", "python3"):
|
| 49 |
+
cmd = [sys.executable] + cmd[1:]
|
| 50 |
+
|
| 51 |
+
run_env = {
|
| 52 |
+
**os.environ,
|
| 53 |
+
"PYTHONPATH": str(REPO_ROOT), # makes lyra_2._src.* importable
|
| 54 |
+
"PYTORCH_CUDA_ALLOC_CONF": "expandable_segments:True",
|
| 55 |
+
}
|
| 56 |
print(f"[Lyra] {desc}: {' '.join(cmd)}")
|
| 57 |
result = subprocess.run(
|
| 58 |
cmd,
|
| 59 |
capture_output=True,
|
| 60 |
text=True,
|
| 61 |
+
env=run_env,
|
| 62 |
+
cwd=str(REPO_ROOT), # run from repo root
|
| 63 |
)
|
| 64 |
log = result.stdout + "\n" + result.stderr
|
| 65 |
return result.returncode == 0, log
|
|
|
|
| 111 |
if use_dmd:
|
| 112 |
cmd.append("--use_dmd")
|
| 113 |
|
| 114 |
+
ok, log = _run(cmd, "ZoomGS video generation")
|
|
|
|
| 115 |
|
| 116 |
# Locate output video
|
| 117 |
video_path = output_dir / "0" / "videos" / "0.mp4"
|
|
|
|
| 143 |
# Custom trajectory (Option 2)
|
| 144 |
# ββββββββββββββββββββββββββββββββββββββββββββββ
|
| 145 |
|
| 146 |
+
@spaces.GPU(duration=900)
|
| 147 |
def run_custom_traj(
|
| 148 |
image,
|
| 149 |
trajectory_file,
|
|
|
|
| 534 |
|
| 535 |
if __name__ == "__main__":
|
| 536 |
demo = build_app()
|
| 537 |
+
demo.launch(css=CSS)
|