Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -432,7 +432,7 @@ def video_generation_handler_streaming(prompt, seed=42, fps=15):
|
|
| 432 |
)
|
| 433 |
|
| 434 |
# Yield None for video but update status (frame-by-frame tracking)
|
| 435 |
-
yield None, frame_status_html, gr.update(visible=False),
|
| 436 |
|
| 437 |
# Encode entire block as one chunk immediately
|
| 438 |
if all_frames_from_block:
|
|
@@ -450,7 +450,7 @@ def video_generation_handler_streaming(prompt, seed=42, fps=15):
|
|
| 450 |
total_progress = (idx + 1) / num_blocks * 100
|
| 451 |
|
| 452 |
# Yield the actual video chunk
|
| 453 |
-
yield ts_path, gr.update(), gr.update(visible=False),
|
| 454 |
|
| 455 |
except Exception as e:
|
| 456 |
print(f"⚠️ Error encoding block {idx}: {e}")
|
|
@@ -492,17 +492,11 @@ def video_generation_handler_streaming(prompt, seed=42, fps=15):
|
|
| 492 |
f"</div>"
|
| 493 |
)
|
| 494 |
|
| 495 |
-
# Show
|
| 496 |
-
yield None, final_status_html, final_mp4_path, gr.update(value=final_mp4_path)
|
| 497 |
|
| 498 |
print(f"✅ PyAV streaming complete! {total_frames_yielded} frames across {num_blocks} blocks")
|
| 499 |
|
| 500 |
-
def download_video(video_path):
|
| 501 |
-
"""Handle video download."""
|
| 502 |
-
if video_path and os.path.exists(video_path):
|
| 503 |
-
return video_path
|
| 504 |
-
return None
|
| 505 |
-
|
| 506 |
# --- Gradio UI Layout ---
|
| 507 |
with gr.Blocks(title="Self-Forcing Streaming Demo") as demo:
|
| 508 |
gr.Markdown("# 🚀 Self-Forcing Video Generation")
|
|
@@ -563,21 +557,20 @@ with gr.Blocks(title="Self-Forcing Streaming Demo") as demo:
|
|
| 563 |
|
| 564 |
gr.Markdown("### 🎬 Complete Video")
|
| 565 |
|
| 566 |
-
# Complete video display
|
| 567 |
complete_video = gr.Video(
|
| 568 |
label="Complete Video",
|
| 569 |
height=400,
|
| 570 |
show_label=False,
|
| 571 |
-
visible=False
|
|
|
|
| 572 |
)
|
| 573 |
|
| 574 |
-
#
|
| 575 |
-
|
| 576 |
-
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
variant="primary"
|
| 580 |
-
)
|
| 581 |
|
| 582 |
status_display = gr.HTML(
|
| 583 |
value=(
|
|
@@ -589,31 +582,18 @@ with gr.Blocks(title="Self-Forcing Streaming Demo") as demo:
|
|
| 589 |
label="Generation Status"
|
| 590 |
)
|
| 591 |
|
| 592 |
-
# Hidden component to store the download file path
|
| 593 |
-
download_file = gr.File(visible=False)
|
| 594 |
-
|
| 595 |
# Connect the generator to the streaming video
|
| 596 |
generation_event = start_btn.click(
|
| 597 |
fn=video_generation_handler_streaming,
|
| 598 |
inputs=[prompt, seed, fps],
|
| 599 |
-
outputs=[streaming_video, status_display, complete_video,
|
| 600 |
)
|
| 601 |
|
| 602 |
-
# When generation completes, show the complete video
|
| 603 |
generation_event.then(
|
| 604 |
-
fn=lambda x:
|
| 605 |
-
inputs=[complete_video],
|
| 606 |
-
outputs=[complete_video, download_button]
|
| 607 |
-
)
|
| 608 |
-
|
| 609 |
-
# Handle download button click
|
| 610 |
-
download_button.click(
|
| 611 |
-
fn=download_video,
|
| 612 |
inputs=[complete_video],
|
| 613 |
-
outputs=[
|
| 614 |
-
).then(
|
| 615 |
-
fn=lambda: gr.update(visible=True),
|
| 616 |
-
outputs=[download_file]
|
| 617 |
)
|
| 618 |
|
| 619 |
enhance_button.click(
|
|
|
|
| 432 |
)
|
| 433 |
|
| 434 |
# Yield None for video but update status (frame-by-frame tracking)
|
| 435 |
+
yield None, frame_status_html, gr.update(visible=False), gr.update(visible=False)
|
| 436 |
|
| 437 |
# Encode entire block as one chunk immediately
|
| 438 |
if all_frames_from_block:
|
|
|
|
| 450 |
total_progress = (idx + 1) / num_blocks * 100
|
| 451 |
|
| 452 |
# Yield the actual video chunk
|
| 453 |
+
yield ts_path, gr.update(), gr.update(visible=False), gr.update(visible=False)
|
| 454 |
|
| 455 |
except Exception as e:
|
| 456 |
print(f"⚠️ Error encoding block {idx}: {e}")
|
|
|
|
| 492 |
f"</div>"
|
| 493 |
)
|
| 494 |
|
| 495 |
+
# Show complete video and file download
|
| 496 |
+
yield None, final_status_html, final_mp4_path, gr.update(value=final_mp4_path, visible=True)
|
| 497 |
|
| 498 |
print(f"✅ PyAV streaming complete! {total_frames_yielded} frames across {num_blocks} blocks")
|
| 499 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 500 |
# --- Gradio UI Layout ---
|
| 501 |
with gr.Blocks(title="Self-Forcing Streaming Demo") as demo:
|
| 502 |
gr.Markdown("# 🚀 Self-Forcing Video Generation")
|
|
|
|
| 557 |
|
| 558 |
gr.Markdown("### 🎬 Complete Video")
|
| 559 |
|
| 560 |
+
# Complete video display with download enabled
|
| 561 |
complete_video = gr.Video(
|
| 562 |
label="Complete Video",
|
| 563 |
height=400,
|
| 564 |
show_label=False,
|
| 565 |
+
visible=False,
|
| 566 |
+
show_download_button=True # Enable download button in video control
|
| 567 |
)
|
| 568 |
|
| 569 |
+
# File component for download
|
| 570 |
+
download_file = gr.File(
|
| 571 |
+
label="📥 Download Video File",
|
| 572 |
+
visible=False
|
| 573 |
+
)
|
|
|
|
|
|
|
| 574 |
|
| 575 |
status_display = gr.HTML(
|
| 576 |
value=(
|
|
|
|
| 582 |
label="Generation Status"
|
| 583 |
)
|
| 584 |
|
|
|
|
|
|
|
|
|
|
| 585 |
# Connect the generator to the streaming video
|
| 586 |
generation_event = start_btn.click(
|
| 587 |
fn=video_generation_handler_streaming,
|
| 588 |
inputs=[prompt, seed, fps],
|
| 589 |
+
outputs=[streaming_video, status_display, complete_video, download_file]
|
| 590 |
)
|
| 591 |
|
| 592 |
+
# When generation completes, show the complete video
|
| 593 |
generation_event.then(
|
| 594 |
+
fn=lambda x: gr.update(visible=True),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 595 |
inputs=[complete_video],
|
| 596 |
+
outputs=[complete_video]
|
|
|
|
|
|
|
|
|
|
| 597 |
)
|
| 598 |
|
| 599 |
enhance_button.click(
|