Download app.py from jmgbbi/modnet-dd: direct link, hf CLI and curl.
- Browser
- Download file 819 Bytes
-
https://huggingface.co/spaces/jmgbbi/modnet-dd/resolve/main/app.py
- Command line
-
hf download hf://spaces/jmgbbi/modnet-dd/app.py
-
curl -L -o app.py https://huggingface.co/spaces/jmgbbi/modnet-dd/resolve/main/app.py
819 Bytes
| import gradio as gr | |
| from rembg import remove | |
| from PIL import Image | |
| import requests | |
| from io import BytesIO | |
| def remove_bg(input_img): | |
| # 如果输入是 URL | |
| if isinstance(input_img, str): | |
| response = requests.get(input_img) | |
| input_img = Image.open(BytesIO(response.content)).convert("RGB") | |
| else: | |
| input_img = input_img.convert("RGB") | |
| # 去背景 | |
| output = remove(input_img) | |
| return output | |
| iface = gr.Interface( | |
| fn=remove_bg, | |
| inputs=gr.Image(type="pil", label="Upload Image or enter URL"), | |
| outputs=gr.Image(type="pil", label="Background Removed"), | |
| title="Background Removal API", | |
| description="Upload an image or enter a URL to remove the background." | |
| ) | |
| # 启动 Gradio 服务 | |
| iface.launch(server_name="0.0.0.0", server_port=7860) |