-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
40 lines (29 loc) · 976 Bytes
/
app.py
File metadata and controls
40 lines (29 loc) · 976 Bytes
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
from typing import Union
from fastapi import FastAPI
from pydantic import BaseModel
from sklearn.ensemble import RandomForestClassifier
import uvicorn
import joblib
app = FastAPI()
loaded_rf = joblib.load(open("weather_random_forest.joblib", "rb"))
class Indicators(BaseModel):
province: int
t_max: int
t_min: int
wind: int
wind_d: int
rain_today: int
humidi: int
cloud: int
pressure: float
day: float
dayofweek: float
month: float
@app.get("/")
def read_root():
return "Welcome"
@app.post("/predict")
def read_item(indicators: Indicators):
return {"result": int(loaded_rf.predict([[indicators.province, indicators.t_max, indicators.t_min, indicators.wind, indicators.wind_d, indicators.rain_today, indicators.humidi, indicators.cloud, indicators.pressure, indicators.day, indicators.dayofweek, indicators.month]])[0])}
if __name__ == '__main__':
uvicorn.run(app, host='127.0.0.1', port=4000, debug=True)