# demo source from: https://github.com/MarcoForte/FBA_Matting import gradio as gr from FBA_Matting import inference from huggingface_hub import hf_hub_download from networks.models import build_model REPO_ID = "leonelhs/FBA-Matting" weights = hf_hub_download(repo_id=REPO_ID, filename="FBA.pth") model = build_model(weights) model.eval().cpu() def predict(image, trimap): return inference(model, image, trimap) footer = r"""
Demo for FBA Matting
""" with gr.Blocks(title="FBA Matting") as app: gr.HTML("

FBA Matting

") gr.HTML("

Foreground, Background, Alpha Matting Generator.

") with gr.Row().style(equal_height=False): with gr.Column(): input_img = gr.Image(type="filepath", label="Input image") input_trimap = gr.Image(type="filepath", label="Trimap image") run_btn = gr.Button(variant="primary") with gr.Column(): fg = gr.Image(type="numpy", label="Foreground") bg = gr.Image(type="numpy", label="Background") alpha = gr.Image(type="numpy", label="Alpha") composite = gr.Image(type="numpy", label="Composite") gr.ClearButton(components=[input_img, input_trimap, fg, bg, alpha, composite], variant="stop") run_btn.click(predict, [input_img, input_trimap], [fg, bg, alpha, composite]) with gr.Row(): blobs = [[ f"./images/{x:02d}.png", f"./trimaps/{x:02d}.png"] for x in range(1, 7)] examples = gr.Dataset(components=[input_img, input_trimap], samples=blobs) examples.click(lambda x: (x[0], x[1]), [examples], [input_img, input_trimap]) with gr.Row(): gr.HTML(footer) app.launch(share=False, debug=True, enable_queue=True, show_error=True)