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")