-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
62 lines (53 loc) · 2.04 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
import os
from flask import Flask, request, jsonify, render_template
import pickle
app = Flask(__name__)
model = pickle.load(open('rfmodel.pkl', 'rb'))
@app.route('/')
def home():
return render_template('mainpage.html')
@app.route('/predict',methods=['POST'])
def predict():
'''
For rendering results on HTML GUI
'''
sm=[6,7,8]
wt=[9,10,11]
sp=[12,1,2,3]
fl=[4,5]
farr= [int(x) for x in request.form.values()]
if farr[1] in sm:
farr.append(0)
elif farr[1] in wt:
farr.append(1)
elif farr[1] in sp:
farr.append(2)
else:
farr.append(3)
final_features=np.array(farr,dtype='int64')
print(final_features)
prediction = model.predict([final_features])
output = round(prediction[0])
if output==0:
return render_template('mainpage.html', prediction_text='No delay will happen {}'.format(output))
elif output==1:
return render_template('mainpage.html', prediction_text='There is a chance to departure delay will happen {}'.format(output))
elif output==2:
return render_template('mainpage.html', prediction_text='here is a chance to both departure and arrival delay will happen {}'.format(output))
elif output==3:
return render_template('mainpage.html', prediction_text='here is a chance to flight will diverted {}'.format(output))
elif output==4:
return render_template('mainpage.html', prediction_text='here is a chance to cancel the flight {}'.format(output))
else:
return render_template('mainpage.html', prediction_text='output {}'.format(output))
'''@app.route('/predict_api',methods=['POST'])
def predict_api():
For direct API calls trought request
data = request.get_json(force=True)
prediction = model.predict([np.array(list(data.values()))])
output = prediction[0]
return jsonify(output)'''
if __name__ == "__main__":
os.environ.setdefault('FLASK_ENV', 'development')
app.run(debug=False)