Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -4,17 +4,33 @@ from PIL import Image
|
|
4 |
import numpy as np
|
5 |
import io
|
6 |
|
7 |
-
def remove_bg(image):
|
8 |
input_image = Image.fromarray(np.array(image))
|
|
|
|
|
9 |
output_image = remove(input_image)
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
iface = gr.Interface(
|
13 |
fn=remove_bg,
|
14 |
-
inputs=
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
18 |
)
|
19 |
|
20 |
iface.launch()
|
|
|
4 |
import numpy as np
|
5 |
import io
|
6 |
|
7 |
+
def remove_bg(image, format, threshold):
|
8 |
input_image = Image.fromarray(np.array(image))
|
9 |
+
|
10 |
+
# Background removal processing
|
11 |
output_image = remove(input_image)
|
12 |
+
|
13 |
+
# Convert to desired format
|
14 |
+
buffer = io.BytesIO()
|
15 |
+
if format == "PNG":
|
16 |
+
output_image.save(buffer, format="PNG")
|
17 |
+
elif format == "JPEG":
|
18 |
+
output_image.save(buffer, format="JPEG")
|
19 |
+
|
20 |
+
buffer.seek(0)
|
21 |
+
return buffer
|
22 |
|
23 |
iface = gr.Interface(
|
24 |
fn=remove_bg,
|
25 |
+
inputs=[
|
26 |
+
gr.Image(type="pil", label="Input Image"),
|
27 |
+
gr.Radio(choices=["PNG", "JPEG"], label="Output Format", value="PNG"),
|
28 |
+
gr.Slider(0, 100, step=1, label="Threshold", value=0)
|
29 |
+
],
|
30 |
+
outputs=gr.Image(type="file", label="Output Image"),
|
31 |
+
title="Enhanced Background Remover",
|
32 |
+
description="Upload an image to remove the background. Adjust the output format and sensitivity.",
|
33 |
+
layout="horizontal"
|
34 |
)
|
35 |
|
36 |
iface.launch()
|