-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
59 lines (43 loc) · 1.64 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
from operator import le
import os
import pickle
import numpy as np
from flask_wtf import FlaskForm
from flask import Flask, render_template
from flask import Flask, request, jsonify, render_template
from flask_bootstrap import Bootstrap
from wtforms import StringField, SubmitField
app = Flask(__name__)
Bootstrap(app)
@app.route('/')
def home():
return render_template('index.html')
@app.route('/predict', methods=['POST'])
def predict():
'''
For rendering results on HTML GUI
'''
data = request.form
model_name = data["model_name"]
if model_name == "logistic_regression":
model = pickle.load(open('models/logistic.pkl', 'rb'))
elif model_name == "naive_bayes":
model = pickle.load(open('models/naive_mdl.pkl', 'rb'))
elif model_name == "random_forest":
model = pickle.load(open('models/rfc_model.pkl', 'rb'))
elif model_name == "support_vector_machine":
model = pickle.load(open('models/SVM_FDM.pkl', 'rb'))
features = [data["lead_time"], data["same_room"], data["Previous_Cancellation"], data["special_requests"], data["booking_changes"]]
final_features = [np.array([float(feature) for feature in features])]
prediction = model.predict(final_features)
output = round(prediction[0])
if output == 0:
result = "Reservation is Cancelled"
else:
result = "Reservation is not Cancelled"
return render_template('index.html', prediction_text=f"{result}")
@app.route('/analysis')
def analysis():
return render_template('analysis.html')
if __name__ == "__main__":
app.run(debug=True)