Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
215 |
|
216 |
-
|
|
|
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 |
-
# β
|
225 |
-
st.
|
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 |
-
# β
|
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:
|