Update app.py
Browse files
app.py
CHANGED
|
@@ -243,6 +243,33 @@ def display_collections_tab():
|
|
| 243 |
if st.session_state.get('selected_collection'):
|
| 244 |
display_collection_details(st.session_state.selected_collection)
|
| 245 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
def display_collection_details(collection):
|
| 247 |
"""Display details and documents for a selected collection."""
|
| 248 |
st.header(collection['name'])
|
|
@@ -396,8 +423,63 @@ def get_response_with_sources(prompt, qa_system):
|
|
| 396 |
|
| 397 |
return list(sources), response.content
|
| 398 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 399 |
def main():
|
| 400 |
-
st.set_page_config(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 401 |
|
| 402 |
if not initialize_database():
|
| 403 |
st.error("Failed to initialize database. Please contact support.")
|
|
@@ -406,16 +488,23 @@ def main():
|
|
| 406 |
initialize_session_state()
|
| 407 |
display_top_bar()
|
| 408 |
|
| 409 |
-
# Main
|
| 410 |
tab1, tab2, tab3 = st.tabs(["Chat", "Collections", "Documents"])
|
| 411 |
-
|
| 412 |
with tab1:
|
| 413 |
display_chat_interface_with_sources()
|
| 414 |
|
| 415 |
with tab2:
|
| 416 |
-
|
| 417 |
|
| 418 |
with tab3:
|
| 419 |
display_documents_tab()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 420 |
if __name__ == "__main__":
|
| 421 |
-
main()
|
|
|
|
| 243 |
if st.session_state.get('selected_collection'):
|
| 244 |
display_collection_details(st.session_state.selected_collection)
|
| 245 |
|
| 246 |
+
def show_collection_dialog():
|
| 247 |
+
"""Show dialog for creating/editing collections."""
|
| 248 |
+
with st.sidebar:
|
| 249 |
+
st.header("Collection Details")
|
| 250 |
+
|
| 251 |
+
name = st.text_input("Collection Name")
|
| 252 |
+
description = st.text_area("Description")
|
| 253 |
+
|
| 254 |
+
col1, col2 = st.columns(2)
|
| 255 |
+
with col1:
|
| 256 |
+
if st.button("Save", type="primary"):
|
| 257 |
+
if name:
|
| 258 |
+
create_collection(
|
| 259 |
+
st.session_state.db_conn,
|
| 260 |
+
name,
|
| 261 |
+
description
|
| 262 |
+
)
|
| 263 |
+
st.session_state.show_collection_dialog = False
|
| 264 |
+
st.rerun()
|
| 265 |
+
else:
|
| 266 |
+
st.error("Please enter a collection name")
|
| 267 |
+
|
| 268 |
+
with col2:
|
| 269 |
+
if st.button("Cancel"):
|
| 270 |
+
st.session_state.show_collection_dialog = False
|
| 271 |
+
st.rerun()
|
| 272 |
+
|
| 273 |
def display_collection_details(collection):
|
| 274 |
"""Display details and documents for a selected collection."""
|
| 275 |
st.header(collection['name'])
|
|
|
|
| 423 |
|
| 424 |
return list(sources), response.content
|
| 425 |
|
| 426 |
+
def display_documents_tab():
|
| 427 |
+
"""Enhanced documents tab with search and preview."""
|
| 428 |
+
st.header("Document Library")
|
| 429 |
+
|
| 430 |
+
# Search and filter section
|
| 431 |
+
col1, col2, col3 = st.columns([2, 1, 1])
|
| 432 |
+
with col1:
|
| 433 |
+
search_query = st.text_input("🔍 Search documents")
|
| 434 |
+
with col2:
|
| 435 |
+
date_filter = st.date_input("Date Filter")
|
| 436 |
+
with col3:
|
| 437 |
+
sort_by = st.selectbox("Sort By", ["Name", "Date", "Size"])
|
| 438 |
+
|
| 439 |
+
# Advanced filters
|
| 440 |
+
with st.expander("Advanced Filters"):
|
| 441 |
+
filter_cols = st.columns(3)
|
| 442 |
+
with filter_cols[0]:
|
| 443 |
+
collections_filter = st.multiselect(
|
| 444 |
+
"Collections",
|
| 445 |
+
options=[c['name'] for c in get_collections(st.session_state.db_conn)]
|
| 446 |
+
)
|
| 447 |
+
with filter_cols[1]:
|
| 448 |
+
date_range = st.date_input("Date Range", value=())
|
| 449 |
+
with filter_cols[2]:
|
| 450 |
+
st.checkbox("Show only uncategorized")
|
| 451 |
+
|
| 452 |
+
# Build filters dictionary
|
| 453 |
+
filters = {
|
| 454 |
+
'collections': collections_filter,
|
| 455 |
+
'date_range': date_range if len(date_range) == 2 else None
|
| 456 |
+
}
|
| 457 |
+
|
| 458 |
+
# Get and display documents
|
| 459 |
+
if search_query:
|
| 460 |
+
documents = search_documents(
|
| 461 |
+
st.session_state.db_conn,
|
| 462 |
+
search_query,
|
| 463 |
+
filters=filters
|
| 464 |
+
)
|
| 465 |
+
if documents:
|
| 466 |
+
st.success(f"Found {len(documents)} matching documents")
|
| 467 |
+
else:
|
| 468 |
+
st.info("No documents found matching your search")
|
| 469 |
+
else:
|
| 470 |
+
documents = get_all_documents(st.session_state.db_conn)
|
| 471 |
+
|
| 472 |
+
# Display documents
|
| 473 |
+
for doc in documents:
|
| 474 |
+
with st.expander(f"📄 {doc['name']}", expanded=False):
|
| 475 |
+
enhanced_document_preview(doc)
|
| 476 |
+
|
| 477 |
def main():
|
| 478 |
+
st.set_page_config(
|
| 479 |
+
layout="wide",
|
| 480 |
+
page_title="SYNAPTYX - RFP Analysis Agent",
|
| 481 |
+
initial_sidebar_state="expanded"
|
| 482 |
+
)
|
| 483 |
|
| 484 |
if not initialize_database():
|
| 485 |
st.error("Failed to initialize database. Please contact support.")
|
|
|
|
| 488 |
initialize_session_state()
|
| 489 |
display_top_bar()
|
| 490 |
|
| 491 |
+
# Main tabs
|
| 492 |
tab1, tab2, tab3 = st.tabs(["Chat", "Collections", "Documents"])
|
| 493 |
+
|
| 494 |
with tab1:
|
| 495 |
display_chat_interface_with_sources()
|
| 496 |
|
| 497 |
with tab2:
|
| 498 |
+
display_enhanced_collections()
|
| 499 |
|
| 500 |
with tab3:
|
| 501 |
display_documents_tab()
|
| 502 |
+
|
| 503 |
+
# Handle collection dialog if needed
|
| 504 |
+
if st.session_state.get('show_collection_dialog'):
|
| 505 |
+
show_collection_dialog()
|
| 506 |
+
|
| 507 |
+
|
| 508 |
+
|
| 509 |
if __name__ == "__main__":
|
| 510 |
+
main()
|