Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -77,17 +77,23 @@ def remove_background():
|
|
| 77 |
# Remove background using withoutBG
|
| 78 |
logger.info("π Removing background...")
|
| 79 |
result = model.remove_background(img)
|
| 80 |
-
logger.info("β
Background removed successfully!")
|
| 81 |
|
| 82 |
-
#
|
| 83 |
-
if result.mode =
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
# Convert to PNG bytes
|
| 93 |
output_buffer = io.BytesIO()
|
|
|
|
| 77 |
# Remove background using withoutBG
|
| 78 |
logger.info("π Removing background...")
|
| 79 |
result = model.remove_background(img)
|
| 80 |
+
logger.info(f"β
Background removed successfully! Mode: {result.mode}, Size: {result.size}")
|
| 81 |
|
| 82 |
+
# Convert to RGBA first if not already
|
| 83 |
+
if result.mode != 'RGBA':
|
| 84 |
+
result = result.convert('RGBA')
|
| 85 |
+
logger.info(f"π Converted to RGBA mode")
|
| 86 |
+
|
| 87 |
+
# Create white background and composite
|
| 88 |
+
logger.info("π¨ Creating white background composite...")
|
| 89 |
+
white_bg = Image.new('RGBA', result.size, (255, 255, 255, 255))
|
| 90 |
+
|
| 91 |
+
# Composite the image onto white background
|
| 92 |
+
output = Image.alpha_composite(white_bg, result)
|
| 93 |
+
|
| 94 |
+
# Convert to RGB (remove alpha channel)
|
| 95 |
+
result = output.convert('RGB')
|
| 96 |
+
logger.info(f"β
Final image mode: {result.mode}")
|
| 97 |
|
| 98 |
# Convert to PNG bytes
|
| 99 |
output_buffer = io.BytesIO()
|