samiee2213 commited on
Commit
8e0ba04
·
verified ·
1 Parent(s): bdcbf55

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -52
app.py CHANGED
@@ -1135,60 +1135,42 @@ elif page == "Therapists":
1135
 
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?":
 
1135
 
1136
  elif page == "Insights":
1137
  st.subheader("Insights")
1138
+ session_titles = [session["title"] for session in st.session_state['sessions']]
1139
+ selected_session_title = st.selectbox("Select a session",, session_titles)
1140
+
1141
+ if selected_session_title:
1142
+ selected_session = next(session for session in st.session_state['sessions'] if session["title"] ==
1143
+ selected_session_title)
1144
+ printf"Selected session for insights: {selected_session}") # Debug statement
1145
+ if selected_session and 'messages' in selected _session:
1146
+ message, conversation_summary, mood_dt = generate_insights (selected_session_title)
1147
+ st.write (f"Messages: {message}")
1148
+ st.write(f" nMood: {mood_df}")
1149
+ st.markdown ("### Conversation Summary")
1150
+ st.write(conversation_summary)
1151
+ if not mood_df.empty:
1152
+ st.markdown ("### Mood Analysis")
1153
+ fig, ax = plt.subplots)
1154
+ ax.pie(mood_df['Count'], labels=mood
1155
+ _df['Mood'], autopct='%1.1f%%', startangle=90,
1156
+ colors=['#4CAF50', '#FFC107', '#F44336'])
1157
+ ax.axis ('equal')
1158
+ st.pyplot(fig)
1159
+ st.markdown ("### Mood Over Time")
1160
+ mood_timeline = pd.Series([msg.content.lower) for msg in selected_session ['messages'] if
1161
+ isinstance(msg, HumanMessage)]).apply(
1162
+ lambda x: 1 if any(word in x for word in ['happy', 'good', 'great', 'awesome']) else ( O if any(word in x for word in ['okay', 'fine', 'alright', 'normal']) else -1
1163
  )
1164
+ mood _timeline.index = pd.to_datetime(mood_timeline.index, unit='s')
1165
+ mood_timeline_df = mood_timeline.reset_
1166
+ _index)
1167
+ mood.
1168
+ _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?":