Spaces:
Running on Zero
Running on Zero
Upload app.py with huggingface_hub
Browse files413 unmodified lines41441541641741841942030 unmodified lines4514524534544554564575 unmodified lines46346446546646746846935 unmodified lines50550650750850951027 unmodified lines538539540541542543544413 unmodified linesfrom h3_inpaint_crop import canvas_for_box, paste_backprogress(0.05, desc="Lifting the subject (alpha matte) ...")green_path, matte_path = cached_matte(clip, int(seed))green = read_video(green_path)matte = read_video(matte_path)30 unmodified linesreferences = [("image", ref_path)]full_prompt = "<Picture 1> " + prompt.strip()progress(0.15, desc="Reading the prompt and reference ...")prompt_embeds, text_token_tags, metadata, _ = encode_remote(full_prompt, references, nearest_canvas_label(box[2], box[3]), n)num_frames = int(metadata["num_frames"])5 unmodified lines"source_video": green, "mask": mask, "source_audio": waveform, "source_audio_sample_rate": sample_rate,"height": height, "width": width, "num_frames": num_frames, "turbo": True,}progress(0.25, desc=f"Repainting the background at {width}x{height} ...")generated, audio, sampling_rate = _generate(request, steps, seed)progress(0.95, desc="Finishing ...")35 unmodified lines"a concert stage with dramatic blue and magenta spotlights and haze, dark background, cinematic", 0.0],]with gr.Blocks(title="Video Replace Background") as demo:gr.Markdown("# Video Replace Background\n"27 unmodified linesgr.Examples(examples=EXAMPLES, inputs=[clip, prompt, relight], label="Examples", cache_examples=False)run.click(replace_background, [clip, prompt, relight, budget, steps, seed, keep_audio, remove_bg],[result, matte_view, mask_view], api_name="replace_background")413 unmodified lines41441541641741841942030 unmodified lines4514524534544554564575 unmodified lines46346446546646746846935 unmodified lines50550650750850951051151251351451551627 unmodified lines544545546547548549550413 unmodified linesfrom h3_inpaint_crop import canvas_for_box, paste_backprogress(0.1, desc="Removing the background (LTX alpha matte) ...")green_path, matte_path = cached_matte(clip, int(seed))green = read_video(green_path)matte = read_video(matte_path)30 unmodified linesreferences = [("image", ref_path)]full_prompt = "<Picture 1> " + prompt.strip()progress(0.4, desc="Generating the new background (MiniMax-H3) ...")prompt_embeds, text_token_tags, metadata, _ = encode_remote(full_prompt, references, nearest_canvas_label(box[2], box[3]), n)num_frames = int(metadata["num_frames"])5 unmodified lines"source_video": green, "mask": mask, "source_audio": waveform, "source_audio_sample_rate": sample_rate,"height": height, "width": width, "num_frames": num_frames, "turbo": True,}progress(0.5, desc=f"Generating the new background (MiniMax-H3, {width}x{height}, ~1-2 min) ...")generated, audio, sampling_rate = _generate(request, steps, seed)progress(0.95, desc="Finishing ...")35 unmodified lines"a concert stage with dramatic blue and magenta spotlights and haze, dark background, cinematic", 0.0],]def run_classic(clip, prompt, relight, budget, steps, seed, keep_audio, remove_only, progress=gr.Progress()):"""Wraps replace_background so gradio injects a progress tracker - the handler then reports its stages(removing the background, then generating the new one) on the UI progress bar."""return replace_background(clip, prompt, relight, budget, steps, seed, keep_audio, remove_only, progress=progress)with gr.Blocks(title="Video Replace Background") as demo:gr.Markdown("# Video Replace Background\n"27 unmodified linesgr.Examples(examples=EXAMPLES, inputs=[clip, prompt, relight], label="Examples", cache_examples=False)run.click(run_classic, [clip, prompt, relight, budget, steps, seed, keep_audio, remove_bg],[result, matte_view, mask_view], api_name="replace_background")
app.py+10-4