cryogenic22 commited on
Commit
17ff205
·
verified ·
1 Parent(s): e1b81dc

Create components/document_store.py

Browse files
components/components/document_store.py CHANGED
@@ -1,14 +1,15 @@
1
  # components/document_store.py
2
 
3
  import streamlit as st
4
- from typing import Dict, List, Optional, Any
5
  from utils.database import (
6
  get_all_documents,
7
  get_collections,
8
  get_collection_documents,
9
  create_collection,
10
  add_document_to_collection,
11
- remove_from_collection
 
12
  )
13
 
14
  def display_documents_tab():
@@ -48,7 +49,7 @@ def display_documents_tab():
48
  ["All Documents", "Uncategorized", "Selected Collection"]
49
  )
50
  with doc_search:
51
- search_query = st.text_input("Search documents", placeholder="Enter search terms...")
52
 
53
  # Get and display documents based on filter
54
  if filter_option == "Selected Collection" and st.session_state.get('selected_collection'):
@@ -56,9 +57,17 @@ def display_documents_tab():
56
  else:
57
  documents = get_all_documents(st.session_state.db_conn)
58
  if filter_option == "Uncategorized":
59
- documents = [doc for doc in documents if not doc['collections']]
60
 
61
  # Display documents
 
 
 
 
 
 
 
 
62
  for doc in documents:
63
  with st.expander(f"📄 {doc['name']}", expanded=False):
64
  # Document metadata
@@ -66,17 +75,29 @@ def display_documents_tab():
66
  if doc.get('collections'):
67
  st.write(f"Collections: {', '.join(doc['collections'])}")
68
 
 
 
 
 
 
 
 
 
 
69
  # Document actions
70
  col1, col2 = st.columns(2)
71
  with col1:
72
  # Collection management
73
  if st.session_state.get('selected_collection'):
74
- if st.session_state.selected_collection not in [c['id'] for c in doc.get('collections', [])]:
 
 
 
75
  if st.button("Add to Collection", key=f"add_{doc['id']}"):
76
  add_document_to_collection(
77
  st.session_state.db_conn,
78
  doc['id'],
79
- st.session_state.selected_collection
80
  )
81
  st.rerun()
82
  else:
@@ -84,12 +105,12 @@ def display_documents_tab():
84
  remove_from_collection(
85
  st.session_state.db_conn,
86
  doc['id'],
87
- st.session_state.selected_collection
88
  )
89
  st.rerun()
90
 
91
  with col2:
92
- # Preview/Chat actions
93
  if st.button("Use for Chat", key=f"chat_{doc['id']}"):
94
  st.session_state.current_document = doc['id']
95
  st.session_state.chat_ready = True
 
1
  # components/document_store.py
2
 
3
  import streamlit as st
4
+ from typing import Dict, List, Optional
5
  from utils.database import (
6
  get_all_documents,
7
  get_collections,
8
  get_collection_documents,
9
  create_collection,
10
  add_document_to_collection,
11
+ remove_from_collection,
12
+ search_documents
13
  )
14
 
15
  def display_documents_tab():
 
49
  ["All Documents", "Uncategorized", "Selected Collection"]
50
  )
51
  with doc_search:
52
+ search_query = st.text_input("🔍 Search documents", placeholder="Enter search terms...")
53
 
54
  # Get and display documents based on filter
55
  if filter_option == "Selected Collection" and st.session_state.get('selected_collection'):
 
57
  else:
58
  documents = get_all_documents(st.session_state.db_conn)
59
  if filter_option == "Uncategorized":
60
+ documents = [doc for doc in documents if not doc.get('collections')]
61
 
62
  # Display documents
63
+ if search_query:
64
+ # Filter documents based on search query
65
+ documents = [
66
+ doc for doc in documents
67
+ if search_query.lower() in doc['name'].lower() or
68
+ search_query.lower() in doc['content'].lower()
69
+ ]
70
+
71
  for doc in documents:
72
  with st.expander(f"📄 {doc['name']}", expanded=False):
73
  # Document metadata
 
75
  if doc.get('collections'):
76
  st.write(f"Collections: {', '.join(doc['collections'])}")
77
 
78
+ # Document preview
79
+ with st.expander("Preview Content"):
80
+ st.text_area(
81
+ "",
82
+ value=doc['content'][:1000] + "..." if len(doc['content']) > 1000 else doc['content'],
83
+ height=200,
84
+ disabled=True
85
+ )
86
+
87
  # Document actions
88
  col1, col2 = st.columns(2)
89
  with col1:
90
  # Collection management
91
  if st.session_state.get('selected_collection'):
92
+ current_collection_id = st.session_state.selected_collection
93
+ doc_collections = [c['id'] for c in doc.get('collections', [])]
94
+
95
+ if current_collection_id not in doc_collections:
96
  if st.button("Add to Collection", key=f"add_{doc['id']}"):
97
  add_document_to_collection(
98
  st.session_state.db_conn,
99
  doc['id'],
100
+ current_collection_id
101
  )
102
  st.rerun()
103
  else:
 
105
  remove_from_collection(
106
  st.session_state.db_conn,
107
  doc['id'],
108
+ current_collection_id
109
  )
110
  st.rerun()
111
 
112
  with col2:
113
+ # Chat action
114
  if st.button("Use for Chat", key=f"chat_{doc['id']}"):
115
  st.session_state.current_document = doc['id']
116
  st.session_state.chat_ready = True