File size: 8,564 Bytes
3d036ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59a62c3
3d036ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7b92ff2
3d036ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33dff72
3d036ba
 
 
 
 
 
 
 
 
33dff72
3d036ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33dff72
3d036ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e3562c3
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import requests
import gradio as gr

from helper import generate_access_token

def yes_no(value, array):
    if value in array:
        return "Yes"
    else:
        return "No"

def generate_worksheet(grade, board, subject, topics, learning_objectives, question_tagging_options, 
                       number_of_questions, easy, medium, hard, remember, understand, apply, analyze, 
                       evaluate, create, mcq_single_answer, mcq_multiple_answer, true_false, fill_in_the_blanks, 
                       match_the_column, very_short_answer, short_answer, long_answer, solution_sheet, format, extras):
    
    data = {
        "institution_id": "inst789",
        "teacher_id": "teacher456",
        "grade": grade,
        "board": board,
        "subject": subject,
        "topics": topics.split(", "),
        "learning_objectives": learning_objectives.split(", "),
        "question_tagging_options": {
            "Hint": yes_no("Hint", question_tagging_options),
            "Curricular_Goal": yes_no("Curricular Goal", question_tagging_options),
            "Competency": yes_no("Competency", question_tagging_options),
            "LO": yes_no("LO", question_tagging_options),
            "LOB": yes_no("LOB", question_tagging_options),
            "Difficulty_level": yes_no("Difficulty Level", question_tagging_options),
            "Bloom_Taxonomy": yes_no("Bloom Taxonomy", question_tagging_options)
        },
        "number_of_questions": number_of_questions,
        "difficulty_distribution_percentage": {
            "easy": easy,
            "medium": medium,
            "hard": hard
        },
        "blooms_taxonomy_distribution_percentage": {
            "Remember": remember,
            "Understand": understand,
            "Apply": apply,
            "Analyze": analyze,
            "Evaluate": evaluate,
            "Create": create
        },
        "question_type_distribution_absolute": {
            "MCQ_single_answer": mcq_single_answer,
            "MCQ_Multiple_answer": mcq_multiple_answer,
            "True_False": true_false,
            "Fill_in_the_blanks": fill_in_the_blanks,
            "Match_the_column": match_the_column,
            "Very_Short_answer": very_short_answer,
            "Short_answer": short_answer,
            "Long_answer": long_answer
        },
        "solution_sheet": solution_sheet,
        "format": format,
        "extras": extras.split(", ")
    }

    access_token = generate_access_token()

    if access_token is None:
        return {"Error": "Failed to generate access token"}

    response = requests.post("http://20.193.151.200:8080/v1/k12/generate/worksheet", 
                             headers={
                                 "accept": "application/json",
                                 "content-type": "application/json",
                                 "Authorization": f"{access_token}"},
                             json=data)

    if(str(response.status_code)[0] != '2'):
        return {"Error": f"{response.status_code}"}

    return response.json()

def get_worksheet(request_id):

    access_token = generate_access_token()

    if access_token is None:
        return {"Error": "Failed to generate access token"}

    url = f"http://20.193.151.200:8080/v1/k12/generate/worksheet/{request_id}"
    headers = {"accept": "application/json",
               "Authorization": access_token}
    
    response = requests.get(url, headers=headers)
    
    if str(response.status_code)[0] == '2':
        return response.json()
    else:
        return {"Error" : f"{response.status_code}"}

