Spaces:
Running on Zero
Running on Zero
Upload app.py with huggingface_hub
Browse files
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 =
|
| 424 |
else:
|
| 425 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|