Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -278,12 +278,8 @@ def display_header():
|
|
| 278 |
def display_collection_management():
|
| 279 |
"""Display collection management interface."""
|
| 280 |
st.header("π Collection Management")
|
| 281 |
-
|
| 282 |
-
# Get existing collections
|
| 283 |
-
collections = get_collections(st.session_state.db_conn)
|
| 284 |
-
|
| 285 |
col1, col2 = st.columns([2, 1])
|
| 286 |
-
|
| 287 |
with col1:
|
| 288 |
# Create new collection form
|
| 289 |
with st.form("create_collection_form"):
|
|
@@ -291,68 +287,58 @@ def display_collection_management():
|
|
| 291 |
name = st.text_input("Collection Name")
|
| 292 |
description = st.text_area("Description")
|
| 293 |
submit = st.form_submit_button("Create Collection", use_container_width=True)
|
| 294 |
-
|
| 295 |
if submit and name:
|
| 296 |
collection_id = create_collection(st.session_state.db_conn, name, description)
|
| 297 |
if collection_id:
|
| 298 |
st.success(f"Collection '{name}' created successfully!")
|
|
|
|
| 299 |
st.rerun()
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
if collections:
|
| 304 |
-
st.
|
| 305 |
-
|
| 306 |
-
"
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
st.write(f"**Description:** {collection.get('description', 'No description')}")
|
| 334 |
-
st.write(f"**Created:** {collection['created_at']}")
|
| 335 |
-
|
| 336 |
-
# Display documents in collection
|
| 337 |
-
docs = get_collection_documents(st.session_state.db_conn, collection['id'])
|
| 338 |
-
if docs:
|
| 339 |
-
st.write("**Documents:**")
|
| 340 |
-
for doc in docs:
|
| 341 |
-
st.write(f"- {doc['name']}")
|
| 342 |
-
tags = get_document_tags(st.session_state.db_conn, doc['id'])
|
| 343 |
-
if tags:
|
| 344 |
-
st.write(f" Tags: {', '.join(tags)}")
|
| 345 |
-
|
| 346 |
-
with col2:
|
| 347 |
-
st.button("Start Chat", key=f"chat_{collection['id']}", use_container_width=True)
|
| 348 |
-
st.button("Upload Files", key=f"upload_{collection['id']}", use_container_width=True)
|
| 349 |
-
if st.button("Delete", key=f"delete_{collection['id']}", use_container_width=True):
|
| 350 |
-
if st.warning("Are you sure you want to delete this collection?"):
|
| 351 |
-
if delete_collection(st.session_state.db_conn, collection['id']):
|
| 352 |
-
st.success("Collection deleted successfully!")
|
| 353 |
st.rerun()
|
| 354 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 355 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 356 |
def display_chat_interface():
|
| 357 |
"""Display the main chat interface with persistent storage."""
|
| 358 |
st.header("π¬ Ask your documents")
|
|
|
|
| 278 |
def display_collection_management():
|
| 279 |
"""Display collection management interface."""
|
| 280 |
st.header("π Collection Management")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 281 |
col1, col2 = st.columns([2, 1])
|
| 282 |
+
|
| 283 |
with col1:
|
| 284 |
# Create new collection form
|
| 285 |
with st.form("create_collection_form"):
|
|
|
|
| 287 |
name = st.text_input("Collection Name")
|
| 288 |
description = st.text_area("Description")
|
| 289 |
submit = st.form_submit_button("Create Collection", use_container_width=True)
|
| 290 |
+
|
| 291 |
if submit and name:
|
| 292 |
collection_id = create_collection(st.session_state.db_conn, name, description)
|
| 293 |
if collection_id:
|
| 294 |
st.success(f"Collection '{name}' created successfully!")
|
| 295 |
+
st.session_state.current_collection_id = collection_id
|
| 296 |
st.rerun()
|
| 297 |
+
|
| 298 |
+
# Display existing collections
|
| 299 |
+
collections = get_collections(st.session_state.db_conn)
|
| 300 |
if collections:
|
| 301 |
+
st.markdown("### Existing Collections")
|
| 302 |
+
for collection in collections:
|
| 303 |
+
with st.expander(f"π {collection['name']} ({collection['doc_count']} documents)"):
|
| 304 |
+
col1, col2 = st.columns([3, 1])
|
| 305 |
+
with col1:
|
| 306 |
+
st.write(f"**Description:** {collection.get('description', 'No description')}")
|
| 307 |
+
st.write(f"**Created:** {collection['created_at']}")
|
| 308 |
+
|
| 309 |
+
# Display documents in collection
|
| 310 |
+
docs = get_collection_documents(st.session_state.db_conn, collection['id'])
|
| 311 |
+
if docs:
|
| 312 |
+
st.write("**Documents:**")
|
| 313 |
+
for doc in docs:
|
| 314 |
+
st.write(f"- {doc['name']}")
|
| 315 |
+
tags = get_document_tags(st.session_state.db_conn, doc['id'])
|
| 316 |
+
if tags:
|
| 317 |
+
st.write(f" Tags: {', '.join(tags)}")
|
| 318 |
+
|
| 319 |
+
with col2:
|
| 320 |
+
# Add documents to collection
|
| 321 |
+
uploaded_files = st.file_uploader(
|
| 322 |
+
"Add Documents",
|
| 323 |
+
type=['pdf'],
|
| 324 |
+
accept_multiple_files=True,
|
| 325 |
+
key=f"collection_upload_{collection['id']}"
|
| 326 |
+
)
|
| 327 |
+
if uploaded_files:
|
| 328 |
+
if handle_document_upload(uploaded_files, collection_id=collection['id']):
|
| 329 |
+
st.success("Documents added successfully!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 330 |
st.rerun()
|
| 331 |
|
| 332 |
+
if st.button("Start Chat", key=f"chat_{collection['id']}", use_container_width=True):
|
| 333 |
+
st.session_state.selected_collection = collection
|
| 334 |
+
initialize_chat_system(collection['id'])
|
| 335 |
+
st.rerun()
|
| 336 |
|
| 337 |
+
if st.button("Delete Collection", key=f"delete_{collection['id']}", use_container_width=True):
|
| 338 |
+
if st.warning("Are you sure you want to delete this collection?"):
|
| 339 |
+
if delete_collection(st.session_state.db_conn, collection['id']):
|
| 340 |
+
st.success("Collection deleted successfully!")
|
| 341 |
+
st.rerun()
|
| 342 |
def display_chat_interface():
|
| 343 |
"""Display the main chat interface with persistent storage."""
|
| 344 |
st.header("π¬ Ask your documents")
|