Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import random | |
| import time | |
| # def send_message(message): | |
| # response = st.write_stream(response_generator(message)) | |
| # st.session_state.messages.append({"role": "assistant", "content": response}) | |
| def send_message(message): | |
| message_placeholder = st.empty() | |
| full_response = "" | |
| # Simulate stream of response with milliseconds delay | |
| for chunk in message.split(): | |
| full_response += chunk + " " | |
| time.sleep(0.05) | |
| # Add a blinking cursor to simulate typing | |
| message_placeholder.markdown(full_response + "β") | |
| message_placeholder.markdown(full_response, unsafe_allow_html=True) | |
| st.session_state.messages.append({"role": "assistant", "content": full_response}) | |
| def response_generator(response): | |
| for word in response.split(): | |
| yield word + " " | |
| time.sleep(0.05) |