Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,8 @@
|
|
1 |
-
## Modified from Akhaliq Hugging Face Demo
|
2 |
-
## https://huggingface.co/akhaliq
|
3 |
-
|
4 |
import gradio as gr
|
5 |
import os
|
6 |
import cv2
|
7 |
|
8 |
-
def inference(file, mask, model
|
9 |
im = cv2.imread(file, cv2.IMREAD_COLOR)
|
10 |
cv2.imwrite(os.path.join("input.png"), im)
|
11 |
|
@@ -19,56 +16,52 @@ def inference(file, mask, model, alpha, segmentation_strength):
|
|
19 |
input = i.read()
|
20 |
output = remove(
|
21 |
input,
|
22 |
-
session=new_session(model),
|
23 |
-
only_mask=(True if mask == "Mask only" else False)
|
24 |
-
alpha=alpha,
|
25 |
-
segmentation_strength=segmentation_strength
|
26 |
)
|
|
|
|
|
|
|
27 |
o.write(output)
|
28 |
return os.path.join("output.png")
|
29 |
-
|
30 |
-
title = "
|
31 |
-
description = "Gradio demo for RemBG.
|
32 |
article = "<p style='text-align: center;'><a href='https://github.com/danielgatis/rembg' target='_blank'>Github Repo</a></p>"
|
33 |
|
|
|
34 |
gr.Interface(
|
35 |
inference,
|
36 |
[
|
37 |
gr.inputs.Image(type="filepath", label="Input"),
|
38 |
-
gr.
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
"sam",
|
57 |
],
|
58 |
type="value",
|
59 |
default="isnet-general-use",
|
60 |
label="Models"
|
61 |
-
|
62 |
-
]),
|
63 |
-
gr.Row([
|
64 |
-
gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.5, label="Alpha (Transparency)"),
|
65 |
-
gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.5, label="Segmentation Strength"),
|
66 |
-
]),
|
67 |
],
|
68 |
gr.outputs.Image(type="filepath", label="Output"),
|
69 |
title=title,
|
70 |
description=description,
|
71 |
article=article,
|
72 |
-
examples=[["lion.png", "Default", "u2net"
|
73 |
enable_queue=True
|
74 |
-
).launch()
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
import cv2
|
4 |
|
5 |
+
def inference(file, mask, model):
|
6 |
im = cv2.imread(file, cv2.IMREAD_COLOR)
|
7 |
cv2.imwrite(os.path.join("input.png"), im)
|
8 |
|
|
|
16 |
input = i.read()
|
17 |
output = remove(
|
18 |
input,
|
19 |
+
session = new_session(model),
|
20 |
+
only_mask = (True if mask == "Mask only" else False)
|
|
|
|
|
21 |
)
|
22 |
+
|
23 |
+
|
24 |
+
|
25 |
o.write(output)
|
26 |
return os.path.join("output.png")
|
27 |
+
|
28 |
+
title = "RemBG"
|
29 |
+
description = "Gradio demo for RemBG. To use it, simply upload your image and wait. Read more at the link below."
|
30 |
article = "<p style='text-align: center;'><a href='https://github.com/danielgatis/rembg' target='_blank'>Github Repo</a></p>"
|
31 |
|
32 |
+
|
33 |
gr.Interface(
|
34 |
inference,
|
35 |
[
|
36 |
gr.inputs.Image(type="filepath", label="Input"),
|
37 |
+
gr.inputs.Radio(
|
38 |
+
[
|
39 |
+
"Default",
|
40 |
+
"Mask only"
|
41 |
+
],
|
42 |
+
type="value",
|
43 |
+
default="Default",
|
44 |
+
label="Choices"
|
45 |
+
),
|
46 |
+
gr.inputs.Dropdown([
|
47 |
+
"u2net",
|
48 |
+
"u2netp",
|
49 |
+
"u2net_human_seg",
|
50 |
+
"u2net_cloth_seg",
|
51 |
+
"silueta",
|
52 |
+
"isnet-general-use",
|
53 |
+
"isnet-anime",
|
54 |
+
"sam",
|
|
|
55 |
],
|
56 |
type="value",
|
57 |
default="isnet-general-use",
|
58 |
label="Models"
|
59 |
+
),
|
|
|
|
|
|
|
|
|
|
|
60 |
],
|
61 |
gr.outputs.Image(type="filepath", label="Output"),
|
62 |
title=title,
|
63 |
description=description,
|
64 |
article=article,
|
65 |
+
examples=[["lion.png", "Default", "u2net"], ["girl.jpg", "Default", "u2net"], ["anime-girl.jpg", "Default", "isnet-anime"]],
|
66 |
enable_queue=True
|
67 |
+
).launch()
|