Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -663,38 +663,50 @@ with gr.Blocks(title="Self-Forcing Streaming Demo") as demo:
|
|
663 |
|
664 |
# Collect all frames from this generation
|
665 |
collected_frames = []
|
|
|
|
|
|
|
666 |
|
667 |
-
# Call the generator function and yield frames, status, and video updates
|
668 |
try:
|
669 |
-
#
|
670 |
-
for
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
671 |
# Track frames for this specific session
|
672 |
if frame is not None and isinstance(frame, np.ndarray):
|
673 |
collected_frames.append(frame.copy())
|
674 |
-
|
675 |
-
# Show status update during generation
|
676 |
-
yield frame, status_html, gr.update(visible=False)
|
677 |
|
678 |
# Check if this is the final frame
|
679 |
-
if "Complete" in str(status_html) or "100%" in str(status_html):
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
if temp_file:
|
685 |
-
# Save these frames as the current set
|
686 |
-
APP_STATE["current_frames"] = collected_frames
|
687 |
-
yield frame, status_html, gr.update(visible=True, value=temp_file)
|
688 |
-
else:
|
689 |
-
yield frame, status_html, gr.update(visible=False)
|
690 |
|
691 |
-
#
|
692 |
-
if collected_frames
|
693 |
-
print(f"Generation complete, creating final video from {len(collected_frames)} frames")
|
694 |
temp_file = save_frames_as_video(collected_frames, f)
|
695 |
if temp_file:
|
696 |
-
|
697 |
-
|
|
|
|
|
698 |
except Exception as e:
|
699 |
import traceback
|
700 |
traceback.print_exc()
|
|
|
663 |
|
664 |
# Collect all frames from this generation
|
665 |
collected_frames = []
|
666 |
+
last_frame = None
|
667 |
+
last_status = None
|
668 |
+
generation_complete = False
|
669 |
|
|
|
670 |
try:
|
671 |
+
# Handle frame generation
|
672 |
+
for output in video_generation_handler_streaming(p, s, f, save_frames=True):
|
673 |
+
# Unpack the output correctly
|
674 |
+
if isinstance(output, tuple):
|
675 |
+
if len(output) == 2:
|
676 |
+
frame, status_html = output
|
677 |
+
else:
|
678 |
+
# Handle any unexpected output format gracefully
|
679 |
+
continue
|
680 |
+
else:
|
681 |
+
# Skip if not a proper tuple
|
682 |
+
continue
|
683 |
+
|
684 |
+
# Save the last valid frame and status
|
685 |
+
if frame is not None:
|
686 |
+
last_frame = frame
|
687 |
+
if status_html is not None:
|
688 |
+
last_status = status_html
|
689 |
+
|
690 |
# Track frames for this specific session
|
691 |
if frame is not None and isinstance(frame, np.ndarray):
|
692 |
collected_frames.append(frame.copy())
|
|
|
|
|
|
|
693 |
|
694 |
# Check if this is the final frame
|
695 |
+
if status_html and ("Complete" in str(status_html) or "100%" in str(status_html)):
|
696 |
+
generation_complete = True
|
697 |
+
|
698 |
+
# Always keep final video hidden during streaming
|
699 |
+
yield frame, status_html, gr.update(visible=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
700 |
|
701 |
+
# After streaming is done, create the final video
|
702 |
+
if collected_frames:
|
703 |
+
print(f"Generation complete, creating final video from {len(collected_frames)} frames at {f} FPS")
|
704 |
temp_file = save_frames_as_video(collected_frames, f)
|
705 |
if temp_file:
|
706 |
+
# Save these frames as the current set
|
707 |
+
APP_STATE["current_frames"] = collected_frames
|
708 |
+
# Use the last valid frame and status
|
709 |
+
yield last_frame, last_status, gr.update(visible=True, value=temp_file)
|
710 |
except Exception as e:
|
711 |
import traceback
|
712 |
traceback.print_exc()
|