not-lain's picture
Update app.py
81b6033 verified
raw
history blame
768 Bytes
import gradio as gr
from gradio_imageslider import ImageSlider
from loadimg import load_img
from transformers import pipeline
pipe = pipeline("image-segmentation", model="briaai/RMBG-1.4", trust_remote_code=True)
def fn(im):
if not im or not im[0]:
return im
# avoid problems when working with images that are actually RGBA
im = im[0].convert('RGB')
path = load_img(im,output_type="str")
rmbg = pipe(path)
# rmbg_path = load_img(rmbg,output_type="str")
out = (im,rmbg)
return out
with gr.Blocks() as demo:
gr.Markdown("# RMBG1.4 tutorial")
with gr.Group():
img1 = ImageSlider(label="RMBG", type="pil")
img1.upload(fn, inputs=img1, outputs=img1)
if __name__ == "__main__":
demo.launch(debug=True)