forked from zjesko/mlops-iris
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
58 lines (45 loc) · 1.45 KB
/
main.py
File metadata and controls
58 lines (45 loc) · 1.45 KB
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
54
55
56
57
58
import uvicorn
from fastapi import FastAPI
from pydantic import BaseModel
from ml_utils import find_better_model,predict
from datetime import datetime
app = FastAPI(
title="Iris Predictor",
docs_url="/"
)
app.add_event_handler("startup", find_better_model)
class QueryIn(BaseModel):
sepal_length: float
sepal_width: float
petal_length: float
petal_width: float
class QueryOut(BaseModel):
flower_class: str
timestamp_str:str
class FeedbackIn(BaseModel):
sepal_length: float
sepal_width: float
petal_length: float
petal_width: float
flower_class:int
@app.get("/ping")
def ping():
return {"ping": "pong"}
@app.post("/predict_flower", response_model=QueryOut, status_code=200)
def predict_flower( query_data: QueryIn):
result = predict(query_data)
ct = datetime.now()
ctStr = ct.strftime("%m/%d/%Y, %H:%M:%S")
output = {'flower_class': result,'timestamp_str':ctStr}
return output
## added this from session and there is no response here except string
# @app.post("/feedback_loop", status_code=200)
# def feedback_loop( data:list[FeedbackIn]):
# retrain(data)
# return {"detail": "Feed back loop successful"}
# @app.post("/feedback_single_data", status_code=200)
# def feedback_single_data( data:FeedbackIn):
# retrain_single(data)
# return {"detail": "Feed single data successful"}
if __name__ == "__main__":
uvicorn.run("main:app", host='127.0.0.1', port=8888, reload=True)