Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from rembg import remove
|
| 3 |
+
from PIL import Image
|
| 4 |
+
|
| 5 |
+
def remove_background(image):
|
| 6 |
+
"""
|
| 7 |
+
Takes a PIL image as input and returns the image with background removed.
|
| 8 |
+
"""
|
| 9 |
+
return remove(image)
|
| 10 |
+
|
| 11 |
+
# Create the Gradio interface
|
| 12 |
+
app = gr.Interface(
|
| 13 |
+
fn=remove_background,
|
| 14 |
+
inputs=gr.Image(type="pil", label="Upload an Image"),
|
| 15 |
+
outputs=gr.Image(type="pil", label="Image with Background Removed"),
|
| 16 |
+
title="Background Removal App",
|
| 17 |
+
description="Upload any image to remove its background using the U²-Net model.",
|
| 18 |
+
examples=[
|
| 19 |
+
["example_images/person.jpg"],
|
| 20 |
+
["example_images/object.png"]
|
| 21 |
+
],
|
| 22 |
+
cache_examples=False,
|
| 23 |
+
theme="default"
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
# Launch the app
|
| 27 |
+
if __name__ == "__main__":
|
| 28 |
+
app.launch()
|