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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -16
app.py CHANGED
@@ -147,27 +147,40 @@ for message in st.session_state.chat_history:
147
  st.markdown("</div>", unsafe_allow_html=True)
148
 
149
  # --- Input & Button Handling ---
150
- user_input = st.text_area("Type your message:", height=100)
 
 
 
 
 
 
 
 
 
 
151
 
152
- send_button_placeholder = st.empty()
 
153
 
154
- if not st.session_state.response_ready:
155
- if send_button_placeholder.button("Send"):
156
- if user_input:
157
- response, follow_up, st.session_state.chat_history, image_url = get_response(
158
- system_message="You are a helpful AI assistant.",
159
- user_text=user_input,
160
- chat_history=st.session_state.chat_history
161
- )
162
 
163
- st.markdown(f"<div class='assistant-msg'><strong>HAL:</strong> {response}</div>", unsafe_allow_html=True)
 
 
164
 
165
- if image_url:
166
- st.image(image_url, caption="NASA Image of the Day")
 
 
 
 
 
 
 
167
 
168
- # Store follow-up question
169
- st.session_state.follow_up = follow_up
170
- st.session_state.response_ready = True # Hide Send button after response
171
 
172
  # Conversational Follow-up
173
  if st.session_state.response_ready and st.session_state.follow_up:
 
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,
157
+ chat_history=st.session_state.chat_history
158
+ )
159
+
160
+ st.markdown(f"<div class='assistant-msg'><strong>HAL:</strong> {response}</div>", unsafe_allow_html=True)
161
 
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)
171
 
172
+ next_input = st.chat_input("HAL is waiting for your response...") # Uses Enter to send
173
+
174
+ if next_input:
175
+ response, _, st.session_state.chat_history, _ = get_response(
176
+ system_message="You are a helpful AI assistant.",
177
+ user_text=next_input,
178
+ chat_history=st.session_state.chat_history
179
+ )
180
+ st.markdown(f"<div class='assistant-msg'><strong>HAL:</strong> {response}</div>", unsafe_allow_html=True)
181
 
182
+ st.session_state.response_ready = False
183
+ st.session_state.follow_up = ""
 
184
 
185
  # Conversational Follow-up
186
  if st.session_state.response_ready and st.session_state.follow_up: