Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from rembg import remove | |
| from PIL import Image | |
| import io | |
| def remove_bg(input_image): | |
| # Convert image to bytes | |
| img_bytes = io.BytesIO() | |
| input_image.save(img_bytes, format="PNG") | |
| img_bytes = img_bytes.getvalue() | |
| # Remove background | |
| output = remove(img_bytes) | |
| # Convert back to PIL | |
| output_image = Image.open(io.BytesIO(output)).convert("RGBA") | |
| return output_image | |
| iface = gr.Interface( | |
| fn=remove_bg, | |
| inputs=gr.Image(type="pil"), | |
| outputs=gr.Image(type="pil"), | |
| title="Background Remover", | |
| description="Upload an image and remove its background instantly." | |
| ) | |
| if __name__ == "__main__": | |
| iface.launch() | |