File size: 7,675 Bytes
1c9c128
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4462439
0f258eb
 
0bc4e32
0f258eb
0bc4e32
1c9c128
0f258eb
 
 
 
4462439
0f258eb
 
 
 
 
 
 
 
1c9c128
0f258eb
 
 
 
 
 
 
4462439
0f258eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1c9c128
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import requests
import gradio as gr

from helper import generate_access_token

def generate_mcq_questions(grade, board, subject, topics, number_of_questions, multiple_answer, single_answer,
                           easy, medium, hard, remember, understand, apply, analyze, evaluate, create,
                           hint, curricular_goal, competency, lo, lob, difficulty_level, bloom_taxonomy,
                           solution_sheet):
        
    data = {
        "institution_id": "string",
        "teacher_id": "string",
        "board": board,
        "grade": grade,
        "subject": subject,
        "topics": topics.split(", "),
        "number_of_questions": number_of_questions,
        "question_type_distribution_percentage": {
            "multiple_answer": multiple_answer,
            "single_answer": single_answer,
        },
        "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_tagging_options": {
            "Hint": hint,
            "Curricular_Goal": curricular_goal,
            "Competency": competency,
            "LO": lo,
            "LOB": lob,
            "Difficulty_level": difficulty_level,
            "Bloom_Taxonomy": bloom_taxonomy
        },
        "solution_sheet": solution_sheet
    }

    print(data)

    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/mcqs", 
                             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_mcq_questions(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/mcqs/{request_id}"
    headers = {"accept": "application/json",
               "Authorization": access_token}
    
    response = requests.get(url, headers=headers)
    
    if response.status_code == 200:
        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="6")
        board = gr.Textbox(label="Board", value="NCERT")
        subject = gr.Textbox(label="Subject", value="Science")
        topics = gr.Textbox(label="Topics (comma-separated)", value="Light")
        number_of_questions = gr.Number(label="Number of Questions", value=20)
        
        gr.Markdown("## Question Type (Multiple Answer, Single Answer) - Absolute")
        with gr.Row():
            with gr.Column():
                multiple_answer = gr.Number(label="Multiple Answer Questions", minimum=0, maximum=100, value=0)
            with gr.Column():
                single_answer = gr.Number(label="Single Answer Questions", minimum=0, maximum=100, value=0)
        
        # easy = gr.Slider(label="Easy Questions (%)", minimum=0, maximum=100, value=0)
        # medium = gr.Slider(label="Medium Questions (%)", minimum=0, maximum=100, value=0)
        # hard = gr.Slider(label="Hard Questions (%)", minimum=0, maximum=100, value=0)

        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)
        
        # remember = gr.Slider(label="Remember (%)", minimum=0, maximum=100, value=0)
        # understand = gr.Slider(label="Understand (%)", minimum=0, maximum=100, value=0)
        # apply = gr.Slider(label="Apply (%)", minimum=0, maximum=100, value=0)
        # analyze = gr.Slider(label="Analyze (%)", minimum=0, maximum=100, value=0)
        # evaluate = gr.Slider(label="Evaluate (%)", minimum=0, maximum=100, value=0)
        # create = gr.Slider(label="Create (%)", 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)
        
        hint = gr.Radio(label="Hint", choices=["Yes", "No"], value="No")
        curricular_goal = gr.Radio(label="Curricular Goal", choices=["Yes", "No"], value="No")
        competency = gr.Radio(label="Competency", choices=["Yes", "No"], value="No")
        lo = gr.Radio(label="LO", choices=["Yes", "No"], value="No")
        lob = gr.Radio(label="LOB", choices=["Yes", "No"], value="No")
        difficulty_level = gr.Radio(label="Difficulty Level", choices=["Yes", "No"], value="No")
        bloom_taxonomy = gr.Radio(label="Bloom Taxonomy", choices=["Yes", "No"], value="No")
        
        solution_sheet = gr.Radio(label="Solution Sheet", choices=["Yes", "No"], value="Yes")
        
        submit_button = gr.Button("Invoke Request")
        
        submit_button.click(generate_mcq_questions, 
                            inputs= [grade, board, subject, topics, number_of_questions, multiple_answer, single_answer,
                            easy, medium, hard, remember, understand, apply, analyze, evaluate, create,
                            hint, curricular_goal, competency, lo, lob, difficulty_level, bloom_taxonomy,
                            solution_sheet],
                            outputs=gr.JSON())
        
    return post_page

def get_interface():

    with gr.Blocks() as get_page:

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

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

    return mcq_generation