CCockrum commited on
Commit
b744871
Β·
verified Β·
1 Parent(s): ea75d1e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -13
app.py CHANGED
@@ -194,30 +194,36 @@ if st.sidebar.button("Reset Chat"):
194
  st.session_state.follow_up = ""
195
 
196
  # βœ… Chat UI
197
- user_input = st.chat_input("Type your message here...")
198
-
199
  if user_input:
200
- # Save user message
201
  st.session_state.chat_history.append({'role': 'user', 'content': user_input})
202
 
203
- # Get AI response (replace with actual function)
204
- response = "This is HAL's response." # Example response
205
- follow_up = "Would you like to explore a related topic?" # Follow-up suggestion
 
 
 
206
 
207
- # Save AI response & follow-up
208
  st.session_state.chat_history.append({'role': 'assistant', 'content': response})
209
- st.session_state.chat_history.append({'role': 'assistant', 'content': follow_up})
210
-
211
- # Store follow-up question separately if needed
212
- st.session_state.follow_up = follow_up
213
 
214
- # βœ… Ensure response is not empty before calling st.markdown()
215
  if response:
216
  st.markdown(f"<div class='assistant-msg'><strong>HAL:</strong> {response}</div>", unsafe_allow_html=True)
217
 
218
- st.session_state.follow_up = follow_up
 
 
 
 
 
 
 
 
219
  st.session_state.response_ready = True
220
 
 
221
  # βœ… Check before displaying follow-up message
222
  if st.session_state.response_ready and st.session_state.follow_up:
223
  st.markdown(f"<div class='assistant-msg'><strong>HAL:</strong> {st.session_state.follow_up}</div>", unsafe_allow_html=True)
 
194
  st.session_state.follow_up = ""
195
 
196
  # βœ… Chat UI
 
 
197
  if user_input:
198
+ # βœ… Save user input to chat history
199
  st.session_state.chat_history.append({'role': 'user', 'content': user_input})
200
 
201
+ # βœ… Invoke the AI model properly
202
+ response, follow_up, st.session_state.chat_history, image_url = get_response(
203
+ system_message="You are a helpful AI assistant.",
204
+ user_text=user_input,
205
+ chat_history=st.session_state.chat_history
206
+ )
207
 
208
+ # βœ… Save AI response to chat history
209
  st.session_state.chat_history.append({'role': 'assistant', 'content': response})
 
 
 
 
210
 
211
+ # βœ… Ensure response is displayed
212
  if response:
213
  st.markdown(f"<div class='assistant-msg'><strong>HAL:</strong> {response}</div>", unsafe_allow_html=True)
214
 
215
+ # βœ… Save and display follow-up question separately
216
+ if follow_up:
217
+ st.session_state.chat_history.append({'role': 'assistant', 'content': follow_up})
218
+ st.markdown(f"<div class='assistant-msg'><strong>HAL:</strong> {follow_up}</div>", unsafe_allow_html=True)
219
+
220
+ # βœ… Display NASA image if available
221
+ if image_url:
222
+ st.image(image_url, caption="NASA Image of the Day")
223
+
224
  st.session_state.response_ready = True
225
 
226
+
227
  # βœ… Check before displaying follow-up message
228
  if st.session_state.response_ready and st.session_state.follow_up:
229
  st.markdown(f"<div class='assistant-msg'><strong>HAL:</strong> {st.session_state.follow_up}</div>", unsafe_allow_html=True)