Anne31415 commited on
Commit
7a066fc
·
verified ·
1 Parent(s): ed6c2ec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -3
app.py CHANGED
@@ -509,16 +509,23 @@ def page3():
509
 
510
  # Check if the collection already exists
511
  try:
512
- # Attempt to create the collection
513
  collection = chroma_client.create_collection(name="Kosten_Strukturdaten0602204")
514
  except Exception as e:
515
- # If the collection already exists, fetch the existing collection
516
  if 'already exists' in str(e):
517
  collection = chroma_client.get_collection(name="Kosten_Strukturdaten0602204")
518
  else:
519
- # If the error is due to some other reason, re-raise the exception
520
  raise e
521
 
 
 
 
 
 
 
 
 
 
 
522
  # Simple interaction
523
  if st.button("Test Button"):
524
  st.write("Button clicked.")
@@ -529,6 +536,7 @@ def page3():
529
 
530
 
531
 
 
532
  def page4():
533
  try:
534
  st.header(":mailbox: Kontakt & Feedback!")
 
509
 
510
  # Check if the collection already exists
511
  try:
 
512
  collection = chroma_client.create_collection(name="Kosten_Strukturdaten0602204")
513
  except Exception as e:
 
514
  if 'already exists' in str(e):
515
  collection = chroma_client.get_collection(name="Kosten_Strukturdaten0602204")
516
  else:
 
517
  raise e
518
 
519
+ # Add documents to the collection (ensure this is not done redundantly)
520
+ # It's important to make sure this step doesn't repeat unnecessarily on each rerun
521
+ if "documents_added" not in st.session_state:
522
+ collection.add(
523
+ documents=[pdf_text],
524
+ metadatas=[{"source": pdf_path3}],
525
+ ids=[("Kosten_Strukturdaten0602204")]
526
+ )
527
+ st.session_state["documents_added"] = True
528
+
529
  # Simple interaction
530
  if st.button("Test Button"):
531
  st.write("Button clicked.")
 
536
 
537
 
538
 
539
+
540
  def page4():
541
  try:
542
  st.header(":mailbox: Kontakt & Feedback!")