Anne31415 commited on
Commit
2b39b13
1 Parent(s): 27f0cf3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -4
app.py CHANGED
@@ -69,7 +69,7 @@ pdf_path3 = "Private_Book/Kosten_Strukturdaten_RAG_vorbereited.pdf"
69
  api_key = os.getenv("OPENAI_API_KEY")
70
  # Retrieve the API key from st.secrets
71
 
72
- @st.cache
73
  def extract_text_from_pdf(pdf_path):
74
  text = ""
75
  reader = PdfReader(pdf_path)
@@ -519,25 +519,32 @@ def page3():
519
  # User query input
520
  query = st.text_input("Geben Sie hier Ihre Frage ein / Enter your question here:")
521
 
522
- # Handling query input
523
  if query:
524
  full_query = ask_bot(query)
525
  st.session_state['chat_history_page3'].append(("User", query, "new"))
526
 
527
  # Query the CromA collection
 
528
  results = collection.query(
529
  query_texts=[full_query],
530
- n_results=5 # Adjust the number of results as needed
531
  )
532
 
 
 
533
  # Process and display response from CromA results
534
  if results:
535
- response = f"Top result: {results[0]['text']}" # Example response using the first result
 
 
 
 
536
  else:
537
  response = "No results found for your query."
538
 
539
  st.session_state['chat_history_page3'].append(("Eve", response, "new"))
540
 
 
541
  # Display new messages at the bottom
542
  new_messages = st.session_state['chat_history_page3'][-2:]
543
  for chat in new_messages:
 
69
  api_key = os.getenv("OPENAI_API_KEY")
70
  # Retrieve the API key from st.secrets
71
 
72
+ @st.cache_data
73
  def extract_text_from_pdf(pdf_path):
74
  text = ""
75
  reader = PdfReader(pdf_path)
 
519
  # User query input
520
  query = st.text_input("Geben Sie hier Ihre Frage ein / Enter your question here:")
521
 
 
522
  if query:
523
  full_query = ask_bot(query)
524
  st.session_state['chat_history_page3'].append(("User", query, "new"))
525
 
526
  # Query the CromA collection
527
+ st.text("Querying CromA collection...") # Diagnostic print
528
  results = collection.query(
529
  query_texts=[full_query],
530
+ n_results=5
531
  )
532
 
533
+ st.text(f"Query results: {results}") # Diagnostic print
534
+
535
  # Process and display response from CromA results
536
  if results:
537
+ try:
538
+ response = f"Top result: {results[0]['text']}"
539
+ except KeyError as ke:
540
+ st.error(f"KeyError encountered: {ke}")
541
+ response = "Error in processing the response."
542
  else:
543
  response = "No results found for your query."
544
 
545
  st.session_state['chat_history_page3'].append(("Eve", response, "new"))
546
 
547
+
548
  # Display new messages at the bottom
549
  new_messages = st.session_state['chat_history_page3'][-2:]
550
  for chat in new_messages: