-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
83 lines (76 loc) · 2.53 KB
/
app.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
from flask import Flask,render_template,url_for,request,jsonify
from flask_cors import cross_origin
import pandas as pd
import numpy as np
import datetime
import pickle
app = Flask(__name__, template_folder="template")
model = pickle.load(open("./models/cat.pkl", "rb"))
print("Model Loaded")
@app.route("/",methods=['GET'])
@cross_origin()
def home():
return render_template("index.html")
@app.route("/predict",methods=['GET', 'POST'])
@cross_origin()
def predict():
if request.method == "POST":
# DATE
date = request.form['date']
day = float(pd.to_datetime(date, format="%Y-%m-%dT").day)
month = float(pd.to_datetime(date, format="%Y-%m-%dT").month)
# MinTemp
minTemp = float(request.form['mintemp'])
# MaxTemp
maxTemp = float(request.form['maxtemp'])
# Rainfall
rainfall = float(request.form['rainfall'])
# Evaporation
evaporation = float(request.form['evaporation'])
# Sunshine
sunshine = float(request.form['sunshine'])
# Wind Gust Speed
windGustSpeed = float(request.form['windgustspeed'])
# Wind Speed 9am
windSpeed9am = float(request.form['windspeed9am'])
# Wind Speed 3pm
windSpeed3pm = float(request.form['windspeed3pm'])
# Humidity 9am
humidity9am = float(request.form['humidity9am'])
# Humidity 3pm
humidity3pm = float(request.form['humidity3pm'])
# Pressure 9am
pressure9am = float(request.form['pressure9am'])
# Pressure 3pm
pressure3pm = float(request.form['pressure3pm'])
# Temperature 9am
temp9am = float(request.form['temp9am'])
# Temperature 3pm
temp3pm = float(request.form['temp3pm'])
# Cloud 9am
cloud9am = float(request.form['cloud9am'])
# Cloud 3pm
cloud3pm = float(request.form['cloud3pm'])
# Cloud 3pm
location = float(request.form['location'])
# Wind Dir 9am
winddDir9am = float(request.form['winddir9am'])
# Wind Dir 3pm
winddDir3pm = float(request.form['winddir3pm'])
# Wind Gust Dir
windGustDir = float(request.form['windgustdir'])
# Rain Today
rainToday = float(request.form['raintoday'])
input_lst = [location , minTemp , maxTemp , rainfall , evaporation , sunshine ,
windGustDir , windGustSpeed , winddDir9am , winddDir3pm , windSpeed9am , windSpeed3pm ,
humidity9am , humidity3pm , pressure9am , pressure3pm , cloud9am , cloud3pm , temp9am , temp3pm ,
rainToday , month , day]
pred = model.predict(input_lst)
output = pred
if output == 0:
return render_template("after_sunny.html")
else:
return render_template("after_rainy.html")
return render_template("predictor.html")
if __name__=='__main__':
app.run(debug=True)