nileshnavrang's picture
Update app.py
b542b7a verified
raw
history blame contribute delete
752 Bytes
import gradio as gr
from rembg import remove
from PIL import Image
import numpy as np
def remove_background(input_image):
# Convert the input image from Gradio to PIL
image = Image.fromarray(input_image.astype('uint8'), 'RGB')
# Remove background using U²-Net
output_image = remove(image)
# Convert the result back to numpy array for Gradio
return np.array(output_image)
# Create interface with example images for testing
demo = gr.Interface(
fn=remove_background,
inputs=gr.Image(label="Upload Photo"),
outputs=gr.Image(label="Background Removed"),
title="Background Remover",
description="Upload a photo → get a PNG with no background!"
)
if __name__ == "__main__":
demo.launch(share=False)