Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,38 +1,39 @@
|
|
1 |
-
from flask import Flask, request, render_template
|
2 |
-
import numpy as np
|
3 |
-
import pickle
|
4 |
-
import warnings
|
5 |
-
|
6 |
-
warnings.filterwarnings('ignore')
|
7 |
-
from feature import FeatureExtraction
|
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 |
-
|
|
|
|
1 |
+
from flask import Flask, request, render_template
|
2 |
+
import numpy as np
|
3 |
+
import pickle
|
4 |
+
import warnings
|
5 |
+
|
6 |
+
warnings.filterwarnings('ignore')
|
7 |
+
from feature import FeatureExtraction
|
8 |
+
|
9 |
+
|
10 |
+
|
11 |
+
with open("model.pkl", "rb") as file:
|
12 |
+
gbc = pickle.load(file)
|
13 |
+
|
14 |
+
app = Flask(__name__)
|
15 |
+
|
16 |
+
@app.route('/', methods=['GET', 'POST'])
|
17 |
+
def index():
|
18 |
+
result = None
|
19 |
+
result_class = None
|
20 |
+
url = None
|
21 |
+
if request.method == 'POST':
|
22 |
+
url = request.form['url']
|
23 |
+
obj = FeatureExtraction(url)
|
24 |
+
x = np.array(obj.getFeaturesList()).reshape(1, 30)
|
25 |
+
|
26 |
+
y_pred = gbc.predict(x)[0]
|
27 |
+
y_pro_phishing = gbc.predict_proba(x)[0, 0]
|
28 |
+
y_pro_non_phishing = gbc.predict_proba(x)[0, 1]
|
29 |
+
|
30 |
+
if y_pred == 1:
|
31 |
+
result = "It is {0:.2f}% safe to go".format(y_pro_non_phishing * 100)
|
32 |
+
result_class = "safe"
|
33 |
+
else:
|
34 |
+
result = "It is {0:.2f}% phishing".format(y_pro_phishing * 100)
|
35 |
+
result_class = "phishing"
|
36 |
+
|
37 |
+
return render_template('index.html', result=result, url=url, result_class=result_class)
|
38 |
+
if __name__ == '__main__':
|
39 |
+
app.run(debug=True)
|