mavinsao commited on
Commit
77639e7
·
verified ·
1 Parent(s): 7f94f63

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -7
app.py CHANGED
@@ -82,14 +82,22 @@ if prompt := st.chat_input("What are you looking to learn?"):
82
  with st.chat_message("user"):
83
  st.markdown(prompt)
84
 
85
- # Assistant response generation with streaming effect
86
  with st.chat_message("assistant"):
87
  response = qa_chain({"question": prompt})
88
  response_text = response["answer"]
89
-
90
- # Stream the response word by word
91
- for accumulated_response in response_text:
92
- st.markdown(accumulated_response, unsafe_allow_html=True)
93
-
 
 
 
 
 
 
 
 
94
  # Add assistant response to chat history
95
- st.session_state.messages.append({"role": "assistant", "content": response_text})
 
82
  with st.chat_message("user"):
83
  st.markdown(prompt)
84
 
85
+ # Assistant response generation with streaming effect
86
  with st.chat_message("assistant"):
87
  response = qa_chain({"question": prompt})
88
  response_text = response["answer"]
89
+
90
+ # Create an empty placeholder
91
+ placeholder = st.empty()
92
+
93
+ # Initialize an empty string to accumulate the response
94
+ accumulated_response = ""
95
+
96
+ # Stream the response character by character
97
+ for char in response_text:
98
+ accumulated_response += char
99
+ placeholder.markdown(accumulated_response, unsafe_allow_html=True)
100
+ time.sleep(0.01) # Add a small delay to create a typing effect
101
+
102
  # Add assistant response to chat history
103
+ st.session_state.messages.append({"role": "assistant", "content": response_text})