cryogenic22 commited on
Commit
4670fef
·
verified ·
1 Parent(s): 3d508bf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -30
app.py CHANGED
@@ -171,36 +171,41 @@ def main():
171
  )
172
  # In the Case Manager tab section, where documents are uploaded
173
  if uploaded_file:
174
- with st.spinner("Processing document..."):
175
- try:
176
- # Process document
177
- text, chunks, metadata = doc_processor.process_and_tag_document(uploaded_file)
178
-
179
- # Add document to vector store
180
- for chunk in chunks:
181
- vector_store.add_document(
182
- doc_id=metadata['doc_id'],
183
- text=chunk['text'],
184
- metadata={
185
- 'doc_id': metadata['doc_id'],
186
- 'chunk_id': chunk['chunk_id'],
187
- 'title': uploaded_file.name,
188
- 'type': metadata.get('document_type', 'unknown')
189
- }
190
- )
191
-
192
- # Add document to case
193
- doc_data = {
194
- "id": metadata['doc_id'],
195
- "title": uploaded_file.name,
196
- "text": text,
197
- "metadata": metadata,
198
- "chunks": chunks
199
- }
200
- case_manager.add_document(case["id"], doc_data)
201
- st.success(f"Document '{uploaded_file.name}' processed and added successfully!")
202
- except Exception as e:
203
- st.error(f"Error processing document: {str(e)}")
 
 
 
 
 
204
  else:
205
  st.info("No cases created yet. Use the form above to create your first case.")
206
  except Exception as e:
 
171
  )
172
  # In the Case Manager tab section, where documents are uploaded
173
  if uploaded_file:
174
+ if uploaded_file:
175
+ with st.spinner("Processing document..."):
176
+ try:
177
+ # Process document
178
+ text, chunks, metadata = doc_processor.process_and_tag_document(uploaded_file)
179
+
180
+ # Add each chunk to vector store
181
+ for chunk in chunks:
182
+ try:
183
+ vector_store.add_document(
184
+ doc_id=f"{metadata['doc_id']}_chunk_{chunk['chunk_id']}",
185
+ text=chunk['text'],
186
+ metadata={
187
+ 'doc_id': metadata['doc_id'],
188
+ 'chunk_id': chunk['chunk_id'],
189
+ 'title': uploaded_file.name,
190
+ 'type': metadata.get('document_type', 'unknown')
191
+ }
192
+ )
193
+ except Exception as e:
194
+ st.warning(f"Error adding chunk to vector store: {str(e)}")
195
+
196
+ # Add document to case
197
+ doc_data = {
198
+ "id": metadata['doc_id'],
199
+ "title": uploaded_file.name,
200
+ "text": text,
201
+ "metadata": metadata,
202
+ "chunks": chunks
203
+ }
204
+ case_manager.add_document(case["id"], doc_data)
205
+ st.success(f"Document '{uploaded_file.name}' processed and added successfully!")
206
+
207
+ except Exception as e:
208
+ st.error(f"Error processing document: {str(e)}")
209
  else:
210
  st.info("No cases created yet. Use the form above to create your first case.")
211
  except Exception as e: