cryogenic22 commited on
Commit
25c34ad
Β·
verified Β·
1 Parent(s): c5d3be7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -62
app.py CHANGED
@@ -1,75 +1,82 @@
1
- #src/app.py
2
-
3
  import streamlit as st
4
- from utils.session_state import initialize_session_state
5
- from utils.database import (
6
- get_documents,
7
- insert_document,
8
- display_vector_store_info,
9
- handle_document_upload,
10
- create_connection,
11
- create_tables
12
- )
13
  from components.chat import display_chat_interface
14
- from components.knowledge_base import display_knowledge_base
15
- from config.settings import APP_SETTINGS
16
-
17
-
18
- def initialize_database():
19
- """Initialize database connection and tables."""
20
- if 'db_conn' not in st.session_state:
21
- # Initialize database connection
22
- conn = create_connection('rfp_analysis.db')
23
- if conn is not None:
24
- # Create tables
25
- create_tables(conn)
26
- # Store connection in session state
27
- st.session_state.db_conn = conn
28
- else:
29
- st.error("Error! Cannot create the database connection.")
30
 
 
 
 
 
 
 
 
 
 
31
 
32
  def main():
33
- # Initialize database connection
34
- initialize_database()
35
-
36
- st.title("πŸ€– SYNAPTYX - RFP Analysis Agent")
37
- st.markdown("Upload RFP documents, analyze requirements, and get intelligent answers powered by AI.")
38
 
39
- # Document Upload Section
40
- st.header("πŸ“„ Upload Documents", anchor=False)
41
- uploaded_files = st.file_uploader(
42
- "Upload PDF documents",
43
- type=['pdf'],
44
- accept_multiple_files=True,
45
- help="Limit 200MB per file β€’ PDF"
46
- )
47
 
48
- # Handle document upload when files are uploaded
49
- if uploaded_files:
50
- # Only process if files haven't been processed yet
51
- if 'processed_files' not in st.session_state or uploaded_files != st.session_state.processed_files:
52
- handle_document_upload(uploaded_files)
53
- # Store the processed files to avoid reprocessing
54
- st.session_state.processed_files = uploaded_files
 
 
 
 
 
55
 
56
- # Knowledge Base Section
57
- st.header("πŸ“š Knowledge Base", anchor=False)
58
-
59
- # Display vector store information
60
- display_vector_store_info()
61
-
62
- # Display available documents if any are uploaded
63
- if uploaded_files:
64
- st.subheader("Available Documents")
65
- for doc in uploaded_files:
66
- st.write(f"β€’ {doc.name}")
67
 
68
- # Chat Interface
69
- if st.session_state.get('vector_store'):
70
- display_chat_interface()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  else:
72
- st.info("πŸ“ Please upload documents first.")
 
73
 
74
  if __name__ == "__main__":
75
  main()
 
 
 
1
  import streamlit as st
 
 
 
 
 
 
 
 
 
2
  from components.chat import display_chat_interface
3
+ from utils.database import display_vector_store_info, handle_document_upload
4
+ import time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
+ def display_example_questions():
7
+ examples = [
8
+ "πŸ“Š Summarize the main points of the document",
9
+ "πŸ“ Draft a 'Why Us' section based on the document",
10
+ "🎯 Extract key success metrics and outcomes",
11
+ "πŸ’‘ What are the innovative solutions mentioned?",
12
+ "🀝 Analyze the partnership benefits described"
13
+ ]
14
+ return examples
15
 
16
  def main():
17
+ # Set up the page configuration
18
+ st.set_page_config(layout="wide", page_title="SYNAPTYX - RFP Analysis Agent")
 
 
 
19
 
20
+ # Initialize session state for UI control
21
+ if 'chat_ready' not in st.session_state:
22
+ st.session_state.chat_ready = False
 
 
 
 
 
23
 
24
+ # Sidebar for document management
25
+ with st.sidebar:
26
+ st.title("πŸ“š Document Manager")
27
+
28
+ # Upload Section
29
+ st.header("Upload Documents", anchor=False)
30
+ uploaded_files = st.file_uploader(
31
+ "Upload PDF documents",
32
+ type=['pdf'],
33
+ accept_multiple_files=True,
34
+ help="Limit 200MB per file β€’ PDF"
35
+ )
36
 
37
+ # Process uploads
38
+ if uploaded_files:
39
+ if 'processed_files' not in st.session_state or uploaded_files != st.session_state.processed_files:
40
+ with st.spinner("Processing documents..."):
41
+ handle_document_upload(uploaded_files)
42
+ st.session_state.processed_files = uploaded_files
43
+ st.session_state.chat_ready = True
44
+ time.sleep(1)
45
+ st.rerun()
 
 
46
 
47
+ # Knowledge Base Status
48
+ if st.session_state.get('vector_store'):
49
+ st.success("βœ… Documents ready for analysis")
50
+ display_vector_store_info()
51
+
52
+ # Document List
53
+ if uploaded_files:
54
+ st.subheader("πŸ“‘ Uploaded Documents")
55
+ for doc in uploaded_files:
56
+ st.write(f"β€’ {doc.name}")
57
+
58
+ # Main chat area
59
+ if not st.session_state.chat_ready:
60
+ # Welcome screen
61
+ st.title("πŸ€– SYNAPTYX - RFP Analysis Agent")
62
+ st.markdown("### Welcome to your AI-powered RFP analysis assistant!")
63
+
64
+ col1, col2 = st.columns(2)
65
+ with col1:
66
+ st.markdown("""
67
+ #### Getting Started:
68
+ 1. Upload your RFP documents using the sidebar
69
+ 2. Wait for the processing to complete
70
+ 3. Start chatting with your documents!
71
+ """)
72
+
73
+ with col2:
74
+ st.markdown("#### Example Questions:")
75
+ for example in display_example_questions():
76
+ st.markdown(f"β€’ {example}")
77
  else:
78
+ # Clean chat interface
79
+ display_chat_interface()
80
 
81
  if __name__ == "__main__":
82
  main()