SystemGPT/system-rule-based-chatbot
1
1import streamlit as st2import time3from generate_response import generate_response4 5st.title("System Bot")6 7# Initialize chat history8if "messages" not in st.session_state:9 st.session_state.messages = []10 11# Display chat messages from history on app rerun12for message in st.session_state.messages:13 with st.chat_message(message["role"]):14 st.markdown(message["content"])15 16# Accept user input17if prompt := st.chat_input("What is up?"):18 # Display user message in chat message container19 # with st.chat_message("user"):20 # st.markdown(prompt)21 # Add user message to chat history22 st.session_state.messages.append({"role": "user", "content": prompt})23 24# Display assistant response in chat message container25with st.chat_message("assistant"):26 message_placeholder = st.empty()27 full_response = ""28 assistant_response = generate_response(str(prompt))29 # Simulate stream of response with milliseconds delay30 for chunk in assistant_response.split():31 full_response += chunk + " "32 time.sleep(0.05)33 # Add a blinking cursor to simulate typing34 message_placeholder.markdown(full_response + "")35 message_placeholder.markdown(full_response)36# Add assistant response to chat history37st.session_state.messages.append({"role": "assistant", "content": full_response})