MLDeveloper commited on
Commit
ef88b24
·
verified ·
1 Parent(s): 778c2e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -8
app.py CHANGED
@@ -4,15 +4,21 @@ import joblib
4
  import re
5
  import string
6
 
7
- # Page configuration
8
  st.set_page_config(page_title="SMS Spam Detector", layout="centered")
9
  st.title("📩 SMS Spam Detection App")
10
  st.markdown("🔍 Enter a message below to check if it's **Spam** or **Not Spam (Ham)**")
11
 
12
- # --- Load Model and Vectorizer ---
13
- # These should be .pkl files, saved using joblib.dump() in your training script
14
- model = joblib.load("model/spam_model.pkl") # Correct path to trained model
15
- vectorizer = joblib.load("model/tfidf_vectorizer.pkl") # Correct path to vectorizer
 
 
 
 
 
 
16
 
17
  # --- Text Cleaning Function ---
18
  def clean_text(text):
@@ -31,7 +37,7 @@ def predict_spam(message):
31
  prediction = model.predict(vector)
32
  return "Spam" if prediction[0] == 1 else "Not Spam"
33
 
34
- # --- Input Section ---
35
  user_input = st.text_area("✉️ Enter your SMS message here:")
36
 
37
  if st.button("Check Message"):
@@ -44,6 +50,9 @@ if st.button("Check Message"):
44
  else:
45
  st.success("✅ This message is classified as **NOT SPAM (HAM)**.")
46
 
47
- # Footer
48
- st.markdown("---")
 
 
 
49
  st.markdown("🔒 **Note**: This is a demo model and not intended for production use without proper testing.")
 
4
  import re
5
  import string
6
 
7
+ # Page config
8
  st.set_page_config(page_title="SMS Spam Detector", layout="centered")
9
  st.title("📩 SMS Spam Detection App")
10
  st.markdown("🔍 Enter a message below to check if it's **Spam** or **Not Spam (Ham)**")
11
 
12
+ # --- Load CSV for reference or stats ---
13
+ csv_path = "https://huggingface.co/spaces/MLDeveloper/Spam_SMS_Detection/resolve/main/spam_sms_detection.csv"
14
+ try:
15
+ df = pd.read_csv(csv_path)
16
+ except Exception as e:
17
+ st.error(f"Error loading dataset: {e}")
18
+
19
+ # --- Load trained model & vectorizer ---
20
+ model = joblib.load("model/spam_model.pkl") # ✅ your trained model
21
+ vectorizer = joblib.load("model/tfidf_vectorizer.pkl") # ✅ your TF-IDF vectorizer
22
 
23
  # --- Text Cleaning Function ---
24
  def clean_text(text):
 
37
  prediction = model.predict(vector)
38
  return "Spam" if prediction[0] == 1 else "Not Spam"
39
 
40
+ # --- UI for prediction ---
41
  user_input = st.text_area("✉️ Enter your SMS message here:")
42
 
43
  if st.button("Check Message"):
 
50
  else:
51
  st.success("✅ This message is classified as **NOT SPAM (HAM)**.")
52
 
53
+ # Optional: Show dataset preview
54
+ with st.expander("📄 View sample dataset (CSV)"):
55
+ st.dataframe(df.head())
56
+
57
+ st.markdown("---")
58
  st.markdown("🔒 **Note**: This is a demo model and not intended for production use without proper testing.")