|
|
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): |
|
|
|
|
|
image = Image.fromarray(input_image.astype('uint8'), 'RGB') |
|
|
|
|
|
|
|
|
output_image = remove(image) |
|
|
|
|
|
|
|
|
return np.array(output_image) |
|
|
|
|
|
|
|
|
example_files = [ |
|
|
"examples/1.png", |
|
|
"examples/2.png", |
|
|
"examples/3.png", |
|
|
"examples/4.jpg", |
|
|
"examples/5.jpg" |
|
|
] |
|
|
|
|
|
|
|
|
with gr.Blocks(css=custom_css) as app: |
|
|
|
|
|
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/> |
|
|
""" |
|
|
) |
|
|
|
|
|
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") |
|
|
|
|
|
|
|
|
btn_remove.click( |
|
|
fn=remove_background, |
|
|
inputs=im_input, |
|
|
outputs=im_output |
|
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
|
app.launch() |
|
|
|