Spaces:
Build error
Build error
Update app.py
Browse files
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
|
| 15 |
-
|
| 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 |
-
#
|
| 34 |
-
|
| 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 |
-
#
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
"Upload PDF documents",
|
| 43 |
-
type=['pdf'],
|
| 44 |
-
accept_multiple_files=True,
|
| 45 |
-
help="Limit 200MB per file β’ PDF"
|
| 46 |
-
)
|
| 47 |
|
| 48 |
-
#
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
for doc in uploaded_files:
|
| 66 |
-
st.write(f"β’ {doc.name}")
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
else:
|
| 72 |
-
|
|
|
|
| 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()
|