gdo commited on
Commit
df80321
·
verified ·
1 Parent(s): 4ca8c2a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import rembg
3
+ from PIL import Image
4
+ from io import BytesIO
5
+
6
+ def remove_background(image):
7
+ """
8
+ Removes the background from an uploaded image using rembg.
9
+ """
10
+ # Ensure image is in RGBA mode
11
+ image = image.convert("RGBA")
12
+
13
+ # Remove background
14
+ output_image = rembg.remove(image)
15
+
16
+ return output_image # Directly return PIL image
17
+
18
+ # Gradio Interface
19
+ demo = gr.Interface(
20
+ fn=remove_background,
21
+ inputs=gr.Image(type="pil", label="Upload Image"),
22
+ outputs=gr.Image(type="pil", label="Processed Image with Transparent Background"),
23
+ title="AI Image Background Remover",
24
+ description="Upload an image and remove its background using AI-powered rembg.",
25
+ )
26
+
27
+ demo.launch()