Spaces:
Runtime error
Runtime error
File size: 772 Bytes
8ceef8d | 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 | 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()
|