raddiv's picture
Create app.py
4fb4090 verified
Raw History Blame Contribute Delete
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()
@app.post("/remove-background")
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"}
@app.post("/remove-background-file")
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")
@app.get("/health")
async def health():
return {"status": "ok"}