Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -117,43 +117,59 @@ if st.button("Predict"):
|
|
| 117 |
|
| 118 |
# Show progress spinner while making predictions
|
| 119 |
with st.spinner('Making prediction...'):
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
|
| 158 |
else:
|
| 159 |
st.error("ERROR!!! Please provide web site information for prediction !!!")
|
|
|
|
| 117 |
|
| 118 |
# Show progress spinner while making predictions
|
| 119 |
with st.spinner('Making prediction...'):
|
| 120 |
+
try:
|
| 121 |
+
# Load the pre-trained scaler
|
| 122 |
+
with open('scaler.pkl', 'rb') as f:
|
| 123 |
+
scaler = pickle.load(f)
|
| 124 |
+
# Scale the new data
|
| 125 |
+
X_new_scaled = scaler.transform(single_sample.reshape(1, -1))
|
| 126 |
+
|
| 127 |
+
# Load the selected model
|
| 128 |
+
if selected_model == 'Logistic Regression':
|
| 129 |
+
with open('logistic_regression_model.pkl', 'rb') as f:
|
| 130 |
+
model = pickle.load(f)
|
| 131 |
+
elif selected_model == 'Decision Tree':
|
| 132 |
+
with open('decision_tree_model.pkl', 'rb') as f:
|
| 133 |
+
model = pickle.load(f)
|
| 134 |
+
elif selected_model == 'KNN':
|
| 135 |
+
with open('knn_model.pkl', 'rb') as f:
|
| 136 |
+
model = pickle.load(f)
|
| 137 |
+
elif selected_model == 'XGBoost':
|
| 138 |
+
with open('xgboost_model.pkl', 'rb') as f:
|
| 139 |
+
model = pickle.load(f)
|
| 140 |
+
elif selected_model == 'Random Forest':
|
| 141 |
+
with open('rf_clf.pkl', 'rb') as f:
|
| 142 |
+
model = pickle.load(f)
|
| 143 |
+
elif selected_model == 'SVM':
|
| 144 |
+
with open('svm_model.pkl', 'rb') as f:
|
| 145 |
+
model = pickle.load(f)
|
| 146 |
+
|
| 147 |
+
# Make predictions
|
| 148 |
+
prediction = model.predict(X_new_scaled)
|
| 149 |
+
y_pred_proba = model.predict_proba(X_new_scaled)
|
| 150 |
+
|
| 151 |
+
# Display the prediction result
|
| 152 |
+
if prediction[0] == 0:
|
| 153 |
+
st.success("The website is not a phishing website.")
|
| 154 |
+
st.markdown(f'<img src="data:image/gif;base64,{data_url_ok}" alt="cat gif">', unsafe_allow_html=True,)
|
| 155 |
+
else:
|
| 156 |
+
st.error("The website is a phishing website.")
|
| 157 |
+
st.markdown(f'<img src="data:image/gif;base64,{data_url_warning}" alt="cat gif">', unsafe_allow_html=True,)
|
| 158 |
+
|
| 159 |
+
# Visualize prediction confidence scores as a bar chart
|
| 160 |
+
st.write("Prediction Confidence Scores:")
|
| 161 |
+
class_names = model.classes_
|
| 162 |
+
plt.figure(figsize=(8, 4))
|
| 163 |
+
sns.barplot(x=class_names, y=y_pred_proba[0])
|
| 164 |
+
plt.title("Prediction Confidence Scores")
|
| 165 |
+
plt.xlabel("Class")
|
| 166 |
+
plt.ylabel("Probability")
|
| 167 |
+
st.pyplot(plt)
|
| 168 |
+
|
| 169 |
+
except FileNotFoundError as e:
|
| 170 |
+
st.error(f"Model file for {selected_model} not found: {str(e)}")
|
| 171 |
+
except Exception as e:
|
| 172 |
+
st.error(f"An error occurred while loading the model: {str(e)}")
|
| 173 |
|
| 174 |
else:
|
| 175 |
st.error("ERROR!!! Please provide web site information for prediction !!!")
|