cryogenic22 commited on
Commit
e1b81dc
·
verified ·
1 Parent(s): 2fef366

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -11
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 components.styled_response import display_styled_chat_message
10
 
11
  from utils.database import (
12
  # Base database operations
@@ -142,11 +141,52 @@ def display_top_bar():
142
  if st.session_state.current_collection:
143
  st.info(f"📁 Active Collection: {st.session_state.current_collection['name']}")
144
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145
  def display_collection_sidebar():
146
- """Display the collection management sidebar."""
147
  with st.sidebar:
148
  st.title("📚 Document Manager")
149
 
 
 
 
 
 
 
 
 
 
150
  # Collection Selection
151
  st.header("Collections")
152
  collections = get_collections(st.session_state.db_conn)
@@ -173,15 +213,6 @@ def display_collection_sidebar():
173
  else:
174
  st.session_state.current_collection = None
175
 
176
- # Upload Section
177
- st.header("Upload Documents")
178
- uploaded_files = st.file_uploader(
179
- "Upload PDF documents",
180
- type=['pdf'],
181
- accept_multiple_files=True,
182
- help="Limit 200MB per file • PDF"
183
- )
184
-
185
  # Process uploads automatically when files are selected
186
  if uploaded_files:
187
  if 'processed_files' not in st.session_state or uploaded_files != st.session_state.processed_files:
@@ -291,6 +322,8 @@ def main():
291
  return
292
 
293
  initialize_session_state()
 
 
294
  display_top_bar()
295
 
296
  # Main content area with tabs
 
6
  from typing import Dict, List, Optional, Any
7
  from datetime import datetime
8
  from threading import Lock
 
9
 
10
  from utils.database import (
11
  # Base database operations
 
141
  if st.session_state.current_collection:
142
  st.info(f"📁 Active Collection: {st.session_state.current_collection['name']}")
143
 
144
+ def display_chat_interface():
145
+ """Display the chat interface with formatted responses."""
146
+ # Initialize chat history if needed
147
+ if "messages" not in st.session_state:
148
+ st.session_state.messages = []
149
+
150
+ # Display chat history
151
+ for message in st.session_state.messages:
152
+ is_user = isinstance(message, HumanMessage)
153
+ display_styled_chat_message(message, is_user=is_user)
154
+
155
+ # Chat input
156
+ if prompt := st.chat_input("Ask about your documents..."):
157
+ # Add user message
158
+ st.session_state.messages.append(HumanMessage(content=prompt))
159
+ display_styled_chat_message(prompt, is_user=True)
160
+
161
+ with st.spinner("Thinking..."):
162
+ # Get AI response
163
+ response = st.session_state.qa_system.invoke({
164
+ "input": prompt,
165
+ "chat_history": st.session_state.messages
166
+ })
167
+
168
+ # Add AI message with metadata
169
+ ai_message = AIMessage(
170
+ content=response.content,
171
+ metadata={'sources': response.metadata.get('sources', [])}
172
+ )
173
+ st.session_state.messages.append(ai_message)
174
+ display_styled_chat_message(ai_message)
175
+
176
  def display_collection_sidebar():
177
+ """Display the document management sidebar."""
178
  with st.sidebar:
179
  st.title("📚 Document Manager")
180
 
181
+ # Upload Section
182
+ st.header("Upload Documents", anchor=False)
183
+ uploaded_files = st.file_uploader(
184
+ "Upload PDF documents",
185
+ type=['pdf'],
186
+ accept_multiple_files=True,
187
+ help="Limit 200MB per file • PDF"
188
+ )
189
+
190
  # Collection Selection
191
  st.header("Collections")
192
  collections = get_collections(st.session_state.db_conn)
 
213
  else:
214
  st.session_state.current_collection = None
215
 
 
 
 
 
 
 
 
 
 
216
  # Process uploads automatically when files are selected
217
  if uploaded_files:
218
  if 'processed_files' not in st.session_state or uploaded_files != st.session_state.processed_files:
 
322
  return
323
 
324
  initialize_session_state()
325
+ # Display sidebar first
326
+ display_collection_sidebar()
327
  display_top_bar()
328
 
329
  # Main content area with tabs