mavinsao commited on
Commit
d281311
·
verified ·
1 Parent(s): 3a9a00e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -75,8 +75,10 @@ for message in st.session_state.messages:
75
 
76
  # Streamed response generator
77
  def response_generator(response):
 
78
  for word in response.split():
79
- yield word + " "
 
80
  time.sleep(0.05) # Adjust this delay to control typing speed
81
 
82
  # Accept user input
@@ -93,8 +95,8 @@ if prompt := st.chat_input("What are you looking to learn?"):
93
  response_text = response["answer"]
94
 
95
  # Stream the response word by word
96
- for word in response_generator(response_text):
97
- st.markdown(word, unsafe_allow_html=True)
98
 
99
  # Add assistant response to chat history
100
  st.session_state.messages.append({"role": "assistant", "content": response_text})
 
75
 
76
  # Streamed response generator
77
  def response_generator(response):
78
+ accumulated_response = ""
79
  for word in response.split():
80
+ accumulated_response += word + " "
81
+ yield accumulated_response.strip() # Yield accumulated response
82
  time.sleep(0.05) # Adjust this delay to control typing speed
83
 
84
  # Accept user input
 
95
  response_text = response["answer"]
96
 
97
  # Stream the response word by word
98
+ for accumulated_response in response_generator(response_text):
99
+ st.markdown(accumulated_response, unsafe_allow_html=True)
100
 
101
  # Add assistant response to chat history
102
  st.session_state.messages.append({"role": "assistant", "content": response_text})