raopa/TextClassification
0
1import streamlit as st2import pandas as pd3from tensorflow.keras.preprocessing.sequence import pad_sequences4from tensorflow.keras.models import load_model5from tensorflow.keras.preprocessing.text import Tokenizer6 7# Load the CNN model8model = load_model('path_to_your_cnn_model') # Replace with the actual path to your CNN model file9tokenizer = Tokenizer(num_words=10000) # Assuming the same tokenizer configuration10 11def preprocess_text(text):12 sequences = tokenizer.texts_to_sequences([text])13 padded_sequences = pad_sequences(sequences, maxlen=100) # Assuming the same max_sequence_length14 return padded_sequences15 16def predict_spam(message):17 preprocessed_message = preprocess_text(message)18 prediction = model.predict(preprocessed_message)[0][0]19 return prediction20 21st.title("SMS Spam Detection App")22 23# User input for message24user_input = st.text_area("Enter your message here:")25 26if st.button("Predict"):27 if user_input:28 prediction = predict_spam(user_input)29 result = "Spam" if prediction > 0.5 else "Not Spam"30 st.success(f"The message is predicted as: {result} (Confidence: {prediction:.2f})")31 else:32 st.warning("Please enter a message for prediction.")33 