cryogenic22 commited on
Commit
67f2631
Β·
verified Β·
1 Parent(s): 46c7a83

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +81 -6
app.py CHANGED
@@ -6,7 +6,6 @@ from pathlib import Path
6
  from typing import Dict, List, Optional, Any
7
  from datetime import datetime
8
  from threading import Lock
9
- from typing import Dict, Any, Optional
10
  from dataclasses import dataclass
11
  from langchain.text_splitter import RecursiveCharacterTextSplitter
12
  from langchain.vectorstores import FAISS
@@ -307,8 +306,8 @@ def initialize_chat_from_collection():
307
  if documents:
308
  embeddings = get_embeddings_model()
309
  text_splitter = RecursiveCharacterTextSplitter(
310
- chunk_size=1000,
311
- chunk_overlap=200,
312
  length_function=len,
313
  separators=["\n\n", "\n", " ", ""]
314
  )
@@ -403,10 +402,14 @@ def display_collection_dialog():
403
  st.rerun()
404
 
405
  def display_welcome_screen():
406
- """Display the welcome screen with getting started information."""
407
  st.title("πŸ€– Welcome to SYNAPTYX")
408
  st.markdown("### Your AI-powered RFP Analysis Assistant")
409
 
 
 
 
 
410
  col1, col2 = st.columns(2)
411
  with col1:
412
  st.markdown("""
@@ -421,6 +424,20 @@ def display_welcome_screen():
421
  - Search across all documents
422
  - Get AI-powered insights and summaries
423
  """)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
424
 
425
  with col2:
426
  st.markdown("#### Example Questions:")
@@ -435,13 +452,71 @@ def display_welcome_screen():
435
  ]
436
  for example in examples:
437
  st.markdown(f"β€’ {example}")
 
 
 
 
 
 
 
 
 
 
 
 
 
438
 
439
  def display_chat_area():
440
- """Display the main chat interface or welcome screen."""
441
  if not st.session_state.chat_ready:
442
  display_welcome_screen()
443
  else:
444
- display_chat_interface()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
445
 
446
  def main():
447
  """Main application function."""
 
6
  from typing import Dict, List, Optional, Any
7
  from datetime import datetime
8
  from threading import Lock
 
9
  from dataclasses import dataclass
10
  from langchain.text_splitter import RecursiveCharacterTextSplitter
11
  from langchain.vectorstores import FAISS
 
306
  if documents:
307
  embeddings = get_embeddings_model()
308
  text_splitter = RecursiveCharacterTextSplitter(
309
+ chunk_size=700,
310
+ chunk_overlap=100,
311
  length_function=len,
312
  separators=["\n\n", "\n", " ", ""]
313
  )
 
402
  st.rerun()
403
 
404
  def display_welcome_screen():
405
+ """Display the welcome screen with getting started information and enhanced features."""
406
  st.title("πŸ€– Welcome to SYNAPTYX")
407
  st.markdown("### Your AI-powered RFP Analysis Assistant")
408
 
409
+ # Check for existing documents
410
+ documents = get_all_documents(st.session_state.db_conn)
411
+ collections = get_collections(st.session_state.db_conn)
412
+
413
  col1, col2 = st.columns(2)
414
  with col1:
415
  st.markdown("""
 
424
  - Search across all documents
425
  - Get AI-powered insights and summaries
426
  """)
427
+
428
+ # Add action buttons if documents exist
429
+ if documents:
430
+ st.success(f"πŸŽ‰ You have {len(documents)} documents ready for analysis!")
431
+ col_a, col_b = st.columns(2)
432
+ with col_a:
433
+ if st.button("Start Chatting", use_container_width=True):
434
+ if initialize_chat_from_collection():
435
+ st.session_state.chat_ready = True
436
+ st.rerun()
437
+ with col_b:
438
+ if st.button("View Documents", use_container_width=True):
439
+ st.session_state.show_document_store = True
440
+ st.rerun()
441
 
442
  with col2:
443
  st.markdown("#### Example Questions:")
 
452
  ]
453
  for example in examples:
454
  st.markdown(f"β€’ {example}")
455
+
456
+ # Add collection stats if they exist
457
+ if collections:
458
+ st.markdown("---")
459
+ st.markdown("#### Your Collections:")
460
+ for collection in collections[:3]: # Show top 3 collections
461
+ with st.container():
462
+ st.markdown(f"""
463
+ πŸ—‚οΈ **{collection['name']}**
464
+ Documents: {collection['doc_count']}
465
+ """)
466
+ if len(collections) > 3:
467
+ st.caption("... and more collections")
468
 
469
  def display_chat_area():
470
+ """Display the main chat interface or welcome screen with proper state management."""
471
  if not st.session_state.chat_ready:
472
  display_welcome_screen()
473
  else:
474
+ col1, col2 = st.columns([3, 1])
475
+ with col1:
476
+ display_chat_interface()
477
+ with col2:
478
+ # Document context panel
479
+ st.markdown("### Current Context")
480
+ if st.session_state.current_collection:
481
+ st.info(f"πŸ“ Using Collection: {st.session_state.current_collection['name']}")
482
+ else:
483
+ st.info("πŸ“š Using All Documents")
484
+
485
+ # Quick actions
486
+ st.markdown("### Quick Actions")
487
+ if st.button("πŸ”„ New Chat", use_container_width=True):
488
+ reset_chat_state()
489
+ st.rerun()
490
+ if st.button("πŸ“‹ Export Chat", use_container_width=True):
491
+ export_chat_history()
492
+
493
+ # Example questions for quick reference
494
+ with st.expander("πŸ’‘ Question Examples", expanded=False):
495
+ examples = [
496
+ "Summarize main points",
497
+ "Extract requirements",
498
+ "Compare solutions",
499
+ "Analyze pricing"
500
+ ]
501
+ for example in examples:
502
+ if st.button(example, key=f"example_{example}"):
503
+ # Set the example as the current question
504
+ st.session_state.current_question = example
505
+ st.rerun()
506
+
507
+ def export_chat_history():
508
+ """Export current chat history."""
509
+ if st.session_state.messages:
510
+ chat_text = "\n\n".join([
511
+ f"{'User' if isinstance(m, HumanMessage) else 'Assistant'}: {m.content}"
512
+ for m in st.session_state.messages
513
+ ])
514
+ st.download_button(
515
+ "Download Chat History",
516
+ chat_text,
517
+ file_name=f"chat_export_{datetime.now().strftime('%Y%m%d_%H%M%S')}.txt",
518
+ mime="text/plain"
519
+ )
520
 
521
  def main():
522
  """Main application function."""