Skip to content

Instantly share code, notes, and snippets.

@zaidmukaddam
Created February 26, 2024 05:59
Show Gist options
  • Save zaidmukaddam/3c00c429d6b951dc4d1a054fe61c94dc to your computer and use it in GitHub Desktop.
Save zaidmukaddam/3c00c429d6b951dc4d1a054fe61c94dc to your computer and use it in GitHub Desktop.
import os
from feature import FeatureExtraction
from flask import Flask, request
from flask_cors import CORS
import numpy as np
import warnings
import pickle
warnings.filterwarnings('ignore')
file = open("pickle/model.pkl", "rb")
gbc = pickle.load(file)
file.close()
app = Flask(__name__)
CORS(app)
@app.route("/", methods=["GET", "POST"])
def index():
if request.method == "POST":
url = request.form["url"]
print(url)
obj = FeatureExtraction(url)
x = np.array(obj.getFeaturesList()).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_non_phishing*100)
print(pred)
xx = round(y_pro_non_phishing, 2)
print(xx)
return str(round(y_pro_non_phishing, 2))
return str(round(y_pro_non_phishing, 2))
if __name__ == "__main__":
PORT = int(os.environ.get('PORT', 3032))
app.run(host='0.0.0.0', port=PORT, debug=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment