Anne31415 commited on
Commit
d48b5c2
·
verified ·
1 Parent(s): 8cced41

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -15
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
- # Check if the collection already exists
531
- existing_collections = chroma_client.list_collections()
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
- else:
536
- # Use the existing collection if it already exists
537
- collection = chroma_client.get_collection(name="Kosten_Strukturdaten0602204")
538
-
539
-
540
- # Add the extracted text from PDF to the Chroma collection
541
- collection.add(
542
- documents=[pdf_text],
543
- metadatas=[{"source": pdf_path3}], # Add any relevant metadata for your document
544
- ids=[("Kosten_Strukturdaten0602204")]
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