Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1136,41 +1136,59 @@ elif page == "Therapists":
|
|
1136 |
elif page == "Insights":
|
1137 |
st.subheader("Insights")
|
1138 |
|
1139 |
-
|
1140 |
-
|
1141 |
-
|
1142 |
-
|
1143 |
-
|
1144 |
-
|
1145 |
-
|
1146 |
-
|
1147 |
-
|
1148 |
-
|
1149 |
-
|
1150 |
-
|
1151 |
-
|
1152 |
-
|
1153 |
-
|
1154 |
-
|
1155 |
-
|
1156 |
-
|
1157 |
-
|
1158 |
-
st.
|
1159 |
-
|
1160 |
-
|
1161 |
-
|
1162 |
-
|
1163 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1164 |
)
|
1165 |
-
|
1166 |
-
|
1167 |
-
|
1168 |
-
|
1169 |
-
|
|
|
|
|
|
|
|
|
|
|
1170 |
else:
|
1171 |
-
st.write("No
|
1172 |
-
|
1173 |
-
|
|
|
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?":
|