efasf commited on
Commit
e0f9ad5
·
verified ·
1 Parent(s): 0d93e88

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from rembg import remove
3
+ from PIL import Image
4
+ import io
5
+
6
+ def remove_bg(input_image):
7
+ # Convert image to bytes
8
+ img_bytes = io.BytesIO()
9
+ input_image.save(img_bytes, format="PNG")
10
+ img_bytes = img_bytes.getvalue()
11
+
12
+ # Remove background
13
+ output = remove(img_bytes)
14
+
15
+ # Convert back to PIL
16
+ output_image = Image.open(io.BytesIO(output)).convert("RGBA")
17
+ return output_image
18
+
19
+ iface = gr.Interface(
20
+ fn=remove_bg,
21
+ inputs=gr.Image(type="pil"),
22
+ outputs=gr.Image(type="pil"),
23
+ title="Background Remover",
24
+ description="Upload an image and remove its background instantly."
25
+ )
26
+
27
+ if __name__ == "__main__":
28
+ iface.launch()