-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
53 lines (39 loc) · 1.22 KB
/
main.py
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
53
from typing import Union
from fastapi import FastAPI, Request, Path
from fastapi.responses import HTMLResponse
from pydantic import BaseModel, Field
from typing import List, Dict, Any, Optional
import pandas as pd
from mlModelSaver import MlModelSaver
mlModelSaverInstance = MlModelSaver({
"baseRelativePath": ".",
"modelsFolder": "models"
})
app = FastAPI()
class ModelsBody(BaseModel):
name: str = Field(..., example="0001_test")
inputs: Optional[List[Dict[str, Any]]] = Field(
None,
example=[
{"Temperature": 56, "Advertising": 15, "Discount": 25}
]
)
@app.get("/")
def read_root():
return "Hello Jason"
@app.get("/models/list")
def models():
return mlModelSaverInstance.listOfModels()
@app.get("/model/info/{modelName}")
def modelInfo(modelName: str = Path(..., example="0001_test")):
model = mlModelSaverInstance.getModel(modelName)
response = model.mlModelSaverConfig
return response
@app.post("/model/predict")
def modelsInfo(body: ModelsBody):
model = mlModelSaverInstance.getModel(body.name)
inputDf = pd.DataFrame(body.inputs)
return model.mlModelSavePredict(
inputDf,
getattr(body, 'typeOfPredict', 'normal')
)