Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
|
|
2 |
from transformers import pipeline
|
3 |
from PIL import Image, ImageOps
|
4 |
import time
|
|
|
5 |
|
6 |
# Initialize Segmentation Pipeline
|
7 |
segformer_b2_clothes_pipe = pipeline("image-segmentation", model="mattmdjaga/segformer_b2_clothes")
|
@@ -13,16 +14,28 @@ def segformer_b2_clothes(img):
|
|
13 |
img.putalpha(mask)
|
14 |
return img
|
15 |
|
|
|
|
|
|
|
16 |
def remove_background(img):
|
|
|
17 |
start = time.time()
|
18 |
segformer_b2_clothes_result = segformer_b2_clothes(img)
|
19 |
end = time.time()
|
20 |
-
segformer_b2_clothes_text = "[mattmdjaga/segformer_b2_clothes](https://huggingface.co/mattmdjaga/segformer_b2_clothes)
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
-
return segformer_b2_clothes_text, segformer_b2_clothes_result
|
23 |
|
24 |
iface = gr.Interface(fn=remove_background,
|
25 |
inputs=gr.Image(type='pil'),
|
26 |
outputs=[gr.Markdown(),
|
27 |
-
gr.Image(label='segformer_b2_clothes', type='pil')
|
|
|
|
|
28 |
iface.launch()
|
|
|
2 |
from transformers import pipeline
|
3 |
from PIL import Image, ImageOps
|
4 |
import time
|
5 |
+
from rembg import remove
|
6 |
|
7 |
# Initialize Segmentation Pipeline
|
8 |
segformer_b2_clothes_pipe = pipeline("image-segmentation", model="mattmdjaga/segformer_b2_clothes")
|
|
|
14 |
img.putalpha(mask)
|
15 |
return img
|
16 |
|
17 |
+
def rembg_remove(img):
|
18 |
+
return remove(img)
|
19 |
+
|
20 |
def remove_background(img):
|
21 |
+
# segformer_b2_clothes
|
22 |
start = time.time()
|
23 |
segformer_b2_clothes_result = segformer_b2_clothes(img)
|
24 |
end = time.time()
|
25 |
+
segformer_b2_clothes_text = "[mattmdjaga/segformer_b2_clothes](https://huggingface.co/mattmdjaga/segformer_b2_clothes) \n" + str(end-start) + " seconds"
|
26 |
+
|
27 |
+
#rembg
|
28 |
+
start = time.time()
|
29 |
+
rembg_result = rembg_remove(img)
|
30 |
+
end = time.time()
|
31 |
+
rembg_text = "[rembg](https://huggingface.co/spaces/openskyml/remove-background-on-image) \n" + str(end-start) + " seconds"
|
32 |
|
33 |
+
return segformer_b2_clothes_text, segformer_b2_clothes_result, rembg_text, rembg_result
|
34 |
|
35 |
iface = gr.Interface(fn=remove_background,
|
36 |
inputs=gr.Image(type='pil'),
|
37 |
outputs=[gr.Markdown(),
|
38 |
+
gr.Image(label='segformer_b2_clothes', type='pil'),
|
39 |
+
gr.Markdown(),
|
40 |
+
gr.Image(label='rembg', type='pil')])
|
41 |
iface.launch()
|