riyageorge commited on
Commit
a82bbda
·
1 Parent(s): 48ec66e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -5
app.py CHANGED
@@ -70,6 +70,7 @@ def rnn_predict_message(input_text):
70
  else:
71
  return "Not spam"
72
 
 
73
  # Load the saved LSTM model
74
  lstm_smsspam_model=tf.keras.models.load_model('lstm_smsspam_model.h5')
75
  # Load the saved tokenizer
@@ -87,6 +88,23 @@ def lstm_predict_message(message):
87
  return 'Not spam'
88
 
89
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
 
91
  # Main function for Streamlit app
92
  def main():
@@ -116,26 +134,28 @@ def main():
116
 
117
 
118
  elif task == "Sentiment Classification":
119
- model = st.sidebar.radio("Select Model", (["Perceptron", "Backpropagation", "DNN", "RNN", "LSTM"]))
120
 
121
- if model == "RNN":
 
 
122
  st.subheader("SMS Spam Detection")
123
  user_input = st.text_area("Enter a message to classify as 'Spam' or 'Not spam': ")
124
 
125
  if st.button("Predict"):
126
  if user_input:
127
- prediction_result = rnn_predict_message(user_input)
128
  st.write(f"The message is classified as: {prediction_result}")
129
  else:
130
  st.write("Please enter some text for prediction")
131
 
132
- elif model == "DNN":
133
  st.subheader("SMS Spam Detection")
134
  user_input = st.text_area("Enter a message to classify as 'Spam' or 'Not spam': ")
135
 
136
  if st.button("Predict"):
137
  if user_input:
138
- prediction_result = dnn_predict_message(user_input)
139
  st.write(f"The message is classified as: {prediction_result}")
140
  else:
141
  st.write("Please enter some text for prediction")
@@ -151,6 +171,19 @@ def main():
151
  else:
152
  st.write("Please enter some text for prediction")
153
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
 
155
  if __name__ == "__main__":
156
  main()
 
70
  else:
71
  return "Not spam"
72
 
73
+
74
  # Load the saved LSTM model
75
  lstm_smsspam_model=tf.keras.models.load_model('lstm_smsspam_model.h5')
76
  # Load the saved tokenizer
 
88
  return 'Not spam'
89
 
90
 
91
+ # Load the saved model
92
+ gru_movie_model = tf.keras.models.load_model('APP/gru_movie_model.h5')
93
+ with open('APP/tokenizer_movie_gru.pickle', 'rb') as handle:
94
+ lstm_movie_tokeniser = pickle.load(handle)
95
+
96
+ # Function to predict sentiment for a given review
97
+ def gru_predict_movie_sentiment(review):
98
+ maxlen = 100
99
+ sequence = lstm_movie_tokeniser.texts_to_sequences([review])
100
+ sequence = tf.keras.preprocessing.sequence.pad_sequences(sequence, padding='post', maxlen=maxlen)
101
+ prediction = gru_movie_model.predict(sequence)
102
+ if prediction > 0.5:
103
+ return "Positive"
104
+ else:
105
+ return "Negative"
106
+
107
+
108
 
109
  # Main function for Streamlit app
110
  def main():
 
134
 
135
 
136
  elif task == "Sentiment Classification":
137
+ model = st.sidebar.radio("Select Model", (["DNN", "RNN", "LSTM", "GRU", "Perceptron", "Backpropagation"]))
138
 
139
+
140
+
141
+ if model == "DNN":
142
  st.subheader("SMS Spam Detection")
143
  user_input = st.text_area("Enter a message to classify as 'Spam' or 'Not spam': ")
144
 
145
  if st.button("Predict"):
146
  if user_input:
147
+ prediction_result = dnn_predict_message(user_input)
148
  st.write(f"The message is classified as: {prediction_result}")
149
  else:
150
  st.write("Please enter some text for prediction")
151
 
152
+ elif model == "RNN":
153
  st.subheader("SMS Spam Detection")
154
  user_input = st.text_area("Enter a message to classify as 'Spam' or 'Not spam': ")
155
 
156
  if st.button("Predict"):
157
  if user_input:
158
+ prediction_result = rnn_predict_message(user_input)
159
  st.write(f"The message is classified as: {prediction_result}")
160
  else:
161
  st.write("Please enter some text for prediction")
 
171
  else:
172
  st.write("Please enter some text for prediction")
173
 
174
+ elif model == "GRU":
175
+ st.subheader("Movie Sentiment Analysis")
176
+ user_review = st.text_area("Enter a movie review: ")
177
+
178
+ if st.button("Analyze Sentiment"):
179
+ if user_review:
180
+ sentiment_result = gru_predict_movie_sentiment(user_review)
181
+ st.write(f"The sentiment of the review is: {sentiment_result}")
182
+ else:
183
+ st.write("Please enter a movie review for sentiment analysis")
184
+
185
+
186
+
187
 
188
  if __name__ == "__main__":
189
  main()