def post_interface():

    with gr.Blocks() as post_page:
  
        grade = gr.Textbox(label="Grade", value="8")
        board = gr.Textbox(label="Board", value="NCERT")
        subject = gr.Textbox(label="Subject", value="Science")
        topics = gr.Textbox(label="Topics (comma-separated)")
        learning_objectives = gr.Textbox(label="Learning Objectives (comma-separated)")
        question_tagging_options = gr.CheckboxGroup(["Hint", "Curricular Goal", "Competency", "LO", "LOB", "Difficulty Level", "Bloom Taxonomy"], label="Question Tagging Options")
        number_of_questions = gr.Number(label="Number of Questions", value=10)
        
        gr.Markdown("## Difficulty Distribution (easy, medium, hard) - Percentage")
        # Difficulty Distribution (easy, medium, hard)
        with gr.Row():
            with gr.Column():
                easy = gr.Number(label="Easy", minimum=0, maximum=100, value=0)
            with gr.Column():
                medium = gr.Number(label="Medium", minimum=0, maximum=100, value=0)
            with gr.Column():
                hard = gr.Number(label="Hard", minimum=0, maximum=100, value=0)

        gr.Markdown("## Bloom Taxonomy Distribution (Remember, Understand, Apply, Analyze, Evaluate, Create) - Percentage")
        # Bloom Taxonomy Distribution (Remember, Understand, Apply, Analyze, Evaluate, Create)
        with gr.Row():
            with gr.Column():
                remember = gr.Number(minimum=0, maximum=100, step=1, label="Remember", value=0)
            with gr.Column():
                understand = gr.Number(minimum=0, maximum=100, step=1, label="Understand", value=0)
            with gr.Column():
                apply = gr.Number(minimum=0, maximum=100, step=1, label="Apply", value=0)
        with gr.Row():    
            with gr.Column():  
                analyze = gr.Number(minimum=0, maximum=100, step=1, label="Analyze", value=0)
            with gr.Column():
                evaluate = gr.Number(minimum=0, maximum=100, step=1, label="Evaluate", value=0)
            with gr.Column():
                create = gr.Number(minimum=0, maximum=100, step=1, label="Create", value=0)

        gr.Markdown("## Question Type Distribution (MCQ Single, MCQ Multiple, True/False, Fill in the Blanks, Match the Column, Very Short, Short, Long) - Absolute")
        with gr.Row():
            with gr.Column():
                mcq_single_answer = gr.Number(minimum=0, maximum=100, step=1, label="MCQ Single Answer", value=0)
            with gr.Column():
                mcq_multiple_answer = gr.Number(minimum=0, maximum=100, step=1, label="MCQ Multiple Answer", value=0)
            with gr.Column():
                true_false = gr.Number(minimum=0, maximum=100, step=1, label="True/False", value=0)
        with gr.Row():
            with gr.Column():
                fill_in_the_blanks = gr.Number(minimum=0, maximum=100, step=1, label="Fill in the Blanks", value=0)
            with gr.Column():
                match_the_column = gr.Number(minimum=0, maximum=100, step=1, label="Match the Column", value=0)
            with gr.Column():
                very_short_answer = gr.Number(minimum=0, maximum=100, step=1, label="Very Short Answer", value=0)
        with gr.Row():
            with gr.Column():
                short_answer = gr.Number(minimum=0, maximum=100, step=1, label="Short Answer", value=0)
            with gr.Column():
                long_answer = gr.Number(minimum=0, maximum=100, step=1, label="Long Answer", value=0)

        solution_sheet = gr.Radio(label="Solution Sheet", choices=["Yes", "No"], value="Yes")       
        format = gr.Textbox(label="Format", value="JSON")
        extras = gr.Textbox(label="Extras (comma-separated)")

        submit_button = gr.Button("Invoke Request")

        output = gr.JSON(label="Request Data")

        submit_button.click(
            generate_worksheet,
            inputs=[grade, board, subject, topics, learning_objectives, question_tagging_options, 
                    number_of_questions, easy, medium, hard, remember, understand, apply, analyze, 
                    evaluate, create, mcq_single_answer, mcq_multiple_answer, true_false, fill_in_the_blanks, 
                    match_the_column, very_short_answer, short_answer, long_answer, solution_sheet, format, extras],
            outputs=output
        )

    return post_page

def get_interface():
    with gr.Blocks() as get_page:

        interface = gr.Interface(
            fn=get_worksheet, 
            inputs=gr.Textbox(label="Enter Request ID"), 
            outputs="json",
        )
        
    return get_page

def worksheet_generation():
    gr.Markdown("# Worksheet Generation")
    with gr.Blocks() as worksheet_generation:
        with gr.Tabs():
            with gr.TabItem("POST"):
                post_interface()
            with gr.TabItem("GET"):
                get_interface()

    return worksheet_generation