Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -169,17 +169,36 @@ def main():
|
|
| 169 |
f"Upload Document to Case: {case['title']}",
|
| 170 |
key=f"upload_{case['id']}"
|
| 171 |
)
|
|
|
|
| 172 |
if uploaded_file:
|
| 173 |
with st.spinner("Processing document..."):
|
| 174 |
try:
|
|
|
|
| 175 |
text, chunks, metadata = doc_processor.process_and_tag_document(uploaded_file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
doc_data = {
|
|
|
|
| 177 |
"title": uploaded_file.name,
|
| 178 |
"text": text,
|
| 179 |
-
"metadata": metadata
|
|
|
|
| 180 |
}
|
| 181 |
case_manager.add_document(case["id"], doc_data)
|
| 182 |
-
st.success(f"Document '{uploaded_file.name}' added successfully!")
|
| 183 |
except Exception as e:
|
| 184 |
st.error(f"Error processing document: {str(e)}")
|
| 185 |
else:
|
|
|
|
| 169 |
f"Upload Document to Case: {case['title']}",
|
| 170 |
key=f"upload_{case['id']}"
|
| 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:
|