Spaces:
Runtime error
Runtime error
Update worksheet.py
Browse files- 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 |
-
"
|
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 |
-
gr.
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
with gr.Column():
|
114 |
-
|
115 |
-
with gr.Column():
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
with gr.Column():
|
124 |
-
|
125 |
-
with gr.Column():
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
with gr.Column():
|
131 |
-
|
132 |
-
with gr.Column():
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
with gr.Column():
|
140 |
-
|
141 |
-
with gr.Column():
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
with gr.Column():
|
147 |
-
|
148 |
-
with gr.Column():
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
with gr.Column():
|
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 |
-
with gr.TabItem("
|
193 |
-
|
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
|