File size: 1,191 Bytes
b59e813
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f59d548
 
 
 
 
 
b59e813
 
1c58ee8
b59e813
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
40
41
42
43
44
45
46
47
48
49
50
51
52
from typing import Optional

from fastapi import APIRouter
from fastapi import FastAPI
from schemas import ClassificationResult
from utils import load_image
from utils import load_model


# from pydantic import BaseModel

model = load_model()

app = FastAPI(
    title="MosAl",
    openapi_url="/openapi.json",
    description="""Obtain classification predictions for mosquito image""",
    version="0.1.0",
)

api_router = APIRouter()


# @api_router.get("/", status_code=200)
# async def root():
#     """
#     Root Get
#     """
#     return {"message": "Hello World!"}


@api_router.get("/classify", status_code=200, response_model=ClassificationResult)
async def predict_image(image_name, model=model):
    img = load_image(image_name)
    prediction, pred_idx, probs = model.predict(img)
    if prediction:
        return {"prediction": prediction,
                "score": round(probs.numpy()[pred_idx], 3),
                }
    else:
        return {"message": [0]}



app.include_router(api_router)

if __name__ == "__main__":
    # Use this for debugging purposes only 0.0.0.0 localhost 8001
    import uvicorn

    uvicorn.run(app, host="0.0.0.0", port=7860, log_level="debug")