Anne31415 commited on
Commit
232a6a7
·
verified ·
1 Parent(s): 9960fe7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -44
app.py CHANGED
@@ -299,60 +299,53 @@ def page1():
299
 
300
 
301
 
302
- if query:
303
  full_query = ask_bot(query)
304
  st.session_state['chat_history_page1'].append(("User", query, "new"))
305
-
306
  # Start timing
307
  start_time = time.time()
308
-
 
 
 
 
309
  with st.spinner('Eve denkt über Ihre Frage nach...'):
310
  chain = load_chatbot()
311
  docs = VectorStore.similarity_search(query=query, k=5)
312
  with get_openai_callback() as cb:
313
  response = chain.run(input_documents=docs, question=full_query)
314
- response = handle_no_answer(response) # Process the response through the new function
315
-
316
-
317
-
318
- # Stop timing
319
- end_time = time.time()
320
-
321
- # Calculate duration
322
- duration = end_time - start_time
323
-
324
- st.session_state['chat_history_page1'].append(("Eve", response, "new"))
325
-
326
-
327
- # Combine chat histories from all pages
328
- all_chat_histories = [
329
- st.session_state['chat_history_page1'],
330
- st.session_state['chat_history_page2'],
331
- st.session_state['chat_history_page3']
332
- ]
333
-
334
- # Save the combined chat histories
335
- save_conversation(all_chat_histories, st.session_state['session_id'])
336
-
337
-
338
-
339
-
340
- # Create a placeholder for the response time
341
- response_time_placeholder = st.empty()
342
-
343
- # Display new messages at the bottom
344
- new_messages = st.session_state['chat_history_page1'][-2:]
345
- for chat in new_messages:
346
- background_color = "#ffeecf" if chat[2] == "new" else "#ffeecf" if chat[0] == "User" else "#ffeecf"
347
- new_messages_placeholder.markdown(f"<div style='background-color: {background_color}; padding: 10px; border-radius: 10px; margin: 10px;'>{chat[0]}: {chat[1]}</div>", unsafe_allow_html=True)
348
-
349
- # Update the response time placeholder after the messages are displayed
350
- response_time_placeholder.text(f"Response time: {duration:.2f} seconds")
351
-
352
-
353
-
354
  # Clear the input field after the query is made
355
- query = ""
356
 
357
  # Mark all messages as old after displaying
358
  st.session_state['chat_history_page1'] = [(sender, msg, "old") for sender, msg, _ in st.session_state['chat_history_page1']]
 
299
 
300
 
301
 
302
+ if query:
303
  full_query = ask_bot(query)
304
  st.session_state['chat_history_page1'].append(("User", query, "new"))
305
+
306
  # Start timing
307
  start_time = time.time()
308
+
309
+ # Create a placeholder for the response time
310
+ response_time_placeholder = st.empty()
311
+
312
+ # Include the spinner around all processing and display operations
313
  with st.spinner('Eve denkt über Ihre Frage nach...'):
314
  chain = load_chatbot()
315
  docs = VectorStore.similarity_search(query=query, k=5)
316
  with get_openai_callback() as cb:
317
  response = chain.run(input_documents=docs, question=full_query)
318
+ response = handle_no_answer(response)
319
+
320
+ # Stop timing
321
+ end_time = time.time()
322
+
323
+ # Calculate duration
324
+ duration = end_time - start_time
325
+
326
+ st.session_state['chat_history_page1'].append(("Eve", response, "new"))
327
+
328
+ # Combine chat histories from all pages
329
+ all_chat_histories = [
330
+ st.session_state['chat_history_page1'],
331
+ st.session_state['chat_history_page2'],
332
+ st.session_state['chat_history_page3']
333
+ ]
334
+
335
+ # Save the combined chat histories
336
+ save_conversation(all_chat_histories, st.session_state['session_id'])
337
+
338
+ # Display new messages at the bottom
339
+ new_messages = st.session_state['chat_history_page1'][-2:]
340
+ for chat in new_messages:
341
+ background_color = "#ffeecf" if chat[2] == "new" else "#ffeecf" if chat[0] == "User" else "#ffeecf"
342
+ new_messages_placeholder.markdown(f"<div style='background-color: {background_color}; padding: 10px; border-radius: 10px; margin: 10px;'>{chat[0]}: {chat[1]}</div>", unsafe_allow_html=True)
343
+
344
+ # Update the response time placeholder after the messages are displayed
345
+ response_time_placeholder.text(f"Response time: {duration:.2f} seconds")
346
+
 
 
 
 
 
 
 
 
 
 
 
347
  # Clear the input field after the query is made
348
+ query = ""
349
 
350
  # Mark all messages as old after displaying
351
  st.session_state['chat_history_page1'] = [(sender, msg, "old") for sender, msg, _ in st.session_state['chat_history_page1']]