nolenfelten commited on
Commit
3aa0fcb
·
verified ·
1 Parent(s): a7b22f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -6
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
- return output_image
 
 
 
 
 
 
 
 
 
11
 
12
  iface = gr.Interface(
13
  fn=remove_bg,
14
- inputs=gr.Image(type="pil"),
15
- outputs=gr.Image(type="pil"),
16
- title="Background Remover",
17
- description="Upload an image to remove the background."
 
 
 
 
 
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()