Spaces:
Runtime error
Runtime error
import gradio as gr | |
from rembg import remove | |
from PIL import Image | |
from io import BytesIO | |
def remove_background(input_image): | |
input = Image.open(input_image) # load image | |
output = remove(input) # remove background | |
return output | |
# define input and output interfaces | |
input_image = gr.inputs.Image(type="filepath", label="Input Image") | |
output_image = gr.outputs.Image(type="filepath", label="Output Image") | |
# define function for downloading output image | |
def download_output(output_image): | |
output_image.save("output.png") | |
with open("output.png", "rb") as f: | |
img_bytes = BytesIO(f.read()) | |
return img_bytes | |
# define output download button | |
output_image_download = gr.outputs.Button(label="Download Output", type="bytes", callback=download_output) | |
# create the interface | |
iface = gr.Interface( | |
fn=remove_background, | |
inputs=input_image, | |
outputs=output_image, | |
output_options=[output_image_download], | |
title='Image Background Remover', | |
description='Upload an image and it will remove.' | |
) | |
# launch the interface | |
iface.launch() | |