-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
42 lines (35 loc) · 873 Bytes
/
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
from fastapi import Request, FastAPI
from fastapi.middleware.cors import CORSMiddleware
from mlModel import MLmodel
app = FastAPI()
mlModel = MLmodel()
origins = ["*"]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_methods=["POST", "GET"],
allow_headers=["*"],
)
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.post("/predict")
async def get_body(request: Request):
json = await request.json()
data = list(json.values())
prediction = mlModel.predict(data)
print(f'{prediction = }')
value = str(int(prediction[0].round(0)))
return value
# {
# "volatile acidity": 0.7,
# "citric acid": 0.0,
# "residual sugar": 1.9,
# "chlorides": 0.076,
# "free sulfur dioxide": 11.0,
# "total sulfur dioxide": 34.0,
# "density": 0.9978,
# "pH": 3.51,
# "sulphates": 0.56,
# "alcohol": 9.4
# }