-
Notifications
You must be signed in to change notification settings - Fork 9
/
app.py
69 lines (55 loc) · 1.58 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
import numpy as np
from flask import Flask, request, jsonify, render_template
import joblib
app = Flask(__name__)
model = joblib.load('model.pkl')
@app.route('/')
def home():
return render_template('index.html')
@app.route('/predict',methods=['POST'])
def predict():
int_features = [float(x) for x in request.form.values()]
if int_features[0]==0:
f_features=[0,0,0]+int_features[1:]
elif int_features[0]==1:
f_features=[1,0,0]+int_features[1:]
elif int_features[0]==2:
f_features=[0,1,0]+int_features[1:]
else:
f_features=[0,0,1]+int_features[1:]
if f_features[6]==0:
fn_features=f_features[:6]+[0,0]+f_features[7:]
elif f_features[6]==1:
fn_features=f_features[:6]+[1,0]+f_features[7:]
else:
fn_features=f_features[:6]+[0,1]+f_features[7:]
final_features = [np.array(fn_features)]
predict = model.predict(final_features)
if predict==0:
output='Normal'
elif predict==1:
output='DOS'
elif predict==2:
output='PROBE'
elif predict==3:
output='R2L'
else:
output='U2R'
return render_template('index.html', output=output)
@app.route('/results',methods=['POST'])
def results():
data = request.get_json(force=True)
predict = model.predict([np.array(list(data.values()))])
if predict==0:
output='Normal'
elif predict==1:
output='DOS'
elif predict==2:
output='PROBE'
elif predict==3:
output='R2L'
else:
output='U2R'
return jsonify(output)
if __name__ == "__main__":
app.run()