piyushmadhukar commited on
Commit
c506c4e
·
verified ·
1 Parent(s): 1b8dddb

Upload 5 files

Browse files
Files changed (5) hide show
  1. app.py +37 -0
  2. requirements.txt +2 -0
  3. spam.csv +0 -0
  4. spam_classifier_lstm.h5 +3 -0
  5. tokenizer.pkl +3 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pickle
3
+ from tensorflow.keras.models import load_model
4
+ from tensorflow.keras.preprocessing.sequence import pad_sequences
5
+
6
+ # Load the trained LSTM model
7
+ model = load_model("spam_classifier_lstm.h5")
8
+
9
+ # Load the tokenizer
10
+ with open("tokenizer.pkl", "rb") as file:
11
+ tokenizer = pickle.load(file)
12
+
13
+ def classify_sms(text):
14
+ """Predict if an SMS is spam or ham."""
15
+ seq = tokenizer.texts_to_sequences([text])
16
+ padded_seq = pad_sequences(seq, maxlen=50)
17
+ prediction = (model.predict(padded_seq) > 0.5).astype("int32")
18
+ return "Spam" if prediction[0][0] == 1 else "Ham"
19
+
20
+ # Streamlit UI
21
+ st.title("📩 SMS Spam Detector")
22
+ st.write("Enter an SMS message below to check if it's Spam or Ham.")
23
+
24
+ # Text input
25
+ sms_text = st.text_area("Enter SMS Message:", "")
26
+
27
+ if st.button("Classify SMS"):
28
+ if sms_text.strip():
29
+ result = classify_sms(sms_text)
30
+ if result == "Spam":
31
+ st.error("🚨 This message is Spam!")
32
+ else:
33
+ st.success("✅ This message is Ham (Not Spam).")
34
+ else:
35
+ st.warning("Please enter a message to classify.")
36
+
37
+ # Run using: streamlit run filename.py
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ streamlit
2
+ tensorflow==2.9.1
spam.csv ADDED
The diff for this file is too large to render. See raw diff
 
spam_classifier_lstm.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a174bc03428243455e5d1392e522403e75bee6351d1fd8052b49ce4ce94e6982
3
+ size 8464136
tokenizer.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c14b2e6bb63cef37ba1fd5c12c5581b86bc13f04d81fe74ef4d20ec8f8b72680
3
+ size 333172