CCockrum commited on
Commit
b998175
·
verified ·
1 Parent(s): 2ed2d41

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -146,11 +146,10 @@ for message in st.session_state.chat_history:
146
  st.markdown(f"<div class='assistant-msg'><strong>HAL:</strong> {message['content']}</div>", unsafe_allow_html=True)
147
  st.markdown("</div>", unsafe_allow_html=True)
148
 
149
- # --- Input & Button Handling ---
150
- # --- Input Handling with "Enter to Send" ---
151
- user_input = st.chat_input("Type your message here...") # Removes "Send" button
152
 
153
- if user_input and not st.session_state.response_ready:
154
  response, follow_up, st.session_state.chat_history, image_url = get_response(
155
  system_message="You are a helpful AI assistant.",
156
  user_text=user_input,
@@ -162,9 +161,18 @@ if user_input and not st.session_state.response_ready:
162
  if image_url:
163
  st.image(image_url, caption="NASA Image of the Day")
164
 
 
165
  st.session_state.follow_up = follow_up
166
  st.session_state.response_ready = True # Ensures response cycle continues
167
 
 
 
 
 
 
 
 
 
168
  # Conversational Follow-up with "Enter to Send"
169
  if st.session_state.response_ready and st.session_state.follow_up:
170
  st.markdown(f"<div class='assistant-msg'><strong>HAL:</strong> {st.session_state.follow_up}</div>", unsafe_allow_html=True)
 
146
  st.markdown(f"<div class='assistant-msg'><strong>HAL:</strong> {message['content']}</div>", unsafe_allow_html=True)
147
  st.markdown("</div>", unsafe_allow_html=True)
148
 
149
+ # --- Single Input Box for Both Initial and Follow-Up Messages ---
150
+ user_input = st.chat_input("Type your message here...") # Single input box
 
151
 
152
+ if user_input:
153
  response, follow_up, st.session_state.chat_history, image_url = get_response(
154
  system_message="You are a helpful AI assistant.",
155
  user_text=user_input,
 
161
  if image_url:
162
  st.image(image_url, caption="NASA Image of the Day")
163
 
164
+ # Store follow-up question in session state
165
  st.session_state.follow_up = follow_up
166
  st.session_state.response_ready = True # Ensures response cycle continues
167
 
168
+ # Display follow-up question inside chat if available
169
+ if st.session_state.response_ready and st.session_state.follow_up:
170
+ st.markdown(f"<div class='assistant-msg'><strong>HAL:</strong> {st.session_state.follow_up}</div>", unsafe_allow_html=True)
171
+
172
+ # Reset response state so user can type next input
173
+ st.session_state.response_ready = False
174
+
175
+
176
  # Conversational Follow-up with "Enter to Send"
177
  if st.session_state.response_ready and st.session_state.follow_up:
178
  st.markdown(f"<div class='assistant-msg'><strong>HAL:</strong> {st.session_state.follow_up}</div>", unsafe_allow_html=True)