-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
58 lines (43 loc) · 1.37 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
# import libraries
from flask import Flask, jsonify, request
import feature
from tensorflow import keras
import numpy as np
# Creating Flask app
app = Flask(__name__)
# Loading pre-trained keras model
def loadModel():
path = "F:\Chrome Extension\Trawling-Chrome-Extention\Server\models48xLSTM-32xDense"
model = keras.models.load_model(path)
return model
model = loadModel()
# Make prediction using loaded keras model
def make_predict(url):
x_pedict = feature.featureExtraction(url)
print(x_pedict, " - Extracted features")
x_pedict = np.array(x_pedict)
x_pedict = np.reshape(x_pedict, (1, 1, x_pedict.shape[0]))
prediction = model.predict(x_pedict)
print(prediction[0], " - Predicted value before thresholding")
return thresholding(prediction[0])
# Thresholding
# legitmate <= 0.8 < phishing
def thresholding(prediction):
threshold = 0.8
if prediction > threshold:
return 1
else:
return 0
#routing post methods
@app.route("/", methods=['GET', 'POST'])
def index():
if (request.method == "POST"):
response = request.get_json()
predict = make_predict(response["url"])
print(predict, "- predicted value")
return jsonify({"state": predict })
else:
print("Error - Not recieved POST method")
return jsonify({"state":-1})
if __name__ == "__main__":
app.run(debug=True)