Ara Yeroyan commited on
Commit
ec044b4
Β·
1 Parent(s): 8729e12

collapse sample questions

Browse files
Files changed (1) hide show
  1. app.py +92 -70
app.py CHANGED
@@ -637,6 +637,13 @@ def main():
637
  - Combine multiple filters for precise searches
638
  - Check the "Retrieved Documents" tab to see source material
639
 
 
 
 
 
 
 
 
640
  #### ⚠️ Important
641
 
642
  **When finished, please close the browser window** to free up computational resources.
@@ -980,6 +987,44 @@ def main():
980
  st.info("No documents were retrieved for the last query.")
981
  else:
982
  st.info("No documents have been retrieved yet. Start a conversation to see retrieved documents here.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
983
 
984
  # Feedback Dashboard Section
985
  st.markdown("---")
@@ -1181,26 +1226,6 @@ def main():
1181
  # Scroll to conversation - this is handled by the auto-scroll at bottom
1182
  pass
1183
 
1184
- # Display retrieval history stats
1185
- if st.session_state.rag_retrieval_history:
1186
- st.markdown("---")
1187
- st.markdown("#### πŸ“Š Retrieval History")
1188
-
1189
- with st.expander(f"View {len(st.session_state.rag_retrieval_history)} retrieval entries", expanded=False):
1190
- for idx, entry in enumerate(st.session_state.rag_retrieval_history, 1):
1191
- st.markdown(f"**Retrieval #{idx}**")
1192
-
1193
- # Display the actual RAG query
1194
- rag_query_expansion = entry.get("rag_query_expansion", "No query available")
1195
- st.code(rag_query_expansion, language="text")
1196
-
1197
- # Display summary stats
1198
- st.json({
1199
- "conversation_length": len(entry.get("conversation_up_to", [])),
1200
- "documents_retrieved": len(entry.get("docs_retrieved", []))
1201
- })
1202
- st.markdown("---")
1203
-
1204
  # Example Questions Section
1205
  st.markdown("---")
1206
  st.markdown(
@@ -1233,56 +1258,53 @@ def main():
1233
 
1234
  st.markdown("---")
1235
 
1236
- # Questions 2 & 3: Editable examples
1237
- st.markdown("#### ✏️ Customizable Questions (Edit and use)")
1238
-
1239
- # Question 2
1240
- # st.markdown("**Question 2:**")
1241
- custom_q1 = st.text_area(
1242
- "Edit question 2:",
1243
- value=st.session_state.custom_question_1,
1244
- height=80,
1245
- key="edit_question_2",
1246
- help="Modify this question to fit your needs, then click 'Use This Question'"
1247
- )
1248
- col1, col2 = st.columns([1, 4])
1249
- with col1:
1250
- if st.button("πŸ“‹ Use Question 2", key="use_custom_1", use_container_width=True):
1251
- if custom_q1.strip():
1252
- st.session_state.pending_question = custom_q1.strip()
1253
- st.session_state.custom_question_1 = custom_q1.strip()
1254
- st.session_state.input_counter = (st.session_state.get('input_counter', 0) + 1) % 1000
1255
- st.rerun()
1256
- else:
1257
- st.warning("Please enter a question first!")
1258
- with col2:
1259
- st.caption("πŸ’‘ Tip: Add specific details like dates, names, or amounts to get more precise answers")
1260
-
1261
- st.info("πŸ’‘ **Filter to apply:** Select District(s) and Year(s) sidebar panel before asking this question.")
1262
-
1263
- st.markdown("---")
1264
-
1265
- # Question 3
1266
- # st.markdown("**Question 3:**")
1267
- custom_q2 = st.text_area(
1268
- "Edit question 3:",
1269
- value=st.session_state.custom_question_2,
1270
- height=80,
1271
- key="edit_question_3",
1272
- help="Modify this question to fit your needs, then click 'Use This Question'"
1273
- )
1274
- col1, col2 = st.columns([1, 4])
1275
- with col1:
1276
- if st.button("πŸ“‹ Use Question 3", key="use_custom_2", use_container_width=True):
1277
- if custom_q2.strip():
1278
- st.session_state.pending_question = custom_q2.strip()
1279
- st.session_state.custom_question_2 = custom_q2.strip()
1280
- st.session_state.input_counter = (st.session_state.get('input_counter', 0) + 1) % 1000
1281
- st.rerun()
1282
- else:
1283
- st.warning("Please enter a question first!")
1284
- with col2:
1285
- st.caption("πŸ’‘ Tip: Use specific terms from the documents (e.g., 'PDM', 'SACCOs', 'FY 2022/23')")
1286
 
1287
 
1288
  # Store selected question for next render (handled in input section above)
 
637
  - Combine multiple filters for precise searches
638
  - Check the "Retrieved Documents" tab to see source material
639
 
640
+ #### πŸ’¬ Feedback Section
641
+
642
+ - Rate your experience (1-5 stars)
643
+ - Provide optional text feedback
644
+ - Help us improve the system
645
+ - Located at the bottom of the page
646
+
647
  #### ⚠️ Important
648
 
649
  **When finished, please close the browser window** to free up computational resources.
 
987
  st.info("No documents were retrieved for the last query.")
988
  else:
989
  st.info("No documents have been retrieved yet. Start a conversation to see retrieved documents here.")
990
+
991
+ # Display retrieval history stats
992
+ st.markdown("---")
993
+ if st.session_state.rag_retrieval_history:
994
+ st.markdown("#### πŸ“Š Retrieval History")
995
+ st.markdown(f"This conversation has **{len(st.session_state.rag_retrieval_history)}** retrieval entries.")
996
+
997
+ with st.expander(f"View {len(st.session_state.rag_retrieval_history)} retrieval entries", expanded=False):
998
+ for idx, entry in enumerate(st.session_state.rag_retrieval_history, 1):
999
+ with st.expander(f"Entry {idx}: {entry.get('rag_query_expansion', 'N/A')[:50]}...", expanded=False):
1000
+ st.markdown(f"**Query:** {entry.get('rag_query_expansion', 'N/A')}")
1001
+ st.markdown(f"**Documents Retrieved:** {len(entry.get('docs_retrieved', []))}")
1002
+
1003
+ # Show conversation up to this point
1004
+ conversation = entry.get('conversation_up_to', [])
1005
+ if conversation:
1006
+ st.markdown("**Conversation Context:**")
1007
+ for msg in conversation[-3:]: # Show last 3 messages
1008
+ role = msg.get('type', 'unknown')
1009
+ content = msg.get('content', '')[:200] + "..." if len(msg.get('content', '')) > 200 else msg.get('content', '')
1010
+ if role == 'human':
1011
+ st.markdown(f"- **You:** {content}")
1012
+ elif role == 'ai':
1013
+ st.markdown(f"- **Bot:** {content}")
1014
+
1015
+ # Show retrieved documents summary
1016
+ docs = entry.get('docs_retrieved', [])
1017
+ if docs:
1018
+ st.markdown("**Retrieved Documents:**")
1019
+ for doc_idx, doc in enumerate(docs[:5], 1): # Show first 5
1020
+ doc_meta = doc.get('metadata', {})
1021
+ filename = doc_meta.get('filename', 'Unknown')[:50]
1022
+ st.markdown(f"{doc_idx}. {filename}")
1023
+ if len(docs) > 5:
1024
+ st.markdown(f"... and {len(docs) - 5} more documents")
1025
+ else:
1026
+ st.markdown("---")
1027
+ st.info("πŸ“Š Retrieval history will appear here after you start asking questions.")
1028
 
1029
  # Feedback Dashboard Section
1030
  st.markdown("---")
 
1226
  # Scroll to conversation - this is handled by the auto-scroll at bottom
1227
  pass
1228
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1229
  # Example Questions Section
1230
  st.markdown("---")
1231
  st.markdown(
 
1258
 
1259
  st.markdown("---")
1260
 
1261
+ # Questions 2 & 3: Editable examples (collapsible, side by side)
1262
+ with st.expander("#### ✏️ Customizable Questions (Edit and use)", expanded=False):
1263
+ # Place questions side by side
1264
+ col1, col2 = st.columns(2)
1265
+
1266
+ # Question 2
1267
+ with col1:
1268
+ st.markdown("**Question 2:**")
1269
+ custom_q1 = st.text_area(
1270
+ "Edit question 2:",
1271
+ value=st.session_state.custom_question_1,
1272
+ height=100,
1273
+ key="edit_question_2",
1274
+ help="Modify this question to fit your needs, then click 'Use This Question'",
1275
+ label_visibility="collapsed"
1276
+ )
1277
+ if st.button("πŸ“‹ Use Question 2", key="use_custom_1", use_container_width=True):
1278
+ if custom_q1.strip():
1279
+ st.session_state.pending_question = custom_q1.strip()
1280
+ st.session_state.custom_question_1 = custom_q1.strip()
1281
+ st.session_state.input_counter = (st.session_state.get('input_counter', 0) + 1) % 1000
1282
+ st.rerun()
1283
+ else:
1284
+ st.warning("Please enter a question first!")
1285
+ st.caption("πŸ’‘ Tip: Add specific details like dates, names, or amounts to get more precise answers")
1286
+ st.info("πŸ’‘ **Filter to apply:** Select District(s) and Year(s) from sidebar panel")
1287
+
1288
+ # Question 3
1289
+ with col2:
1290
+ st.markdown("**Question 3:**")
1291
+ custom_q2 = st.text_area(
1292
+ "Edit question 3:",
1293
+ value=st.session_state.custom_question_2,
1294
+ height=100,
1295
+ key="edit_question_3",
1296
+ help="Modify this question to fit your needs, then click 'Use This Question'",
1297
+ label_visibility="collapsed"
1298
+ )
1299
+ if st.button("πŸ“‹ Use Question 3", key="use_custom_2", use_container_width=True):
1300
+ if custom_q2.strip():
1301
+ st.session_state.pending_question = custom_q2.strip()
1302
+ st.session_state.custom_question_2 = custom_q2.strip()
1303
+ st.session_state.input_counter = (st.session_state.get('input_counter', 0) + 1) % 1000
1304
+ st.rerun()
1305
+ else:
1306
+ st.warning("Please enter a question first!")
1307
+ st.caption("πŸ’‘ Tip: Use specific terms from the documents (e.g., 'PDM', 'SACCOs', 'FY 2022/23')")
 
 
 
1308
 
1309
 
1310
  # Store selected question for next render (handled in input section above)