Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,7 @@ from nltk.stem import WordNetLemmatizer
|
|
8 |
from tensorflow.keras.preprocessing.text import Tokenizer
|
9 |
from tensorflow.keras.preprocessing.sequence import pad_sequences
|
10 |
from tensorflow import keras
|
11 |
-
|
12 |
|
13 |
# Ensure necessary NLTK resources are downloaded
|
14 |
nltk.download('punkt')
|
@@ -58,6 +58,10 @@ with open('url_tokenizer.pkl', 'rb') as file:
|
|
58 |
with open('html_tokenizer.pkl', 'rb') as file:
|
59 |
html_tokenizer = pickle.load(file)
|
60 |
|
|
|
|
|
|
|
|
|
61 |
# Define the prediction function
|
62 |
def predict_phishing(url, html):
|
63 |
cleaned_url = preprocess_url(url)
|
@@ -72,10 +76,10 @@ def predict_phishing(url, html):
|
|
72 |
new_predictions_prob = model.predict([new_url_padded, new_html_padded])
|
73 |
new_predictions = (new_predictions_prob > 0.5).astype(int)
|
74 |
|
75 |
-
predicted_category =
|
76 |
predicted_probability = f"{new_predictions_prob[0][0]:.4f}"
|
77 |
|
78 |
-
return predicted_category, predicted_probability
|
79 |
|
80 |
# Create Gradio Interface
|
81 |
interface = gr.Interface(
|
|
|
8 |
from tensorflow.keras.preprocessing.text import Tokenizer
|
9 |
from tensorflow.keras.preprocessing.sequence import pad_sequences
|
10 |
from tensorflow import keras
|
11 |
+
from sklearn.preprocessing import LabelEncoder
|
12 |
|
13 |
# Ensure necessary NLTK resources are downloaded
|
14 |
nltk.download('punkt')
|
|
|
58 |
with open('html_tokenizer.pkl', 'rb') as file:
|
59 |
html_tokenizer = pickle.load(file)
|
60 |
|
61 |
+
# Load the label encoder
|
62 |
+
with open('label_encoder.pkl', 'rb') as file:
|
63 |
+
label_encoder = pickle.load(file)
|
64 |
+
|
65 |
# Define the prediction function
|
66 |
def predict_phishing(url, html):
|
67 |
cleaned_url = preprocess_url(url)
|
|
|
76 |
new_predictions_prob = model.predict([new_url_padded, new_html_padded])
|
77 |
new_predictions = (new_predictions_prob > 0.5).astype(int)
|
78 |
|
79 |
+
predicted_category = label_encoder.inverse_transform(new_predictions)[0]
|
80 |
predicted_probability = f"{new_predictions_prob[0][0]:.4f}"
|
81 |
|
82 |
+
return predicted_category.capitalize(), predicted_probability
|
83 |
|
84 |
# Create Gradio Interface
|
85 |
interface = gr.Interface(
|