linoyts HF Staff commited on
Commit
bc3a026
·
verified ·
1 Parent(s): 8ff1b07

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +10 -2
app.py CHANGED
@@ -415,11 +415,19 @@ def replace_background(clip, prompt, relight, budget, steps, seed, keep_audio, p
415
 
416
  progress(0.95, desc="Finishing ...")
417
  raw = np.stack([np.asarray(f) for f in generated])
 
418
  if float(relight) > 0:
419
  # keep H3's own frame so the relight it applied to the subject survives
420
- frames = np.stack([np.asarray(Image.fromarray(f).resize((clip_w, clip_h))) for f in raw])
421
  else:
422
- frames = paste_back(green, raw, (0, 0, clip_h, clip_w), mask=(mask > 0.5).astype(np.float32), feather=8)
 
 
 
 
 
 
 
423
 
424
  from diffusers.utils import encode_video
425
  import torch
 
415
 
416
  progress(0.95, desc="Finishing ...")
417
  raw = np.stack([np.asarray(f) for f in generated])
418
+ gen = np.stack([np.asarray(Image.fromarray(f).resize((clip_w, clip_h), Image.Resampling.LANCZOS)) for f in raw])
419
  if float(relight) > 0:
420
  # keep H3's own frame so the relight it applied to the subject survives
421
+ frames = gen
422
  else:
423
+ # Full-frame composite: restore the exact subject pixels, feathering ONLY the subject boundary. paste_back's
424
+ # border ramp fades to the plate at the frame edges, which here is the green screen - so it is not used; the
425
+ # background (incl. the frame edge) is taken fully from the generated frame.
426
+ from h3_inpaint_crop import _feather_mask
427
+
428
+ weight = _feather_mask((mask > 0.5).astype(np.float32), 8)[..., None]
429
+ frames = (green.astype(np.float32) * (1 - weight) + gen.astype(np.float32) * weight)
430
+ frames = frames.round().clip(0, 255).astype(np.uint8)
431
 
432
  from diffusers.utils import encode_video
433
  import torch