Spaces:
Sleeping
Sleeping
File size: 700 Bytes
11ff1a1 7214801 7aca475 7214801 3591e6a 7214801 7aca475 11ff1a1 7aca475 7214801 6fdb77f 11ff1a1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | from fastapi import FastAPI, UploadFile, File
from fastapi.responses import Response
from rembg import remove, new_session
app = FastAPI()
# Create ONE session (cached in memory)
SESSION = new_session(
"u2net",
alpha_matting=True,
alpha_matting_foreground_threshold=240,
alpha_matting_background_threshold=10,
alpha_matting_erode_size=10,
)
@app.get("/")
def health():
return {"status": "ok"}
@app.post("/remove-bg")
async def remove_bg(file: UploadFile = File(...)):
input_bytes = await file.read()
output_bytes = remove(
input_bytes,
session=SESSION
)
return Response(
content=output_bytes,
media_type="image/png"
)
|