Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,42 +1,17 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
-
import numpy as np
|
| 4 |
-
import requests
|
| 5 |
from PIL import Image
|
| 6 |
-
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
|
| 12 |
-
# Download model if not present
|
| 13 |
-
if not os.path.exists(model_path):
|
| 14 |
-
with open(model_path, "wb") as f:
|
| 15 |
-
f.write(requests.get(model_url).content)
|
| 16 |
-
|
| 17 |
-
def remove_background(image):
|
| 18 |
-
transform = transforms.Compose([
|
| 19 |
-
transforms.Resize((320, 320)), # Smaller size for speed
|
| 20 |
-
transforms.ToTensor()
|
| 21 |
-
])
|
| 22 |
-
|
| 23 |
-
input_tensor = transform(image).unsqueeze(0)
|
| 24 |
-
|
| 25 |
-
# Process with model (fake example, replace with actual U²-Net processing)
|
| 26 |
-
mask = np.random.randint(0, 256, (320, 320), dtype=np.uint8)
|
| 27 |
-
mask = np.stack([mask] * 3, axis=-1)
|
| 28 |
-
|
| 29 |
-
image = np.array(image.resize((320, 320)))
|
| 30 |
-
result = np.dstack((image, mask[:, :, 0])) # Add transparency
|
| 31 |
-
|
| 32 |
-
return Image.fromarray(result)
|
| 33 |
-
|
| 34 |
-
# Gradio Interface
|
| 35 |
iface = gr.Interface(
|
| 36 |
-
fn=
|
| 37 |
inputs=gr.Image(type="pil"),
|
| 38 |
outputs=gr.Image(type="pil"),
|
| 39 |
-
title="
|
| 40 |
)
|
| 41 |
|
| 42 |
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from rembg import remove
|
|
|
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
+
import io
|
| 5 |
|
| 6 |
+
def remove_bg(image):
|
| 7 |
+
image = remove(image)
|
| 8 |
+
return image
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
iface = gr.Interface(
|
| 11 |
+
fn=remove_bg,
|
| 12 |
inputs=gr.Image(type="pil"),
|
| 13 |
outputs=gr.Image(type="pil"),
|
| 14 |
+
title="Instant Background Remover"
|
| 15 |
)
|
| 16 |
|
| 17 |
iface.launch()
|