Created
February 26, 2024 05:59
-
-
Save zaidmukaddam/3c00c429d6b951dc4d1a054fe61c94dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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