danushkhanna commited on
Commit
d9bdf5f
·
1 Parent(s): 8675d60

Create ineuron_interface.py

Browse files
Files changed (1) hide show
  1. ineuron_interface.py +60 -0
ineuron_interface.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pickle
3
+ import pandas as pd
4
+ from extract_features import ExtractFeatures
5
+
6
+ @st.cache_resource
7
+ def get_model():
8
+ """
9
+ Loads the phishing URL detection model from a pickle file.
10
+
11
+ This function reads and loads a pickled file containing the classifier.
12
+
13
+ Returns:
14
+ object: The loaded phishing URL detection model.
15
+
16
+ Note:
17
+ The model should be saved in a file named 'phishing_url_detector.pkl'.
18
+ XGBoost module must be installed before using the file.
19
+ """
20
+ with open('phishing_url_detector.pkl', 'rb') as pickle_model:
21
+ phishing_url_detector = pickle.load(pickle_model)
22
+ return phishing_url_detector
23
+
24
+ st.title("Phishing Website Detector")
25
+ st.header("Are you sure your 'bank' sent that link?")
26
+
27
+ # Takes in user input
28
+ input_url = st.text_area("Put in your sus site link here: ")
29
+
30
+ if input_url != "":
31
+
32
+ # Extracts features from the URL and converts it into a dataframe
33
+ features_url = ExtractFeatures().url_to_features(url=input_url)
34
+ features_dataframe = pd.DataFrame.from_dict([features_url])
35
+ features_dataframe = features_dataframe.fillna(-1)
36
+ features_dataframe = features_dataframe.astype(int)
37
+
38
+ st.write("Okay!")
39
+ st.cache_data.clear()
40
+ prediction_str = ""
41
+
42
+ # Predict outcome using extracted features
43
+ try:
44
+ phishing_url_detector = get_model()
45
+ prediction = phishing_url_detector.predict(features_dataframe)
46
+ if prediction == int(True):
47
+ prediction_str = 'Phishing Website. Do not click!'
48
+ elif prediction == int(False):
49
+ prediction_str = 'Not Phishing Website, stay safe!'
50
+ else:
51
+ prediction_str = ''
52
+ st.write(prediction_str)
53
+ st.write(features_dataframe)
54
+
55
+ except Exception as e:
56
+ print(e)
57
+ st.error("Not sure, what went wrong. We'll get back to you shortly!")
58
+
59
+ else:
60
+ st.write("")