eagle0504 commited on
Commit
7a2dc35
·
verified ·
1 Parent(s): 439f722

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +7 -6
src/streamlit_app.py CHANGED
@@ -105,22 +105,23 @@ except KeyError as e:
105
  if "messages" not in st.session_state:
106
  st.session_state.messages = []
107
 
108
- # Display chat messages from history on app rerun
109
- for message in st.session_state.messages:
110
- with st.chat_message(message["role"]):
111
- st.markdown(message["content"])
112
-
113
  with st.sidebar:
114
  instruction = st.selectbox(
115
  "What's the task you want this LLM to do?",
116
  ("math", "SQL", "python", "medical"),
117
  )
118
 
119
- # Add clear history button
120
  if st.button("Clear History"):
121
  st.session_state.messages = []
122
  st.rerun()
123
 
 
 
 
 
124
 
125
  # Accept user input
126
  if prompt := st.chat_input("Enter a question based on a selected task."):
 
105
  if "messages" not in st.session_state:
106
  st.session_state.messages = []
107
 
108
+ # 💡 Move this block up so it runs BEFORE chat messages are rendered
109
+ # Handle sidebar early to ensure proper app flow
 
 
 
110
  with st.sidebar:
111
  instruction = st.selectbox(
112
  "What's the task you want this LLM to do?",
113
  ("math", "SQL", "python", "medical"),
114
  )
115
 
116
+ # Handle clear history BEFORE rendering messages
117
  if st.button("Clear History"):
118
  st.session_state.messages = []
119
  st.rerun()
120
 
121
+ # Display chat messages from history on app rerun
122
+ for message in st.session_state.messages:
123
+ with st.chat_message(message["role"]):
124
+ st.markdown(message["content"])
125
 
126
  # Accept user input
127
  if prompt := st.chat_input("Enter a question based on a selected task."):