Spaces:
Sleeping
Sleeping
Download app.py from raddiv/background-removal-api: direct link, hf CLI and curl.
- Browser
- Download file 753 Bytes
-
https://huggingface.co/spaces/raddiv/background-removal-api/resolve/main/app.py
- Command line
-
hf download hf://spaces/raddiv/background-removal-api/app.py
-
curl -L -o app.py https://huggingface.co/spaces/raddiv/background-removal-api/resolve/main/app.py
753 Bytes
| from fastapi import FastAPI, UploadFile, File | |
| from fastapi.responses import Response | |
| from rembg import remove | |
| from PIL import Image | |
| import io, base64 | |
| app = FastAPI() | |
| async def remove_background(file: UploadFile = File(...)): | |
| input_bytes = await file.read() | |
| output_bytes = remove(input_bytes) | |
| img_b64 = base64.b64encode(output_bytes).decode() | |
| return {"image_base64": img_b64, "format": "png"} | |
| async def remove_background_file(file: UploadFile = File(...)): | |
| input_bytes = await file.read() | |
| output_bytes = remove(input_bytes) | |
| return Response(content=output_bytes, media_type="image/png") | |
| async def health(): | |
| return {"status": "ok"} |