|
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 |
|
|
|
iface = gr.Interface( |
|
fn=remove_background, |
|
inputs=gr.Image(label="Upload Image"), |
|
outputs=gr.Image(label="Output Image"), |
|
layout="vertical", |
|
css=""" |
|
.container { margin-top: 0px !important; } |
|
.input_image, .output_image { |
|
display: flex; |
|
justify-content: center; |
|
align-items: center; |
|
margin: 10px 0; |
|
} |
|
.button { |
|
background-color: #4CAF50; |
|
color: white; |
|
border: none; |
|
padding: 10px 20px; |
|
text-align: center; |
|
text-decoration: none; |
|
display: inline-block; |
|
font-size: 16px; |
|
margin: 4px 2px; |
|
cursor: pointer; |
|
border-radius: 8px; |
|
} |
|
""" |
|
) |
|
|
|
if __name__ == "__main__": |
|
iface.launch() |
|
|