Removeblg / app.py
Doubleupai's picture
Create app.py
8ceef8d verified
Raw
History Blame Contribute Delete
772 Bytes
import gradio as gr
from rembg import remove
from PIL import Image
import io
def remove_background(input_image):
# Convert the input image to a PIL Image
image = Image.open(input_image)
# Remove the background
output_image = remove(image)
# Convert the output image to bytes
output_bytes = io.BytesIO()
output_image.save(output_bytes, format='PNG')
output_bytes.seek(0)
return output_bytes
# Create the Gradio interface
iface = gr.Interface(
fn=remove_background,
inputs=gr.Image(type="file", label="Upload Image"),
outputs=gr.Image(type="file", label="Image with Background Removed"),
title="Background Removal",
description="Upload an image to remove its background."
)
# Launch the interface
iface.launch()