File size: 1,190 Bytes
c506c4e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import streamlit as st
import pickle
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing.sequence import pad_sequences

# Load the trained LSTM model
model = load_model("spam_classifier_lstm.h5")

# Load the tokenizer
with open("tokenizer.pkl", "rb") as file:
    tokenizer = pickle.load(file)

def classify_sms(text):
    """Predict if an SMS is spam or ham."""
    seq = tokenizer.texts_to_sequences([text])
    padded_seq = pad_sequences(seq, maxlen=50)
    prediction = (model.predict(padded_seq) > 0.5).astype("int32")
    return "Spam" if prediction[0][0] == 1 else "Ham"

# Streamlit UI
st.title("📩 SMS Spam Detector")
st.write("Enter an SMS message below to check if it's Spam or Ham.")

# Text input
sms_text = st.text_area("Enter SMS Message:", "")

if st.button("Classify SMS"):
    if sms_text.strip():
        result = classify_sms(sms_text)
        if result == "Spam":
            st.error("🚨 This message is Spam!")
        else:
            st.success("✅ This message is Ham (Not Spam).")
    else:
        st.warning("Please enter a message to classify.")

# Run using: streamlit run filename.py