Umut Kocasari Claude Opus 4.8 commited on
Commit
d35e4df
·
1 Parent(s): e92e6bd

Fix RVM background removal crash on the Space (trust_repo + fallback)

Browse files

torch.hub.load('PeterL1n/RobustVideoMatting') prompts 'trust this repo?', which
raises EOFError in the non-interactive Space. Pass trust_repo=True. Also wrap the
background-removal call so any failure logs a warning and falls back to full-frame
reconstruction instead of aborting the whole run.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Files changed (2) hide show
  1. app.py +8 -3
  2. src/faceanything/background.py +3 -1
app.py CHANGED
@@ -250,9 +250,14 @@ def run(
250
  _say(0.08, "Removing background (Robust Video Matting)…")
251
  from faceanything.background import generate_masks
252
 
253
- mask_paths = generate_masks(
254
- frame_paths, os.path.join(workdir, "masks"), device=device
255
- )
 
 
 
 
 
256
 
257
  # ---- model + inference ----
258
  _say(0.15, "Loading model (first run downloads/loads the checkpoint)…")
 
250
  _say(0.08, "Removing background (Robust Video Matting)…")
251
  from faceanything.background import generate_masks
252
 
253
+ try:
254
+ mask_paths = generate_masks(
255
+ frame_paths, os.path.join(workdir, "masks"), device=device
256
+ )
257
+ except Exception as bg_err: # don't let RVM take down the whole run
258
+ mask_paths = None
259
+ log.append(f"WARNING: background removal failed ({bg_err}); "
260
+ f"reconstructing the full frame instead.")
261
 
262
  # ---- model + inference ----
263
  _say(0.15, "Loading model (first run downloads/loads the checkpoint)…")
src/faceanything/background.py CHANGED
@@ -30,7 +30,9 @@ def generate_masks(image_paths, output_dir, model_name: str = "resnet50",
30
 
31
  if verbose:
32
  print(f"[faceanything] loading Robust Video Matting ({model_name}) ...", flush=True)
33
- model = torch.hub.load("PeterL1n/RobustVideoMatting", model_name)
 
 
34
  model = model.to(dev).eval()
35
 
36
  rec = [None] * 4 # recurrent state
 
30
 
31
  if verbose:
32
  print(f"[faceanything] loading Robust Video Matting ({model_name}) ...", flush=True)
33
+ # trust_repo=True avoids the interactive "trust this repo?" prompt, which
34
+ # would otherwise raise EOFError in a non-interactive Space.
35
+ model = torch.hub.load("PeterL1n/RobustVideoMatting", model_name, trust_repo=True)
36
  model = model.to(dev).eval()
37
 
38
  rec = [None] * 4 # recurrent state