rembg / app.py
nolenfelten's picture
Update app.py
3aa0fcb verified
raw
history blame
1.02 kB
import gradio as gr
from rembg import remove
from PIL import Image
import numpy as np
import io
def remove_bg(image, format, threshold):
input_image = Image.fromarray(np.array(image))
# Background removal processing
output_image = remove(input_image)
# Convert to desired format
buffer = io.BytesIO()
if format == "PNG":
output_image.save(buffer, format="PNG")
elif format == "JPEG":
output_image.save(buffer, format="JPEG")
buffer.seek(0)
return buffer
iface = gr.Interface(
fn=remove_bg,
inputs=[
gr.Image(type="pil", label="Input Image"),
gr.Radio(choices=["PNG", "JPEG"], label="Output Format", value="PNG"),
gr.Slider(0, 100, step=1, label="Threshold", value=0)
],
outputs=gr.Image(type="file", label="Output Image"),
title="Enhanced Background Remover",
description="Upload an image to remove the background. Adjust the output format and sensitivity.",
layout="horizontal"
)
iface.launch()