Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from rembg import remove | |
| from PIL import Image | |
| import numpy as np | |
| def remove_background(input_image): | |
| # Convert gradio image to PIL Image | |
| input_image = Image.fromarray(input_image.astype('uint8'), 'RGB') | |
| # Remove background | |
| output_image = remove(input_image) | |
| # Convert RGBA to RGB (remove alpha channel) | |
| output_image = output_image.convert("RGB") | |
| # Convert PIL Image back to numpy array | |
| return np.array(output_image) | |
| iface = gr.Interface( | |
| fn=remove_background, | |
| inputs=gr.Image(), | |
| outputs=gr.Image(), | |
| title="Background Removal App", | |
| description="Upload an image to remove its background." | |
| ) | |
| iface.launch() | |