Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -10,26 +10,37 @@ def inference(file, mask, model, alpha_influence, segmentation_strength):
|
|
10 |
|
11 |
input_path = 'input.png'
|
12 |
output_path = 'output.png'
|
|
|
13 |
|
14 |
with open(input_path, 'rb') as i:
|
15 |
with open(output_path, 'wb') as o:
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
24 |
|
25 |
-
|
26 |
-
return os.path.join("output.png")
|
27 |
|
28 |
-
title = "
|
29 |
-
description = "Gradio demo for RemBG.
|
30 |
article = "<p style='text-align: center;'><a href='https://github.com/danielgatis/rembg' target='_blank'>Github Repo</a></p>"
|
31 |
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
inference,
|
34 |
[
|
35 |
gr.inputs.Image(type="filepath", label="Input"),
|
@@ -59,10 +70,15 @@ gr.Interface(
|
|
59 |
gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.5, label="Alpha Influence"),
|
60 |
gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.5, label="Segmentation Strength"),
|
61 |
],
|
62 |
-
|
|
|
|
|
|
|
63 |
title=title,
|
64 |
description=description,
|
65 |
article=article,
|
66 |
examples=[["lion.png", "Default", "u2net", 0.5, 0.5], ["girl.jpg", "Default", "u2net", 0.5, 0.5], ["anime-girl.jpg", "Default", "isnet-anime", 0.5, 0.5]],
|
67 |
enable_queue=True
|
68 |
-
)
|
|
|
|
|
|
10 |
|
11 |
input_path = 'input.png'
|
12 |
output_path = 'output.png'
|
13 |
+
mask_path = 'mask.png'
|
14 |
|
15 |
with open(input_path, 'rb') as i:
|
16 |
with open(output_path, 'wb') as o:
|
17 |
+
with open(mask_path, 'wb') as m:
|
18 |
+
input = i.read()
|
19 |
+
output = remove(
|
20 |
+
input,
|
21 |
+
session=new_session(model),
|
22 |
+
only_mask=(True if mask == "Mask only" else False),
|
23 |
+
alpha=alpha_influence,
|
24 |
+
bg_color=(0, 0, 0, segmentation_strength)
|
25 |
+
)
|
26 |
+
o.write(output)
|
27 |
+
m.write(output)
|
28 |
|
29 |
+
return os.path.join("output.png"), os.path.join("mask.png")
|
|
|
30 |
|
31 |
+
title = "RemBG"
|
32 |
+
description = "Gradio demo for RemBG. To use it, simply upload your image and adjust the alpha influence and segmentation strength."
|
33 |
article = "<p style='text-align: center;'><a href='https://github.com/danielgatis/rembg' target='_blank'>Github Repo</a></p>"
|
34 |
|
35 |
+
def show_processed_image(output_image_path):
|
36 |
+
output_image = cv2.imread(output_image_path)
|
37 |
+
return output_image
|
38 |
+
|
39 |
+
def show_processed_mask(mask_image_path):
|
40 |
+
mask_image = cv2.imread(mask_image_path)
|
41 |
+
return mask_image
|
42 |
+
|
43 |
+
iface = gr.Interface(
|
44 |
inference,
|
45 |
[
|
46 |
gr.inputs.Image(type="filepath", label="Input"),
|
|
|
70 |
gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.5, label="Alpha Influence"),
|
71 |
gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.5, label="Segmentation Strength"),
|
72 |
],
|
73 |
+
[
|
74 |
+
gr.outputs.Image(type="plot", label="Processed Image"),
|
75 |
+
gr.outputs.Image(type="plot", label="Processed Mask"),
|
76 |
+
],
|
77 |
title=title,
|
78 |
description=description,
|
79 |
article=article,
|
80 |
examples=[["lion.png", "Default", "u2net", 0.5, 0.5], ["girl.jpg", "Default", "u2net", 0.5, 0.5], ["anime-girl.jpg", "Default", "isnet-anime", 0.5, 0.5]],
|
81 |
enable_queue=True
|
82 |
+
)
|
83 |
+
|
84 |
+
iface.launch()
|