Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
201 |
st.session_state.chat_history.append({'role': 'user', 'content': user_input})
|
202 |
|
203 |
-
#
|
204 |
-
response
|
205 |
-
|
|
|
|
|
|
|
206 |
|
207 |
-
# Save AI response
|
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
|
215 |
if response:
|
216 |
st.markdown(f"<div class='assistant-msg'><strong>HAL:</strong> {response}</div>", unsafe_allow_html=True)
|
217 |
|
218 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|