Spaces:
Sleeping
Sleeping
fix: PNG plots (ZeroGPU pickling), example rows, prefetch patterns
Browse files
app.py
CHANGED
|
@@ -135,6 +135,13 @@ def export_video(frames: torch.Tensor, fps: float) -> str:
|
|
| 135 |
return path
|
| 136 |
|
| 137 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
def actions_heatmap(actions: torch.Tensor, title: str):
|
| 139 |
a = actions[0].float().cpu().numpy()
|
| 140 |
fig, ax = plt.subplots(figsize=(9, 3.2))
|
|
@@ -220,7 +227,7 @@ def run_transfer(source_video, first_frame, model_key, guidance, steps, seed):
|
|
| 220 |
guidance=ActionGuidance(scale=float(guidance)),
|
| 221 |
)
|
| 222 |
video = pipe.decode_latents(latents)[0]
|
| 223 |
-
return export_video(video, pipe.fps), actions_heatmap(actions, "Latent actions driving the replay")
|
| 224 |
|
| 225 |
|
| 226 |
@spaces.GPU(duration=240)
|
|
@@ -238,7 +245,7 @@ def run_idm(source_video, model_key, block, head):
|
|
| 238 |
extractor = get_extractor(model_key)
|
| 239 |
out_path = tempfile.mktemp(suffix=".mp4")
|
| 240 |
extractor.visualize(Path(path), Path(out_path), block=int(block), head=int(head))
|
| 241 |
-
return out_path, fig_heat, fig_pca
|
| 242 |
|
| 243 |
|
| 244 |
@spaces.GPU(duration=240)
|
|
@@ -274,7 +281,7 @@ def run_atomic(first_frame, action, num_frames, steps, seed):
|
|
| 274 |
ax.set_title(f"Atomic action token: {action} (32 dims)")
|
| 275 |
ax.set_xlabel("action dim")
|
| 276 |
fig.tight_layout()
|
| 277 |
-
return export_video(video, pipe.fps), fig
|
| 278 |
|
| 279 |
|
| 280 |
# ---------------------------------------------------------------- startup prefetch
|
|
@@ -284,7 +291,7 @@ def _prefetch():
|
|
| 284 |
try:
|
| 285 |
from huggingface_hub import snapshot_download
|
| 286 |
|
| 287 |
-
snapshot_download(REPO_ID)
|
| 288 |
snapshot_download("Wan-AI/Wan2.2-TI2V-5B-Diffusers")
|
| 289 |
except Exception as exc: # never block the UI on prefetch
|
| 290 |
print(f"prefetch failed: {exc}")
|
|
@@ -300,8 +307,12 @@ def ex_path(name: str) -> str:
|
|
| 300 |
return str(EXAMPLES_DIR / name)
|
| 301 |
|
| 302 |
|
| 303 |
-
def
|
| 304 |
-
return [[ex_path(v) if
|
|
|
|
|
|
|
|
|
|
|
|
|
| 305 |
|
| 306 |
|
| 307 |
css = """
|
|
@@ -344,9 +355,9 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css, title="O2LaF") as demo:
|
|
| 344 |
go = gr.Button("Generate", variant="primary")
|
| 345 |
with gr.Column(scale=1):
|
| 346 |
out_video = gr.Video(label="Generated video")
|
| 347 |
-
out_heat = gr.
|
| 348 |
gr.Examples(
|
| 349 |
-
examples=
|
| 350 |
inputs=[src, first, model_radio],
|
| 351 |
examples_per_page=12,
|
| 352 |
)
|
|
@@ -375,10 +386,10 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css, title="O2LaF") as demo:
|
|
| 375 |
go2 = gr.Button("Extract actions", variant="primary")
|
| 376 |
with gr.Column(scale=1):
|
| 377 |
attn_video = gr.Video(label="Action-query attention overlay")
|
| 378 |
-
heat2 = gr.
|
| 379 |
-
pca2 = gr.
|
| 380 |
gr.Examples(
|
| 381 |
-
examples=
|
| 382 |
inputs=[vid_in, model_radio2],
|
| 383 |
examples_per_page=12,
|
| 384 |
)
|
|
@@ -400,7 +411,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css, title="O2LaF") as demo:
|
|
| 400 |
go3 = gr.Button("Generate", variant="primary")
|
| 401 |
with gr.Column(scale=1):
|
| 402 |
a_video = gr.Video(label="Generated video")
|
| 403 |
-
a_plot = gr.
|
| 404 |
gr.Examples(
|
| 405 |
examples=[[ex_path("first_west.png")], [ex_path("first_gta5.png")], [ex_path("first_gr1.png")]],
|
| 406 |
inputs=[atomic_frame],
|
|
|
|
| 135 |
return path
|
| 136 |
|
| 137 |
|
| 138 |
+
def fig_to_png(fig):
|
| 139 |
+
path = tempfile.mktemp(suffix=".png")
|
| 140 |
+
fig.savefig(path, dpi=110, bbox_inches="tight")
|
| 141 |
+
plt.close(fig)
|
| 142 |
+
return path
|
| 143 |
+
|
| 144 |
+
|
| 145 |
def actions_heatmap(actions: torch.Tensor, title: str):
|
| 146 |
a = actions[0].float().cpu().numpy()
|
| 147 |
fig, ax = plt.subplots(figsize=(9, 3.2))
|
|
|
|
| 227 |
guidance=ActionGuidance(scale=float(guidance)),
|
| 228 |
)
|
| 229 |
video = pipe.decode_latents(latents)[0]
|
| 230 |
+
return export_video(video, pipe.fps), fig_to_png(actions_heatmap(actions, "Latent actions driving the replay"))
|
| 231 |
|
| 232 |
|
| 233 |
@spaces.GPU(duration=240)
|
|
|
|
| 245 |
extractor = get_extractor(model_key)
|
| 246 |
out_path = tempfile.mktemp(suffix=".mp4")
|
| 247 |
extractor.visualize(Path(path), Path(out_path), block=int(block), head=int(head))
|
| 248 |
+
return out_path, fig_to_png(fig_heat), fig_to_png(fig_pca)
|
| 249 |
|
| 250 |
|
| 251 |
@spaces.GPU(duration=240)
|
|
|
|
| 281 |
ax.set_title(f"Atomic action token: {action} (32 dims)")
|
| 282 |
ax.set_xlabel("action dim")
|
| 283 |
fig.tight_layout()
|
| 284 |
+
return export_video(video, pipe.fps), fig_to_png(fig)
|
| 285 |
|
| 286 |
|
| 287 |
# ---------------------------------------------------------------- startup prefetch
|
|
|
|
| 291 |
try:
|
| 292 |
from huggingface_hub import snapshot_download
|
| 293 |
|
| 294 |
+
snapshot_download(REPO_ID, allow_patterns=["o2laf_dit_egodexmix/*", "o2laf_dit_mixed/*"])
|
| 295 |
snapshot_download("Wan-AI/Wan2.2-TI2V-5B-Diffusers")
|
| 296 |
except Exception as exc: # never block the UI on prefetch
|
| 297 |
print(f"prefetch failed: {exc}")
|
|
|
|
| 307 |
return str(EXAMPLES_DIR / name)
|
| 308 |
|
| 309 |
|
| 310 |
+
def transfer_rows():
|
| 311 |
+
return [[ex_path(v), ex_path(f) if f else None, m] for v, f, m, _ in TRANSFER_EXAMPLES]
|
| 312 |
+
|
| 313 |
+
|
| 314 |
+
def idm_rows():
|
| 315 |
+
return [[ex_path(v), m] for v, m in IDM_EXAMPLES]
|
| 316 |
|
| 317 |
|
| 318 |
css = """
|
|
|
|
| 355 |
go = gr.Button("Generate", variant="primary")
|
| 356 |
with gr.Column(scale=1):
|
| 357 |
out_video = gr.Video(label="Generated video")
|
| 358 |
+
out_heat = gr.Image(label="Latent actions used")
|
| 359 |
gr.Examples(
|
| 360 |
+
examples=transfer_rows(),
|
| 361 |
inputs=[src, first, model_radio],
|
| 362 |
examples_per_page=12,
|
| 363 |
)
|
|
|
|
| 386 |
go2 = gr.Button("Extract actions", variant="primary")
|
| 387 |
with gr.Column(scale=1):
|
| 388 |
attn_video = gr.Video(label="Action-query attention overlay")
|
| 389 |
+
heat2 = gr.Image(label="Action tokens")
|
| 390 |
+
pca2 = gr.Image(label="Latent action space")
|
| 391 |
gr.Examples(
|
| 392 |
+
examples=idm_rows(),
|
| 393 |
inputs=[vid_in, model_radio2],
|
| 394 |
examples_per_page=12,
|
| 395 |
)
|
|
|
|
| 411 |
go3 = gr.Button("Generate", variant="primary")
|
| 412 |
with gr.Column(scale=1):
|
| 413 |
a_video = gr.Video(label="Generated video")
|
| 414 |
+
a_plot = gr.Image(label="Action token")
|
| 415 |
gr.Examples(
|
| 416 |
examples=[[ex_path("first_west.png")], [ex_path("first_gta5.png")], [ex_path("first_gr1.png")]],
|
| 417 |
inputs=[atomic_frame],
|