Drop files here
or click to upload
import streamlit as st
import random
import time
def response_generator():
responses = [
"Hello there! How can I assist you today?",
"Hi, human! Is there anything I can help you with?",
"Do you need help?",
]
return random.choice(responses)
st.set_page_config(page_title="Simple Chat Bot")
st.title("Simple Chat Bot")
if "messages" not in st.session_state:
st.session_state.messages = []
if "waiting_for_response" not in st.session_state:
st.session_state.waiting_for_response = False
for message in st.session_state.messages:
with st.chat_message(message["role"]):
st.markdown(message["content"])
if prompt := st.chat_input("What is up?", disabled=st.session_state.waiting_for_response) or st.session_state.waiting_for_response:
if not st.session_state.waiting_for_response:
st.session_state.messages.append({"role": "user", "content": prompt})
with st.chat_message("user"):
st.markdown(prompt)
st.session_state.waiting_for_response = True
st.rerun()
else:
with st.spinner("Assistant is typing..."):
time.sleep(1)
response = response_generator()
st.session_state.messages.append({"role": "assistant", "content": response})
with st.chat_message("assistant"):
st.markdown(response)
st.session_state.waiting_for_response = False
st.rerun()
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?