rahul-appu commited on
Commit
3d036ba
·
verified ·
1 Parent(s): 0f258eb

Update worksheet.py

Browse files
Files changed (1) hide show
  1. worksheet.py +196 -194
worksheet.py CHANGED
@@ -1,195 +1,197 @@
1
- import requests
2
- import gradio as gr
3
-
4
- from helper import generate_access_token
5
-
6
- def yes_no(value, array):
7
- if value in array:
8
- return "Yes"
9
- else:
10
- return "No"
11
-
12
- def generate_worksheet(grade, subject, topics, learning_objectives, question_tagging_options,
13
- number_of_questions, easy, medium, hard, remember, understand, apply, analyze,
14
- evaluate, create, mcq_single_answer, mcq_multiple_answer, true_false, fill_in_the_blanks,
15
- match_the_column, very_short_answer, short_answer, long_answer, solution_sheet, format, extras):
16
-
17
- data = {
18
- "institution_id": "inst789",
19
- "teacher_id": "teacher456",
20
- "grade": grade,
21
- "subject": subject,
22
- "topics": topics.split(", "),
23
- "learning_objectives": learning_objectives.split(", "),
24
- "question_tagging_options": {
25
- "Hint": yes_no("Hint", question_tagging_options),
26
- "Curricular_Goal": yes_no("Curricular Goal", question_tagging_options),
27
- "Competency": yes_no("Competency", question_tagging_options),
28
- "LO": yes_no("LO", question_tagging_options),
29
- "LOB": yes_no("LOB", question_tagging_options),
30
- "Difficulty_level": yes_no("Difficulty Level", question_tagging_options),
31
- "Bloom_Taxonomy": yes_no("Bloom Taxonomy", question_tagging_options)
32
- },
33
- "number_of_questions": number_of_questions,
34
- "difficulty_distribution_percentage": {
35
- "easy": easy,
36
- "medium": medium,
37
- "hard": hard
38
- },
39
- "blooms_taxonomy_distribution_percentage": {
40
- "Remember": remember,
41
- "Understand": understand,
42
- "Apply": apply,
43
- "Analyze": analyze,
44
- "Evaluate": evaluate,
45
- "Create": create
46
- },
47
- "question_type_distribution_absolute": {
48
- "MCQ_single_answer": mcq_single_answer,
49
- "MCQ_Multiple_answer": mcq_multiple_answer,
50
- "True_False": true_false,
51
- "Fill_in_the_blanks": fill_in_the_blanks,
52
- "Match_the_column": match_the_column,
53
- "Very_Short_answer": very_short_answer,
54
- "Short_answer": short_answer,
55
- "Long_answer": long_answer
56
- },
57
- "solution_sheet": solution_sheet,
58
- "format": format,
59
- "extras": extras.split(", ")
60
- }
61
-
62
- access_token = generate_access_token()
63
-
64
- if access_token is None:
65
- return {"Error": "Failed to generate access token"}
66
-
67
- response = requests.post("http://20.193.151.200:8080/k12/generate/worksheet",
68
- headers={
69
- "accept": "application/json",
70
- "content-type": "application/json",
71
- "Authorization": f"{access_token}"},
72
- json=data)
73
-
74
- if(str(response.status_code)[0] != '2'):
75
- return {"Error": f"{response.status_code}"}
76
-
77
- return response.json()
78
-
79
- def get_worksheet(request_id):
80
-
81
- access_token = generate_access_token()
82
-
83
- if access_token is None:
84
- return {"Error": "Failed to generate access token"}
85
-
86
- url = f"http://20.193.151.200:8080/k12/generate/worksheet/{request_id}"
87
- headers = {"accept": "application/json",
88
- "Authorization": access_token}
89
-
90
- response = requests.get(url, headers=headers)
91
-
92
- if str(response.status_code)[0] == '2':
93
- return response.json()
94
- else:
95
- return {"Error" : f"{response.status_code}"}
96
-
97
- def post_interface():
98
-
99
- with gr.Blocks() as post_page:
100
-
101
- grade = gr.Textbox(label="Grade", value="8")
102
- subject = gr.Textbox(label="Subject", value="Science")
103
- topics = gr.Textbox(label="Topics (comma-separated)")
104
- learning_objectives = gr.Textbox(label="Learning Objectives (comma-separated)")
105
- question_tagging_options = gr.CheckboxGroup(["Hint", "Curricular Goal", "Competency", "LO", "LOB", "Difficulty Level", "Bloom Taxonomy"], label="Question Tagging Options")
106
- number_of_questions = gr.Number(label="Number of Questions", value=10)
107
-
108
- gr.Markdown("## Difficulty Distribution (easy, medium, hard)")
109
- # Difficulty Distribution (easy, medium, hard)
110
- with gr.Row():
111
- with gr.Column():
112
- easy = gr.Number(label="Easy", minimum=0, maximum=100, value=0)
113
- with gr.Column():
114
- medium = gr.Number(label="Medium", minimum=0, maximum=100, value=0)
115
- with gr.Column():
116
- hard = gr.Number(label="Hard", minimum=0, maximum=100, value=0)
117
-
118
- gr.Markdown("## Bloom Taxonomy Distribution (Remember, Understand, Apply, Analyze, Evaluate, Create)")
119
- # Bloom Taxonomy Distribution (Remember, Understand, Apply, Analyze, Evaluate, Create)
120
- with gr.Row():
121
- with gr.Column():
122
- remember = gr.Number(minimum=0, maximum=100, step=1, label="Remember", value=0)
123
- with gr.Column():
124
- understand = gr.Number(minimum=0, maximum=100, step=1, label="Understand", value=0)
125
- with gr.Column():
126
- apply = gr.Number(minimum=0, maximum=100, step=1, label="Apply", value=0)
127
- with gr.Row():
128
- with gr.Column():
129
- analyze = gr.Number(minimum=0, maximum=100, step=1, label="Analyze", value=0)
130
- with gr.Column():
131
- evaluate = gr.Number(minimum=0, maximum=100, step=1, label="Evaluate", value=0)
132
- with gr.Column():
133
- create = gr.Number(minimum=0, maximum=100, step=1, label="Create", value=0)
134
-
135
- gr.Markdown("## Question Type Distribution (MCQ Single, MCQ Multiple, True/False, Fill in the Blanks, Match the Column, Very Short, Short, Long)")
136
- with gr.Row():
137
- with gr.Column():
138
- mcq_single_answer = gr.Number(minimum=0, maximum=100, step=1, label="MCQ Single Answer", value=0)
139
- with gr.Column():
140
- mcq_multiple_answer = gr.Number(minimum=0, maximum=100, step=1, label="MCQ Multiple Answer", value=0)
141
- with gr.Column():
142
- true_false = gr.Number(minimum=0, maximum=100, step=1, label="True/False", value=0)
143
- with gr.Row():
144
- with gr.Column():
145
- fill_in_the_blanks = gr.Number(minimum=0, maximum=100, step=1, label="Fill in the Blanks", value=0)
146
- with gr.Column():
147
- match_the_column = gr.Number(minimum=0, maximum=100, step=1, label="Match the Column", value=0)
148
- with gr.Column():
149
- very_short_answer = gr.Number(minimum=0, maximum=100, step=1, label="Very Short Answer", value=0)
150
- with gr.Row():
151
- with gr.Column():
152
- short_answer = gr.Number(minimum=0, maximum=100, step=1, label="Short Answer", value=0)
153
- with gr.Column():
154
- long_answer = gr.Number(minimum=0, maximum=100, step=1, label="Long Answer", value=0)
155
-
156
- solution_sheet = gr.Radio(label="Solution Sheet", choices=["Yes", "No"], value="Yes")
157
- format = gr.Textbox(label="Format", value="JSON")
158
- extras = gr.Textbox(label="Extras (comma-separated)")
159
-
160
- submit_button = gr.Button("Invoke Request")
161
-
162
- output = gr.JSON(label="Request Data")
163
-
164
- submit_button.click(
165
- generate_worksheet,
166
- inputs=[grade, subject, topics, learning_objectives, question_tagging_options,
167
- number_of_questions, easy, medium, hard, remember, understand, apply, analyze,
168
- evaluate, create, mcq_single_answer, mcq_multiple_answer, true_false, fill_in_the_blanks,
169
- match_the_column, very_short_answer, short_answer, long_answer, solution_sheet, format, extras],
170
- outputs=output
171
- )
172
-
173
- return post_page
174
-
175
- def get_interface():
176
- with gr.Blocks() as get_page:
177
-
178
- interface = gr.Interface(
179
- fn=get_worksheet,
180
- inputs=gr.Textbox(label="Enter Request ID"),
181
- outputs="json",
182
- )
183
-
184
- return get_page
185
-
186
- def worksheet_generation():
187
- gr.Markdown("# Worksheet Generation")
188
- with gr.Blocks() as worksheet_generation:
189
- with gr.Tabs():
190
- with gr.TabItem("POST"):
191
- post_interface()
192
- with gr.TabItem("GET"):
193
- get_interface()
194
-
 
 
195
  return worksheet_generation
 
