Can someone help me understand why this simple conversational interface won’t work?
import streamlit as st
# Main Streamlit app code
def main():
# Set page title and heading
st.title("Conversational Interface")
st.header("Chat with the Chatbot")
# Initialize variables
user_input = ""
chat_history = []
counter = 1
while user_input.lower() != "bye":
# User input section
user_input = st.text_input(f"User Input {counter}", key=f'{counter}')
if st.button("Submit", key=counter) or st.session_state.get('enter_pressed'):
if user_input:
# Store user input in chat history
chat_history.append(user_input)
# Display chat history
st.subheader("Chat History")
for i, chat in enumerate(chat_history):
st.text(f"Chat {i + 1}: {chat}")
# Clear user input
user_input = ""
counter += 1
st.session_state['enter_pressed'] = False
# Capture the Enter key press
if user_input:
st.session_state['enter_pressed'] = st.session_state.get('enter_pressed', False) or st.session_state.get(
'last_input') != user_input
st.session_state['last_input'] = user_input
# Run the app
if __name__ =
= ‘main’:
main()