Spaces:
Build error
Build error
| import streamlit as st | |
| # Initialize session state for conversation history | |
| if 'conversation' not in st.session_state: | |
| st.session_state['conversation'] = [] | |
| # Function to update conversation | |
| def update_conversation(message): | |
| st.session_state['conversation'].append(message) | |
| # Chat interface | |
| st.title("Streamlit Chat Interface") | |
| # Text input for user message | |
| user_message = st.text_input("Type your message here:") | |
| # On message send | |
| if user_message: | |
| update_conversation(f"You: {user_message}") | |
| # Here you can add your processing (e.g., sending message to a chatbot) | |
| # For demonstration, echoing the user message | |
| bot_response = f"Bot: Echoing '{user_message}'" | |
| update_conversation(bot_response) | |
| # Clear the input box after sending the message | |
| st.session_state['user_message'] = '' | |
| # Display conversation history | |
| for message in st.session_state['conversation']: | |
| st.text(message) | |