-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
42 lines (36 loc) · 1.15 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
from fastapi import FastAPI
from pydantic import BaseModel
import pickle
app = FastAPI()
@app.get("/")
def read_root():
return {"message": "A Simple Prediction API"}
def load_model():
with open('model/classifier.pkl', 'rb') as f:
model = pickle.load(f)
return model
class WineFeatures(BaseModel):
alcohol: float
malic_acid: float
ash: float
alcalinity_of_ash: float
magnesium: float
total_phenols: float
flavanoids: float
nonflavanoid_phenols: float
proanthocyanins: float
color_intensity: float
hue: float
od280_od315_of_diluted_wines: float
proline: float
@app.post("/predict")
def predict_wine(features: WineFeatures):
model = load_model()
input_data = [[
features.alcohol, features.malic_acid, features.ash, features.alcalinity_of_ash,
features.magnesium, features.total_phenols, features.flavanoids,
features.nonflavanoid_phenols, features.proanthocyanins, features.color_intensity,
features.hue, features.od280_od315_of_diluted_wines, features.proline
]]
prediction = model.predict(input_data)
return {"prediction": int(prediction)}