File size: 827 Bytes
1fdd208 | 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 34 35 36 37 38 39 | """
Optional FastAPI microservice for Imager-1-Tiny.
Run: uvicorn src.server:app --host 0.0.0.0 --port 8000
"""
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-Tiny", 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-tiny", "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)
|