-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
62 lines (51 loc) · 1.9 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
import numpy as np
from flask import Flask, request, jsonify, render_template
import joblib
app = Flask(__name__,template_folder='templates')
model = joblib.load(open('ML_model.sav', 'rb'))
scaler = joblib.load("scaler.sav")
@app.route('/')
def home():
return render_template('index.html')
@app.route('/predict',methods=['POST'])
def predict():
if request.method == "POST":
features = [x for x in request.form.values()]
Holiday=request.form.get('holiday')
Seasons=request.form.get('season')
Functioning=request.form.get('functioningDay')
# Encoding the categorical features
if(Holiday.lower=="no holiday"):
features[9]=str(0)
else:
features[9]=str(1)
if(Seasons=="Winter"):
features[8]=str(3)
elif(Seasons=="Summer"):
features[8]=str(2)
elif(Seasons=="Spring"):
features[8]=str(1)
elif(Seasons=="Autumn"):
features[8]=str(0)
if(Functioning.lower=="no"):
features[10]=str(0)
else:
features[10]=str(1)
final_features = [np.array(features)]
# Scaling the final features
final_features=scaler.transform(final_features)
# Predicting the response
prediction = model.predict(final_features)
output = int(round(prediction[0]))
return render_template('Result.html', prediction_text='Rented Bike Count:- {}'.format(output))
@app.route('/results',methods=['POST'])
def results():
data = request.get_json(force=True)
prediction = model.predict([np.array(list(data.values()))])
output = prediction[0]
return jsonify(output)
if __name__ == "__main__":
try:
app.run(port=5000,debug=True)
except:
print("Oops! Server got exited unexpectedly.\nPlease contact server admin!")