Update app.py
Browse files
app.py
CHANGED
@@ -17,38 +17,39 @@ if not OPENAI_API_KEY:
|
|
17 |
|
18 |
client = OpenAI(api_key=OPENAI_API_KEY)
|
19 |
|
|
|
|
|
|
|
20 |
# ✅ Chatbot Response Function
|
21 |
def respond(user_message, history):
|
22 |
"""
|
23 |
Handles user input for the chatbot.
|
24 |
-
-
|
25 |
-
- AI
|
|
|
26 |
"""
|
|
|
|
|
27 |
user_message = user_message.strip().lower()
|
28 |
|
29 |
-
# ✅ Check if
|
30 |
-
if
|
31 |
-
|
32 |
-
get_prompt_for_method(
|
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 |
-
# ✅
|
42 |
-
if
|
43 |
-
response =
|
44 |
history.append((user_message, response))
|
45 |
return "", history
|
46 |
|
47 |
-
# ✅
|
48 |
-
if not
|
49 |
return "I didn’t understand that. Please select a method first (Bar Model, Double Number Line, or Equation).", history
|
50 |
|
51 |
-
return "", history # ✅
|
52 |
|
53 |
# ✅ Gradio UI Setup
|
54 |
with gr.Blocks() as demo:
|
|
|
17 |
|
18 |
client = OpenAI(api_key=OPENAI_API_KEY)
|
19 |
|
20 |
+
# ✅ Track the selected method
|
21 |
+
selected_method = None # This will store which method the teacher selects
|
22 |
+
|
23 |
# ✅ Chatbot Response Function
|
24 |
def respond(user_message, history):
|
25 |
"""
|
26 |
Handles user input for the chatbot.
|
27 |
+
- Step 1: Teacher selects a method (Bar Model, Double Number Line, or Equation).
|
28 |
+
- Step 2: AI asks teacher to explain their reasoning before giving guidance.
|
29 |
+
- Step 3: AI listens to teacher's explanation and provides feedback.
|
30 |
"""
|
31 |
+
global selected_method # Store the selected method so AI remembers it
|
32 |
+
|
33 |
user_message = user_message.strip().lower()
|
34 |
|
35 |
+
# ✅ Step 1: Check if user selected a method (but hasn't explained yet)
|
36 |
+
if user_message in ["bar model", "double number line", "equation"]:
|
37 |
+
selected_method = user_message # Store selected method
|
38 |
+
response = get_prompt_for_method(user_message) # Ask for reasoning
|
|
|
|
|
|
|
|
|
|
|
39 |
history.append((user_message, response))
|
40 |
return "", history
|
41 |
|
42 |
+
# ✅ Step 2: If a method was selected, process teacher's explanation
|
43 |
+
if selected_method:
|
44 |
+
response = get_feedback_for_method(selected_method, user_message) # Give feedback
|
45 |
history.append((user_message, response))
|
46 |
return "", history
|
47 |
|
48 |
+
# ✅ If no method is selected yet, ask the user to select one
|
49 |
+
if not selected_method:
|
50 |
return "I didn’t understand that. Please select a method first (Bar Model, Double Number Line, or Equation).", history
|
51 |
|
52 |
+
return "", history # ✅ Maintain conversation flow
|
53 |
|
54 |
# ✅ Gradio UI Setup
|
55 |
with gr.Blocks() as demo:
|