<jupyter_start><jupyter_text>Safe User Experience (phishing url detection using Flask)   Virtual Environment forrunning flask<jupyter_code>!pip install flask-ngrok<jupyter_output>Requirement already satisfied: flask-ngrok in /usr/local/lib/python3.6/dist-packages (0.0.25)
Requirement already satisfied: requests in /usr/local/lib/python3.6/dist-packages (from flask-ngrok) (2.23.0)
Requirement already satisfied: Flask>=0.8 in /usr/local/lib/python3.6/dist-packages (from flask-ngrok) (1.1.2)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.6/dist-packages (from requests->flask-ngrok) (2020.6.20)
Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.6/dist-packages (from requests->flask-ngrok) (2.10)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.6/dist-packages (from requests->flask-ngrok) (1.24.3)
Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.6/dist-packages (from requests->flask-ngrok) (3.0.4)
Requirement already satisfied: click>=5.1 in /usr/local/lib/python3.6/dist-packages (from Flask>=0.8->flask-ngrok) (7.1.2)
Requirement already satisfie[...]<jupyter_text>Importing necessary modules<jupyter_code>from flask_ngrok import run_with_ngrok
from flask import Flask, request, jsonify, render_template
import pickle<jupyter_output><empty_output><jupyter_text>Mounting drive<jupyter_code>from google.colab import drive
drive.mount('/content/drive')<jupyter_output>Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount("/content/drive", force_remount=True).<jupyter_text>loading model<jupyter_code>model = pickle.load(open('/content/drive/My Drive/SUE/XGBoostClassifier.pkl', 'rb'))<jupyter_output><empty_output><jupyter_text>modules for importing colab notebook<jupyter_code>!pip install import-ipynb
import import_ipynb
import pandas as pd<jupyter_output>Requirement already satisfied: import-ipynb in /usr/local/lib/python3.6/dist-packages (0.1.3)<jupyter_text>changing path<jupyter_code>%cd "/content/drive/My Drive/Colab Notebooks/"<jupyter_output>/content/drive/My Drive/Colab Notebooks<jupyter_text>Importing Notebook with model and functions<jupyter_code>import UrlFeatureExtract<jupyter_output>importing Jupyter notebook from UrlFeatureExtract.ipynb
Requirement already satisfied: tldextract in /usr/local/lib/python3.6/dist-packages (2.2.3)
Requirement already satisfied: requests-file>=1.4 in /usr/local/lib/python3.6/dist-packages (from tldextract) (1.5.1)
Requirement already satisfied: idna in /usr/local/lib/python3.6/dist-packages (from tldextract) (2.10)
Requirement already satisfied: requests>=2.1.0 in /usr/local/lib/python3.6/dist-packages (from tldextract) (2.23.0)
Requirement already satisfied: six in /usr/local/lib/python3.6/dist-packages (from requests-file>=1.4->tldextract) (1.15.0)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.6/dist-packages (from requests>=2.1.0->tldextract) (1.24.3)
Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.6/dist-packages (from requests>=2.1.0->tldextract) (3.0.4)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.6/dist-packages (from re[...]<jupyter_text>Main application<jupyter_code>predic = model.predict(pd.DataFrame([UrlFeatureExtract.final("www.google.com")], columns = UrlFeatureExtract.col))
predic.item() == 1
def predict(url):
  url_features = UrlFeatureExtract.final(url)
  model_input = pd.DataFrame([url_features], columns = UrlFeatureExtract.col)
  prediction = model.predict(model_input)
  if prediction.item() == 1:
    return 1
  elif prediction.item() == -1:
    return -1
  else:
    return 0
# print(predict("www.google.com"), file = sys.stdout)
predict("www.google.com")
import sys
app = Flask("Safe_User_Experience", template_folder='/content/drive/My Drive/SUE/templates')
run_with_ngrok(app)


@app.route("/")
def home():
    return render_template("1.html")

@app.route("/predict", methods=['POST', 'GET'])
def predict():
  url = request.form.values()
  url_features = UrlFeatureExtract.final(url)
  model_input = pd.DataFrame([url_features], columns = UrlFeatureExtract.col)
  prediction = model.predict(model_input)
  if prediction.item() == 1:
    return render_template("1.html", pred = 'This is a legitimate Website')
  elif prediction.item() == -1:
    return render_template("1.html", pred = 'This is a Phishing Website')
  else:
    return render_template("1.html", pred = 'This is a suspicious Website')
  

app.run()<jupyter_output>* Serving Flask app "Safe_User_Experience" (lazy loading)
 * Environment: production
[31m   WARNING: This is a development server. Do not use it in a production deployment.[0m
[2m   Use a production WSGI server instead.[0m
 * Debug mode: off
{'fraction_non_alphanumeric': 0.13964521452145215, 'fraction_numerical': 0.03816006600660066, 'mean_word_length': 5.679063360881543, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 3, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '648310', 'license': 'MIT', 'n_tokens_mistral': 1739, 'n_tokens_neox': 1703, 'n_words': 347, 'path': 'Flask Application/SUE_Flask__1_.ipynb', 'repo_name': 'syedareehaquasar/SUE-Safe-User-Experience-', 'size': '4848'}