File size: 4,517 Bytes
41b5325 511782b 41b5325 1a48e66 10329ab 1a48e66 10329ab 1a48e66 10329ab 41b5325 511782b 1a48e66 511782b 41b5325 1a48e66 41b5325 1a48e66 10329ab 41b5325 1a48e66 d7c7741 9b6d5bc d7c7741 10329ab d7c7741 9b6d5bc 10329ab 1a48e66 10329ab 1a48e66 10329ab 1a48e66 10329ab 1a48e66 41b5325 1a48e66 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
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(
"""
<a href="https://miniai.live" style="display: flex; align-items: center;">
<img src="https://miniai.live/wp-content/uploads/2024/02/logo_name-1-768x426-1.png" style="width: 18%; margin-right: 15px;"/>
<div>
<p style="font-size: 40px; font-weight: bold; margin-right: 20px;">Background Removal Pro</p>
</div>
</a>
<div style="display: flex; justify-content: center; align-items: center;">
<table style="text-align: center;">
<tr>
<td style="text-align: center; vertical-align: middle;"><a href="https://github.com/MiniAiLive"><img src="https://miniai.live/wp-content/uploads/2024/10/new_git-1-300x67.png" style="height: 50px; margin-right: 5px;" title="GITHUB"/></a></td>
<td style="text-align: center; vertical-align: middle;"><a href="https://huggingface.co/MiniAiLive"><img src="https://miniai.live/wp-content/uploads/2024/10/new_hugging-1-300x67.png" style="height: 50px; margin-right: 5px;" title="HuggingFace"/></a></td>
<td style="text-align: center; vertical-align: middle;"><a href="https://demo.miniai.live"><img src="https://miniai.live/wp-content/uploads/2024/10/new_gradio-300x67.png" style="height: 50px; margin-right: 5px;" title="Gradio"/></a></td>
</tr>
<tr>
<td style="text-align: center; vertical-align: middle;"><a href="https://docs.miniai.live/"><img src="https://miniai.live/wp-content/uploads/2024/10/a-300x70.png" style="height: 50px; margin-right: 5px;" title="Documentation"/></a></td>
<td style="text-align: center; vertical-align: middle;"><a href="https://www.youtube.com/@miniailive"><img src="https://miniai.live/wp-content/uploads/2024/10/Untitled-1-300x70.png" style="height: 50px; margin-right: 5px;" title="Youtube"/></a></td>
<td style="text-align: center; vertical-align: middle;"><a href="https://play.google.com/store/apps/dev?id=5831076207730531667"><img src="https://miniai.live/wp-content/uploads/2024/10/googleplay-300x62.png" style="height: 50px; margin-right: 5px;" title="Google Play"/></a></td>
</tr>
</table>
</div>
<br/>
"""
)
# Main Interface
with gr.Row():
with gr.Column(scale=0.5):
im_input = gr.Image(height=400, label="Input Image")
gr.Examples(
examples=example_files,
inputs=im_input,
label="Try example images ↓"
)
btn_remove = gr.Button("Remove Background 🚀 🚀 🚀", elem_classes="button-gradient")
with gr.Column(scale=0.5):
im_output = gr.Image(height=400, label="Result")
# Connect the button
btn_remove.click(
fn=remove_background,
inputs=im_input,
outputs=im_output
)
if __name__ == "__main__":
app.launch()
|