import gradio as gr
from rembg import remove
from PIL import Image
import numpy as np
custom_css = """
.button-gradient {
background: linear-gradient(45deg, #ff416c, #ff4b2b, #ff9b00, #ff416c);
background-size: 400% 400%;
border: none;
padding: 14px 28px;
font-size: 16px;
font-weight: bold;
color: white;
border-radius: 10px;
cursor: pointer;
transition: 0.3s ease-in-out;
animation: gradientAnimation 2s infinite linear;
box-shadow: 0 4px 10px rgba(255, 65, 108, 0.6);
}
@keyframes gradientAnimation {
0% { background-position: 0% 50%; }
25% { background-position: 50% 100%; }
50% { background-position: 100% 50%; }
75% { background-position: 50% 0%; }
100% { background-position: 0% 50%; }
}
.button-gradient:hover {
transform: scale(1.05);
box-shadow: 0 6px 15px rgba(255, 75, 43, 0.8);
}
"""
def remove_background(input_image):
# Конвертируем изображение из Gradio в PIL
image = Image.fromarray(input_image.astype('uint8'), 'RGB')
# Удаляем фон с помощью U²-Net
output_image = remove(image)
# Конвертируем результат обратно в numpy array для Gradio
return np.array(output_image)
# Define examples as a list of lists: [source, target, enhance]
example_files = [
"examples/1.png",
"examples/2.png",
"examples/3.png",
"examples/4.jpg",
"examples/5.jpg"
]
# APP Interface
with gr.Blocks(css=custom_css) as app:
# Header with logo and title
gr.Markdown(
"""
Background Removal Pro