SwatGarg commited on
Commit
52593f1
1 Parent(s): ffbf5ed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -28
app.py CHANGED
@@ -121,28 +121,27 @@ else:
121
  with input_container:
122
  if user_message:
123
  st.session_state.entered_text.append(user_message)
124
-
125
  st.session_state.messages.append({"role": "user", "content": user_message})
 
 
126
  with st.chat_message("user"):
127
  st.write(user_message)
128
 
129
- with st.spinner("processing....."):
130
- response = generate_response(user_message)
131
- st.session_state.past.append(user_message)
132
- st.session_state.messages.append(
133
- {"role": "ai", "content": response}
134
- )
135
- #st.session_state.generated.append(response)
136
-
137
- # Detect sentiment
138
- user_sentiment = chatbot.detect_sentiment(user_message)
139
-
140
- # Update mood history / mood_trend
141
- chatbot.update_mood_history()
142
- mood_trend = chatbot.check_mood_trend()
143
-
144
- # Define rewards
145
- if user_sentiment in ["Positive", "Moderately Positive"]:
146
  if mood_trend == "increased":
147
  reward = +1
148
  mood_trend_symbol = " ⬆️"
@@ -151,8 +150,8 @@ with input_container:
151
  mood_trend_symbol = ""
152
  else: # decreased
153
  reward = -0.2
154
- mood_trend_symbol = " ⬇️"
155
- else:
156
  if mood_trend == "increased":
157
  reward = +1
158
  mood_trend_symbol = " ⬆️"
@@ -165,20 +164,19 @@ with input_container:
165
 
166
  print(
167
  f"mood_trend - sentiment - reward: {mood_trend} - {user_sentiment} - 🛑{reward}🛑"
168
- )
169
 
170
- # Update Q-values
171
- chatbot.update_q_values(
172
- user_sentiment, reward, user_sentiment
173
- )
174
-
175
  with st.chat_message("ai"):
176
  st.markdown(llm_reponse_with_quesiton)
177
- # Update data to memory
178
  st.session_state.user_sentiment = user_sentiment
179
  st.session_state.mood_trend = mood_trend
180
  st.session_state.mood_trend_symbol = mood_trend_symbol
181
-
182
  # Convert the response to speech
183
  speech_fp = text_to_speech(response)
184
  # Play the speech
 
121
  with input_container:
122
  if user_message:
123
  st.session_state.entered_text.append(user_message)
 
124
  st.session_state.messages.append({"role": "user", "content": user_message})
125
+
126
+ # Display the user's message
127
  with st.chat_message("user"):
128
  st.write(user_message)
129
 
130
+ # Process the user's message and generate a response
131
+ with st.spinner("Processing..."):
132
+ response = generate_response(user_message)
133
+ st.session_state.past.append(user_message)
134
+ st.session_state.messages.append({"role": "ai", "content": response})
135
+
136
+ # Detect sentiment
137
+ user_sentiment = chatbot.detect_sentiment(user_message)
138
+
139
+ # Update mood history / mood_trend
140
+ chatbot.update_mood_history()
141
+ mood_trend = chatbot.check_mood_trend()
142
+
143
+ # Define rewards
144
+ if user_sentiment in ["Positive", "Moderately Positive"]:
 
 
145
  if mood_trend == "increased":
146
  reward = +1
147
  mood_trend_symbol = " ⬆️"
 
150
  mood_trend_symbol = ""
151
  else: # decreased
152
  reward = -0.2
153
+ mood_trend_symbol = " ⬇️"
154
+ else:
155
  if mood_trend == "increased":
156
  reward = +1
157
  mood_trend_symbol = " ⬆️"
 
164
 
165
  print(
166
  f"mood_trend - sentiment - reward: {mood_trend} - {user_sentiment} - 🛑{reward}🛑"
167
+ )
168
 
169
+
170
+ # Update Q-values
171
+ chatbot.update_q_values(user_sentiment, reward, user_sentiment)
172
+
173
+ # Display the AI's response
174
  with st.chat_message("ai"):
175
  st.markdown(llm_reponse_with_quesiton)
 
176
  st.session_state.user_sentiment = user_sentiment
177
  st.session_state.mood_trend = mood_trend
178
  st.session_state.mood_trend_symbol = mood_trend_symbol
179
+
180
  # Convert the response to speech
181
  speech_fp = text_to_speech(response)
182
  # Play the speech