Update app.py
Browse files
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 |
-
|
86 |
with st.chat_message("assistant"):
|
87 |
response = qa_chain({"question": prompt})
|
88 |
response_text = response["answer"]
|
89 |
-
|
90 |
-
#
|
91 |
-
|
92 |
-
|
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})
|