cryogenic22 commited on
Commit
4a2b28d
·
verified ·
1 Parent(s): 746f752

Update components/document_store.py

Browse files
Files changed (1) hide show
  1. components/document_store.py +5 -111
components/document_store.py CHANGED
@@ -13,123 +13,17 @@ from utils.database import (
13
  )
14
 
15
  def display_documents_tab():
16
- """Display the documents management interface."""
17
  col1, col2 = st.columns([1, 2])
18
 
19
  with col1:
20
  st.header("Collections")
21
 
22
- # Create new collection - now directly in the interface, not in an expander
23
  st.subheader("Create New Collection")
24
- col_name = st.text_input("Collection Name")
25
- col_desc = st.text_area("Description", height=100)
26
- if st.button("Create Collection", use_container_width=True):
27
  if col_name:
28
  if create_collection(st.session_state.db_conn, col_name, col_desc):
29
  st.success(f"Collection '{col_name}' created!")
30
- st.rerun()
31
-
32
- # Divider
33
- st.divider()
34
-
35
- # List all collections
36
- st.subheader("Existing Collections")
37
- collections = get_collections(st.session_state.db_conn)
38
- if collections:
39
- for col in collections:
40
- if st.button(f"📁 {col['name']} ({col['doc_count']} documents)",
41
- key=f"col_{col['id']}", use_container_width=True):
42
- st.session_state.selected_collection = col['id']
43
- st.rerun()
44
- else:
45
- st.info("No collections yet. Create your first collection above.")
46
-
47
- with col2:
48
- st.header("Documents")
49
-
50
- # Filter controls
51
- col_filter, doc_search = st.columns([1, 2])
52
- with col_filter:
53
- filter_option = st.selectbox(
54
- "View",
55
- ["All Documents", "Uncategorized", "Selected Collection"]
56
- )
57
- with doc_search:
58
- search_query = st.text_input("🔍 Search documents", placeholder="Enter search terms...")
59
-
60
- # Get and display documents based on filter
61
- if filter_option == "Selected Collection" and st.session_state.get('selected_collection'):
62
- documents = get_collection_documents(st.session_state.db_conn, st.session_state.selected_collection)
63
- else:
64
- documents = get_all_documents(st.session_state.db_conn)
65
- if filter_option == "Uncategorized":
66
- documents = [doc for doc in documents if not doc.get('collections')]
67
-
68
- # Display documents
69
- if search_query:
70
- # Filter documents based on search query
71
- documents = [
72
- doc for doc in documents
73
- if search_query.lower() in doc['name'].lower() or
74
- search_query.lower() in doc['content'].lower()
75
- ]
76
-
77
- if documents:
78
- for doc in documents:
79
- with st.expander(f"📄 {doc['name']}", expanded=False):
80
- # Create columns for metadata and actions
81
- meta_col, action_col = st.columns([2, 1])
82
-
83
- with meta_col:
84
- st.write(f"**Uploaded:** {doc['upload_date']}")
85
- if doc.get('collections'):
86
- st.write(f"**Collections:** {', '.join(doc['collections'])}")
87
-
88
- with action_col:
89
- # Preview button
90
- if st.button("Preview Content", key=f"preview_{doc['id']}"):
91
- st.session_state[f"show_preview_{doc['id']}"] = True
92
-
93
- # Use for Chat button
94
- if st.button("Use for Chat", key=f"chat_{doc['id']}", type="primary"):
95
- st.session_state.current_document = doc['id']
96
- st.session_state.chat_ready = True
97
- st.rerun()
98
-
99
- # Collection management
100
- if st.session_state.get('selected_collection'):
101
- current_collection_id = st.session_state.selected_collection
102
- doc_collections = [c['id'] for c in doc.get('collections', [])]
103
-
104
- if current_collection_id not in doc_collections:
105
- if st.button("Add to Collection", key=f"add_{doc['id']}", use_container_width=True):
106
- add_document_to_collection(
107
- st.session_state.db_conn,
108
- doc['id'],
109
- current_collection_id
110
- )
111
- st.rerun()
112
- else:
113
- if st.button("Remove from Collection", key=f"remove_{doc['id']}", use_container_width=True):
114
- remove_from_collection(
115
- st.session_state.db_conn,
116
- doc['id'],
117
- current_collection_id
118
- )
119
- st.rerun()
120
-
121
- # Show preview if button was clicked
122
- if st.session_state.get(f"show_preview_{doc['id']}", False):
123
- st.text_area(
124
- "Document Content",
125
- value=doc['content'][:1000] + "..." if len(doc['content']) > 1000 else doc['content'],
126
- height=200,
127
- disabled=True
128
- )
129
- else:
130
- if filter_option == "Selected Collection":
131
- st.info("No documents in this collection. Upload documents or add existing ones to this collection.")
132
- elif filter_option == "Uncategorized":
133
- st.info("No uncategorized documents found.")
134
- else:
135
- st.info("No documents found. Upload some documents to get started!")
 
13
  )
14
 
15
  def display_documents_tab():
 
16
  col1, col2 = st.columns([1, 2])
17
 
18
  with col1:
19
  st.header("Collections")
20
 
21
+ # Create new collection
22
  st.subheader("Create New Collection")
23
+ col_name = st.text_input("Collection Name", key="doc_store_collection_name")
24
+ col_desc = st.text_area("Description", height=100, key="doc_store_collection_desc")
25
+ if st.button("Create Collection", use_container_width=True, key="doc_store_create_btn"):
26
  if col_name:
27
  if create_collection(st.session_state.db_conn, col_name, col_desc):
28
  st.success(f"Collection '{col_name}' created!")
29
+ st.rerun()