-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
57 lines (44 loc) · 1.62 KB
/
Copy pathapp.py
File metadata and controls
57 lines (44 loc) · 1.62 KB
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
#importing required libraries
from flask import Flask, request, render_template
import numpy as np
import pandas as pd
from sklearn import metrics
import warnings
warnings.filterwarnings('ignore')
from feature import generate_data_set
# Gradient Boosting Classifier Model
from sklearn.ensemble import GradientBoostingClassifier
data = pd.read_csv("phishing.csv")
#droping index column
data = data.drop(['Index'],axis = 1)
#print(data)
# Splitting the dataset into dependant and independant fetature
X = data.drop(["class"],axis =1)
y = data["class"]
# instantiate the model
gbc = GradientBoostingClassifier(max_depth=4,learning_rate=0.7)
# fit the model
gbc.fit(X,y)
app = Flask(__name__)
@app.route("/")
def index():
return render_template("index.html", xx= -1)
@app.route("/predict", methods=["GET", "POST"])
def predict():
if request.method == "POST":
url = request.form["url"]
x = np.array(generate_data_set(url)).reshape(1,30)
y_pred =gbc.predict(x)[0]
#1 is safe
#-1 is unsafe
y_pro_phishing = gbc.predict_proba(x)[0,0]
y_pro_non_phishing = gbc.predict_proba(x)[0,1]
# if(y_pred ==1 ):
pred = "It is {0:.2f} % safe to go ".format(y_pro_phishing*100)
return render_template('index.html',xx =round(y_pro_non_phishing,2),url=url )
# else:
# pred = "It is {0:.2f} % unsafe to go ".format(y_pro_non_phishing*100)
# return render_template('index.html',x =y_pro_non_phishing,url=url )
return render_template("index.html", xx =-1)
if __name__ == "__main__":
app.run(host="0.0.0.0" , port=5050,debug=True)