Spaces:
Sleeping
Sleeping
File size: 989 Bytes
7a2a7c0 2090f0f 7a2a7c0 5e34709 fe31561 5e34709 7a2a7c0 fe31561 14ae180 ad587f6 fe31561 |
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 |
import gradio as gr
from rembg import remove
from PIL import Image
import io
import numpy as np
def remove_bg(image):
try:
img = Image.open(image) if isinstance(image, str) else Image.fromarray(image)
img_byte_arr = io.BytesIO()
img.save(img_byte_arr, format='PNG')
output_bytes = remove(img_byte_arr.getvalue())
return Image.open(io.BytesIO(output_bytes))
except Exception as e:
raise gr.Error(f"Error processing image: {str(e)}")
with gr.Blocks() as demo:
gr.Markdown("# Background Remover")
with gr.Row():
with gr.Column():
input_image = gr.Image(type="filepath", label="Input Image")
submit_btn = gr.Button("Remove Background")
with gr.Column():
output_image = gr.Image(label="Output Image", type="pil")
submit_btn.click(remove_bg, inputs=input_image, outputs=output_image)
if __name__ == "__main__":
demo.launch(server_name="0.0.0.0", server_port=7860) |