rishi9440's picture
Update app.py
caab2d1
raw
history blame
1.14 kB
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
def download_image(output_image):
img_bytes = output_image.getvalue()
return gradio.Interface.download(img_bytes, "output_image.png")
# define input and output interfaces
input_image = gr.inputs.Image(type="filepath", label="Input Image")
output_image = gr.inputs.Image(type="filepath", label="Output Image")
# define the download button
download_button = gr.Interface(
fn=download_image,
inputs=output_image,
outputs="file",
title="Download"
)
# create the interface
iface = gr.Interface(
fn=remove_background,
inputs=input_image,
outputs=output_image,
title='Image Background Remover',
description='Upload an image and it will remove.',
allow_download=True
)
# combine the main interface and the download button
interface_with_download = gr.Interface([iface, download_button], "grid")
# launch the interface
interface_with_download.launch()