Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from rembg import remove
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import numpy as np
|
| 5 |
+
import time
|
| 6 |
+
import random
|
| 7 |
+
|
| 8 |
+
def washing_machine(image):
|
| 9 |
+
# Convert to PIL Image if it's a numpy array
|
| 10 |
+
if isinstance(image, np.ndarray):
|
| 11 |
+
image = Image.fromarray(image)
|
| 12 |
+
|
| 13 |
+
# Simulate washing process with progress updates
|
| 14 |
+
for i in range(1, 6):
|
| 15 |
+
time.sleep(0.5) # Simulate washing cycles
|
| 16 |
+
yield f"Washing cycle {i}/5...", image
|
| 17 |
+
|
| 18 |
+
# Actual background removal
|
| 19 |
+
result = remove(image)
|
| 20 |
+
|
| 21 |
+
# Add some "spin cycle" effects
|
| 22 |
+
for angle in [15, -15, 0]:
|
| 23 |
+
rotated = result.rotate(angle)
|
| 24 |
+
yield "Spin cycle complete!", rotated
|
| 25 |
+
|
| 26 |
+
# Final clean image
|
| 27 |
+
yield "Your image is clean and background-free!", result
|
| 28 |
+
|
| 29 |
+
# Custom CSS for washing machine theme
|
| 30 |
+
css = """
|
| 31 |
+
#wash-btn {background-color: #00a8ff; 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: 12px;}
|
| 32 |
+
#wash-btn:hover {background-color: #0095e6;}
|
| 33 |
+
.title {font-family: Arial; color: #333; text-align: center;}
|
| 34 |
+
.description {font-family: Arial; color: #666; text-align: center;}
|
| 35 |
+
#output-image {border: 5px dashed #00a8ff; border-radius: 10px;}
|
| 36 |
+
#input-image {border: 5px dashed #ccc; border-radius: 10px;}
|
| 37 |
+
"""
|
| 38 |
+
|
| 39 |
+
with gr.Blocks(css=css) as demo:
|
| 40 |
+
gr.Markdown("<h1 class='title'>🚀 Background Washing Machine �</h1>")
|
| 41 |
+
gr.Markdown("<p class='description'>Upload your image and we'll wash the background right off!</p>")
|
| 42 |
+
|
| 43 |
+
with gr.Row():
|
| 44 |
+
with gr.Column():
|
| 45 |
+
input_image = gr.Image(label="Dirty Image (with background)")
|
| 46 |
+
wash_btn = gr.Button("Start Washing!", elem_id="wash-btn")
|
| 47 |
+
|
| 48 |
+
with gr.Column():
|
| 49 |
+
status = gr.Textbox(label="Washing Status")
|
| 50 |
+
output_image = gr.Image(label="Clean Image (no background)")
|
| 51 |
+
|
| 52 |
+
wash_btn.click(
|
| 53 |
+
washing_machine,
|
| 54 |
+
inputs=input_image,
|
| 55 |
+
outputs=[status, output_image]
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
gr.Markdown("### How it works:")
|
| 59 |
+
gr.Markdown("1. Upload your image 🖼️\n2. Click the washing button �\n3. Wait while we wash away the background 🫧\n4. Get your clean, background-free image! ✅")
|
| 60 |
+
|
| 61 |
+
demo.launch()
|