1
+ import requests
2
+ import gradio as gr
3
+
4
+ from helper import generate_access_token
5
+
6
+ def yes_no(value, array):
7
+ if value in array:
8
+ return "Yes"
9
+ else:
10
+ return "No"
11
+
12
+ def generate_worksheet(grade, board, subject, topics, learning_objectives, question_tagging_options,
13
+ number_of_questions, easy, medium, hard, remember, understand, apply, analyze,
14
+ evaluate, create, mcq_single_answer, mcq_multiple_answer, true_false, fill_in_the_blanks,
15
+ match_the_column, very_short_answer, short_answer, long_answer, solution_sheet, format, extras):
16
+
17
+ data = {
18
+ "institution_id": "inst789",
19
+ "teacher_id": "teacher456",
20
+ "grade": grade,
21
+ "board": board,
22
+ "subject": subject,
23
+ "topics": topics.split(", "),
24
+ "learning_objectives": learning_objectives.split(", "),
25
+ "question_tagging_options": {
26
+ "Hint": yes_no("Hint", question_tagging_options),
27
+ "Curricular_Goal": yes_no("Curricular Goal", question_tagging_options),
28
+ "Competency": yes_no("Competency", question_tagging_options),
29
+ "LO": yes_no("LO", question_tagging_options),
30
+ "LOB": yes_no("LOB", question_tagging_options),
31
+ "Difficulty_level": yes_no("Difficulty Level", question_tagging_options),
32
+ "Bloom_Taxonomy": yes_no("Bloom Taxonomy", question_tagging_options)
33
+ },
34
+ "number_of_questions": number_of_questions,
35
+ "difficulty_distribution_percentage": {
36
+ "easy": easy,
37
+ "medium": medium,
38
+ "hard": hard
39
+ },
40
+ "blooms_taxonomy_distribution_percentage": {
41
+ "Remember": remember,
42
+ "Understand": understand,
43
+ "Apply": apply,
44
+ "Analyze": analyze,
45
+ "Evaluate": evaluate,
46
+ "Create": create
47
+ },
48
+ "question_type_distribution_absolute": {
49
+ "MCQ_single_answer": mcq_single_answer,
50
+ "MCQ_Multiple_answer": mcq_multiple_answer,
51
+ "True_False": true_false,
52
+ "Fill_in_the_blanks": fill_in_the_blanks,
53
+ "Match_the_column": match_the_column,
54
+ "Very_Short_answer": very_short_answer,
55
+ "Short_answer": short_answer,
56
+ "Long_answer": long_answer
57
+ },
58
+ "solution_sheet": solution_sheet,
59
+ "format": format,
60
+ "extras": extras.split(", ")
61
+ }
62
+
63
+ access_token = generate_access_token()
64
+
65
+ if access_token is None:
66
+ return {"Error": "Failed to generate access token"}
67
+
68
+ response = requests.post("http://20.193.151.200:8080/k12/generate/worksheet",
69
+ headers={
70
+ "accept": "application/json",
71
+ "content-type": "application/json",
72
+ "Authorization": f"{access_token}"},
73
+ json=data)
74
+
75
+ if(str(response.status_code)[0] != '2'):
76
+ return {"Error": f"{response.status_code}"}
77
+
78
+ return response.json()
79
+
80
+ def get_worksheet(request_id):
81
+
82
+ access_token = generate_access_token()
83
+
84
+ if access_token is None:
85
+ return {"Error": "Failed to generate access token"}
86
+
87
+ url = f"http://20.193.151.200:8080/k12/generate/worksheet/{request_id}"
88
+ headers = {"accept": "application/json",
89
+ "Authorization": access_token}
90
+
91
+ response = requests.get(url, headers=headers)
92
+
93
+ if str(response.status_code)[0] == '2':
94
+ return response.json()
95
+ else:
96
+ return {"Error" : f"{response.status_code}"}
97
+
98
+ def post_interface():
99
+
100
+ with gr.Blocks() as post_page:
101
+
102
+ grade = gr.Textbox(label="Grade", value="8")
103
+ board = gr.Textbox(label="Board", value="NCERT")
104
+ subject = gr.Textbox(label="Subject", value="Science")
105
+ topics = gr.Textbox(label="Topics (comma-separated)")
106
+ learning_objectives = gr.Textbox(label="Learning Objectives (comma-separated)")
107
+ question_tagging_options = gr.CheckboxGroup(["Hint", "Curricular Goal", "Competency", "LO", "LOB", "Difficulty Level", "Bloom Taxonomy"], label="Question Tagging Options")
108
+ number_of_questions = gr.Number(label="Number of Questions", value=10)
109
+
110
+ gr.Markdown("## Difficulty Distribution (easy, medium, hard)")
111
+ # Difficulty Distribution (easy, medium, hard)
112
+ with gr.Row():
113
+ with gr.Column():
114
+ easy = gr.Number(label="Easy", minimum=0, maximum=100, value=0)
115
+ with gr.Column():
116
+ medium = gr.Number(label="Medium", minimum=0, maximum=100, value=0)
117
+ with gr.Column():
118
+ hard = gr.Number(label="Hard", minimum=0, maximum=100, value=0)
119
+
120
+ gr.Markdown("## Bloom Taxonomy Distribution (Remember, Understand, Apply, Analyze, Evaluate, Create)")
121
+ # Bloom Taxonomy Distribution (Remember, Understand, Apply, Analyze, Evaluate, Create)
122
+ with gr.Row():
123
+ with gr.Column():
124
+ remember = gr.Number(minimum=0, maximum=100, step=1, label="Remember", value=0)
125
+ with gr.Column():
126
+ understand = gr.Number(minimum=0, maximum=100, step=1, label="Understand", value=0)
127
+ with gr.Column():
128
+ apply = gr.Number(minimum=0, maximum=100, step=1, label="Apply", value=0)
129
+ with gr.Row():
130
+ with gr.Column():
131
+ analyze = gr.Number(minimum=0, maximum=100, step=1, label="Analyze", value=0)
132
+ with gr.Column():
133
+ evaluate = gr.Number(minimum=0, maximum=100, step=1, label="Evaluate", value=0)
134
+ with gr.Column():
135
+ create = gr.Number(minimum=0, maximum=100, step=1, label="Create", value=0)
136
+
137
+ gr.Markdown("## Question Type Distribution (MCQ Single, MCQ Multiple, True/False, Fill in the Blanks, Match the Column, Very Short, Short, Long)")
138
+ with gr.Row():
139
+ with gr.Column():
140
+ mcq_single_answer = gr.Number(minimum=0, maximum=100, step=1, label="MCQ Single Answer", value=0)
141
+ with gr.Column():
142
+ mcq_multiple_answer = gr.Number(minimum=0, maximum=100, step=1, label="MCQ Multiple Answer", value=0)
143
+ with gr.Column():
144
+ true_false = gr.Number(minimum=0, maximum=100, step=1, label="True/False", value=0)
145
+ with gr.Row():
146
+ with gr.Column():
147
+ fill_in_the_blanks = gr.Number(minimum=0, maximum=100, step=1, label="Fill in the Blanks", value=0)
148
+ with gr.Column():
149
+ match_the_column = gr.Number(minimum=0, maximum=100, step=1, label="Match the Column", value=0)
150
+ with gr.Column():
151
+ very_short_answer = gr.Number(minimum=0, maximum=100, step=1, label="Very Short Answer", value=0)
152
+ with gr.Row():
153
+ with gr.Column():
154
+ short_answer = gr.Number(minimum=0, maximum=100, step=1, label="Short Answer", value=0)
155
+ with gr.Column():
156
+ long_answer = gr.Number(minimum=0, maximum=100, step=1, label="Long Answer", value=0)
157
+
158
+ solution_sheet = gr.Radio(label="Solution Sheet", choices=["Yes", "No"], value="Yes")
159
+ format = gr.Textbox(label="Format", value="JSON")
160
+ extras = gr.Textbox(label="Extras (comma-separated)")
161
+
162
+ submit_button = gr.Button("Invoke Request")
163
+
164
+ output = gr.JSON(label="Request Data")
165
+
166
+ submit_button.click(
167
+ generate_worksheet,
168
+ inputs=[grade, board, subject, topics, learning_objectives, question_tagging_options,
169
+ number_of_questions, easy, medium, hard, remember, understand, apply, analyze,
170
+ evaluate, create, mcq_single_answer, mcq_multiple_answer, true_false, fill_in_the_blanks,
171
+ match_the_column, very_short_answer, short_answer, long_answer, solution_sheet, format, extras],
172
+ outputs=output
173
+ )
174
+
175
+ return post_page
176
+
177
+ def get_interface():
178
+ with gr.Blocks() as get_page:
179
+
180
+ interface = gr.Interface(
181
+ fn=get_worksheet,
182
+ inputs=gr.Textbox(label="Enter Request ID"),
183
+ outputs="json",
184
+ )
185
+
186
+ return get_page
187
+
188
+ def worksheet_generation():
189
+ gr.Markdown("# Worksheet Generation")
190
+ with gr.Blocks() as worksheet_generation:
191
+ with gr.Tabs():
192
+ with gr.TabItem("POST"):
193
+ post_interface()
194
+ with gr.TabItem("GET"):
195
+ get_interface()
196
+
197
  return worksheet_generation