bgr / app.py
mrbeliever's picture
Update app.py
6dcc89e verified
raw
history blame
1.23 kB
import gradio as gr
from transparent_background import Remover
from PIL import Image
import numpy as np
def remove_background(image):
remover = Remover()
if isinstance(image, Image.Image):
output = remover.process(image)
elif isinstance(image, np.ndarray):
image_pil = Image.fromarray(image)
output = remover.process(image_pil)
else:
raise TypeError("Unsupported image type")
return output
css = """
body {
background-color: #f5f5f5;
font-family: Arial, sans-serif;
}
.input_image, .output_image {
border-radius: 10px;
box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.1);
}
.gr-button {
background-color: #4CAF50;
color: white;
border: none;
padding: 10px 20px;
text-align: center;
font-size: 16px;
cursor: pointer;
border-radius: 5px;
margin: 4px 2px;
}
.gr-button:hover {
background-color: #45a049;
}
"""
iface = gr.Interface(
fn=remove_background,
inputs=gr.Image(label="Upload Image", css_class="input_image"),
outputs=gr.Image(label="Output Image", css_class="output_image"),
live=True,
css=css
)
iface.launch()