Spaces:
Runtime error
Runtime error
File size: 1,126 Bytes
161f497 |
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 32 33 34 35 36 37 |
import gradio as gr
from rembg import remove
from PIL import Image
import io
# Function to remove the background
def remove_background(image):
# Convert the uploaded image to bytes
img_bytes = io.BytesIO()
image.save(img_bytes, format="PNG")
img_bytes = img_bytes.getvalue()
# Use rembg to remove the background
output_bytes = remove(img_bytes)
# Convert the output bytes back to an image
output_image = Image.open(io.BytesIO(output_bytes)).convert("RGBA")
return output_image
# Gradio interface
with gr.Blocks() as demo:
gr.Markdown("# Background Remover AI")
gr.Markdown("Upload an image, and the AI will remove the background for you.")
with gr.Row():
with gr.Column():
input_image = gr.Image(type="pil", label="Upload Image")
with gr.Column():
output_image = gr.Image(type="pil", label="Output Image")
remove_button = gr.Button("Remove Background")
# Link the button to the function
remove_button.click(remove_background, inputs=input_image, outputs=output_image)
# Launch the app
demo.launch() |