Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -106,15 +106,15 @@ def generate_follow_up(user_text):
|
|
| 106 |
|
| 107 |
# β
Main Response Function
|
| 108 |
def get_response(system_message, chat_history, user_text, max_new_tokens=512):
|
| 109 |
-
action = predict_action(user_text)
|
| 110 |
|
| 111 |
# β
Handle NASA-Specific Queries
|
| 112 |
if action == "nasa_info":
|
| 113 |
nasa_url, nasa_title, nasa_explanation = get_nasa_apod()
|
| 114 |
response = f"**{nasa_title}**\n\n{nasa_explanation}"
|
|
|
|
| 115 |
chat_history.append({'role': 'user', 'content': user_text})
|
| 116 |
chat_history.append({'role': 'assistant', 'content': response})
|
| 117 |
-
follow_up = generate_follow_up(user_text)
|
| 118 |
chat_history.append({'role': 'assistant', 'content': follow_up})
|
| 119 |
return response, follow_up, chat_history, nasa_url
|
| 120 |
|
|
@@ -146,10 +146,9 @@ def get_response(system_message, chat_history, user_text, max_new_tokens=512):
|
|
| 146 |
if not response:
|
| 147 |
response = "I'm sorry, but I couldn't generate a response. Can you rephrase your question?"
|
| 148 |
|
|
|
|
| 149 |
chat_history.append({'role': 'user', 'content': user_text})
|
| 150 |
chat_history.append({'role': 'assistant', 'content': response})
|
| 151 |
-
|
| 152 |
-
follow_up = generate_follow_up(user_text)
|
| 153 |
chat_history.append({'role': 'assistant', 'content': follow_up})
|
| 154 |
|
| 155 |
return response, follow_up, chat_history, None
|
|
@@ -210,18 +209,18 @@ if st.sidebar.button("Reset Chat"):
|
|
| 210 |
|
| 211 |
user_input = st.chat_input("Type your message here...") # Make sure this is executed first
|
| 212 |
|
|
|
|
| 213 |
# β
Chat UI
|
| 214 |
if user_input:
|
| 215 |
-
# β
Save user input to chat history
|
| 216 |
-
st.session_state.chat_history.append({'role': 'user', 'content': user_input})
|
| 217 |
|
| 218 |
-
|
| 219 |
response, follow_up, st.session_state.chat_history, image_url = get_response(
|
| 220 |
system_message="You are a helpful AI assistant.",
|
| 221 |
user_text=user_input,
|
| 222 |
chat_history=st.session_state.chat_history
|
| 223 |
)
|
| 224 |
|
|
|
|
| 225 |
# β
Save AI response to chat history
|
| 226 |
st.session_state.chat_history.append({'role': 'assistant', 'content': response})
|
| 227 |
|
|
|
|
| 106 |
|
| 107 |
# β
Main Response Function
|
| 108 |
def get_response(system_message, chat_history, user_text, max_new_tokens=512):
|
| 109 |
+
action = predict_action(user_text)
|
| 110 |
|
| 111 |
# β
Handle NASA-Specific Queries
|
| 112 |
if action == "nasa_info":
|
| 113 |
nasa_url, nasa_title, nasa_explanation = get_nasa_apod()
|
| 114 |
response = f"**{nasa_title}**\n\n{nasa_explanation}"
|
| 115 |
+
follow_up = generate_follow_up(user_text)
|
| 116 |
chat_history.append({'role': 'user', 'content': user_text})
|
| 117 |
chat_history.append({'role': 'assistant', 'content': response})
|
|
|
|
| 118 |
chat_history.append({'role': 'assistant', 'content': follow_up})
|
| 119 |
return response, follow_up, chat_history, nasa_url
|
| 120 |
|
|
|
|
| 146 |
if not response:
|
| 147 |
response = "I'm sorry, but I couldn't generate a response. Can you rephrase your question?"
|
| 148 |
|
| 149 |
+
follow_up = generate_follow_up(user_text)
|
| 150 |
chat_history.append({'role': 'user', 'content': user_text})
|
| 151 |
chat_history.append({'role': 'assistant', 'content': response})
|
|
|
|
|
|
|
| 152 |
chat_history.append({'role': 'assistant', 'content': follow_up})
|
| 153 |
|
| 154 |
return response, follow_up, chat_history, None
|
|
|
|
| 209 |
|
| 210 |
user_input = st.chat_input("Type your message here...") # Make sure this is executed first
|
| 211 |
|
| 212 |
+
|
| 213 |
# β
Chat UI
|
| 214 |
if user_input:
|
|
|
|
|
|
|
| 215 |
|
| 216 |
+
st.session_state.chat_history.append({'role': 'user', 'content': user_input})
|
| 217 |
response, follow_up, st.session_state.chat_history, image_url = get_response(
|
| 218 |
system_message="You are a helpful AI assistant.",
|
| 219 |
user_text=user_input,
|
| 220 |
chat_history=st.session_state.chat_history
|
| 221 |
)
|
| 222 |
|
| 223 |
+
|
| 224 |
# β
Save AI response to chat history
|
| 225 |
st.session_state.chat_history.append({'role': 'assistant', 'content': response})
|
| 226 |
|