Please create a full chat application that offers a interactive chat in the main screen and has a list of chats on the left
Drop files here
or click to upload
import streamlit as st
import random
import time
# Streamed response emulator
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?",
]
response = random.choice(responses)
for word in response.split():
yield word + " "
time.sleep(0.05)
st.title("Chat Application")
# Sidebar for chat list
with st.sidebar:
st.header("Chat List")
chat_titles = ["Chat 1", "Chat 2", "Chat 3"]
selected_chat = st.selectbox("Select a chat:", chat_titles)
# Initialize chat history
if "messages" not in st.session_state:
st.session_state.messages = []
# Display chat messages from history on app rerun
for message in st.session_state.messages:
with st.chat_message(message["role"]):
st.markdown(message["content"])
# Accept user input
if prompt := st.chat_input("What do you want to say?"):
# Add user message to chat history
st.session_state.messages.append({"role": "user", "content": prompt})
# Display user message in chat message container
with st.chat_message("user"):
st.markdown(prompt)
# Display assistant response in chat message container
with st.chat_message("assistant"):
response = st.write_stream(response_generator())
# Add assistant response to chat history
st.session_state.messages.append({"role": "assistant", "content": response})
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?