linoyts HF Staff commited on
Commit
d5663b8
·
verified ·
1 Parent(s): 7489c72

Upload app.py with huggingface_hub

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