Spaces:
Running on Zero
Running on Zero
MacstudioM2 commited on
Commit ·
9fcacea
1
Parent(s): 07533d8
Add Stop button to cancel running video generation
Browse filesWrap Generate Video button in a Row with a Stop button.
Capture click event and use cancels= to abort the running task.
app.py
CHANGED
|
@@ -710,7 +710,9 @@ with gr.Blocks(theme=gr.themes.Soft(), css=CSS, delete_cache=(3600, 3700)) as de
|
|
| 710 |
safety_checker_input = gr.Checkbox(label="Enable Safety Filter", value=True, info="Prevents unrequested sensitive or explicit content.")
|
| 711 |
play_result_video = gr.Checkbox(label="Display result", value=True, interactive=True)
|
| 712 |
|
| 713 |
-
|
|
|
|
|
|
|
| 714 |
|
| 715 |
with gr.Column():
|
| 716 |
# ASSIGNED elem_id="generated-video" so JS can find it
|
|
@@ -732,12 +734,20 @@ with gr.Blocks(theme=gr.themes.Soft(), css=CSS, delete_cache=(3600, 3700)) as de
|
|
| 732 |
play_result_video, safe_mode_checkbox, safety_checker_input
|
| 733 |
]
|
| 734 |
|
| 735 |
-
generate_button.click(
|
| 736 |
-
fn=generate_video,
|
| 737 |
-
inputs=ui_inputs,
|
| 738 |
outputs=[video_output, file_output, seed_input]
|
| 739 |
)
|
| 740 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 741 |
# --- Frame Grabbing Events ---
|
| 742 |
# 1. Click button -> JS runs -> puts time in hidden number box
|
| 743 |
grab_frame_btn.click(
|
|
|
|
| 710 |
safety_checker_input = gr.Checkbox(label="Enable Safety Filter", value=True, info="Prevents unrequested sensitive or explicit content.")
|
| 711 |
play_result_video = gr.Checkbox(label="Display result", value=True, interactive=True)
|
| 712 |
|
| 713 |
+
with gr.Row():
|
| 714 |
+
generate_button = gr.Button("Generate Video", variant="primary", scale=4)
|
| 715 |
+
stop_button = gr.Button("⏹ Stop", variant="stop", scale=1)
|
| 716 |
|
| 717 |
with gr.Column():
|
| 718 |
# ASSIGNED elem_id="generated-video" so JS can find it
|
|
|
|
| 734 |
play_result_video, safe_mode_checkbox, safety_checker_input
|
| 735 |
]
|
| 736 |
|
| 737 |
+
generate_event = generate_button.click(
|
| 738 |
+
fn=generate_video,
|
| 739 |
+
inputs=ui_inputs,
|
| 740 |
outputs=[video_output, file_output, seed_input]
|
| 741 |
)
|
| 742 |
+
|
| 743 |
+
# Stop button: cancels the currently-running generate_video event.
|
| 744 |
+
stop_button.click(
|
| 745 |
+
fn=None,
|
| 746 |
+
inputs=None,
|
| 747 |
+
outputs=None,
|
| 748 |
+
cancels=[generate_event],
|
| 749 |
+
)
|
| 750 |
+
|
| 751 |
# --- Frame Grabbing Events ---
|
| 752 |
# 1. Click button -> JS runs -> puts time in hidden number box
|
| 753 |
grab_frame_btn.click(
|