File size: 680 Bytes
e0f9ad5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from rembg import remove
from PIL import Image
import io

def remove_bg(input_image):
    # Convert image to bytes
    img_bytes = io.BytesIO()
    input_image.save(img_bytes, format="PNG")
    img_bytes = img_bytes.getvalue()

    # Remove background
    output = remove(img_bytes)

    # Convert back to PIL
    output_image = Image.open(io.BytesIO(output)).convert("RGBA")
    return output_image

iface = gr.Interface(
    fn=remove_bg,
    inputs=gr.Image(type="pil"),
    outputs=gr.Image(type="pil"),
    title="Background Remover",
    description="Upload an image and remove its background instantly."
)

if __name__ == "__main__":
    iface.launch()