Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -105,10 +105,6 @@ def get_response(system_message, chat_history, user_text, max_new_tokens=256):
|
|
105 |
chat_history.append({'role': 'user', 'content': user_text})
|
106 |
chat_history.append({'role': 'assistant', 'content': response})
|
107 |
|
108 |
-
# β
Removes unnecessary sentiment apology
|
109 |
-
if sentiment == "NEGATIVE":
|
110 |
-
response += "" # Keeps response normal instead of adding "I'm sorry to hear that"
|
111 |
-
|
112 |
follow_up = generate_follow_up(user_text)
|
113 |
chat_history.append({'role': 'assistant', 'content': follow_up})
|
114 |
|
@@ -116,77 +112,4 @@ def get_response(system_message, chat_history, user_text, max_new_tokens=256):
|
|
116 |
|
117 |
# --- Chat UI ---
|
118 |
st.title("π HAL - Your NASA AI Assistant")
|
119 |
-
st
|
120 |
-
|
121 |
-
# Sidebar: Reset Chat
|
122 |
-
if st.sidebar.button("Reset Chat"):
|
123 |
-
st.session_state.chat_history = [{"role": "assistant", "content": "Hello! How can I assist you today?"}]
|
124 |
-
st.session_state.response_ready = False
|
125 |
-
st.session_state.follow_up = ""
|
126 |
-
st.experimental_rerun()
|
127 |
-
|
128 |
-
# Custom Chat Styling
|
129 |
-
st.markdown("""
|
130 |
-
<style>
|
131 |
-
.user-msg {
|
132 |
-
background-color: #0078D7;
|
133 |
-
color: white;
|
134 |
-
padding: 10px;
|
135 |
-
border-radius: 10px;
|
136 |
-
margin-bottom: 5px;
|
137 |
-
width: fit-content;
|
138 |
-
max-width: 80%;
|
139 |
-
}
|
140 |
-
.assistant-msg {
|
141 |
-
background-color: #333333;
|
142 |
-
color: white;
|
143 |
-
padding: 10px;
|
144 |
-
border-radius: 10px;
|
145 |
-
margin-bottom: 5px;
|
146 |
-
width: fit-content;
|
147 |
-
max-width: 80%;
|
148 |
-
}
|
149 |
-
.container {
|
150 |
-
display: flex;
|
151 |
-
flex-direction: column;
|
152 |
-
align-items: flex-start;
|
153 |
-
}
|
154 |
-
@media (max-width: 600px) {
|
155 |
-
.user-msg, .assistant-msg { font-size: 16px; max-width: 100%; }
|
156 |
-
}
|
157 |
-
</style>
|
158 |
-
""", unsafe_allow_html=True)
|
159 |
-
|
160 |
-
# Chat History Display
|
161 |
-
st.markdown("<div class='container'>", unsafe_allow_html=True)
|
162 |
-
for message in st.session_state.chat_history:
|
163 |
-
if message["role"] == "user":
|
164 |
-
st.markdown(f"<div class='user-msg'><strong>You:</strong> {message['content']}</div>", unsafe_allow_html=True)
|
165 |
-
else:
|
166 |
-
st.markdown(f"<div class='assistant-msg'><strong>HAL:</strong> {message['content']}</div>", unsafe_allow_html=True)
|
167 |
-
st.markdown("</div>", unsafe_allow_html=True)
|
168 |
-
|
169 |
-
# --- Single Input Box for Both Initial and Follow-Up Messages ---
|
170 |
-
user_input = st.chat_input("Type your message here...") # Only ONE chat_input()
|
171 |
-
|
172 |
-
if user_input:
|
173 |
-
response, follow_up, st.session_state.chat_history, image_url = get_response(
|
174 |
-
system_message="You are a helpful AI assistant.",
|
175 |
-
user_text=user_input,
|
176 |
-
chat_history=st.session_state.chat_history
|
177 |
-
)
|
178 |
-
|
179 |
-
st.markdown(f"<div class='assistant-msg'><strong>HAL:</strong> {response}</div>", unsafe_allow_html=True)
|
180 |
-
|
181 |
-
if image_url:
|
182 |
-
st.image(image_url, caption="NASA Image of the Day")
|
183 |
-
|
184 |
-
st.session_state.follow_up = follow_up
|
185 |
-
st.session_state.response_ready = True # Enables follow-up response cycle
|
186 |
-
|
187 |
-
# Display follow-up question inside chat if available
|
188 |
-
if st.session_state.response_ready and st.session_state.follow_up:
|
189 |
-
st.markdown(f"<div class='assistant-msg'><strong>HAL:</strong> {st.session_state.follow_up}</div>", unsafe_allow_html=True)
|
190 |
-
|
191 |
-
# Reset response state so user can type next input
|
192 |
-
st.session_state.response_ready = False
|
|
|
105 |
chat_history.append({'role': 'user', 'content': user_text})
|
106 |
chat_history.append({'role': 'assistant', 'content': response})
|
107 |
|
|
|
|
|
|
|
|
|
108 |
follow_up = generate_follow_up(user_text)
|
109 |
chat_history.append({'role': 'assistant', 'content': follow_up})
|
110 |
|
|
|
112 |
|
113 |
# --- Chat UI ---
|
114 |
st.title("π HAL - Your NASA AI Assistant")
|
115 |
+
st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|