Spaces:
Runtime error
Runtime error
| # app.py | |
| import gradio as gr | |
| from rembg import remove | |
| from PIL import Image | |
| import numpy as np | |
| def remove_background(image): | |
| """ | |
| Remove background from an uploaded image using rembg CPU backend. | |
| Returns the processed image with transparency. | |
| """ | |
| # Ensure the image is RGBA | |
| pil_image = Image.fromarray(image).convert("RGBA") | |
| # Remove background | |
| result = remove(pil_image) | |
| return result | |
| # Gradio Interface | |
| title = "AI Background Remover" | |
| description = "Upload an image and remove its background instantly! Made by Viateur Irasubiza." | |
| iface = gr.Interface( | |
| fn=remove_background, | |
| inputs=gr.Image(type="numpy", label="Upload Your Image"), | |
| outputs=gr.Image(type="pil", label="Result"), | |
| title=title, | |
| description=description, | |
| allow_flagging="never" | |
| ) | |
| if __name__ == "__main__": | |
| iface.launch() |