Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from rembg import remove
|
3 |
+
from PIL import Image
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
def remove_background(input_image):
|
7 |
+
# Convert gradio image to PIL Image
|
8 |
+
input_image = Image.fromarray(input_image.astype('uint8'), 'RGB')
|
9 |
+
|
10 |
+
# Remove background
|
11 |
+
output_image = remove(input_image)
|
12 |
+
|
13 |
+
# Convert RGBA to RGB (remove alpha channel)
|
14 |
+
output_image = output_image.convert("RGB")
|
15 |
+
|
16 |
+
# Convert PIL Image back to numpy array
|
17 |
+
return np.array(output_image)
|
18 |
+
|
19 |
+
iface = gr.Interface(
|
20 |
+
fn=remove_background,
|
21 |
+
inputs=gr.Image(),
|
22 |
+
outputs=gr.Image(),
|
23 |
+
title="Background Removal App",
|
24 |
+
description="Upload an image to remove its background."
|
25 |
+
)
|
26 |
+
|
27 |
+
iface.launch()
|