Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,14 +2,14 @@
|
|
| 2 |
|
| 3 |
import streamlit as st
|
| 4 |
import os
|
| 5 |
-
import sqlite3
|
| 6 |
from pathlib import Path
|
| 7 |
from components.chat import display_chat_interface
|
| 8 |
from utils.database import (
|
| 9 |
-
display_vector_store_info,
|
| 10 |
handle_document_upload,
|
| 11 |
create_connection,
|
| 12 |
-
create_tables
|
|
|
|
| 13 |
)
|
| 14 |
import time
|
| 15 |
from threading import Lock
|
|
@@ -19,88 +19,28 @@ conn_lock = Lock()
|
|
| 19 |
|
| 20 |
def initialize_database():
|
| 21 |
"""Initialize database connection and tables."""
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
if 'db_conn' not in st.session_state:
|
| 25 |
-
data_dir = "data"
|
| 26 |
-
if not os.path.exists(data_dir):
|
| 27 |
-
os.makedirs(data_dir)
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
try:
|
| 32 |
-
with open(db_path, 'a') as f:
|
| 33 |
-
pass
|
| 34 |
-
except IOError as e:
|
| 35 |
-
return False
|
| 36 |
-
|
| 37 |
-
conn = create_connection(db_path)
|
| 38 |
-
|
| 39 |
-
if conn is not None:
|
| 40 |
-
create_tables(conn)
|
| 41 |
-
st.session_state.db_conn = conn
|
| 42 |
-
return True
|
| 43 |
-
else:
|
| 44 |
-
return False
|
| 45 |
-
else:
|
| 46 |
-
return True
|
| 47 |
-
|
| 48 |
-
except Exception:
|
| 49 |
-
return False
|
| 50 |
-
|
| 51 |
-
def display_header():
|
| 52 |
-
"""Display application header with logo."""
|
| 53 |
-
header_col1, header_col2 = st.columns([1, 4])
|
| 54 |
-
|
| 55 |
-
with header_col1:
|
| 56 |
-
if os.path.exists("img/logo.png"):
|
| 57 |
-
st.image("img/logo.png", width=100)
|
| 58 |
-
else:
|
| 59 |
-
st.error("Logo not found at img/logo.png")
|
| 60 |
-
|
| 61 |
-
with header_col2:
|
| 62 |
-
st.title("Synaptyx.AI - RFP Analysis Agent")
|
| 63 |
-
|
| 64 |
-
def display_example_questions():
|
| 65 |
-
examples = [
|
| 66 |
-
"π Summarize the main points of the document",
|
| 67 |
-
"π Draft a 'Why Us' section based on the document",
|
| 68 |
-
"π― Extract key success metrics and outcomes",
|
| 69 |
-
"π‘ What are the innovative solutions mentioned?",
|
| 70 |
-
"π€ Analyze the partnership benefits described"
|
| 71 |
-
]
|
| 72 |
-
return examples
|
| 73 |
-
|
| 74 |
-
def main():
|
| 75 |
-
# Set up the page configuration
|
| 76 |
-
st.set_page_config(layout="wide", page_title="SYNAPTYX - RFP Analysis Agent")
|
| 77 |
-
|
| 78 |
-
# Custom CSS for logo positioning
|
| 79 |
-
st.markdown("""
|
| 80 |
-
<style>
|
| 81 |
-
[data-testid="stSidebarNav"] {
|
| 82 |
-
background-image: url('img/logo.png');
|
| 83 |
-
background-repeat: no-repeat;
|
| 84 |
-
background-position: 20px 20px;
|
| 85 |
-
background-size: 150px auto;
|
| 86 |
-
padding-top: 120px;
|
| 87 |
-
}
|
| 88 |
-
</style>
|
| 89 |
-
""", unsafe_allow_html=True)
|
| 90 |
-
|
| 91 |
-
# Initialize database silently
|
| 92 |
-
if not initialize_database():
|
| 93 |
-
st.error("Failed to initialize database. Please contact support.")
|
| 94 |
-
return
|
| 95 |
-
|
| 96 |
-
# Initialize session state for UI control
|
| 97 |
-
if 'chat_ready' not in st.session_state:
|
| 98 |
-
st.session_state.chat_ready = False
|
| 99 |
-
|
| 100 |
-
# Sidebar for document management
|
| 101 |
with st.sidebar:
|
| 102 |
st.title("π Document Manager")
|
| 103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
# Upload Section
|
| 105 |
st.header("Upload Documents", anchor=False)
|
| 106 |
uploaded_files = st.file_uploader(
|
|
@@ -114,7 +54,15 @@ def main():
|
|
| 114 |
if uploaded_files:
|
| 115 |
if 'processed_files' not in st.session_state or uploaded_files != st.session_state.processed_files:
|
| 116 |
with st.spinner("Processing documents..."):
|
| 117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
st.session_state.processed_files = uploaded_files
|
| 119 |
st.session_state.chat_ready = True
|
| 120 |
time.sleep(1)
|
|
@@ -131,28 +79,86 @@ def main():
|
|
| 131 |
for doc in uploaded_files:
|
| 132 |
st.write(f"β’ {doc.name}")
|
| 133 |
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
st.
|
| 138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
st.markdown("""
|
| 143 |
-
#### Getting Started:
|
| 144 |
-
1. Upload your RFP documents using the sidebar
|
| 145 |
-
2. Wait for the processing to complete
|
| 146 |
-
3. Start chatting with your documents!
|
| 147 |
-
""")
|
| 148 |
|
| 149 |
-
with
|
| 150 |
-
st.
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
|
| 157 |
if __name__ == "__main__":
|
| 158 |
-
main()
|
|
|
|
| 2 |
|
| 3 |
import streamlit as st
|
| 4 |
import os
|
|
|
|
| 5 |
from pathlib import Path
|
| 6 |
from components.chat import display_chat_interface
|
| 7 |
from utils.database import (
|
| 8 |
+
display_vector_store_info,
|
| 9 |
handle_document_upload,
|
| 10 |
create_connection,
|
| 11 |
+
create_tables,
|
| 12 |
+
get_collections
|
| 13 |
)
|
| 14 |
import time
|
| 15 |
from threading import Lock
|
|
|
|
| 19 |
|
| 20 |
def initialize_database():
|
| 21 |
"""Initialize database connection and tables."""
|
| 22 |
+
# [Previous initialize_database code remains the same]
|
| 23 |
+
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
+
def display_sidebar():
|
| 26 |
+
"""Display the document management sidebar."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
with st.sidebar:
|
| 28 |
st.title("π Document Manager")
|
| 29 |
|
| 30 |
+
# Collection selector
|
| 31 |
+
st.subheader("Select Collection")
|
| 32 |
+
collections = get_collections()
|
| 33 |
+
collection_names = ["All Documents"] + [c['name'] for c in collections]
|
| 34 |
+
selected_collection = st.selectbox(
|
| 35 |
+
"Working Collection",
|
| 36 |
+
collection_names,
|
| 37 |
+
index=0,
|
| 38 |
+
key="collection_selector"
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
# Update session state
|
| 42 |
+
st.session_state.current_collection = selected_collection if selected_collection != "All Documents" else None
|
| 43 |
+
|
| 44 |
# Upload Section
|
| 45 |
st.header("Upload Documents", anchor=False)
|
| 46 |
uploaded_files = st.file_uploader(
|
|
|
|
| 54 |
if uploaded_files:
|
| 55 |
if 'processed_files' not in st.session_state or uploaded_files != st.session_state.processed_files:
|
| 56 |
with st.spinner("Processing documents..."):
|
| 57 |
+
# Get collection ID if a collection is selected
|
| 58 |
+
collection_id = None
|
| 59 |
+
if st.session_state.current_collection:
|
| 60 |
+
collection_id = next(
|
| 61 |
+
(c['id'] for c in collections if c['name'] == st.session_state.current_collection),
|
| 62 |
+
None
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
handle_document_upload(uploaded_files, collection_id)
|
| 66 |
st.session_state.processed_files = uploaded_files
|
| 67 |
st.session_state.chat_ready = True
|
| 68 |
time.sleep(1)
|
|
|
|
| 79 |
for doc in uploaded_files:
|
| 80 |
st.write(f"β’ {doc.name}")
|
| 81 |
|
| 82 |
+
def display_top_navigation():
|
| 83 |
+
"""Display the top navigation bar."""
|
| 84 |
+
with st.container():
|
| 85 |
+
cols = st.columns([1, 3, 1])
|
| 86 |
+
with cols[0]:
|
| 87 |
+
if os.path.exists("img/logo.png"):
|
| 88 |
+
st.image("img/logo.png", width=100)
|
| 89 |
+
else:
|
| 90 |
+
st.error("Logo not found")
|
| 91 |
|
| 92 |
+
with cols[1]:
|
| 93 |
+
st.title("Synaptyx.AI - RFP Analysis Agent")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
+
with cols[2]:
|
| 96 |
+
if st.session_state.get('current_collection'):
|
| 97 |
+
st.write(f"π Collection: {st.session_state.current_collection}")
|
| 98 |
+
|
| 99 |
+
def display_welcome_screen():
|
| 100 |
+
"""Display the welcome screen for new users."""
|
| 101 |
+
st.title("π€ SYNAPTYX - RFP Analysis Agent")
|
| 102 |
+
st.markdown("### Welcome to your AI-powered RFP analysis assistant!")
|
| 103 |
+
|
| 104 |
+
col1, col2 = st.columns(2)
|
| 105 |
+
with col1:
|
| 106 |
+
st.markdown("""
|
| 107 |
+
#### Getting Started:
|
| 108 |
+
1. Upload your RFP documents using the sidebar
|
| 109 |
+
2. Wait for the processing to complete
|
| 110 |
+
3. Start chatting with your documents!
|
| 111 |
+
""")
|
| 112 |
+
|
| 113 |
+
with col2:
|
| 114 |
+
st.markdown("#### Example Questions:")
|
| 115 |
+
examples = [
|
| 116 |
+
"π Summarize the main points of the document",
|
| 117 |
+
"π Draft a 'Why Us' section based on the document",
|
| 118 |
+
"π― Extract key success metrics and outcomes",
|
| 119 |
+
"π‘ What are the innovative solutions mentioned?",
|
| 120 |
+
"π€ Analyze the partnership benefits described"
|
| 121 |
+
]
|
| 122 |
+
for example in examples:
|
| 123 |
+
st.markdown(f"β’ {example}")
|
| 124 |
+
|
| 125 |
+
def main():
|
| 126 |
+
# Set up the page configuration
|
| 127 |
+
st.set_page_config(
|
| 128 |
+
layout="wide",
|
| 129 |
+
page_title="SYNAPTYX - RFP Analysis Agent",
|
| 130 |
+
initial_sidebar_state="expanded"
|
| 131 |
+
)
|
| 132 |
+
|
| 133 |
+
# Initialize database
|
| 134 |
+
if not initialize_database():
|
| 135 |
+
st.error("Failed to initialize database. Please contact support.")
|
| 136 |
+
return
|
| 137 |
+
|
| 138 |
+
# Initialize session state
|
| 139 |
+
if 'chat_ready' not in st.session_state:
|
| 140 |
+
st.session_state.chat_ready = False
|
| 141 |
+
if 'current_collection' not in st.session_state:
|
| 142 |
+
st.session_state.current_collection = None
|
| 143 |
+
|
| 144 |
+
# Display sidebar (maintain existing functionality)
|
| 145 |
+
display_sidebar()
|
| 146 |
+
|
| 147 |
+
# Main content area
|
| 148 |
+
display_top_navigation()
|
| 149 |
+
|
| 150 |
+
# Tabs for different sections
|
| 151 |
+
tab1, tab2 = st.tabs(["Chat", "Document Store"])
|
| 152 |
+
|
| 153 |
+
with tab1:
|
| 154 |
+
if not st.session_state.chat_ready:
|
| 155 |
+
display_welcome_screen()
|
| 156 |
+
else:
|
| 157 |
+
display_chat_interface()
|
| 158 |
+
|
| 159 |
+
with tab2:
|
| 160 |
+
from pages.document_store import display_document_store
|
| 161 |
+
display_document_store()
|
| 162 |
|
| 163 |
if __name__ == "__main__":
|
| 164 |
+
main()
|