Spaces:
Running
Running
File size: 1,875 Bytes
67d263e def3395 617d6e1 def3395 617d6e1 def3395 e070f1c def3395 617d6e1 def3395 617d6e1 def3395 67d263e def3395 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# 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"""
<center>
<b>
Demo for <a href='https://github.com/MarcoForte/FBA_Matting'>FBA Matting</a>
</b>
</center>
"""
with gr.Blocks(title="FBA Matting") as app:
gr.HTML("<center><h1>FBA Matting</h1></center>")
gr.HTML("<center><h3>Foreground, Background, Alpha Matting Generator.</h3></center>")
with gr.Row(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)
|