Anne31415 commited on
Commit
0272cf0
1 Parent(s): 1e98064

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -92,6 +92,11 @@ def display_chat_history(chat_history):
92
  background_color = "#ffeecf" if chat[2] == "new" else "#ffeecf" if chat[0] == "User" else "#ffeecf"
93
  st.markdown(f"<div style='background-color: {background_color}; padding: 10px; border-radius: 10px; margin: 10px;'>{chat[0]}: {chat[1]}</div>", unsafe_allow_html=True)
94
 
 
 
 
 
 
95
 
96
 
97
 
@@ -165,11 +170,12 @@ def page1():
165
  start_time = time.time()
166
 
167
  with st.spinner('Bot is thinking...'):
168
- # Use the VectorStore loaded at the start from the session state
169
  chain = load_chatbot()
170
  docs = VectorStore.similarity_search(query=query, k=3)
171
  with get_openai_callback() as cb:
172
  response = chain.run(input_documents=docs, question=query)
 
 
173
 
174
 
175
  # Stop timing
@@ -277,11 +283,12 @@ def page2():
277
  start_time = time.time()
278
 
279
  with st.spinner('Bot is thinking...'):
280
- # Use the VectorStore loaded at the start from the session state
281
  chain = load_chatbot()
282
  docs = VectorStore.similarity_search(query=query, k=3)
283
  with get_openai_callback() as cb:
284
  response = chain.run(input_documents=docs, question=query)
 
 
285
 
286
 
287
  # Stop timing
 
92
  background_color = "#ffeecf" if chat[2] == "new" else "#ffeecf" if chat[0] == "User" else "#ffeecf"
93
  st.markdown(f"<div style='background-color: {background_color}; padding: 10px; border-radius: 10px; margin: 10px;'>{chat[0]}: {chat[1]}</div>", unsafe_allow_html=True)
94
 
95
+ def handle_no_answer(response):
96
+ if response.strip().lower() in ["i don't know", "i am not sure", ""]:
97
+ # Return a more engaging response
98
+ return "Hmm, that's a tough one. I might not have all the answers, but let's try exploring this together. Can you provide more details or ask a different question?"
99
+ return response
100
 
101
 
102
 
 
170
  start_time = time.time()
171
 
172
  with st.spinner('Bot is thinking...'):
 
173
  chain = load_chatbot()
174
  docs = VectorStore.similarity_search(query=query, k=3)
175
  with get_openai_callback() as cb:
176
  response = chain.run(input_documents=docs, question=query)
177
+ response = handle_no_answer(response) # Process the response through the new function
178
+
179
 
180
 
181
  # Stop timing
 
283
  start_time = time.time()
284
 
285
  with st.spinner('Bot is thinking...'):
 
286
  chain = load_chatbot()
287
  docs = VectorStore.similarity_search(query=query, k=3)
288
  with get_openai_callback() as cb:
289
  response = chain.run(input_documents=docs, question=query)
290
+ response = handle_no_answer(response) # Process the response through the new function
291
+
292
 
293
 
294
  # Stop timing