|
import gradio as gr |
|
import rembg |
|
from PIL import Image |
|
import io |
|
import numpy as np |
|
|
|
def remove_background(input_image): |
|
|
|
image_array = input_image.astype(np.uint8) |
|
image_pil = Image.fromarray(image_array) |
|
|
|
|
|
image_buffer = io.BytesIO() |
|
image_pil.save(image_buffer, format='PNG') |
|
|
|
|
|
output_data = rembg.remove(image_buffer.getvalue()) |
|
|
|
|
|
output_image = Image.open(io.BytesIO(output_data)) |
|
|
|
|
|
return np.array(output_image) |
|
|
|
iface = gr.Interface( |
|
fn=remove_background, |
|
inputs=gr.Image(), |
|
outputs=gr.Image() |
|
) |
|
|
|
iface.launch() |