cryogenic22 commited on
Commit
4bc807f
ยท
verified ยท
1 Parent(s): 1fdfeb1

Update utils/case_manager_interface.py

Browse files
Files changed (1) hide show
  1. utils/case_manager_interface.py +76 -38
utils/case_manager_interface.py CHANGED
@@ -75,6 +75,7 @@ class CaseManagerInterface:
75
  st.divider()
76
 
77
  def _render_document_manager(self):
 
78
  # Case selection
79
  cases = self.case_manager.get_all_cases()
80
  if not cases:
@@ -134,45 +135,82 @@ class CaseManagerInterface:
134
  # Document list
135
  if documents:
136
  st.subheader("Documents")
137
- for doc in documents:
138
- with st.container():
139
- col1, col2, col3, col4 = st.columns([3, 1, 1, 1])
140
-
141
- with col1:
142
- st.markdown(f"**{doc['title']}**")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  st.markdown(f"Added: {doc.get('added_at', 'Unknown')}")
144
-
145
- with col2:
146
- if st.button("๐Ÿ‘๏ธ View", key=f"view_{doc['id']}"):
147
- with st.expander("Document Content", expanded=True):
148
- st.text_area("Content", doc.get('text', 'No content available'), height=300)
149
-
150
- with col3:
151
- if st.button("๐Ÿ“ฅ Download", key=f"download_{doc['id']}"):
152
- try:
153
- # Get document content
154
- doc_content = doc.get('text', '')
155
- # Provide download
156
- st.download_button(
157
- "Download",
158
- doc_content,
159
- file_name=doc['title'],
160
- mime='text/plain'
161
- )
162
- except Exception as e:
163
- st.error(f"Error downloading: {str(e)}")
164
-
165
- with col4:
166
- if st.button("๐Ÿ—‘๏ธ", key=f"del_doc_{doc['id']}"):
167
- try:
168
- self.vector_store.delete_document(doc['id'])
169
- self.case_manager.remove_document(selected_case['id'], doc['id'])
170
- st.success(f"Deleted: {doc['title']}")
171
- st.rerun()
172
- except Exception as e:
173
- st.error(f"Error deleting: {str(e)}")
174
-
175
- st.divider()
176
  else:
177
  st.info("No documents in this case yet.")
178
 
 
75
  st.divider()
76
 
77
  def _render_document_manager(self):
78
+ """Render document management interface with file preview."""
79
  # Case selection
80
  cases = self.case_manager.get_all_cases()
81
  if not cases:
 
135
  # Document list
136
  if documents:
137
  st.subheader("Documents")
138
+
139
+ # Add tabs for different document views
140
+ doc_tab1, doc_tab2 = st.tabs(["List View", "Grid View"])
141
+
142
+ with doc_tab1:
143
+ for doc in documents:
144
+ with st.container():
145
+ # Create a clickable document title that shows preview
146
+ if st.markdown(f"[๐Ÿ“„ {doc['title']}](#{doc['id']})", help="Click to preview"):
147
+ with st.expander("Document Preview", expanded=True):
148
+ # Add tabs for different preview modes
149
+ preview_tab1, preview_tab2, preview_tab3 = st.tabs(["Content", "Metadata", "Chunks"])
150
+
151
+ with preview_tab1:
152
+ st.text_area("Document Content", doc.get('text', 'No content available'),
153
+ height=300, key=f"content_{doc['id']}")
154
+
155
+ with preview_tab2:
156
+ st.json(doc.get('metadata', {}))
157
+
158
+ with preview_tab3:
159
+ chunks = doc.get('chunks', [])
160
+ for idx, chunk in enumerate(chunks):
161
+ st.markdown(f"**Chunk {idx + 1}**")
162
+ st.text_area(f"Chunk Content",
163
+ chunk.get('text', 'No content available'),
164
+ height=100,
165
+ key=f"chunk_{doc['id']}_{idx}")
166
+
167
+ col1, col2, col3 = st.columns([1, 1, 1])
168
+
169
+ with col1:
170
+ if st.button("๐Ÿ“ฅ Download", key=f"download_{doc['id']}"):
171
+ try:
172
+ st.download_button(
173
+ "Click to Download",
174
+ doc.get('text', ''),
175
+ file_name=doc['title'],
176
+ mime='text/plain',
177
+ key=f"download_button_{doc['id']}"
178
+ )
179
+ except Exception as e:
180
+ st.error(f"Error downloading: {str(e)}")
181
+
182
+ with col2:
183
+ if st.button("๐Ÿ”„ Reprocess", key=f"reprocess_{doc['id']}"):
184
+ try:
185
+ # Implement reprocessing logic
186
+ st.info("Reprocessing document...")
187
+ except Exception as e:
188
+ st.error(f"Error reprocessing: {str(e)}")
189
+
190
+ with col3:
191
+ if st.button("๐Ÿ—‘๏ธ Delete", key=f"delete_{doc['id']}"):
192
+ if st.warning("Are you sure you want to delete this document?"):
193
+ try:
194
+ self.vector_store.delete_document(doc['id'])
195
+ self.case_manager.remove_document(selected_case['id'], doc['id'])
196
+ st.success(f"Deleted: {doc['title']}")
197
+ st.rerun()
198
+ except Exception as e:
199
+ st.error(f"Error deleting: {str(e)}")
200
+
201
+ st.divider()
202
+
203
+ with doc_tab2:
204
+ # Grid view of documents
205
+ cols = st.columns(3)
206
+ for idx, doc in enumerate(documents):
207
+ with cols[idx % 3]:
208
+ st.markdown(f"### ๐Ÿ“„ {doc['title']}")
209
  st.markdown(f"Added: {doc.get('added_at', 'Unknown')}")
210
+ st.markdown(f"Size: {len(doc.get('text', ''))}")
211
+ if st.button("Preview", key=f"grid_preview_{doc['id']}"):
212
+ with st.expander("Document Preview", expanded=True):
213
+ st.text_area("Content", doc.get('text', ''), height=200)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
214
  else:
215
  st.info("No documents in this case yet.")
216