CCockrum commited on
Commit
f543f0b
·
verified ·
1 Parent(s): 073538f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -20
app.py CHANGED
@@ -146,30 +146,42 @@ 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
- # --- Single Input Box for Both Initial and Follow-Up Messages ---
150
- user_input = st.chat_input("Type your message here...") # Only ONE chat_input()
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,
156
- chat_history=st.session_state.chat_history
157
- )
 
 
 
 
158
 
159
- # Display HAL's response
160
- st.markdown(f"<div class='assistant-msg'><strong>HAL:</strong> {response}</div>", unsafe_allow_html=True)
161
 
162
- # Display NASA image if available
163
- if image_url:
164
- st.image(image_url, caption="NASA Image of the Day")
165
 
166
- # Store follow-up question in session state
167
- st.session_state.follow_up = follow_up
168
- st.session_state.response_ready = True # Enables follow-up response cycle
169
 
170
- # Display follow-up question inside chat if available
171
  if st.session_state.response_ready and st.session_state.follow_up:
172
  st.markdown(f"<div class='assistant-msg'><strong>HAL:</strong> {st.session_state.follow_up}</div>", unsafe_allow_html=True)
173
 
174
- # Reset response state so user can type next input
175
- st.session_state.response_ready = False
 
 
 
 
 
 
 
 
 
 
 
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
+ 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:
174
  st.markdown(f"<div class='assistant-msg'><strong>HAL:</strong> {st.session_state.follow_up}</div>", unsafe_allow_html=True)
175
 
176
+ next_input = st.text_input("HAL is waiting for your response...")
177
+
178
+ if next_input:
179
+ response, _, st.session_state.chat_history, _ = get_response(
180
+ system_message="You are a helpful AI assistant.",
181
+ user_text=next_input,
182
+ chat_history=st.session_state.chat_history
183
+ )
184
+ st.markdown(f"<div class='assistant-msg'><strong>HAL:</strong> {response}</div>", unsafe_allow_html=True)
185
+
186
+ st.session_state.response_ready = False
187
+ st.session_state.follow_up = ""