Spaces:
Sleeping
Sleeping
import spaces | |
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 | |
# Gradio Interface | |
iface = gr.Interface( | |
fn=remove_background, | |
inputs=gr.Image(label="Upload Image"), | |
outputs=gr.Image(label="Output Image"), | |
css=""" | |
body { | |
font-family: 'Arial', sans-serif; | |
background-color: #1a1a2e; | |
color: #ffffff; | |
} | |
.gradio-container { | |
background-color: #1a1a2e; | |
color: #ffffff; | |
} | |
.gr-button { | |
background-color: #4CAF50; | |
color: white; | |
border: none; | |
border-radius: 4px; | |
} | |
.gr-button:hover { | |
background-color: #45a049; | |
} | |
.gr-input, .gr-output { | |
background-color: #2a2a3e; | |
color: #ffffff; | |
border: 1px solid #4a4a5e; | |
display: block; | |
margin: 0 auto; | |
} | |
.gr-input img { | |
width: 30px; | |
height: 30px; | |
object-fit: contain; | |
} | |
.gr-output img { | |
max-width: 300px; | |
max-height: 300px; | |
object-fit: contain; | |
display: block; | |
margin: 0 auto; | |
} | |
.gr-input:focus, .gr-output:focus { | |
outline: none; | |
border-color: #6a6a7e; | |
} | |
.gr-file-upload { | |
background-color: #2a2a3e; | |
color: #ffffff; | |
} | |
.gr-slider { | |
background-color: #2a2a3e; | |
color: #ffffff; | |
} | |
.gr-dropdown { | |
background-color: #2a2a3e; | |
color: #ffffff; | |
} | |
.gr-image-preview { | |
border: 2px solid #4a4a5e; | |
background-color: #2a2a3e; | |
} | |
.gr-textbox { | |
background-color: #2a2a3e; | |
color: #ffffff; | |
border: 1px solid #4a4a5e; | |
} | |
.gr-textbox:focus { | |
outline: none; | |
border-color: #6a6a7e; | |
} | |
""", | |
title="", | |
description="" | |
) | |
if __name__ == "__main__": | |
iface.launch() | |