File size: 862 Bytes
643f829
 
 
7cc1b6e
3d80a56
eb15366
643f829
3d80a56
 
 
 
 
643f829
 
 
 
 
 
eb15366
3d80a56
643f829
 
eb15366
643f829
 
 
 
 
 
 
 
eb15366
3d80a56
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# 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()