riyageorge commited on
Commit
ef54a66
·
1 Parent(s): 729003b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py CHANGED
@@ -48,6 +48,22 @@ def rnn_predict_message(input_text):
48
  else:
49
  return "Not spam"
50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
 
52
 
53
  # Main function for Streamlit app
@@ -90,6 +106,17 @@ def main():
90
  st.write(f"The message is classified as: {prediction_result}")
91
  else:
92
  st.write("Please enter some text for prediction")
 
 
 
 
 
 
 
 
 
 
 
93
 
94
 
95
  elif task == "Movie Sentiment Analysis":
 
48
  else:
49
  return "Not spam"
50
 
51
+ # Load the saved LSTM model
52
+ lstm_smsspam_model=tf.keras.models.load_model('lstm_smsspam_model.h5')
53
+ # Load the saved tokenizer
54
+ with open('lstm_smsspam_tokenizer.pickle', 'rb') as handle:
55
+ lstm_smsspam_tokenizer = pickle.load(handle)
56
+
57
+ def lstm_predict_message(message):
58
+ maxlen=50
59
+ sequence = lstm_smsspam_tokenizer.texts_to_sequences([message])
60
+ sequence = tf.keras.preprocessing.sequence.pad_sequences(sequence, padding='post', maxlen=maxlen)
61
+ prediction = lstm_smsspam_model.predict(sequence)[0, 0]
62
+ if prediction > 0.5:
63
+ return 'Spam'
64
+ else:
65
+ return 'Not spam'
66
+
67
 
68
 
69
  # Main function for Streamlit app
 
106
  st.write(f"The message is classified as: {prediction_result}")
107
  else:
108
  st.write("Please enter some text for prediction")
109
+
110
+ elif model == "LSTM":
111
+ st.subheader("SMS Spam Detection")
112
+ user_input = st.text_area("Enter a message to classify as 'Spam' or 'Not spam': ")
113
+
114
+ if st.button("Predict"):
115
+ if user_input:
116
+ prediction_result = lstm_predict_message(user_input)
117
+ st.write(f"The message is classified as: {prediction_result}")
118
+ else:
119
+ st.write("Please enter some text for prediction")
120
 
121
 
122
  elif task == "Movie Sentiment Analysis":