Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,16 +1,17 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from PIL import Image, ImageChops, ImageFilter
|
| 3 |
import rembg
|
|
|
|
| 4 |
import tempfile
|
| 5 |
import os
|
| 6 |
import zipfile
|
| 7 |
|
| 8 |
def remove_background(image):
|
| 9 |
-
"""Remove background using rembg"""
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
return Image.open(
|
| 14 |
|
| 15 |
def add_outline(image, outline_width=2, outline_color=(255, 255, 255)):
|
| 16 |
"""Add white outline to transparent image"""
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from PIL import Image, ImageChops, ImageFilter
|
| 3 |
import rembg
|
| 4 |
+
import io
|
| 5 |
import tempfile
|
| 6 |
import os
|
| 7 |
import zipfile
|
| 8 |
|
| 9 |
def remove_background(image):
|
| 10 |
+
"""Remove background using rembg (fixed bytes handling)"""
|
| 11 |
+
img_byte_arr = io.BytesIO()
|
| 12 |
+
image.save(img_byte_arr, format='PNG')
|
| 13 |
+
result_bytes = rembg.remove(img_byte_arr.getvalue()) # Process bytes directly
|
| 14 |
+
return Image.open(io.BytesIO(result_bytes)).convert("RGBA")
|
| 15 |
|
| 16 |
def add_outline(image, outline_width=2, outline_color=(255, 255, 255)):
|
| 17 |
"""Add white outline to transparent image"""
|