Update app.py
Browse files
app.py
CHANGED
|
@@ -1,13 +1,28 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import pickle
|
| 3 |
-
import
|
|
|
|
| 4 |
|
| 5 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
try:
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
except Exception as e:
|
| 10 |
-
print(f"Error loading model: {e}")
|
|
|
|
|
|
|
| 11 |
|
| 12 |
def predict_sms(message):
|
| 13 |
try:
|
|
@@ -15,7 +30,9 @@ def predict_sms(message):
|
|
| 15 |
prediction = model.predict(transformed_text)[0]
|
| 16 |
return "Spam" if prediction == 1 else "Not Spam"
|
| 17 |
except Exception as e:
|
| 18 |
-
|
|
|
|
|
|
|
| 19 |
|
| 20 |
# Gradio Web Interface
|
| 21 |
iface = gr.Interface(
|
|
@@ -26,5 +43,5 @@ iface = gr.Interface(
|
|
| 26 |
description="Enter a message to check if it's spam or not."
|
| 27 |
)
|
| 28 |
|
| 29 |
-
#
|
| 30 |
-
iface.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import pickle
|
| 3 |
+
import os
|
| 4 |
+
import sys
|
| 5 |
|
| 6 |
+
# Add debugging information
|
| 7 |
+
print("Current directory:", os.getcwd())
|
| 8 |
+
print("Files in directory:", os.listdir())
|
| 9 |
+
|
| 10 |
+
# Load the trained model and vectorizer with better error handling
|
| 11 |
try:
|
| 12 |
+
model_path = 'model.pkl'
|
| 13 |
+
vectorizer_path = 'vectorizer.pkl'
|
| 14 |
+
|
| 15 |
+
print(f"Loading model from {model_path}")
|
| 16 |
+
model = pickle.load(open(model_path, 'rb'))
|
| 17 |
+
|
| 18 |
+
print(f"Loading vectorizer from {vectorizer_path}")
|
| 19 |
+
vectorizer = pickle.load(open(vectorizer_path, 'rb'))
|
| 20 |
+
|
| 21 |
+
print("Model and vectorizer loaded successfully")
|
| 22 |
except Exception as e:
|
| 23 |
+
print(f"Error loading model or vectorizer: {e}")
|
| 24 |
+
print(f"Python version: {sys.version}")
|
| 25 |
+
print(f"System path: {sys.path}")
|
| 26 |
|
| 27 |
def predict_sms(message):
|
| 28 |
try:
|
|
|
|
| 30 |
prediction = model.predict(transformed_text)[0]
|
| 31 |
return "Spam" if prediction == 1 else "Not Spam"
|
| 32 |
except Exception as e:
|
| 33 |
+
error_msg = f"Error during prediction: {e}"
|
| 34 |
+
print(error_msg)
|
| 35 |
+
return error_msg
|
| 36 |
|
| 37 |
# Gradio Web Interface
|
| 38 |
iface = gr.Interface(
|
|
|
|
| 43 |
description="Enter a message to check if it's spam or not."
|
| 44 |
)
|
| 45 |
|
| 46 |
+
# For Hugging Face deployment
|
| 47 |
+
iface.launch(server_name="0.0.0.0", server_port=7860)
|