-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
102 lines (87 loc) · 3.29 KB
/
server.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
from fastapi import FastAPI, Request
from fastapi.responses import HTMLResponse
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from typing import Optional
from sklearn.linear_model import LogisticRegression
import pickle
app = FastAPI()
app.mount("/static", StaticFiles(directory="static"), name="static")
templates = Jinja2Templates(directory="templates")
@app.get("/", response_class=HTMLResponse)
async def read_item(request: Request):
return templates.TemplateResponse("home.html", {"request": request})
@app.get("/run-prediction", response_class=HTMLResponse)
async def read_item(request: Request):
dummy = "hello i am dummy logic!"
# print(jan)
return templates.TemplateResponse("run-predict.html", {"request": request})
@app.get("/test/{id}", response_class=HTMLResponse)
async def read_item(request: Request, id: str):
return templates.TemplateResponse("home.html", {"request": request, "id": id})
@app.get("/engine", response_class=HTMLResponse)
async def read_item(request: Request):
# year = int(request.query_params["year"])
if(request.query_params["jan"]):
jan = float(request.query_params["jan"])
else:
jan = 66.9
if(request.query_params["feb"]):
feb = float(request.query_params["feb"])
else:
feb = 74.9
if(request.query_params["mar"]):
mar = float(request.query_params["mar"])
else:
mar = 83.8
if(request.query_params["april"]):
april = float(request.query_params["april"])
else:
april = 60.3
if(request.query_params["may"]):
may = float(request.query_params["may"])
else:
may = 45.6
if(request.query_params["june"]):
june = float(request.query_params["june"])
else:
june = 44.9
if(request.query_params["jul"]):
jul = float(request.query_params["jul"])
else:
jul = 111.7
if(request.query_params["aug"]):
aug = float(request.query_params["aug"])
else:
aug = 112.6
if(request.query_params["sept"]):
sept = float(request.query_params["sept"])
else:
sept = 57.5
if(request.query_params["oct"]):
oct = float(request.query_params["oct"])
else:
oct = 26.2
if(request.query_params["nov"]):
nov = float(request.query_params["nov"])
else:
nov = 17.2
if(request.query_params["dec"]):
dec = float(request.query_params["dec"])
else:
dec = 37.2
annual = jan + feb + mar + april + may + june + jul + aug + sept + oct + nov + dec
JF = jan + feb
MAM = mar + april + may
JJAS = june + jul + aug + sept
OND = oct + nov + dec
# load the trained modal
loaded_model = pickle.load(open('../saved-models/modelSaved_refinedV1.sav', 'rb'))
finalOP = loaded_model.predict([[jan,feb,mar,april,may,june,jul,aug,sept,oct,nov,dec,annual,JF,MAM,JJAS,OND]])
print(finalOP)
prid = loaded_model.predict_proba([[jan,feb,mar,april,may,june,jul,aug,sept,oct,nov,dec,annual,JF,MAM,JJAS,OND]])
print(prid)
print(format(prid[0][1], '.3f'))
prediction = format(prid[0][1], '.3f')
# print("Prams: "+str(request.query_params["year"]))
return templates.TemplateResponse("engine.html", {"request": request, "result": finalOP[0], "prediction": prediction})