tonyassi commited on
Commit
97c5c48
·
1 Parent(s): 04c2a90

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -0
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ from PIL import Image, ImageOps
4
+
5
+ # Initialize Segmentation Pipeline
6
+ segformer_b2_clothes_pipe = pipeline("image-segmentation", model="mattmdjaga/segformer_b2_clothes")
7
+
8
+ def segformer_b2_clothes(img):
9
+ result = segmentation_pipe(img)
10
+ mask = result[0]['mask'].convert('L')
11
+ mask = ImageOps.invert(mask)
12
+ img.putalpha(mask)
13
+ return img
14
+
15
+ def remove_background(img):
16
+ segformer_b2_clothes_result = segformer_b2_clothes(img)
17
+
18
+ return segformer_b2_clothes_result
19
+
20
+ iface = gr.Interface(fn=remove_background,
21
+ inputs=gr.Image(type='pil'),
22
+ outputs=gr.Image(label='segformer_b2_clothes', type='pil'))
23
+ iface.launch()