Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
# ---
|
150 |
-
user_input = st.
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
|
|
|
|
|
|
|
|
158 |
|
159 |
-
|
160 |
-
st.markdown(f"<div class='assistant-msg'><strong>HAL:</strong> {response}</div>", unsafe_allow_html=True)
|
161 |
|
162 |
-
|
163 |
-
|
164 |
-
st.image(image_url, caption="NASA Image of the Day")
|
165 |
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
|
170 |
-
#
|
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 |
-
|
175 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 = ""
|