cryogenic22 commited on
Commit
ed40d54
Β·
verified Β·
1 Parent(s): 60ad641

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -37
app.py CHANGED
@@ -451,7 +451,13 @@ def display_chat_area():
451
  display_chat_interface()
452
 
453
  def main():
454
- st.set_page_config(layout="wide", page_title="SYNAPTYX - RFP Analysis Agent")
 
 
 
 
 
 
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
- st.image("img/logo.png", width=200) # Increased logo size
 
 
 
467
  with col2:
468
  st.title("SYNAPTYX - RFP Analysis Agent")
 
 
 
469
 
470
- # Single sidebar implementation
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
- st.session_state.messages = []
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
- upload_to = st.selectbox(
494
  "Select Collection",
495
- options=["Select Collection..."] + [c['name'] for c in collections],
496
- key="upload_destination"
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 and upload_to != "Select Collection...":
509
- collection_id = next(
510
- (c['id'] for c in collections if c['name'] == upload_to),
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.get('show_collection_dialog', False):
518
  show_collection_creation_dialog()
519
 
520
  # Main content area
521
- tab1, tab2 = st.tabs(["Chat", "Collections"])
522
-
523
- with tab1:
524
- # Initialize chat if documents exist
525
- if not st.session_state.chat_ready:
526
- initialize_chat_from_collection()
527
-
528
- if st.session_state.chat_ready:
529
- display_chat_interface()
530
- else:
531
- display_welcome_screen()
532
-
533
- with tab2:
534
- from components.collection_manager import display_enhanced_collections
535
- display_enhanced_collections()
536
-
537
- # After collection operations, check if we need to reinitialize chat
538
- if st.session_state.get('reinitialize_chat'):
539
- initialize_chat_from_collection()
540
- st.session_state.reinitialize_chat = False
 
 
 
 
 
 
 
 
 
 
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()