Spaces:
Running on Zero
Running on Zero
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,524 +0,0 @@
|
|
| 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 |
-
import gradio as gr
|
| 10 |
-
import spaces
|
| 11 |
-
import numpy as np
|
| 12 |
-
import torch
|
| 13 |
-
|
| 14 |
-
# ──────────────────────────────────────────────
|
| 15 |
-
# flash_attn install — must happen before any
|
| 16 |
-
# lyra_2 import that pulls in flash_attn.
|
| 17 |
-
# We pick the pre-built wheel that matches the
|
| 18 |
-
# running torch+CUDA version automatically.
|
| 19 |
-
# ──────────────────────────────────────────────
|
| 20 |
-
|
| 21 |
-
def _install_flash_attn():
|
| 22 |
-
"""
|
| 23 |
-
Install flash-attn from the pre-built wheels hosted on GitHub.
|
| 24 |
-
Matches the wheel to the running torch + CUDA version so the
|
| 25 |
-
.so symbols line up — which is exactly what caused the
|
| 26 |
-
'undefined symbol: _ZN3c104cuda...' error.
|
| 27 |
-
"""
|
| 28 |
-
try:
|
| 29 |
-
import flash_attn # already installed and importable → done
|
| 30 |
-
return
|
| 31 |
-
except ImportError:
|
| 32 |
-
pass
|
| 33 |
-
|
| 34 |
-
import torch, platform
|
| 35 |
-
|
| 36 |
-
torch_ver = torch.__version__.split("+")[0].replace(".", "") # e.g. "240"
|
| 37 |
-
cuda_ver = torch.version.cuda.replace(".", "") # e.g. "121"
|
| 38 |
-
py_ver = f"cp{sys.version_info.major}{sys.version_info.minor}" # e.g. "cp310"
|
| 39 |
-
arch = platform.machine() # "x86_64"
|
| 40 |
-
|
| 41 |
-
# Official pre-built wheel index from the flash-attn GitHub releases.
|
| 42 |
-
# Pattern: flash_attn-<fa_ver>+pt<torch>cu<cuda>-<py>-<py>-linux_<arch>.whl
|
| 43 |
-
# We try the newest FA2 release first then fall back to pip --no-build-isolation.
|
| 44 |
-
wheel_url = (
|
| 45 |
-
f"https://github.com/Dao-AILab/flash-attention/releases/download/"
|
| 46 |
-
f"v2.7.4.post1/"
|
| 47 |
-
f"flash_attn-2.7.4.post1+pt{torch_ver}cu{cuda_ver}-{py_ver}-{py_ver}"
|
| 48 |
-
f"-linux_{arch}.whl"
|
| 49 |
-
)
|
| 50 |
-
|
| 51 |
-
print(f"[Lyra] Installing flash-attn wheel: {wheel_url}")
|
| 52 |
-
result = subprocess.run(
|
| 53 |
-
[sys.executable, "-m", "pip", "install", wheel_url, "--no-deps", "-q"],
|
| 54 |
-
capture_output=True, text=True,
|
| 55 |
-
)
|
| 56 |
-
if result.returncode != 0:
|
| 57 |
-
print(f"[Lyra] Pre-built wheel not found for this env, "
|
| 58 |
-
f"falling back to pip install flash-attn --no-build-isolation ...")
|
| 59 |
-
# This compiles from source — slow (~20 min) but always works.
|
| 60 |
-
subprocess.run(
|
| 61 |
-
[sys.executable, "-m", "pip", "install", "flash-attn",
|
| 62 |
-
"--no-build-isolation", "-q"],
|
| 63 |
-
check=True,
|
| 64 |
-
)
|
| 65 |
-
|
| 66 |
-
try:
|
| 67 |
-
import flash_attn
|
| 68 |
-
print(f"[Lyra] flash_attn {flash_attn.__version__} ready.")
|
| 69 |
-
except ImportError as e:
|
| 70 |
-
raise RuntimeError(f"flash_attn install succeeded but import still fails: {e}")
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
_install_flash_attn()
|
| 74 |
-
|
| 75 |
-
# ──────────────────────────────────────────────
|
| 76 |
-
# Paths
|
| 77 |
-
# ──────────────────────────────────────────────
|
| 78 |
-
REPO_ROOT = Path(__file__).parent.resolve()
|
| 79 |
-
CKPT_DIR = REPO_ROOT / "checkpoints"
|
| 80 |
-
|
| 81 |
-
# Sentinel files — if any are missing we trigger a fresh download
|
| 82 |
-
_REQUIRED_FILES = [
|
| 83 |
-
CKPT_DIR / "text_encoder" / "negative_prompt.pt",
|
| 84 |
-
CKPT_DIR / "model", # directory is enough as a sentinel
|
| 85 |
-
]
|
| 86 |
-
|
| 87 |
-
_ckpts_ready = False
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
# ──────────────────────────────────────────────
|
| 91 |
-
# Checkpoint helpers
|
| 92 |
-
# ──────────────────────────────────────────────
|
| 93 |
-
|
| 94 |
-
def _checkpoints_present() -> bool:
|
| 95 |
-
for p in _REQUIRED_FILES:
|
| 96 |
-
if not p.exists():
|
| 97 |
-
print(f"[Lyra] Missing checkpoint path: {p}")
|
| 98 |
-
return False
|
| 99 |
-
return True
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
def _download_checkpoints() -> str:
|
| 103 |
-
"""
|
| 104 |
-
Download all checkpoints from nvidia/Lyra-2.0 on HuggingFace Hub.
|
| 105 |
-
Uses snapshot_download so the full checkpoints/ tree lands at
|
| 106 |
-
REPO_ROOT/checkpoints/ — exactly where the inference scripts expect them.
|
| 107 |
-
Returns a status string for display in the UI.
|
| 108 |
-
"""
|
| 109 |
-
if _checkpoints_present():
|
| 110 |
-
return "✅ Checkpoints already present — skipping download."
|
| 111 |
-
|
| 112 |
-
print("[Lyra] Checkpoints not found — downloading from nvidia/Lyra-2.0 …")
|
| 113 |
-
|
| 114 |
-
try:
|
| 115 |
-
from huggingface_hub import snapshot_download
|
| 116 |
-
except ImportError:
|
| 117 |
-
subprocess.run(
|
| 118 |
-
[sys.executable, "-m", "pip", "install", "huggingface_hub", "-q"],
|
| 119 |
-
check=True,
|
| 120 |
-
)
|
| 121 |
-
from huggingface_hub import snapshot_download
|
| 122 |
-
|
| 123 |
-
snapshot_download(
|
| 124 |
-
repo_id="nvidia/Lyra-2.0",
|
| 125 |
-
allow_patterns=["checkpoints/**"], # only grab the checkpoints subtree
|
| 126 |
-
local_dir=str(REPO_ROOT), # → REPO_ROOT/checkpoints/...
|
| 127 |
-
local_dir_use_symlinks=False,
|
| 128 |
-
)
|
| 129 |
-
|
| 130 |
-
if _checkpoints_present():
|
| 131 |
-
msg = "✅ Checkpoints downloaded successfully."
|
| 132 |
-
print(f"[Lyra] {msg}")
|
| 133 |
-
return msg
|
| 134 |
-
|
| 135 |
-
msg = ("❌ Download finished but sentinel files are still missing. "
|
| 136 |
-
"Check Space logs and available disk space (~50 GB required).")
|
| 137 |
-
print(f"[Lyra] {msg}")
|
| 138 |
-
return msg
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
def _ensure_models():
|
| 142 |
-
"""Called before every inference run — downloads checkpoints if needed."""
|
| 143 |
-
global _ckpts_ready
|
| 144 |
-
if _ckpts_ready:
|
| 145 |
-
return
|
| 146 |
-
_download_checkpoints()
|
| 147 |
-
_ckpts_ready = _checkpoints_present()
|
| 148 |
-
if not _ckpts_ready:
|
| 149 |
-
raise RuntimeError(
|
| 150 |
-
"Checkpoints unavailable. Please click 'Download Checkpoints', "
|
| 151 |
-
"check the Space logs, and ensure ~50 GB of storage is available."
|
| 152 |
-
)
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
# ── Kick off download at module load so it's done before the first request ──
|
| 156 |
-
print("[Lyra] Startup checkpoint check …")
|
| 157 |
-
_download_checkpoints()
|
| 158 |
-
_ckpts_ready = _checkpoints_present()
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
# ──────────────────────────────────────────────
|
| 162 |
-
# Subprocess helper
|
| 163 |
-
# ──────────────────────────────────────────────
|
| 164 |
-
|
| 165 |
-
def _run(cmd: list, desc: str = "") -> tuple:
|
| 166 |
-
"""
|
| 167 |
-
Run a `python -m …` command with:
|
| 168 |
-
• sys.executable → correct venv interpreter
|
| 169 |
-
• PYTHONPATH → REPO_ROOT so lyra_2._src.* is importable
|
| 170 |
-
• cwd → REPO_ROOT so 'checkpoints/model' resolves correctly
|
| 171 |
-
"""
|
| 172 |
-
if cmd[0] in ("python", "python3"):
|
| 173 |
-
cmd = [sys.executable] + cmd[1:]
|
| 174 |
-
|
| 175 |
-
run_env = {
|
| 176 |
-
**os.environ,
|
| 177 |
-
"PYTHONPATH": str(REPO_ROOT),
|
| 178 |
-
"PYTORCH_CUDA_ALLOC_CONF": "expandable_segments:True",
|
| 179 |
-
}
|
| 180 |
-
print(f"[Lyra] {desc}: {' '.join(str(c) for c in cmd)}")
|
| 181 |
-
result = subprocess.run(
|
| 182 |
-
cmd,
|
| 183 |
-
capture_output=True,
|
| 184 |
-
text=True,
|
| 185 |
-
env=run_env,
|
| 186 |
-
cwd=str(REPO_ROOT),
|
| 187 |
-
)
|
| 188 |
-
log = result.stdout + "\n" + result.stderr
|
| 189 |
-
return result.returncode == 0, log
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
# ──────────────────────────────────────────────
|
| 193 |
-
# Zoom-in / Zoom-out trajectory (Option 1)
|
| 194 |
-
# ──────────────────────────────────────────────
|
| 195 |
-
|
| 196 |
-
@spaces.GPU(duration=900)
|
| 197 |
-
def run_zoomgs(
|
| 198 |
-
image,
|
| 199 |
-
caption,
|
| 200 |
-
zoom_in_strength,
|
| 201 |
-
zoom_out_strength,
|
| 202 |
-
num_frames_in,
|
| 203 |
-
num_frames_out,
|
| 204 |
-
use_dmd,
|
| 205 |
-
run_reconstruction,
|
| 206 |
-
):
|
| 207 |
-
_ensure_models()
|
| 208 |
-
|
| 209 |
-
with tempfile.TemporaryDirectory() as tmp:
|
| 210 |
-
from PIL import Image as PILImage
|
| 211 |
-
|
| 212 |
-
img_path = Path(tmp) / "input.png"
|
| 213 |
-
caption_path = Path(tmp) / "input.txt"
|
| 214 |
-
PILImage.fromarray(image).save(img_path)
|
| 215 |
-
caption_path.write_text(caption.strip() or "A scenic outdoor environment.")
|
| 216 |
-
|
| 217 |
-
output_dir = Path(tmp) / "outputs" / "zoomgs"
|
| 218 |
-
output_dir.mkdir(parents=True, exist_ok=True)
|
| 219 |
-
|
| 220 |
-
cmd = [
|
| 221 |
-
"python", "-m", "lyra_2._src.inference.lyra2_zoomgs_inference",
|
| 222 |
-
"--input_image_path", str(tmp),
|
| 223 |
-
"--sample_id", "0",
|
| 224 |
-
"--experiment", "lyra2",
|
| 225 |
-
"--checkpoint_dir", str(CKPT_DIR / "model"),
|
| 226 |
-
"--prompt_dir", str(tmp),
|
| 227 |
-
"--output_path", str(output_dir),
|
| 228 |
-
"--num_frames_zoom_in", str(int(num_frames_in)),
|
| 229 |
-
"--num_frames_zoom_out", str(int(num_frames_out)),
|
| 230 |
-
"--zoom_in_strength", str(zoom_in_strength),
|
| 231 |
-
"--zoom_out_strength", str(zoom_out_strength),
|
| 232 |
-
]
|
| 233 |
-
if use_dmd:
|
| 234 |
-
cmd.append("--use_dmd")
|
| 235 |
-
|
| 236 |
-
ok, log = _run(cmd, "ZoomGS video generation")
|
| 237 |
-
|
| 238 |
-
# The script writes to <output_dir>/<sample_id>/videos/<sample_id>.mp4
|
| 239 |
-
video_path = output_dir / "0" / "videos" / "0.mp4"
|
| 240 |
-
if not video_path.exists():
|
| 241 |
-
candidates = list(output_dir.rglob("*.mp4"))
|
| 242 |
-
video_path = candidates[0] if candidates else None
|
| 243 |
-
|
| 244 |
-
gs_video = None
|
| 245 |
-
if run_reconstruction and video_path and Path(video_path).exists():
|
| 246 |
-
ok2, log2 = _run(
|
| 247 |
-
["python", "-m", "lyra_2._src.inference.vipe_da3_gs_recon",
|
| 248 |
-
"--input_video_path", str(video_path)],
|
| 249 |
-
"GS reconstruction",
|
| 250 |
-
)
|
| 251 |
-
log += "\n" + log2
|
| 252 |
-
gs_candidates = list(output_dir.rglob("gs_trajectory.mp4"))
|
| 253 |
-
if gs_candidates:
|
| 254 |
-
gs_video = str(gs_candidates[0])
|
| 255 |
-
|
| 256 |
-
return (
|
| 257 |
-
str(video_path) if video_path and Path(video_path).exists() else None,
|
| 258 |
-
gs_video,
|
| 259 |
-
log[-4000:],
|
| 260 |
-
)
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
# ──────────────────────────────────────────────
|
| 264 |
-
# Custom trajectory (Option 2)
|
| 265 |
-
# ────────────────────────────────��─────────────
|
| 266 |
-
|
| 267 |
-
@spaces.GPU(duration=900)
|
| 268 |
-
def run_custom_traj(
|
| 269 |
-
image,
|
| 270 |
-
trajectory_file,
|
| 271 |
-
captions_json,
|
| 272 |
-
num_frames,
|
| 273 |
-
pose_scale,
|
| 274 |
-
use_dmd,
|
| 275 |
-
run_reconstruction,
|
| 276 |
-
):
|
| 277 |
-
_ensure_models()
|
| 278 |
-
|
| 279 |
-
with tempfile.TemporaryDirectory() as tmp:
|
| 280 |
-
from PIL import Image as PILImage
|
| 281 |
-
|
| 282 |
-
img_path = Path(tmp) / "first_frame.png"
|
| 283 |
-
PILImage.fromarray(image).save(img_path)
|
| 284 |
-
|
| 285 |
-
traj_path = Path(tmp) / "trajectory.npz"
|
| 286 |
-
shutil.copy(trajectory_file.name, traj_path)
|
| 287 |
-
|
| 288 |
-
captions_path = Path(tmp) / "captions.json"
|
| 289 |
-
try:
|
| 290 |
-
json.loads(captions_json)
|
| 291 |
-
captions_path.write_text(captions_json)
|
| 292 |
-
except (json.JSONDecodeError, TypeError):
|
| 293 |
-
captions_path.write_text(json.dumps({"0": captions_json or ""}))
|
| 294 |
-
|
| 295 |
-
output_dir = Path(tmp) / "outputs" / "custom"
|
| 296 |
-
output_dir.mkdir(parents=True, exist_ok=True)
|
| 297 |
-
|
| 298 |
-
cmd = [
|
| 299 |
-
"python", "-m", "lyra_2._src.inference.lyra2_custom_traj_inference",
|
| 300 |
-
"--input_image_path", str(img_path),
|
| 301 |
-
"--trajectory_path", str(traj_path),
|
| 302 |
-
"--experiment", "lyra2",
|
| 303 |
-
"--checkpoint_dir", str(CKPT_DIR / "model"),
|
| 304 |
-
"--captions_path", str(captions_path),
|
| 305 |
-
"--num_frames", str(int(num_frames)),
|
| 306 |
-
"--output_path", str(output_dir),
|
| 307 |
-
"--pose_scale", str(pose_scale),
|
| 308 |
-
]
|
| 309 |
-
if use_dmd:
|
| 310 |
-
cmd.append("--use_dmd")
|
| 311 |
-
|
| 312 |
-
ok, log = _run(cmd, "Custom trajectory video generation")
|
| 313 |
-
|
| 314 |
-
video_candidates = list(output_dir.rglob("*.mp4"))
|
| 315 |
-
video_path = video_candidates[0] if video_candidates else None
|
| 316 |
-
|
| 317 |
-
gs_video = None
|
| 318 |
-
if run_reconstruction and video_path:
|
| 319 |
-
ok2, log2 = _run(
|
| 320 |
-
["python", "-m", "lyra_2._src.inference.vipe_da3_gs_recon",
|
| 321 |
-
"--input_video_path", str(video_path)],
|
| 322 |
-
"GS reconstruction",
|
| 323 |
-
)
|
| 324 |
-
log += "\n" + log2
|
| 325 |
-
gs_candidates = list(output_dir.rglob("gs_trajectory.mp4"))
|
| 326 |
-
if gs_candidates:
|
| 327 |
-
gs_video = str(gs_candidates[0])
|
| 328 |
-
|
| 329 |
-
return (
|
| 330 |
-
str(video_path) if video_path else None,
|
| 331 |
-
gs_video,
|
| 332 |
-
log[-4000:],
|
| 333 |
-
)
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
# ──────────────────────────────────────────────
|
| 337 |
-
# Manual download button handler
|
| 338 |
-
# ──────────────────────────────────────────────
|
| 339 |
-
|
| 340 |
-
def manual_download():
|
| 341 |
-
global _ckpts_ready
|
| 342 |
-
msg = _download_checkpoints()
|
| 343 |
-
_ckpts_ready = _checkpoints_present()
|
| 344 |
-
return msg
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
# ──────────────────────────────────────────────
|
| 348 |
-
# UI
|
| 349 |
-
# ──────────────────────────────────────────────
|
| 350 |
-
|
| 351 |
-
CSS = """
|
| 352 |
-
@import url('https://fonts.googleapis.com/css2?family=Syne:wght@400;600;700;800&family=DM+Mono:wght@300;400;500&display=swap');
|
| 353 |
-
:root {
|
| 354 |
-
--bg:#0a0c10; --surface:#111318; --border:#1e2230;
|
| 355 |
-
--accent:#5affb0; --accent2:#a78bfa; --text:#e8eaf0; --muted:#5a5f72;
|
| 356 |
-
--radius:12px; --font-head:'Syne',sans-serif; --font-mono:'DM Mono',monospace;
|
| 357 |
-
}
|
| 358 |
-
body,.gradio-container{background:var(--bg)!important;color:var(--text)!important;font-family:var(--font-head)!important;}
|
| 359 |
-
#header{background:linear-gradient(135deg,#0d1117 0%,#161b27 60%,#0f1520 100%);border:1px solid var(--border);border-radius:var(--radius);padding:32px 40px 28px;margin-bottom:24px;position:relative;overflow:hidden;}
|
| 360 |
-
#header::before{content:'';position:absolute;inset:0;background:radial-gradient(ellipse 70% 60% at 80% 50%,rgba(94,255,176,.06) 0%,transparent 70%),radial-gradient(ellipse 50% 80% at 20% 80%,rgba(167,139,250,.06) 0%,transparent 70%);pointer-events:none;}
|
| 361 |
-
#header h1{font-size:2.4rem;font-weight:800;letter-spacing:-.02em;margin:0 0 8px;background:linear-gradient(90deg,var(--accent) 0%,var(--accent2) 100%);-webkit-background-clip:text;-webkit-text-fill-color:transparent;}
|
| 362 |
-
#header p{color:var(--muted);font-family:var(--font-mono);font-size:.85rem;margin:0;}
|
| 363 |
-
#header .badge{display:inline-block;margin-right:8px;padding:3px 10px;background:rgba(94,255,176,.1);border:1px solid rgba(94,255,176,.25);border-radius:20px;color:var(--accent);font-size:.75rem;font-family:var(--font-mono);}
|
| 364 |
-
.tab-nav button{background:transparent!important;border:none!important;border-bottom:2px solid transparent!important;color:var(--muted)!important;font-family:var(--font-head)!important;font-weight:600!important;font-size:.95rem!important;padding:10px 20px!important;transition:all .2s!important;}
|
| 365 |
-
.tab-nav button.selected,.tab-nav button:hover{color:var(--accent)!important;border-bottom-color:var(--accent)!important;background:transparent!important;}
|
| 366 |
-
.gr-panel,.gr-box,.gradio-group{background:var(--surface)!important;border:1px solid var(--border)!important;border-radius:var(--radius)!important;}
|
| 367 |
-
input,textarea,.gr-input,.gr-textbox textarea{background:#0d0f14!important;border:1px solid var(--border)!important;color:var(--text)!important;font-family:var(--font-mono)!important;border-radius:8px!important;}
|
| 368 |
-
input:focus,textarea:focus{border-color:var(--accent)!important;box-shadow:0 0 0 2px rgba(94,255,176,.12)!important;}
|
| 369 |
-
input[type=range]{accent-color:var(--accent)!important;}
|
| 370 |
-
button.primary,.gr-button-primary{background:linear-gradient(135deg,var(--accent) 0%,#38d9a9 100%)!important;color:#0a0c10!important;font-family:var(--font-head)!important;font-weight:700!important;border:none!important;border-radius:8px!important;padding:12px 28px!important;font-size:.95rem!important;transition:opacity .2s!important;}
|
| 371 |
-
button.primary:hover{opacity:.85!important;}
|
| 372 |
-
button.secondary,.gr-button-secondary{background:transparent!important;border:1px solid var(--border)!important;color:var(--muted)!important;font-family:var(--font-head)!important;border-radius:8px!important;}
|
| 373 |
-
label,.gr-form>label,.block>label span{color:var(--muted)!important;font-family:var(--font-mono)!important;font-size:.8rem!important;letter-spacing:.04em!important;text-transform:uppercase!important;}
|
| 374 |
-
#log-box textarea{font-size:.78rem!important;color:#7af0b0!important;background:#060709!important;}
|
| 375 |
-
.info-note{background:rgba(167,139,250,.07);border:1px solid rgba(167,139,250,.2);border-radius:8px;padding:12px 16px;font-family:var(--font-mono);font-size:.8rem;color:#c4b5fd;line-height:1.6;}
|
| 376 |
-
"""
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
def build_app():
|
| 380 |
-
initial_status = (
|
| 381 |
-
"✅ Checkpoints ready."
|
| 382 |
-
if _ckpts_ready else
|
| 383 |
-
"⚠️ Checkpoints not found locally. Click 'Download Checkpoints' or they will be fetched automatically on first inference."
|
| 384 |
-
)
|
| 385 |
-
|
| 386 |
-
with gr.Blocks() as demo:
|
| 387 |
-
|
| 388 |
-
gr.HTML("""
|
| 389 |
-
<div id="header">
|
| 390 |
-
<h1>✦ Lyra 2.0</h1>
|
| 391 |
-
<p>
|
| 392 |
-
<span class="badge">NVIDIA Research</span>
|
| 393 |
-
<span class="badge">3D Gaussian Splatting</span>
|
| 394 |
-
<span class="badge">arXiv 2604.13036</span>
|
| 395 |
-
</p>
|
| 396 |
-
<p style="margin-top:14px;color:#8892a4;font-size:.9rem;font-family:'Syne',sans-serif;">
|
| 397 |
-
Generate persistent, explorable 3D worlds from a single image —
|
| 398 |
-
no spatial forgetting, no temporal drift.
|
| 399 |
-
</p>
|
| 400 |
-
</div>
|
| 401 |
-
""")
|
| 402 |
-
|
| 403 |
-
# ── Checkpoint status bar ────────────────────
|
| 404 |
-
with gr.Row():
|
| 405 |
-
ckpt_status = gr.Textbox(
|
| 406 |
-
value=initial_status, label="Checkpoint Status",
|
| 407 |
-
interactive=False, scale=4,
|
| 408 |
-
)
|
| 409 |
-
ckpt_btn = gr.Button("⬇️ Download Checkpoints", variant="secondary", scale=1)
|
| 410 |
-
ckpt_btn.click(fn=manual_download, outputs=ckpt_status)
|
| 411 |
-
|
| 412 |
-
with gr.Tabs():
|
| 413 |
-
|
| 414 |
-
# ── Tab 1: Zoom Trajectory ───────────────
|
| 415 |
-
with gr.Tab("🔭 Zoom Trajectory"):
|
| 416 |
-
gr.HTML('<div class="info-note">Generate a zoom-in → zoom-out exploration video from a single image, then optionally lift it to a 3D Gaussian Splatting scene.</div>')
|
| 417 |
-
with gr.Row():
|
| 418 |
-
with gr.Column(scale=1):
|
| 419 |
-
z_image = gr.Image(label="Input Image", type="numpy", height=280)
|
| 420 |
-
z_caption = gr.Textbox(
|
| 421 |
-
label="Scene Caption",
|
| 422 |
-
placeholder="A sunlit forest clearing with tall pine trees…",
|
| 423 |
-
lines=2,
|
| 424 |
-
)
|
| 425 |
-
with gr.Accordion("Advanced Options", open=False):
|
| 426 |
-
with gr.Row():
|
| 427 |
-
z_in_str = gr.Slider(0.1, 3.0, value=0.5, step=0.1, label="Zoom-in Strength")
|
| 428 |
-
z_out_str = gr.Slider(0.1, 3.0, value=1.5, step=0.1, label="Zoom-out Strength")
|
| 429 |
-
with gr.Row():
|
| 430 |
-
z_frames_in = gr.Slider(81, 401, value=81, step=80, label="Frames Zoom-in (1+80k)")
|
| 431 |
-
z_frames_out = gr.Slider(81, 401, value=241, step=80, label="Frames Zoom-out (1+80k)")
|
| 432 |
-
with gr.Row():
|
| 433 |
-
z_dmd = gr.Checkbox(label="⚡ Fast Mode (DMD ×15 speedup, lower quality)", value=False)
|
| 434 |
-
z_recon = gr.Checkbox(label="🧊 Run 3DGS Reconstruction after video", value=True)
|
| 435 |
-
z_btn = gr.Button("Generate World", variant="primary")
|
| 436 |
-
with gr.Column(scale=1):
|
| 437 |
-
z_video = gr.Video(label="Generated Exploration Video", height=280)
|
| 438 |
-
z_gs_vid = gr.Video(label="3DGS Flythrough", height=280)
|
| 439 |
-
z_log = gr.Textbox(label="Log", lines=8, interactive=False, elem_id="log-box")
|
| 440 |
-
|
| 441 |
-
z_btn.click(
|
| 442 |
-
fn=run_zoomgs,
|
| 443 |
-
inputs=[z_image, z_caption,
|
| 444 |
-
z_in_str, z_out_str, z_frames_in, z_frames_out,
|
| 445 |
-
z_dmd, z_recon],
|
| 446 |
-
outputs=[z_video, z_gs_vid, z_log],
|
| 447 |
-
)
|
| 448 |
-
|
| 449 |
-
# ── Tab 2: Custom Trajectory ─────────────
|
| 450 |
-
with gr.Tab("🎮 Custom Trajectory"):
|
| 451 |
-
gr.HTML('<div class="info-note">Provide a custom camera trajectory (.npz with <code>w2c</code>, <code>intrinsics</code>, <code>image_height</code>, <code>image_width</code>) and per-chunk captions as JSON keyed by frame index.</div>')
|
| 452 |
-
with gr.Row():
|
| 453 |
-
with gr.Column(scale=1):
|
| 454 |
-
c_image = gr.Image(label="First Frame", type="numpy", height=240)
|
| 455 |
-
c_traj = gr.File(label="Trajectory (.npz)", file_types=[".npz"])
|
| 456 |
-
c_captions = gr.Textbox(
|
| 457 |
-
label='Per-chunk Captions (JSON or single string)',
|
| 458 |
-
placeholder='{"0": "A grand hall interior", "81": "Corridor leading outside"}',
|
| 459 |
-
lines=3,
|
| 460 |
-
)
|
| 461 |
-
with gr.Accordion("Advanced Options", open=False):
|
| 462 |
-
with gr.Row():
|
| 463 |
-
c_frames = gr.Slider(81, 961, value=481, step=80, label="Num Frames (1+80k)")
|
| 464 |
-
c_pose_scale = gr.Slider(0.1, 5.0, value=1.0, step=0.1, label="Pose Scale")
|
| 465 |
-
with gr.Row():
|
| 466 |
-
c_dmd = gr.Checkbox(label="⚡ Fast Mode (DMD)", value=False)
|
| 467 |
-
c_recon = gr.Checkbox(label="🧊 Run 3DGS Reconstruction", value=True)
|
| 468 |
-
c_btn = gr.Button("Generate World", variant="primary")
|
| 469 |
-
with gr.Column(scale=1):
|
| 470 |
-
c_video = gr.Video(label="Generated Video", height=260)
|
| 471 |
-
c_gs_vid = gr.Video(label="3DGS Flythrough", height=260)
|
| 472 |
-
c_log = gr.Textbox(label="Log", lines=8, interactive=False, elem_id="log-box")
|
| 473 |
-
|
| 474 |
-
c_btn.click(
|
| 475 |
-
fn=run_custom_traj,
|
| 476 |
-
inputs=[c_image, c_traj, c_captions,
|
| 477 |
-
c_frames, c_pose_scale, c_dmd, c_recon],
|
| 478 |
-
outputs=[c_video, c_gs_vid, c_log],
|
| 479 |
-
)
|
| 480 |
-
|
| 481 |
-
# ── Tab 3: About ─────────────────────────
|
| 482 |
-
with gr.Tab("ℹ️ About"):
|
| 483 |
-
gr.Markdown("""
|
| 484 |
-
## Lyra 2.0 — Explorable Generative 3D Worlds
|
| 485 |
-
|
| 486 |
-
**NVIDIA Research** · [Paper](https://arxiv.org/abs/2604.13036) · [Project Page](https://research.nvidia.com/labs/sil/projects/lyra2/) · [HuggingFace](https://huggingface.co/nvidia/Lyra-2.0)
|
| 487 |
-
|
| 488 |
-
### How it works
|
| 489 |
-
| Problem | Solution |
|
| 490 |
-
|---|---|
|
| 491 |
-
| **Spatial Forgetting** — revisited regions hallucinated when outside temporal context | Per-frame 3D geometry used for routing: retrieve past frames + dense correspondences |
|
| 492 |
-
| **Temporal Drifting** — autoregressive errors accumulate over long trajectories | Self-augmented histories teach the model to correct drift rather than propagate it |
|
| 493 |
-
|
| 494 |
-
### Checkpoint layout
|
| 495 |
-
```
|
| 496 |
-
checkpoints/
|
| 497 |
-
├── model/ ← main generation model weights
|
| 498 |
-
└── text_encoder/
|
| 499 |
-
└── negative_prompt.pt ← required for CFG negative guidance
|
| 500 |
-
```
|
| 501 |
-
Checkpoints are auto-downloaded (~50 GB) from `nvidia/Lyra-2.0` on HuggingFace at startup.
|
| 502 |
-
|
| 503 |
-
### GPU requirements
|
| 504 |
-
- Recommended: **H100 80 GB** or A100 80 GB
|
| 505 |
-
- ~9 min / 80 frames full quality · ~35 s with DMD fast mode
|
| 506 |
-
- GS reconstruction adds ~1 min
|
| 507 |
-
|
| 508 |
-
### Citation
|
| 509 |
-
```bibtex
|
| 510 |
-
@article{shen2026lyra2,
|
| 511 |
-
title = {Lyra 2.0: Explorable Generative 3D Worlds},
|
| 512 |
-
author = {Shen, Tianchang and Bahmani, Sherwin and He, Kai and others},
|
| 513 |
-
journal = {arXiv preprint arXiv:2604.13036},
|
| 514 |
-
year = {2026}
|
| 515 |
-
}
|
| 516 |
-
```
|
| 517 |
-
""")
|
| 518 |
-
|
| 519 |
-
return demo
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
if __name__ == "__main__":
|
| 523 |
-
demo = build_app()
|
| 524 |
-
demo.launch(css=CSS)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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