Codex Bot
Deploy FastAPI face swap Docker app
05a3220
raw
history blame contribute delete
968 Bytes
from fastapi import FastAPI, File, HTTPException, UploadFile
from fastapi.responses import Response
from modules.api_service import initialize_runtime, swap_face_from_uploads
app = FastAPI(title="Deep Live Cam Face Swap API", version="1.0.0")
@app.on_event("startup")
def startup_event() -> None:
initialize_runtime()
@app.get("/health")
def health() -> dict[str, str]:
return {"status": "ok"}
@app.post("/face-swap")
async def face_swap(
source_image: UploadFile = File(...),
target_image: UploadFile = File(...),
) -> Response:
try:
content, media_type = swap_face_from_uploads(
await source_image.read(),
await target_image.read(),
)
except ValueError as exc:
raise HTTPException(status_code=400, detail=str(exc)) from exc
except Exception as exc:
raise HTTPException(status_code=500, detail=str(exc)) from exc
return Response(content=content, media_type=media_type)