Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,11 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from PIL import Image
|
| 3 |
-
from
|
| 4 |
-
|
| 5 |
-
pipe = pipeline("image-segmentation", model="briaai/RMBG-2.0", trust_remote_code=True)
|
| 6 |
|
| 7 |
def remove_background(image):
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
output = result.get("image") or result.get("mask")
|
| 12 |
-
if output is None:
|
| 13 |
-
return image
|
| 14 |
-
rgba = image.convert("RGBA")
|
| 15 |
-
mask = output.convert("L").resize(rgba.size)
|
| 16 |
-
rgba.putalpha(mask)
|
| 17 |
-
white_bg = Image.new("RGBA", rgba.size, (255, 255, 255, 255))
|
| 18 |
-
white_bg.paste(rgba, mask=mask)
|
| 19 |
return white_bg.convert("RGB")
|
| 20 |
|
| 21 |
demo = gr.Interface(
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from PIL import Image
|
| 3 |
+
from rembg import remove
|
|
|
|
|
|
|
| 4 |
|
| 5 |
def remove_background(image):
|
| 6 |
+
output = remove(image)
|
| 7 |
+
white_bg = Image.new("RGBA", output.size, (255, 255, 255, 255))
|
| 8 |
+
white_bg.paste(output, mask=output.split()[3])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
return white_bg.convert("RGB")
|
| 10 |
|
| 11 |
demo = gr.Interface(
|