Spaces:
Running on Zero
Running on Zero
Fix: canonical /edit_video API endpoint (7 inputs) + input-scaled GPU duration (~68s worst case vs fixed 300)
Browse files
app.py
CHANGED
|
@@ -74,8 +74,33 @@ def chunks_for_seconds(seconds: float) -> int:
|
|
| 74 |
return max(1, 1 + (wanted - 1) // FRAMES_PER_CHUNK)
|
| 75 |
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
# ---------------------------------------------------------------------- handler
|
| 78 |
-
@spaces.GPU(duration=
|
| 79 |
def edit_video(
|
| 80 |
video_path,
|
| 81 |
instruction,
|
|
@@ -251,8 +276,13 @@ result streams back while it is still being generated (2 flow-matching steps per
|
|
| 251 |
|
| 252 |
inputs = [video_in, instruction, seconds, seed, randomize_seed, steps, reference_image]
|
| 253 |
outputs = [preview, video_out, status]
|
| 254 |
-
|
| 255 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
|
| 257 |
if __name__ == "__main__":
|
| 258 |
demo.queue(max_size=12).launch(theme=gr.themes.Citrus(), css=CSS)
|
|
|
|
| 74 |
return max(1, 1 + (wanted - 1) // FRAMES_PER_CHUNK)
|
| 75 |
|
| 76 |
|
| 77 |
+
def _estimate_duration(
|
| 78 |
+
video_path=None,
|
| 79 |
+
instruction="",
|
| 80 |
+
seconds=2.0,
|
| 81 |
+
seed=42,
|
| 82 |
+
randomize_seed=False,
|
| 83 |
+
num_inference_steps=2,
|
| 84 |
+
*args,
|
| 85 |
+
**kwargs,
|
| 86 |
+
):
|
| 87 |
+
"""Reserve GPU time scaled to the real per-chunk cost.
|
| 88 |
+
|
| 89 |
+
Measured on the live sm_120 slice: ~1.0 s per (chunk × step) plus fixed
|
| 90 |
+
overhead (condition encode + mux). Worst case (12 chunks × 4 steps) runs in
|
| 91 |
+
~48 s of GPU compute, so 15 + units × 1.1 (≈68 s worst case) covers it with
|
| 92 |
+
a modest margin while keeping short runs cheap and high-priority.
|
| 93 |
+
"""
|
| 94 |
+
try:
|
| 95 |
+
chunks = chunks_for_seconds(float(seconds))
|
| 96 |
+
steps = max(1, int(num_inference_steps))
|
| 97 |
+
except (TypeError, ValueError):
|
| 98 |
+
chunks, steps = 12, 4
|
| 99 |
+
return int(min(120, 15 + chunks * steps * 1.1))
|
| 100 |
+
|
| 101 |
+
|
| 102 |
# ---------------------------------------------------------------------- handler
|
| 103 |
+
@spaces.GPU(duration=_estimate_duration, size="large")
|
| 104 |
def edit_video(
|
| 105 |
video_path,
|
| 106 |
instruction,
|
|
|
|
| 276 |
|
| 277 |
inputs = [video_in, instruction, seconds, seed, randomize_seed, steps, reference_image]
|
| 278 |
outputs = [preview, video_out, status]
|
| 279 |
+
# Canonical API endpoint — the click handler owns `/edit_video` with the full
|
| 280 |
+
# 7-input signature. The submit handler gets a distinct name so it can't shadow
|
| 281 |
+
# the primary binding or register with a truncated signature.
|
| 282 |
+
run_btn.click(edit_video, inputs=inputs, outputs=outputs,
|
| 283 |
+
concurrency_limit=1, api_name="edit_video")
|
| 284 |
+
instruction.submit(edit_video, inputs=inputs, outputs=outputs,
|
| 285 |
+
concurrency_limit=1, api_name="edit_video_submit")
|
| 286 |
|
| 287 |
if __name__ == "__main__":
|
| 288 |
demo.queue(max_size=12).launch(theme=gr.themes.Citrus(), css=CSS)
|