CCockrum commited on
Commit
b54b055
Β·
verified Β·
1 Parent(s): 792148f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -12
app.py CHANGED
@@ -211,34 +211,31 @@ user_input = st.chat_input("Type your message here...") # Make sure this is exe
211
 
212
 
213
  # βœ… Chat UI
214
- if user_input:
215
 
216
- st.session_state.chat_history.append({'role': 'user', 'content': user_input})
 
217
  response, follow_up, st.session_state.chat_history, image_url = get_response(
218
  system_message="You are a helpful AI assistant.",
219
  user_text=user_input,
220
  chat_history=st.session_state.chat_history
221
  )
222
 
 
 
 
223
 
224
- # βœ… Save AI response to chat history
225
- st.session_state.chat_history.append({'role': 'assistant', 'content': response})
226
-
227
- # βœ… Ensure response is displayed
228
- if response:
229
- st.markdown(f"<div class='assistant-msg'><strong>HAL:</strong> {response}</div>", unsafe_allow_html=True)
230
 
231
- # βœ… Save and display follow-up question separately
232
  if follow_up:
233
- st.session_state.chat_history.append({'role': 'assistant', 'content': follow_up})
234
  st.markdown(f"<div class='assistant-msg'><strong>HAL:</strong> {follow_up}</div>", unsafe_allow_html=True)
235
 
236
  # βœ… Display NASA image if available
237
  if image_url:
238
  st.image(image_url, caption="NASA Image of the Day")
239
 
240
- st.session_state.response_ready = True
241
-
242
 
243
  # βœ… Check before displaying follow-up message
244
  if st.session_state.response_ready and st.session_state.follow_up:
 
211
 
212
 
213
  # βœ… Chat UI
214
+ user_input = st.chat_input("Type your message here...")
215
 
216
+ if user_input:
217
+ # βœ… Ensure get_response() returns a response
218
  response, follow_up, st.session_state.chat_history, image_url = get_response(
219
  system_message="You are a helpful AI assistant.",
220
  user_text=user_input,
221
  chat_history=st.session_state.chat_history
222
  )
223
 
224
+ # βœ… Set default value if `response` is missing
225
+ if not response:
226
+ response = "I'm sorry, but I couldn't generate a response."
227
 
228
+ # βœ… Display chatbot response
229
+ st.markdown(f"<div class='assistant-msg'><strong>HAL:</strong> {response}</div>", unsafe_allow_html=True)
 
 
 
 
230
 
231
+ # βœ… Handle follow-up question
232
  if follow_up:
 
233
  st.markdown(f"<div class='assistant-msg'><strong>HAL:</strong> {follow_up}</div>", unsafe_allow_html=True)
234
 
235
  # βœ… Display NASA image if available
236
  if image_url:
237
  st.image(image_url, caption="NASA Image of the Day")
238
 
 
 
239
 
240
  # βœ… Check before displaying follow-up message
241
  if st.session_state.response_ready and st.session_state.follow_up: