Spaces:
Sleeping
Sleeping
File size: 2,054 Bytes
654b04a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
import streamlit as st
# Set page config
st.set_page_config(
page_title="Echo Chatbot",
page_icon="🤖",
layout="centered",
initial_sidebar_state="collapsed"
)
# App title and description
st.title("🤖 Echo Chatbot")
st.write("I'm a simple echo bot - I'll repeat everything you say!")
# Initialize chat history
if "messages" not in st.session_state:
st.session_state.messages = []
# Add a welcome message
st.session_state.messages.append({
"role": "assistant",
"content": "Hello! I'm your echo bot. Type something and I'll echo it back to you! 👋"
})
# 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("Type your message here..."):
# Add user message to chat history
st.session_state.messages.append({"role": "user", "content": prompt})
# Display user message
with st.chat_message("user"):
st.markdown(prompt)
# Generate echo response
echo_response = f"You said: '{prompt}'"
# Add assistant response to chat history
st.session_state.messages.append({"role": "assistant", "content": echo_response})
# Display assistant response
with st.chat_message("assistant"):
st.markdown(echo_response)
# Add a sidebar with info
with st.sidebar:
st.header("ℹ️ About")
st.write("This is a simple echo chatbot built with Streamlit.")
st.write("**Features:**")
st.write("- Echoes your messages")
st.write("- Maintains chat history")
st.write("- Clean chat interface")
if st.button("Clear Chat History"):
st.session_state.messages = []
st.session_state.messages.append({
"role": "assistant",
"content": "Hello! I'm your echo bot. Type something and I'll echo it back to you! 👋"
})
st.rerun()
# Footer
st.markdown("---")
st.markdown("Built with ❤️ using Streamlit") |