Update app.py
Browse files
app.py
CHANGED
|
@@ -26,25 +26,29 @@ def respond(user_message, history):
|
|
| 26 |
"""
|
| 27 |
user_message = user_message.strip().lower()
|
| 28 |
|
| 29 |
-
# ✅
|
| 30 |
-
if
|
| 31 |
-
response = get_prompt_for_method(user_message)
|
| 32 |
-
history.append((user_message, response))
|
| 33 |
-
return "", history
|
| 34 |
-
|
| 35 |
-
# ✅ If AI expects an explanation, process the response
|
| 36 |
-
elif len(history) > 0 and history[-1][1] in [
|
| 37 |
get_prompt_for_method("bar model"),
|
| 38 |
get_prompt_for_method("double number line"),
|
| 39 |
get_prompt_for_method("equation")
|
| 40 |
]:
|
|
|
|
| 41 |
last_method = history[-1][1].split("**")[1].split(" ")[0].lower()
|
| 42 |
response = get_feedback_for_method(last_method, user_message)
|
| 43 |
history.append((user_message, response))
|
| 44 |
return "", history
|
| 45 |
|
| 46 |
-
# ✅
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
# ✅ Gradio UI Setup
|
| 50 |
with gr.Blocks() as demo:
|
|
|
|
| 26 |
"""
|
| 27 |
user_message = user_message.strip().lower()
|
| 28 |
|
| 29 |
+
# ✅ Check if the last message in history was a method selection prompt
|
| 30 |
+
if history and history[-1][1] in [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
get_prompt_for_method("bar model"),
|
| 32 |
get_prompt_for_method("double number line"),
|
| 33 |
get_prompt_for_method("equation")
|
| 34 |
]:
|
| 35 |
+
# ✅ Retrieve the last selected method
|
| 36 |
last_method = history[-1][1].split("**")[1].split(" ")[0].lower()
|
| 37 |
response = get_feedback_for_method(last_method, user_message)
|
| 38 |
history.append((user_message, response))
|
| 39 |
return "", history
|
| 40 |
|
| 41 |
+
# ✅ If user selects a method, ask them to explain their reasoning
|
| 42 |
+
if user_message in ["bar model", "double number line", "equation"]:
|
| 43 |
+
response = get_prompt_for_method(user_message)
|
| 44 |
+
history.append((user_message, response))
|
| 45 |
+
return "", history
|
| 46 |
+
|
| 47 |
+
# ✅ Default response if input is unclear and no method has been selected
|
| 48 |
+
if not history or history[-1][0] not in ["bar model", "double number line", "equation"]:
|
| 49 |
+
return "I didn’t understand that. Please select a method first (Bar Model, Double Number Line, or Equation).", history
|
| 50 |
+
|
| 51 |
+
return "", history # ✅ Keep the conversation flowing without errors
|
| 52 |
|
| 53 |
# ✅ Gradio UI Setup
|
| 54 |
with gr.Blocks() as demo:
|