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