forked from hsezhiyan/ecs193b_web_service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
143 lines (108 loc) · 4.27 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
from flask import Flask, render_template, request, url_for, redirect
from sklearn.svm import SVC # for the SVM cath prediction model
from svm_helper import process_svm_dict
from ef_helper import prediction, ef_output_string
from followup_ef_helper import prediction_and_uncertainty, create_output_string
from svm_helper import process_svm_dict
from NNprocess_code import process_nn_dict
from keras.models import model_from_json
import numpy as np
import joblib
app = Flask(__name__, static_url_path='', static_folder='')
@app.route("/", methods=["GET"])
def home():
return render_template("search_page.html")
@app.route("/ef_page", methods=["GET"])
def ef_page():
return render_template("ef_model.html")
@app.route("/ef_calc", methods=["GET"])
def ef_calc():
ef_data = request.args.to_dict()
try:
result = prediction(ef_data)
except Exception as error:
return str(error)
return_string = ef_output_string(result)
return render_template('result_page.html', title='EF Prediction Results',result=return_string)
@app.route("/followup_ef_page", methods=["GET"])
def followup_ef_page():
return render_template("f_ef_model.html")
@app.route("/followup_ef_calc", methods=["GET"])
def followup_ef_calc():
ef_data = request.args.to_dict()
try:
mean, variance = prediction_and_uncertainty(ef_data)
except Exception as error:
return str(error)
return_string = create_output_string(mean, variance)
return render_template('result_page.html', title='Follow Up EF Prediction Results',result=return_string)
@app.route("/NN_cath_page", methods=["GET"])
def NN_cath_page():
return render_template("NN_model.html")
@app.route("/NN_cath_calc", methods=["GET"])
def NN_cath_calc():
# load json and create model
json_file = open('trained_models/Cath_NNmodel.json', 'r')
loaded_model_json = json_file.read()
json_file.close()
loaded_model = model_from_json(loaded_model_json)
# load weights into new model
loaded_model.load_weights("trained_models/CathNNwts.h5")
print("Loaded model from disk")
cath_data = request.args.to_dict()
try:
cath_data_list = process_nn_dict(cath_data)
except Exception as error:
return str(error)
# print(cath_data_list)
# cath_data_list = []
# for key in cath_data:
# try:
# float(cath_data[key])
# float_bool = True
# except:
# float_bool = False
# if float_bool:
# cath_data_list.append(float(cath_data[key]))
# elif cath_data[key] == "":
# cath_data_list.append(-1)
# should be 1
# cath_data_list = [66, 1, 1, 0, 0, 0, 0, 0, 0, 175.0, 87.6, 0, 1, 0, 0, 0, -1, 2, 2, 1, 1, 2, 4, 1, 0, 0.0, 0, 0.0, 0, 0.5, 0, 0.9, 0, 0.0, 1, 1, 1, 1, 1, 1]
# should be 0
# cath_data_list = [63, 0, 1, 1, 0, 0, 1, 0, 0, 188.0, 71.0, 0, 0, 0, 0, 0, -1, 1, -1, 1, 0, 2, 1, 2, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 1, 1, 1, 1, 1, 1]
cath_data_list = np.array(cath_data_list)
cath_prediction = loaded_model.predict(np.array([cath_data_list]))[0][0]
return_string = f"Cath result is {cath_prediction}"
return render_template('result_page.html', title='Neural Network Prediction Results',result=return_string)
@app.route("/svm_cath_page", methods=["GET"])
def svm_cath_page():
return render_template("svm_model.html")
@app.route("/svm_cath_calc", methods=["GET"])
def svm_cath_calc():
loaded_model = joblib.load("trained_models/svm_cath.sav")
cath_data = request.args.to_dict()
try:
cath_data_list = process_svm_dict(cath_data)
except Exception as error:
return str(error)
# print(cath_data_list)
# cath_data_list = []
# for key in cath_data:
# try:
# float(cath_data[key])
# float_bool = True
# except:
# float_bool = False
# if float_bool:
# cath_data_list.append(float(cath_data[key]))
# elif cath_data[key] == "":
# cath_data_list.append(-1)
# should be 1
# cath_data_list = [66, 1, 1, 0, 0, 0, 0, 0, 0, 175.0, 87.6, 0, 1, 0, 0, 0, -1, 2, 2, 1, 1, 2, 4, 1, 0, 0.0, 0, 0.0, 0, 0.5, 0, 0.9, 0, 0.0, 1, 1, 1, 1, 1, 1]
# should be 0
# cath_data_list = [63, 0, 1, 1, 0, 0, 1, 0, 0, 188.0, 71.0, 0, 0, 0, 0, 0, -1, 1, -1, 1, 0, 2, 1, 2, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 1, 1, 1, 1, 1, 1]
cath_prediction = loaded_model.predict([cath_data_list])
return_string = f"Cath result is {cath_prediction}"
return render_template('result_page.html', title='SVM Prediction Results',result=return_string)
if __name__ == "__main__":
app.run()