linoyts HF Staff commited on
Commit
08b50dc
·
verified ·
1 Parent(s): 7b30dd2

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -414,7 +414,7 @@ def replace_background(clip, prompt, relight, budget, steps, seed, keep_audio, r
414
 
415
  from h3_inpaint_crop import canvas_for_box, paste_back
416
 
417
- progress(0.05, desc="Lifting the subject (alpha matte) ...")
418
  green_path, matte_path = cached_matte(clip, int(seed))
419
  green = read_video(green_path)
420
  matte = read_video(matte_path)
@@ -451,7 +451,7 @@ def replace_background(clip, prompt, relight, budget, steps, seed, keep_audio, r
451
 
452
  references = [("image", ref_path)]
453
  full_prompt = "<Picture 1> " + prompt.strip()
454
- progress(0.15, desc="Reading the prompt and reference ...")
455
  prompt_embeds, text_token_tags, metadata, _ = encode_remote(
456
  full_prompt, references, nearest_canvas_label(box[2], box[3]), n)
457
  num_frames = int(metadata["num_frames"])
@@ -463,7 +463,7 @@ def replace_background(clip, prompt, relight, budget, steps, seed, keep_audio, r
463
  "source_video": green, "mask": mask, "source_audio": waveform, "source_audio_sample_rate": sample_rate,
464
  "height": height, "width": width, "num_frames": num_frames, "turbo": True,
465
  }
466
- progress(0.25, desc=f"Repainting the background at {width}x{height} ...")
467
  generated, audio, sampling_rate = _generate(request, steps, seed)
468
 
469
  progress(0.95, desc="Finishing ...")
@@ -505,6 +505,12 @@ EXAMPLES = [
505
  "a concert stage with dramatic blue and magenta spotlights and haze, dark background, cinematic", 0.0],
506
  ]
507
 
 
 
 
 
 
 
508
  with gr.Blocks(title="Video Replace Background") as demo:
509
  gr.Markdown(
510
  "# Video Replace Background\n"
@@ -538,7 +544,7 @@ with gr.Blocks(title="Video Replace Background") as demo:
538
 
539
  gr.Examples(examples=EXAMPLES, inputs=[clip, prompt, relight], label="Examples", cache_examples=False)
540
 
541
- run.click(replace_background, [clip, prompt, relight, budget, steps, seed, keep_audio, remove_bg],
542
  [result, matte_view, mask_view], api_name="replace_background")
543
 
544
 
 
414
 
415
  from h3_inpaint_crop import canvas_for_box, paste_back
416
 
417
+ progress(0.1, desc="Removing the background (LTX alpha matte) ...")
418
  green_path, matte_path = cached_matte(clip, int(seed))
419
  green = read_video(green_path)
420
  matte = read_video(matte_path)
 
451
 
452
  references = [("image", ref_path)]
453
  full_prompt = "<Picture 1> " + prompt.strip()
454
+ progress(0.4, desc="Generating the new background (MiniMax-H3) ...")
455
  prompt_embeds, text_token_tags, metadata, _ = encode_remote(
456
  full_prompt, references, nearest_canvas_label(box[2], box[3]), n)
457
  num_frames = int(metadata["num_frames"])
 
463
  "source_video": green, "mask": mask, "source_audio": waveform, "source_audio_sample_rate": sample_rate,
464
  "height": height, "width": width, "num_frames": num_frames, "turbo": True,
465
  }
466
+ progress(0.5, desc=f"Generating the new background (MiniMax-H3, {width}x{height}, ~1-2 min) ...")
467
  generated, audio, sampling_rate = _generate(request, steps, seed)
468
 
469
  progress(0.95, desc="Finishing ...")
 
505
  "a concert stage with dramatic blue and magenta spotlights and haze, dark background, cinematic", 0.0],
506
  ]
507
 
508
+ def run_classic(clip, prompt, relight, budget, steps, seed, keep_audio, remove_only, progress=gr.Progress()):
509
+ """Wraps replace_background so gradio injects a progress tracker - the handler then reports its stages
510
+ (removing the background, then generating the new one) on the UI progress bar."""
511
+ return replace_background(clip, prompt, relight, budget, steps, seed, keep_audio, remove_only, progress=progress)
512
+
513
+
514
  with gr.Blocks(title="Video Replace Background") as demo:
515
  gr.Markdown(
516
  "# Video Replace Background\n"
 
544
 
545
  gr.Examples(examples=EXAMPLES, inputs=[clip, prompt, relight], label="Examples", cache_examples=False)
546
 
547
+ run.click(run_classic, [clip, prompt, relight, budget, steps, seed, keep_audio, remove_bg],
548
  [result, matte_view, mask_view], api_name="replace_background")
549
 
550