File size: 755 Bytes
919f974
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import gradio as gr
from rembg import remove
from PIL import Image

def remove_background(image):
    """
    Takes a PIL image as input and returns the image with background removed.
    """
    return remove(image)

# Create the Gradio interface
app = gr.Interface(
    fn=remove_background,
    inputs=gr.Image(type="pil", label="Upload an Image"),
    outputs=gr.Image(type="pil", label="Image with Background Removed"),
    title="Background Removal App",
    description="Upload any image to remove its background using the U²-Net model.",
    examples=[
        ["example_images/person.jpg"],
        ["example_images/object.png"]
    ],
    cache_examples=False,
    theme="default"
)

# Launch the app
if __name__ == "__main__":
    app.launch()