not-lain commited on
Commit
06e63b6
1 Parent(s): 55e29e3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -12
app.py CHANGED
@@ -4,23 +4,24 @@ from loadimg import load_img
4
  from transformers import pipeline
5
  pipe = pipeline("image-segmentation", model="briaai/RMBG-1.4", trust_remote_code=True)
6
 
7
- def fn(im):
8
- if not im or not im[0]:
9
- return im
10
- # avoid problems when working with images that are actually RGBA
11
- im = im[0].convert('RGB')
12
  path = load_img(im,output_type="str")
13
  rmbg = pipe(path)
14
- # rmbg_path = load_img(rmbg,output_type="str")
15
- out = (im,rmbg)
16
  return out
17
 
 
 
 
 
18
 
19
- with gr.Blocks() as demo:
20
- gr.Markdown("# RMBG1.4 tutorial")
21
- with gr.Group():
22
- img1 = ImageSlider(label="RMBG", type="pil")
23
- img1.upload(fn, inputs=img1, outputs=img1)
24
 
25
  if __name__ == "__main__":
26
  demo.launch(debug=True)
 
4
  from transformers import pipeline
5
  pipe = pipeline("image-segmentation", model="briaai/RMBG-1.4", trust_remote_code=True)
6
 
7
+ def fn(image):
8
+ im = load_img(image)
9
+ im = im.convert('RGB')
 
 
10
  path = load_img(im,output_type="str")
11
  rmbg = pipe(path)
12
+ out = (rmbg , im)
 
13
  return out
14
 
15
+ slider1 = ImageSlider(label="RMBG", type="pil")
16
+ slider2 = ImageSlider(label="RMBG", type="pil")
17
+ image = gr.Image(label="Upload an image")
18
+ text = gr.Textbox(label="Paste an image URL")
19
 
20
+
21
+ tab1 = gr.Interface(fn,inputs= image, outputs= slider1, api_name="image")
22
+ tab2 = gr.Interface(fn,inputs= text, outputs= slider2, api_name="text")
23
+
24
+ demo = gr.TabbedInterface([tab1,tab2],["image","text"],title="RMBG with image slider")
25
 
26
  if __name__ == "__main__":
27
  demo.launch(debug=True)