"""Optional FastAPI microservice for Imager-1-Pro.""" from fastapi import FastAPI, File, UploadFile from fastapi.responses import JSONResponse from io import BytesIO from PIL import Image from .config import load_model, predict app = FastAPI(title="Imager-1-Pro", version="1.0.0") _model = None def get_model(): global _model if _model is None: _model = load_model() return _model @app.get("/") def root(): return {"name": "imager-1-pro", "status": "ok"} @app.get("/health") def health(): return {"status": "healthy"} @app.post("/predict") async def predict_endpoint(file: UploadFile = File(...)): image = Image.open(BytesIO(await file.read())) result = predict(image, model=get_model()) return JSONResponse(result)