File size: 768 Bytes
f74a8bb
 
81b6033
 
 
f74a8bb
 
 
 
81b6033
 
 
 
 
 
 
f74a8bb
 
 
81b6033
f74a8bb
81b6033
f74a8bb
 
 
81b6033
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
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)