Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -84,6 +84,21 @@ def ensure_english(text):
|
|
84 |
return "⚠️ Language detection failed. Please ask your question again."
|
85 |
return text
|
86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
# ✅ Main Response Function
|
88 |
def get_response(system_message, chat_history, user_text, max_new_tokens=512):
|
89 |
action = predict_action(user_text) # 🔥 Fix: Define 'action'
|
|
|
84 |
return "⚠️ Language detection failed. Please ask your question again."
|
85 |
return text
|
86 |
|
87 |
+
# ✅ Ensure Every Response Has a Follow-Up Question
|
88 |
+
def generate_follow_up(user_text):
|
89 |
+
"""Generates a follow-up question to guide the user toward related topics or next steps."""
|
90 |
+
prompt_text = (
|
91 |
+
f"Given the user's question: '{user_text}', generate a SHORT follow-up question "
|
92 |
+
"suggesting either a related topic or asking if they need further help. "
|
93 |
+
"Example: 'Would you like to explore quantum superposition or ask about another physics concept?' "
|
94 |
+
"Keep it concise and engaging."
|
95 |
+
)
|
96 |
+
hf = get_llm_hf_inference(max_new_tokens=40, temperature=0.8)
|
97 |
+
output = hf.invoke(input=prompt_text).strip()
|
98 |
+
|
99 |
+
# Fallback in case of an empty response
|
100 |
+
return output if output else "Would you like to explore another related topic or ask about something else?"
|
101 |
+
|
102 |
# ✅ Main Response Function
|
103 |
def get_response(system_message, chat_history, user_text, max_new_tokens=512):
|
104 |
action = predict_action(user_text) # 🔥 Fix: Define 'action'
|