Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -90,7 +90,7 @@ def get_response(system_message, chat_history, user_text, max_new_tokens=256):
|
|
90 |
# --- Streamlit UI Setup ---
|
91 |
st.set_page_config(page_title="NASA ChatBot", page_icon="π")
|
92 |
|
93 |
-
st.title("π HAL -
|
94 |
st.markdown("π *Ask me about space, NASA, and beyond!*")
|
95 |
|
96 |
# Ensure chat history is initialized
|
@@ -141,55 +141,13 @@ for message in st.session_state.chat_history:
|
|
141 |
if message["role"] == "user":
|
142 |
st.markdown(f"<div class='user-msg'><strong>You:</strong> {message['content']}</div>", unsafe_allow_html=True)
|
143 |
else:
|
144 |
-
st.markdown(f"<div class='assistant-msg'><strong>
|
145 |
|
146 |
st.markdown("</div>", unsafe_allow_html=True)
|
147 |
|
148 |
# User Input Section
|
149 |
user_input = st.text_area("Type your message:", height=100)
|
150 |
|
151 |
-
# Ensure session state is initialized for response tracking
|
152 |
-
if "response_ready" not in st.session_state:
|
153 |
-
st.session_state.response_ready = False # False until HAL responds
|
154 |
-
|
155 |
-
# Input box for user message
|
156 |
-
user_input = st.text_area("Type your message:", height=100)
|
157 |
-
|
158 |
-
# Create a placeholder for the Send button so it can be removed dynamically
|
159 |
-
send_button_placeholder = st.empty()
|
160 |
-
|
161 |
-
# Only show the Send button if HAL has not responded
|
162 |
-
# Ensure session state is initialized for response tracking
|
163 |
-
if "response_ready" not in st.session_state:
|
164 |
-
st.session_state.response_ready = False # False until HAL responds
|
165 |
-
|
166 |
-
# Input box for user message
|
167 |
-
user_input = st.text_area("Type your message:", height=100)
|
168 |
-
|
169 |
-
# Create a placeholder for the Send button so it can be removed dynamically
|
170 |
-
send_button_placeholder = st.empty()
|
171 |
-
|
172 |
-
# Only show the Send button if HAL has not responded
|
173 |
-
if not st.session_state.response_ready:
|
174 |
-
if send_button_placeholder.button("Send"):
|
175 |
-
if user_input:
|
176 |
-
response, follow_up, st.session_state.chat_history, image_url = get_response(
|
177 |
-
system_message="You are a helpful AI assistant.",
|
178 |
-
user_text=user_input,
|
179 |
-
chat_history=st.session_state.chat_history
|
180 |
-
)
|
181 |
-
|
182 |
-
# Display HAL's response
|
183 |
-
st.markdown(f"<div class='assistant-msg'><strong>HAL:</strong> {response}</div>", unsafe_allow_html=True)
|
184 |
-
|
185 |
-
# Display NASA image if available
|
186 |
-
if image_url:
|
187 |
-
st.image(image_url, caption="NASA Image of the Day")
|
188 |
-
|
189 |
-
# Set response_ready to True so the Send button disappears
|
190 |
-
st.session_state.response_ready = True
|
191 |
-
|
192 |
-
# Show follow-up questions & continue button **only if HAL has responded**
|
193 |
if st.button("Send"):
|
194 |
if user_input:
|
195 |
response, follow_up, st.session_state.chat_history, image_url = get_response(
|
@@ -199,7 +157,7 @@ if st.button("Send"):
|
|
199 |
)
|
200 |
|
201 |
# Display response
|
202 |
-
st.markdown(f"<div class='assistant-msg'><strong>
|
203 |
|
204 |
# Display NASA image if available
|
205 |
if image_url:
|
@@ -216,7 +174,4 @@ if st.button("Send"):
|
|
216 |
user_text=selected_option,
|
217 |
chat_history=st.session_state.chat_history
|
218 |
)
|
219 |
-
st.markdown(f"<div class='assistant-msg'><strong>
|
220 |
-
|
221 |
-
|
222 |
-
|
|
|
90 |
# --- Streamlit UI Setup ---
|
91 |
st.set_page_config(page_title="NASA ChatBot", page_icon="π")
|
92 |
|
93 |
+
st.title("π HAL - Your NASA AI Assistant")
|
94 |
st.markdown("π *Ask me about space, NASA, and beyond!*")
|
95 |
|
96 |
# Ensure chat history is initialized
|
|
|
141 |
if message["role"] == "user":
|
142 |
st.markdown(f"<div class='user-msg'><strong>You:</strong> {message['content']}</div>", unsafe_allow_html=True)
|
143 |
else:
|
144 |
+
st.markdown(f"<div class='assistant-msg'><strong>Bot:</strong> {message['content']}</div>", unsafe_allow_html=True)
|
145 |
|
146 |
st.markdown("</div>", unsafe_allow_html=True)
|
147 |
|
148 |
# User Input Section
|
149 |
user_input = st.text_area("Type your message:", height=100)
|
150 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
if st.button("Send"):
|
152 |
if user_input:
|
153 |
response, follow_up, st.session_state.chat_history, image_url = get_response(
|
|
|
157 |
)
|
158 |
|
159 |
# Display response
|
160 |
+
st.markdown(f"<div class='assistant-msg'><strong>Bot:</strong> {response}</div>", unsafe_allow_html=True)
|
161 |
|
162 |
# Display NASA image if available
|
163 |
if image_url:
|
|
|
174 |
user_text=selected_option,
|
175 |
chat_history=st.session_state.chat_history
|
176 |
)
|
177 |
+
st.markdown(f"<div class='assistant-msg'><strong>Bot:</strong> {response}</div>", unsafe_allow_html=True)
|
|
|
|
|
|