BoxOfColors Claude Opus 4.7 (1M context) commited on
Commit
be10025
·
1 Parent(s): 89dfe5f

fix: surface mask-validation ValueError as gr.Error in run_pipeline

Browse files

Critique of 89dfe5f caught an inconsistency: on_preview_crop wraps
_compute_crop_and_mask in try/except so the ValueError messages from
mask_to_bbox / compute_crop_region (e.g. "The drawn area is too small",
"Watermark area is too large", "Frame is too small") show up as clean
status text. run_pipeline did NOT wrap the same call, so clicking
Remove Watermark with a too-small mask surfaced as a raw ValueError
stack trace in the Gradio UI instead of a styled red toast.

Now run_pipeline catches ValueError from _compute_crop_and_mask and
re-raises as gr.Error, matching the on_preview_crop UX.

Also tidy the upload-status notes formatting: when both auto-trim and
fps-cap apply (a >15s 60fps clip), the two warnings are now separated
by a blank line so they don't visually run together.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

Files changed (1) hide show
  1. app.py +13 -4
app.py CHANGED
@@ -299,7 +299,9 @@ def on_video_upload(video_path: str | None):
299
  f"⚠️ Source is {meta.fps:.0f} fps — output will be "
300
  f"{PROCESS_FPS_MAX:.0f} fps to fit GPU budget."
301
  )
302
- notes_str = ("\n\n" + "\n".join(notes)) if notes else ""
 
 
303
  return (
304
  gr.update(value=editor_val),
305
  gr.update(value=None),
@@ -498,9 +500,16 @@ def run_pipeline(
498
  raise gr.Error("Draw over the watermark before processing.")
499
 
500
  progress(0.05, desc="Computing crop region…")
501
- meta, _bbox, crop_region, inpaint_mask = _compute_crop_and_mask(
502
- raw_mask, meta_state, context_px,
503
- )
 
 
 
 
 
 
 
504
 
505
  # Cap working fps so per-frame LaMa and per-chunk VACE both fit within
506
  # their @spaces.GPU duration budgets at the worst-case input rate.
 
299
  f"⚠️ Source is {meta.fps:.0f} fps — output will be "
300
  f"{PROCESS_FPS_MAX:.0f} fps to fit GPU budget."
301
  )
302
+ # Double newline between notes so they don't visually run together
303
+ # in the Gradio status box.
304
+ notes_str = ("\n\n" + "\n\n".join(notes)) if notes else ""
305
  return (
306
  gr.update(value=editor_val),
307
  gr.update(value=None),
 
500
  raise gr.Error("Draw over the watermark before processing.")
501
 
502
  progress(0.05, desc="Computing crop region…")
503
+ try:
504
+ meta, _bbox, crop_region, inpaint_mask = _compute_crop_and_mask(
505
+ raw_mask, meta_state, context_px,
506
+ )
507
+ except ValueError as e:
508
+ # mask_to_bbox / compute_crop_region raise ValueError with user-
509
+ # facing messages ("drawn area too small", "watermark too large",
510
+ # "frame too small", etc.). Surface as gr.Error so the UI shows a
511
+ # clean red toast instead of a generic stack-traced exception.
512
+ raise gr.Error(str(e)) from e
513
 
514
  # Cap working fps so per-frame LaMa and per-chunk VACE both fit within
515
  # their @spaces.GPU duration budgets at the worst-case input rate.