feat: add Export Last Frame and Download Video buttons below generated video
Browse files
app.py
CHANGED
|
@@ -417,6 +417,28 @@ def generate(prompt, image_path=None, last_image_path=None, canvas=DEFAULT_CANVA
|
|
| 417 |
return path, report, refined, gr.update(visible=bool(refined))
|
| 418 |
|
| 419 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 420 |
def _fit_keyframe(image_path, current_canvas):
|
| 421 |
"""Cover-crop an uploaded keyframe to the closest supported aspect ratio and select that ratio's smallest
|
| 422 |
(fastest) canvas, unless the user already picked a matching ratio."""
|
|
@@ -729,6 +751,11 @@ with gr.Blocks(title="MiniMax-H3") as demo:
|
|
| 729 |
|
| 730 |
with gr.Column():
|
| 731 |
video = gr.Video(label="Video + soundtrack")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 732 |
report = gr.Markdown(visible=False)
|
| 733 |
# An output, so it can be revealed only for a request that asked for a rewrite.
|
| 734 |
with gr.Accordion("Upsampled prompt", open=False, visible=False) as upsampled_panel:
|
|
@@ -758,6 +785,18 @@ with gr.Blocks(title="MiniMax-H3") as demo:
|
|
| 758 |
api_name="generate",
|
| 759 |
)
|
| 760 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 761 |
|
| 762 |
if __name__ == "__main__":
|
| 763 |
demo.launch(show_error=True, theme=gr.themes.Base(), css=CSS)
|
|
|
|
| 417 |
return path, report, refined, gr.update(visible=bool(refined))
|
| 418 |
|
| 419 |
|
| 420 |
+
def export_last_frame(video_path):
|
| 421 |
+
"""Extract the last frame from a generated video and return it as an image file."""
|
| 422 |
+
if not video_path:
|
| 423 |
+
raise gr.Error("No video to extract from.")
|
| 424 |
+
import subprocess, tempfile
|
| 425 |
+
out = os.path.join(tempfile.gettempdir(), f"h3-lastframe-{int(time.time() * 1000)}.png")
|
| 426 |
+
result = subprocess.run(
|
| 427 |
+
["ffmpeg", "-sseof", "-0.1", "-i", video_path, "-frames:v", "1", "-y", out],
|
| 428 |
+
capture_output=True, text=True,
|
| 429 |
+
)
|
| 430 |
+
if result.returncode != 0:
|
| 431 |
+
raise gr.Error(f"ffmpeg failed: {result.stderr[-300:]}")
|
| 432 |
+
return out
|
| 433 |
+
|
| 434 |
+
|
| 435 |
+
def download_video(video_path):
|
| 436 |
+
"""Return the video path for Gradio's built-in download."""
|
| 437 |
+
if not video_path:
|
| 438 |
+
raise gr.Error("No video to download.")
|
| 439 |
+
return video_path
|
| 440 |
+
|
| 441 |
+
|
| 442 |
def _fit_keyframe(image_path, current_canvas):
|
| 443 |
"""Cover-crop an uploaded keyframe to the closest supported aspect ratio and select that ratio's smallest
|
| 444 |
(fastest) canvas, unless the user already picked a matching ratio."""
|
|
|
|
| 751 |
|
| 752 |
with gr.Column():
|
| 753 |
video = gr.Video(label="Video + soundtrack")
|
| 754 |
+
with gr.Row():
|
| 755 |
+
last_frame_btn = gr.Button("Export Last Frame", size="sm")
|
| 756 |
+
download_btn = gr.Button("Download Video", size="sm")
|
| 757 |
+
last_frame_output = gr.Image(label="Last frame", visible=False)
|
| 758 |
+
download_file = gr.File(visible=False)
|
| 759 |
report = gr.Markdown(visible=False)
|
| 760 |
# An output, so it can be revealed only for a request that asked for a rewrite.
|
| 761 |
with gr.Accordion("Upsampled prompt", open=False, visible=False) as upsampled_panel:
|
|
|
|
| 785 |
api_name="generate",
|
| 786 |
)
|
| 787 |
|
| 788 |
+
last_frame_btn.click(
|
| 789 |
+
export_last_frame,
|
| 790 |
+
[video],
|
| 791 |
+
[last_frame_output],
|
| 792 |
+
)
|
| 793 |
+
|
| 794 |
+
download_btn.click(
|
| 795 |
+
download_video,
|
| 796 |
+
[video],
|
| 797 |
+
[download_file],
|
| 798 |
+
)
|
| 799 |
+
|
| 800 |
|
| 801 |
if __name__ == "__main__":
|
| 802 |
demo.launch(show_error=True, theme=gr.themes.Base(), css=CSS)
|