Spaces:
Runtime error
Runtime error
Download app.py from efasf/background-remover: direct link, hf CLI and curl.
- Browser
- Download file 680 Bytes
-
https://huggingface.co/spaces/efasf/background-remover/resolve/main/app.py
- Command line
-
hf download hf://spaces/efasf/background-remover/app.py
-
curl -L -o app.py https://huggingface.co/spaces/efasf/background-remover/resolve/main/app.py
680 Bytes
| 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() | |