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

Update components/document_store.py

Browse files
Files changed (1) hide show
  1. components/document_store.py +55 -37
components/document_store.py CHANGED
@@ -19,17 +19,21 @@ def display_documents_tab():
19
  with col1:
20
  st.header("Collections")
21
 
22
- # Create new collection
23
- with st.expander("Create New Collection", expanded=False):
24
- col_name = st.text_input("Collection Name")
25
- col_desc = st.text_area("Description")
26
- if st.button("Create Collection"):
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
  # List all collections
 
33
  collections = get_collections(st.session_state.db_conn)
34
  if collections:
35
  for col in collections:
@@ -37,6 +41,8 @@ def display_documents_tab():
37
  key=f"col_{col['id']}", use_container_width=True):
38
  st.session_state.selected_collection = col['id']
39
  st.rerun()
 
 
40
 
41
  with col2:
42
  st.header("Documents")
@@ -68,32 +74,35 @@ def display_documents_tab():
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
74
- st.write(f"Uploaded: {doc['upload_date']}")
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'],
@@ -101,17 +110,26 @@ def display_documents_tab():
101
  )
102
  st.rerun()
103
  else:
104
- if st.button("Remove from Collection", key=f"remove_{doc['id']}"):
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
117
- st.rerun()
 
 
 
 
 
 
 
 
 
 
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:
 
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")
 
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'],
 
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!")