Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,20 +6,19 @@ from PIL import Image
|
|
| 6 |
# Load Hugging Face background removal model
|
| 7 |
# -------------------------------
|
| 8 |
pipe = pipeline(
|
| 9 |
-
"image-segmentation",
|
| 10 |
model="briaai/RMBG-1.4",
|
| 11 |
-
trust_remote_code=True
|
| 12 |
)
|
| 13 |
|
| 14 |
# -------------------------------
|
| 15 |
# Function to remove background
|
| 16 |
# -------------------------------
|
| 17 |
def remove_bg(image: Image.Image):
|
| 18 |
-
# Run model
|
| 19 |
-
|
| 20 |
-
mask = result[0]["mask"] # segmentation mask (white=foreground, black=background)
|
| 21 |
|
| 22 |
-
#
|
| 23 |
mask = mask.convert("L")
|
| 24 |
|
| 25 |
# Apply mask to original image
|
|
@@ -37,7 +36,7 @@ demo = gr.Interface(
|
|
| 37 |
inputs=gr.Image(type="pil", label="Upload an image"),
|
| 38 |
outputs=gr.Image(type="pil", label="Background Removed"),
|
| 39 |
title="Background Remover",
|
| 40 |
-
description="Upload an image to remove its background using Hugging Face model.",
|
| 41 |
)
|
| 42 |
|
| 43 |
# -------------------------------
|
|
|
|
| 6 |
# Load Hugging Face background removal model
|
| 7 |
# -------------------------------
|
| 8 |
pipe = pipeline(
|
| 9 |
+
task="image-segmentation",
|
| 10 |
model="briaai/RMBG-1.4",
|
| 11 |
+
trust_remote_code=True
|
| 12 |
)
|
| 13 |
|
| 14 |
# -------------------------------
|
| 15 |
# Function to remove background
|
| 16 |
# -------------------------------
|
| 17 |
def remove_bg(image: Image.Image):
|
| 18 |
+
# Run model → this returns a PIL mask directly
|
| 19 |
+
mask = pipe(image)
|
|
|
|
| 20 |
|
| 21 |
+
# Ensure mask is grayscale
|
| 22 |
mask = mask.convert("L")
|
| 23 |
|
| 24 |
# Apply mask to original image
|
|
|
|
| 36 |
inputs=gr.Image(type="pil", label="Upload an image"),
|
| 37 |
outputs=gr.Image(type="pil", label="Background Removed"),
|
| 38 |
title="Background Remover",
|
| 39 |
+
description="Upload an image to remove its background using Hugging Face RMBG model.",
|
| 40 |
)
|
| 41 |
|
| 42 |
# -------------------------------
|