-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
75 lines (57 loc) · 2.82 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
from waitress import serve
from flask import Flask, request, render_template, jsonify, make_response
import pandas as pd
from pycaret.classification import *
vxm_model = load_model('notebook/vxm_model')
app = Flask(__name__)
@app.route("/", methods=['GET'])
def index():
return render_template('index.html')
@app.route("/predict", methods=['GET'])
def predict():
try:
data = {
'max_mfi_a': [None],
'max_mfi_b': [None],
'max_mfi_c': [None],
'max_mfi_drb': [None],
'max_mfi_dqa': [None],
'max_mfi_dqb': [None],
'max_mfi_dpa': [None],
'max_mfi_dpb': [None]
}
# Refactor this ugly code
if request.args.get('max_mfi_a') != None and request.args.get('max_mfi_a') != '':
data['max_mfi_a'] = [request.args.get('max_mfi_a')]
if request.args.get('max_mfi_b') != None and request.args.get('max_mfi_b') != '':
data['max_mfi_b'] = [request.args.get('max_mfi_b')]
if request.args.get('max_mfi_c') != None and request.args.get('max_mfi_c') != '':
data['max_mfi_c'] = [request.args.get('max_mfi_c')]
if request.args.get('max_mfi_drb') != None and request.args.get('max_mfi_drb') != '':
data['max_mfi_drb'] = [request.args.get('max_mfi_drb')]
if request.args.get('max_mfi_dqa') != None and request.args.get('max_mfi_dqa') != '':
data['max_mfi_dqa'] = [request.args.get('max_mfi_dqa')]
if request.args.get('max_mfi_dqb') != None and request.args.get('max_mfi_dqb') != '':
data['max_mfi_dqb'] = [request.args.get('max_mfi_dqb')]
if request.args.get('max_mfi_dpa') != None and request.args.get('max_mfi_dpa') != '':
data['max_mfi_dpa'] = [request.args.get('max_mfi_dpa')]
if request.args.get('max_mfi_dpb') != None and request.args.get('max_mfi_dpb') != '':
data['max_mfi_dpb'] = [request.args.get('max_mfi_dpb')]
instances = pd.DataFrame(data, columns = ['max_mfi_a',
'max_mfi_b',
'max_mfi_c',
'max_mfi_drb',
'max_mfi_dqa',
'max_mfi_dqb',
'max_mfi_dpa',
'max_mfi_dpb'])
new_predictions = predict_model(vxm_model, data=instances)
output = jsonify(label=str(new_predictions['Label'][0]), score=str(new_predictions['Score'][0]))
response = make_response(output)
response.mimetype = 'application/json'
return response
except:
return "Please, verify if all parameters (max_mfi_a, max_mfi_b, max_mfi_c, max_mfi_drb, max_mfi_dqa, max_mfi_dqb, max_mfi_dpa and max_mfi_dpb) contain integer values.", 500
if __name__ == "__main__":
#app.run(host='0.0.0.0')
serve(app, host='0.0.0.0', port=80)