File size: 5,548 Bytes
cf815ef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#teachers_dashboard.py
import gradio as gr
import thinkingframes
from dotenv import load_dotenv
from openai import OpenAI
from database_functions import get_submissions_by_date_and_class, getUniqueSubmitDate, getUniqueClass

load_dotenv()
client = OpenAI()

def validate_password(password):
    correct_password = "Happyteacher2024"
    return password == correct_password

def show_dashboard(password):
    if validate_password(password):
        date_choices = getUniqueSubmitDate()
        class_choices = getUniqueClass()
        return "<p>Dashboard content goes here</p>", gr.update(visible=True), gr.update(visible=False), gr.Dropdown(choices=date_choices, label="Select a date"), gr.Dropdown(choices=class_choices, label="Select a class")
    return "<p>Incorrect password</p>", gr.update(visible=False), gr.update(visible=False), gr.Dropdown(choices='', label="Select a date"), gr.Dropdown(choices='', label="Select a class")

def updateReportByDateAndClass(start_date, end_date, class_name, display_ai_feedback):
    json_output = get_submissions_by_date_and_class(start_date, end_date, class_name, display_ai_feedback)
    chat_history = []
    return json_output, chat_history

def chat_with_json_output(query, json_output, chat_history):
    questions = thinkingframes.questions
    strategies = [strategy[0] for strategy in thinkingframes.strategy_options.values()]
    picture_description = thinkingframes.description

    history_openai_format = [
        {"role": "system", "content": f"Here is the JSON output of the student responses and AI interactions:\n{json_output}"},
        {"role": "user", "content": f"Selected Analysis Prompt: {query}"}
    ]
    for human, assistant in chat_history:
        history_openai_format.append({"role": "user", "content": human})
        history_openai_format.append({"role": "assistant", "content": assistant})
    
    system_prompt = f"""
    You are an English Language Teacher analyzing student responses to oral questions. The questions and strategies used are:

    Questions:
    1. {questions[0]}
    2. {questions[1]}
    3. {questions[2]}

    Strategies:
    1. {strategies[0]}
    2. {strategies[1]}
    3. {strategies[2]}

    Picture Description (relevant only for Question 1):
    {picture_description}

    Based on the provided JSON output and the selected analysis prompt, please perform the following:

    General Analysis:
    - If the selected prompt is "General Analysis: Summarize overall performance and identify patterns":
      - Summarize the overall performance of students for each question, considering the relevant strategies and picture description.
      - Identify notable patterns and trends in student responses and AI feedback.
      - Highlight exemplary responses or feedback that demonstrate effective use of strategies or insightful interpretations.

    Specific Analysis:
    - If the selected prompt is "Specific Analysis: Identify common misconceptions and suggest interventions":
      - Identify common misconceptions or errors in student responses.
      - Suggest targeted interventions to address these misconceptions and improve student understanding.

    - If the selected prompt is "Specific Analysis: Analyze the effectiveness of strategies used":
      - Analyze the effectiveness of each strategy used by students.
      - Provide recommendations for improving the use of strategies and enhancing student performance.

    - If the selected prompt is "Specific Analysis: Compare performance of different student groups":
      - Compare the performance of different student groups (e.g., high performers vs. struggling students).
      - Offer insights and recommendations based on the identified differences and patterns.

    - If the selected prompt is "Specific Analysis: Track individual student progress over time":
      - Track the progress of individual students over time, if data is available.
      - Highlight areas where students have shown improvement or require additional support.

    Completion Rate Analysis:
    - If the selected prompt is "Completion Rate Analysis: Breakdown of questions attempted and insights":
      - Identify the students who have attempted all three questions, two questions, only Question 1, or no questions at all.
      - Calculate the percentage of students in each category.
      - Provide insights on the potential reasons for the completion rates (e.g., difficulty level, student engagement, etc.).
      - Offer recommendations for improving completion rates, such as providing additional support or incentives.

    Please provide the analysis in a clear and organized format, using bullet points, tables, or paragraphs as appropriate. Include specific examples and data-driven insights to support your recommendations. Focus on actionable feedback that can directly impact student learning and engagement.
    """

    history_openai_format.append({"role": "user", "content": system_prompt})
    history_openai_format.append({"role": "user", "content": query})

    response = client.chat.completions.create(
        model='gpt-4o-2024-05-13',
        messages=history_openai_format,
        temperature=0.2,
        max_tokens=1000,
        stream=True
    )

    partial_message = ""
    for chunk in response:
        if chunk.choices[0].delta.content is not None:
            partial_message += chunk.choices[0].delta.content
            yield chat_history + [("Assistant", partial_message)]

    chat_history.append(("Assistant", partial_message))
    return chat_history