Update app.py
Browse files
app.py
CHANGED
|
@@ -12,6 +12,34 @@ if os.path.exists(".env"):
|
|
| 12 |
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
| 13 |
client = OpenAI(api_key=OPENAI_API_KEY)
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
def gpt_call(history, user_message, model="gpt-4o-mini", max_tokens=1024, temperature=0.7, top_p=0.95):
|
| 16 |
messages = [{"role": "system", "content": MAIN_PROMPT}]
|
| 17 |
|
|
@@ -31,8 +59,24 @@ def respond(user_message, history):
|
|
| 31 |
if not user_message:
|
| 32 |
return "", history
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
assistant_reply = gpt_call(history, user_message)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
history.append((user_message, assistant_reply))
|
|
|
|
|
|
|
| 36 |
return "", history
|
| 37 |
|
| 38 |
with gr.Blocks() as demo:
|
|
|
|
| 12 |
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
| 13 |
client = OpenAI(api_key=OPENAI_API_KEY)
|
| 14 |
|
| 15 |
+
# Define sequential reflection steps
|
| 16 |
+
REFLECTION_STEPS = [
|
| 17 |
+
{
|
| 18 |
+
"question": "Now that you've watched the video, let's start with **Observing Creativity-Directed Practices**.\n\nWhat stood out to you the most about how the teacher encouraged student creativity?",
|
| 19 |
+
"follow_up": "Interesting! You mentioned **{response}**. Why do you think that approach was effective? Can you give an example from the video?"
|
| 20 |
+
},
|
| 21 |
+
{
|
| 22 |
+
"question": "Now, let’s move to **Small Group Interactions**.\n\nWhat did you notice about how the teacher engaged with students in small groups?",
|
| 23 |
+
"follow_up": "You noted **{response}**. How do you think that influenced students' understanding of the problem?"
|
| 24 |
+
},
|
| 25 |
+
{
|
| 26 |
+
"question": "Next, let’s analyze **Student Reasoning and Connections**.\n\nHow did students reason through the task? What connections did they make between percent relationships and fractions?",
|
| 27 |
+
"follow_up": "That’s a great point about **{response}**. Can you explain why this was significant in their problem-solving process?"
|
| 28 |
+
},
|
| 29 |
+
{
|
| 30 |
+
"question": "Now, let’s discuss **Common Core Practice Standards**.\n\nWhich Common Core practice standards do you think the teacher emphasized during the lesson?",
|
| 31 |
+
"follow_up": "You mentioned **{response}**. How do you see this practice supporting students' proportional reasoning?"
|
| 32 |
+
},
|
| 33 |
+
{
|
| 34 |
+
"question": "Finally, let’s engage in a **Problem-Posing Activity**.\n\nBased on what you observed, pose a problem that encourages students to use visuals and proportional reasoning.",
|
| 35 |
+
"follow_up": "That's an interesting problem! Does it allow for multiple solution paths? How does it connect to the Common Core practices we discussed?"
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"question": "📚 **Final Reflection**\n\nWhat’s one change you will make in your own teaching based on this module?",
|
| 39 |
+
"follow_up": "That’s a great insight! How do you think implementing **{response}** will impact student learning?"
|
| 40 |
+
}
|
| 41 |
+
]
|
| 42 |
+
|
| 43 |
def gpt_call(history, user_message, model="gpt-4o-mini", max_tokens=1024, temperature=0.7, top_p=0.95):
|
| 44 |
messages = [{"role": "system", "content": MAIN_PROMPT}]
|
| 45 |
|
|
|
|
| 59 |
if not user_message:
|
| 60 |
return "", history
|
| 61 |
|
| 62 |
+
# Determine current step in reflection process
|
| 63 |
+
reflection_index = len([h for h in history if "Reflection Step" in h[1]])
|
| 64 |
+
if reflection_index < len(REFLECTION_STEPS):
|
| 65 |
+
next_reflection = REFLECTION_STEPS[reflection_index]["question"]
|
| 66 |
+
else:
|
| 67 |
+
next_reflection = "You've completed the reflections. Would you like to discuss anything further?"
|
| 68 |
+
|
| 69 |
assistant_reply = gpt_call(history, user_message)
|
| 70 |
+
|
| 71 |
+
# Adjust AI response to guide sequential discussion
|
| 72 |
+
if reflection_index > 0:
|
| 73 |
+
follow_up_prompt = REFLECTION_STEPS[reflection_index - 1]["follow_up"].format(response=user_message)
|
| 74 |
+
assistant_reply += f"\n\n{follow_up_prompt}"
|
| 75 |
+
|
| 76 |
+
# Append the assistant's response and next reflection question
|
| 77 |
history.append((user_message, assistant_reply))
|
| 78 |
+
history.append(("", f"**Reflection Step {reflection_index + 1}:** {next_reflection}"))
|
| 79 |
+
|
| 80 |
return "", history
|
| 81 |
|
| 82 |
with gr.Blocks() as demo:
|