seansullivan commited on
Commit
75b08cc
·
verified ·
1 Parent(s): 3469934

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -8
app.py CHANGED
@@ -223,24 +223,20 @@ display_conversation()
223
 
224
  # --- Chat Input Form ---
225
  with st.form("chat_form", clear_on_submit=True):
226
- # Use st.text_area for multi-line text input with text wrapping
227
  user_input = st.text_area("Enter your message:", height=150)
228
  submitted = st.form_submit_button("Send")
229
  if submitted and user_input:
230
  st.session_state.chat_history.append(("user", user_input))
231
- st.experimental_rerun()
 
232
 
233
  # --- Generate Assistant Response ---
234
  if st.session_state.chat_history and st.session_state.chat_history[-1][0] == "user":
235
  inputs = {"messages": st.session_state.chat_history}
236
-
237
- # Placeholder for real-time streaming of the response.
238
  response_placeholder = st.empty()
239
  assistant_message = ""
240
 
241
- # Stream the agent's response chunk-by-chunk.
242
  for s in graph.stream(inputs, stream_mode="values"):
243
- # Extract the last message from the messages list.
244
  message = s["messages"][-1]
245
  if isinstance(message, tuple):
246
  role, text = message
@@ -249,6 +245,5 @@ if st.session_state.chat_history and st.session_state.chat_history[-1][0] == "us
249
  assistant_message += text
250
  response_placeholder.markdown(f"**Assistant:** {assistant_message}")
251
 
252
- # Append the complete assistant response to the chat history.
253
  st.session_state.chat_history.append(("assistant", assistant_message))
254
- st.experimental_rerun()
 
223
 
224
  # --- Chat Input Form ---
225
  with st.form("chat_form", clear_on_submit=True):
 
226
  user_input = st.text_area("Enter your message:", height=150)
227
  submitted = st.form_submit_button("Send")
228
  if submitted and user_input:
229
  st.session_state.chat_history.append(("user", user_input))
230
+ # No need to force a rerun—Streamlit re-runs automatically on widget interaction.
231
+
232
 
233
  # --- Generate Assistant Response ---
234
  if st.session_state.chat_history and st.session_state.chat_history[-1][0] == "user":
235
  inputs = {"messages": st.session_state.chat_history}
 
 
236
  response_placeholder = st.empty()
237
  assistant_message = ""
238
 
 
239
  for s in graph.stream(inputs, stream_mode="values"):
 
240
  message = s["messages"][-1]
241
  if isinstance(message, tuple):
242
  role, text = message
 
245
  assistant_message += text
246
  response_placeholder.markdown(f"**Assistant:** {assistant_message}")
247
 
 
248
  st.session_state.chat_history.append(("assistant", assistant_message))
249
+ # No rerun needed here either.