Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -524,25 +524,27 @@ def page3():
|
|
524 |
st.error("File not found. Please check the file path.")
|
525 |
return
|
526 |
|
|
|
527 |
# Initialize CromA client
|
528 |
chroma_client = chromadb.Client()
|
529 |
|
530 |
-
|
531 |
-
|
532 |
-
if "Kosten_Strukturdaten0602204" not in existing_collections:
|
533 |
-
# Create the collection if it does not exist
|
534 |
collection = chroma_client.create_collection(name="Kosten_Strukturdaten0602204")
|
535 |
-
|
536 |
-
#
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
|
|
|
|
|
|
546 |
|
547 |
display_chat_history(st.session_state['chat_history_page3'])
|
548 |
|
|
|
524 |
st.error("File not found. Please check the file path.")
|
525 |
return
|
526 |
|
527 |
+
|
528 |
# Initialize CromA client
|
529 |
chroma_client = chromadb.Client()
|
530 |
|
531 |
+
try:
|
532 |
+
# Attempt to create the collection
|
|
|
|
|
533 |
collection = chroma_client.create_collection(name="Kosten_Strukturdaten0602204")
|
534 |
+
except Exception as e:
|
535 |
+
# If the collection already exists, fetch the existing collection
|
536 |
+
if 'already exists' in str(e):
|
537 |
+
collection = chroma_client.get_collection(name="Kosten_Strukturdaten0602204")
|
538 |
+
else:
|
539 |
+
# If the error is due to some other reason, re-raise the exception
|
540 |
+
raise e
|
541 |
+
|
542 |
+
# Add the extracted text from PDF to the Chroma collection
|
543 |
+
collection.add(
|
544 |
+
documents=[pdf_text],
|
545 |
+
metadatas=[{"source": pdf_path3}], # Add any relevant metadata for your document
|
546 |
+
ids=[("Kosten_Strukturdaten0602204")]
|
547 |
+
)
|
548 |
|
549 |
display_chat_history(st.session_state['chat_history_page3'])
|
550 |
|