Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -451,7 +451,13 @@ def display_chat_area():
|
|
| 451 |
display_chat_interface()
|
| 452 |
|
| 453 |
def main():
|
| 454 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 455 |
|
| 456 |
# Initialize database and session state
|
| 457 |
if not initialize_database():
|
|
@@ -463,19 +469,24 @@ def main():
|
|
| 463 |
# Top bar with larger logo
|
| 464 |
col1, col2, col3 = st.columns([1.5, 4, 1])
|
| 465 |
with col1:
|
| 466 |
-
|
|
|
|
|
|
|
|
|
|
| 467 |
with col2:
|
| 468 |
st.title("SYNAPTYX - RFP Analysis Agent")
|
|
|
|
|
|
|
|
|
|
| 469 |
|
| 470 |
-
#
|
| 471 |
with st.sidebar:
|
| 472 |
# Chat Controls Section
|
| 473 |
st.title("π¬ Chat Controls")
|
| 474 |
|
| 475 |
# New Chat button
|
| 476 |
if st.button("π Start New Chat", use_container_width=True):
|
| 477 |
-
|
| 478 |
-
st.session_state.current_chat_id = None
|
| 479 |
st.rerun()
|
| 480 |
|
| 481 |
st.divider()
|
|
@@ -484,17 +495,23 @@ def main():
|
|
| 484 |
st.title("π Document Manager")
|
| 485 |
|
| 486 |
# Collection Creation Button
|
| 487 |
-
if st.button("β Create New Collection"):
|
| 488 |
st.session_state.show_collection_dialog = True
|
| 489 |
|
| 490 |
# Collection Selection
|
| 491 |
collections = get_collections(st.session_state.db_conn)
|
| 492 |
if collections:
|
| 493 |
-
|
| 494 |
"Select Collection",
|
| 495 |
-
options=["
|
| 496 |
-
key="
|
| 497 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 498 |
|
| 499 |
# Upload Section
|
| 500 |
st.header("Upload Documents")
|
|
@@ -505,39 +522,45 @@ def main():
|
|
| 505 |
help="Limit 200MB per file β’ PDF"
|
| 506 |
)
|
| 507 |
|
| 508 |
-
if uploaded_files
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
None
|
| 512 |
-
)
|
| 513 |
-
if collection_id:
|
| 514 |
-
handle_document_upload(uploaded_files, collection_id=collection_id)
|
| 515 |
|
| 516 |
# Show collection creation dialog if triggered
|
| 517 |
-
if st.session_state.
|
| 518 |
show_collection_creation_dialog()
|
| 519 |
|
| 520 |
# Main content area
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 541 |
|
| 542 |
if __name__ == "__main__":
|
| 543 |
main()
|
|
|
|
| 451 |
display_chat_interface()
|
| 452 |
|
| 453 |
def main():
|
| 454 |
+
"""Main application function."""
|
| 455 |
+
# Page configuration
|
| 456 |
+
st.set_page_config(
|
| 457 |
+
layout="wide",
|
| 458 |
+
page_title="SYNAPTYX - RFP Analysis Agent",
|
| 459 |
+
initial_sidebar_state="expanded"
|
| 460 |
+
)
|
| 461 |
|
| 462 |
# Initialize database and session state
|
| 463 |
if not initialize_database():
|
|
|
|
| 469 |
# Top bar with larger logo
|
| 470 |
col1, col2, col3 = st.columns([1.5, 4, 1])
|
| 471 |
with col1:
|
| 472 |
+
if os.path.exists("img/logo.png"):
|
| 473 |
+
st.image("img/logo.png", width=200) # Increased logo size
|
| 474 |
+
else:
|
| 475 |
+
st.info("Logo not found")
|
| 476 |
with col2:
|
| 477 |
st.title("SYNAPTYX - RFP Analysis Agent")
|
| 478 |
+
with col3:
|
| 479 |
+
if st.session_state.current_collection:
|
| 480 |
+
st.info(f"π Active Collection: {st.session_state.current_collection['name']}")
|
| 481 |
|
| 482 |
+
# Sidebar
|
| 483 |
with st.sidebar:
|
| 484 |
# Chat Controls Section
|
| 485 |
st.title("π¬ Chat Controls")
|
| 486 |
|
| 487 |
# New Chat button
|
| 488 |
if st.button("π Start New Chat", use_container_width=True):
|
| 489 |
+
reset_chat_state()
|
|
|
|
| 490 |
st.rerun()
|
| 491 |
|
| 492 |
st.divider()
|
|
|
|
| 495 |
st.title("π Document Manager")
|
| 496 |
|
| 497 |
# Collection Creation Button
|
| 498 |
+
if st.button("β Create New Collection", use_container_width=True):
|
| 499 |
st.session_state.show_collection_dialog = True
|
| 500 |
|
| 501 |
# Collection Selection
|
| 502 |
collections = get_collections(st.session_state.db_conn)
|
| 503 |
if collections:
|
| 504 |
+
selected = st.selectbox(
|
| 505 |
"Select Collection",
|
| 506 |
+
options=["All Documents"] + [c['name'] for c in collections],
|
| 507 |
+
key="collection_select"
|
| 508 |
)
|
| 509 |
+
|
| 510 |
+
if selected != "All Documents":
|
| 511 |
+
collection = next((c for c in collections if c['name'] == selected), None)
|
| 512 |
+
if collection:
|
| 513 |
+
st.session_state.current_collection = collection
|
| 514 |
+
display_collection_documents(collection['id'])
|
| 515 |
|
| 516 |
# Upload Section
|
| 517 |
st.header("Upload Documents")
|
|
|
|
| 522 |
help="Limit 200MB per file β’ PDF"
|
| 523 |
)
|
| 524 |
|
| 525 |
+
if uploaded_files:
|
| 526 |
+
handle_document_upload(uploaded_files,
|
| 527 |
+
collection_id=st.session_state.current_collection.get('id') if st.session_state.current_collection else None)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 528 |
|
| 529 |
# Show collection creation dialog if triggered
|
| 530 |
+
if st.session_state.show_collection_dialog:
|
| 531 |
show_collection_creation_dialog()
|
| 532 |
|
| 533 |
# Main content area
|
| 534 |
+
if st.session_state.chat_ready:
|
| 535 |
+
display_chat_interface()
|
| 536 |
+
else:
|
| 537 |
+
display_welcome_screen()
|
| 538 |
+
|
| 539 |
+
# Debug mode (if enabled)
|
| 540 |
+
if st.session_state.debug_mode and st.sidebar.checkbox("Show Debug Info"):
|
| 541 |
+
st.sidebar.write("Current State:", get_current_state())
|
| 542 |
+
|
| 543 |
+
def display_collection_documents(collection_id: int):
|
| 544 |
+
"""Display documents in the selected collection."""
|
| 545 |
+
documents = get_collection_documents(st.session_state.db_conn, collection_id)
|
| 546 |
+
if documents:
|
| 547 |
+
st.markdown("### Documents in Collection")
|
| 548 |
+
for doc in documents:
|
| 549 |
+
with st.expander(f"π {doc['name']}", expanded=False):
|
| 550 |
+
st.caption(f"Uploaded: {doc['upload_date']}")
|
| 551 |
+
col1, col2 = st.columns(2)
|
| 552 |
+
with col1:
|
| 553 |
+
if st.button("Preview", key=f"preview_{doc['id']}"):
|
| 554 |
+
st.text_area(
|
| 555 |
+
"Content Preview",
|
| 556 |
+
value=doc['content'][:500] + "..." if len(doc['content']) > 500 else doc['content'],
|
| 557 |
+
height=100,
|
| 558 |
+
disabled=True
|
| 559 |
+
)
|
| 560 |
+
with col2:
|
| 561 |
+
if st.button("Use for Chat", key=f"chat_{doc['id']}"):
|
| 562 |
+
initialize_chat_from_collection()
|
| 563 |
+
st.rerun()
|
| 564 |
|
| 565 |
if __name__ == "__main__":
|
| 566 |
main()
|