Spaces:
Sleeping
Sleeping
Ara Yeroyan
commited on
Commit
Β·
ec044b4
1
Parent(s):
8729e12
collapse sample questions
Browse files
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.
|
| 1238 |
-
|
| 1239 |
-
|
| 1240 |
-
|
| 1241 |
-
|
| 1242 |
-
|
| 1243 |
-
|
| 1244 |
-
|
| 1245 |
-
|
| 1246 |
-
|
| 1247 |
-
|
| 1248 |
-
|
| 1249 |
-
|
| 1250 |
-
|
| 1251 |
-
|
| 1252 |
-
|
| 1253 |
-
|
| 1254 |
-
|
| 1255 |
-
|
| 1256 |
-
|
| 1257 |
-
|
| 1258 |
-
|
| 1259 |
-
|
| 1260 |
-
|
| 1261 |
-
|
| 1262 |
-
|
| 1263 |
-
|
| 1264 |
-
|
| 1265 |
-
|
| 1266 |
-
|
| 1267 |
-
|
| 1268 |
-
|
| 1269 |
-
|
| 1270 |
-
|
| 1271 |
-
|
| 1272 |
-
|
| 1273 |
-
|
| 1274 |
-
|
| 1275 |
-
|
| 1276 |
-
|
| 1277 |
-
|
| 1278 |
-
|
| 1279 |
-
|
| 1280 |
-
|
| 1281 |
-
|
| 1282 |
-
|
| 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)
|