samiee2213 commited on
Commit
bdcbf55
1 Parent(s): c7cae04

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -33
app.py CHANGED
@@ -1136,41 +1136,59 @@ elif page == "Therapists":
1136
  elif page == "Insights":
1137
  st.subheader("Insights")
1138
 
1139
- session_titles = [session["title"] for session in st.session_state['sessions']]
1140
- selected_session_title = st.selectbox("Select a session", session_titles)
1141
-
1142
- if selected_session_title:
1143
- selected_session = next(session for session in st.session_state['sessions'] if session["title"] == selected_session_title)
1144
- print(f"Selected session for insights: {selected_session}") # Debug statement
1145
-
1146
- if selected_session and 'messages' in selected_session:
1147
- st.write(f"Messages: {selected_session['messages']}")
1148
- conversation_summary, mood_df = generate_insights(selected_session)
1149
-
1150
- st.markdown("### Conversation Summary")
1151
- st.write(conversation_summary)
1152
-
1153
- if not mood_df.empty:
1154
- st.markdown("### Mood Analysis")
1155
- fig, ax = plt.subplots()
1156
- ax.pie(mood_df['Count'], labels=mood_df['Mood'], autopct='%1.1f%%', startangle=90, colors=['#4CAF50', '#FFC107', '#F44336'])
1157
- ax.axis('equal')
1158
- st.pyplot(fig)
1159
-
1160
- st.markdown("### Mood Over Time")
1161
- mood_timeline = pd.Series([msg.content.lower() for msg in selected_session['messages'] if isinstance(msg, HumanMessage)]).apply(
1162
- lambda x: 1 if any(word in x for word in ['happy', 'good', 'great', 'awesome']) else (
1163
- 0 if any(word in x for word in ['okay', 'fine', 'alright', 'normal']) else -1
 
 
 
 
 
 
 
 
 
 
 
 
1164
  )
1165
- )
1166
- mood_timeline.index = pd.to_datetime(mood_timeline.index, unit='s')
1167
- mood_timeline_df = mood_timeline.reset_index()
1168
- mood_timeline_df.columns = ['Time', 'Mood']
1169
- st.line_chart(mood_timeline_df.set_index('Time'))
 
 
 
 
 
1170
  else:
1171
- st.write("No mood data to display.")
1172
- else:
1173
- st.write("No messages to summarize.")
 
1174
 
1175
 
1176
  elif page == "How to use?":
 
1136
  elif page == "Insights":
1137
  st.subheader("Insights")
1138
 
1139
+ # Check if sessions exist in the state
1140
+ if 'sessions' in st.session_state and st.session_state['sessions']:
1141
+ # Extract session titles
1142
+ session_titles = [session["title"] for session in st.session_state['sessions']]
1143
+ selected_session_title = st.selectbox("Select a session", session_titles)
1144
+
1145
+ if selected_session_title:
1146
+ # Find the selected session by title
1147
+ selected_session = next(
1148
+ (session for session in st.session_state['sessions'] if session["title"] == selected_session_title), None
1149
+ )
1150
+
1151
+ if selected_session and 'messages' in selected_session:
1152
+ # Display the messages
1153
+ st.write(f"Messages: {selected_session['messages']}")
1154
+
1155
+ # Call your generate_insights function (ensure this function returns the required values)
1156
+ conversation_summary, mood_df = generate_insights(selected_session)
1157
+
1158
+ st.markdown("### Conversation Summary")
1159
+ st.write(conversation_summary)
1160
+
1161
+ if not mood_df.empty:
1162
+ st.markdown("### Mood Analysis")
1163
+ fig, ax = plt.subplots()
1164
+ ax.pie(mood_df['Count'], labels=mood_df['Mood'], autopct='%1.1f%%', startangle=90, colors=['#4CAF50', '#FFC107', '#F44336'])
1165
+ ax.axis('equal')
1166
+ st.pyplot(fig)
1167
+
1168
+ # Mood over time plot
1169
+ st.markdown("### Mood Over Time")
1170
+ mood_timeline = pd.Series(
1171
+ [msg.content.lower() for msg in selected_session['messages'] if isinstance(msg, HumanMessage)]
1172
+ ).apply(
1173
+ lambda x: 1 if any(word in x for word in ['happy', 'good', 'great', 'awesome']) else (
1174
+ 0 if any(word in x for word in ['okay', 'fine', 'alright', 'normal']) else -1
1175
+ )
1176
  )
1177
+
1178
+ # If there's no timestamp, create a simple timeline based on message indices
1179
+ mood_timeline.index = pd.date_range(start='2023-01-01', periods=len(mood_timeline), freq='T')
1180
+
1181
+ mood_timeline_df = mood_timeline.reset_index()
1182
+ mood_timeline_df.columns = ['Time', 'Mood']
1183
+
1184
+ st.line_chart(mood_timeline_df.set_index('Time'))
1185
+ else:
1186
+ st.write("No mood data to display.")
1187
  else:
1188
+ st.write("No messages to summarize.")
1189
+ else:
1190
+ st.write("No sessions found.")
1191
+
1192
 
1193
 
1194
  elif page == "How to use?":