Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,20 +2,22 @@
|
|
| 2 |
import gradio as gr
|
| 3 |
from rembg import remove
|
| 4 |
from PIL import Image
|
| 5 |
-
import
|
| 6 |
|
| 7 |
-
# Function to remove background
|
| 8 |
def remove_background(image):
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
pil_image = Image.fromarray(image).convert("RGBA")
|
| 11 |
|
| 12 |
# Remove background
|
| 13 |
result = remove(pil_image)
|
| 14 |
|
| 15 |
-
# Convert result to displayable format
|
| 16 |
return result
|
| 17 |
|
| 18 |
-
# Gradio
|
| 19 |
title = "AI Background Remover"
|
| 20 |
description = "Upload an image and remove its background instantly! Made by Viateur Irasubiza."
|
| 21 |
|
|
@@ -28,5 +30,5 @@ iface = gr.Interface(
|
|
| 28 |
allow_flagging="never"
|
| 29 |
)
|
| 30 |
|
| 31 |
-
|
| 32 |
-
iface.launch()
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
from rembg import remove
|
| 4 |
from PIL import Image
|
| 5 |
+
import numpy as np
|
| 6 |
|
|
|
|
| 7 |
def remove_background(image):
|
| 8 |
+
"""
|
| 9 |
+
Remove background from an uploaded image using rembg CPU backend.
|
| 10 |
+
Returns the processed image with transparency.
|
| 11 |
+
"""
|
| 12 |
+
# Ensure the image is RGBA
|
| 13 |
pil_image = Image.fromarray(image).convert("RGBA")
|
| 14 |
|
| 15 |
# Remove background
|
| 16 |
result = remove(pil_image)
|
| 17 |
|
|
|
|
| 18 |
return result
|
| 19 |
|
| 20 |
+
# Gradio Interface
|
| 21 |
title = "AI Background Remover"
|
| 22 |
description = "Upload an image and remove its background instantly! Made by Viateur Irasubiza."
|
| 23 |
|
|
|
|
| 30 |
allow_flagging="never"
|
| 31 |
)
|
| 32 |
|
| 33 |
+
if __name__ == "__main__":
|
| 34 |
+
iface.launch()
|