aeblymt commited on
Commit
9651f92
·
verified ·
1 Parent(s): 66ace25

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -99,10 +99,12 @@ for message in st.session_state.messages:
99
  role_class = "user-message" if message["role"] == "user" else "bot-message"
100
  st.markdown(f'<div class="{role_class} message-box">{message["content"]}</div>', unsafe_allow_html=True)
101
 
102
- # ✅ User Input
103
- user_input = st.text_input("How can I help you today?", key="input")
 
 
104
 
105
- if st.button("Send") and user_input:
106
  try:
107
  response = client.chat.completions.create(
108
  model="gpt-3.5-turbo",
@@ -117,8 +119,8 @@ if st.button("Send") and user_input:
117
  st.session_state.messages.append({"role": "user", "content": user_input})
118
  st.session_state.messages.append({"role": "bot", "content": bot_reply})
119
 
120
- # Refresh the page to display messages
121
- st.experimental_rerun()
122
 
123
  except Exception as e:
124
  st.error(f"Error: {str(e)}")
 
99
  role_class = "user-message" if message["role"] == "user" else "bot-message"
100
  st.markdown(f'<div class="{role_class} message-box">{message["content"]}</div>', unsafe_allow_html=True)
101
 
102
+ # ✅ User Input Form (Allows "Enter" to Send)
103
+ with st.form("chat_form", clear_on_submit=True):
104
+ user_input = st.text_input("How can I help you today?", key="input")
105
+ submit_button = st.form_submit_button("Send")
106
 
107
+ if submit_button and user_input:
108
  try:
109
  response = client.chat.completions.create(
110
  model="gpt-3.5-turbo",
 
119
  st.session_state.messages.append({"role": "user", "content": user_input})
120
  st.session_state.messages.append({"role": "bot", "content": bot_reply})
121
 
122
+ # ✅ Use st.rerun() instead of experimental_rerun
123
+ st.rerun()
124
 
125
  except Exception as e:
126
  st.error(f"Error: {str(e)}")