Spaces:
Runtime error
Runtime error
Update mcq.py
Browse files
mcq.py
CHANGED
@@ -1,147 +1,150 @@
|
|
1 |
-
import requests
|
2 |
-
import gradio as gr
|
3 |
-
|
4 |
-
from helper import generate_access_token
|
5 |
-
|
6 |
-
def generate_mcq_questions(grade, subject, topics, number_of_questions, multiple_answer, single_answer,
|
7 |
-
easy, medium, hard, remember, understand, apply, analyze, evaluate, create,
|
8 |
-
hint, curricular_goal, competency, lo, lob, difficulty_level, bloom_taxonomy,
|
9 |
-
solution_sheet):
|
10 |
-
|
11 |
-
data = {
|
12 |
-
"institution_id": "string",
|
13 |
-
"teacher_id": "string",
|
14 |
-
"board":
|
15 |
-
"grade": grade,
|
16 |
-
"subject": subject,
|
17 |
-
"topics": topics.split(", "),
|
18 |
-
"number_of_questions": number_of_questions,
|
19 |
-
"question_type_distribution_percentage": {
|
20 |
-
"multiple_answer": multiple_answer,
|
21 |
-
"single_answer": single_answer,
|
22 |
-
},
|
23 |
-
"difficulty_distribution_percentage": {
|
24 |
-
"easy": easy,
|
25 |
-
"medium": medium,
|
26 |
-
"hard": hard
|
27 |
-
},
|
28 |
-
"blooms_taxonomy_distribution_percentage": {
|
29 |
-
"Remember": remember,
|
30 |
-
"Understand": understand,
|
31 |
-
"Apply": apply,
|
32 |
-
"Analyze": analyze,
|
33 |
-
"Evaluate": evaluate,
|
34 |
-
"Create": create
|
35 |
-
},
|
36 |
-
"question_tagging_options": {
|
37 |
-
"Hint": hint,
|
38 |
-
"Curricular_Goal": curricular_goal,
|
39 |
-
"Competency": competency,
|
40 |
-
"LO": lo,
|
41 |
-
"LOB": lob,
|
42 |
-
"Difficulty_level": difficulty_level,
|
43 |
-
"Bloom_Taxonomy": bloom_taxonomy
|
44 |
-
},
|
45 |
-
"solution_sheet": solution_sheet
|
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 |
-
return
|
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 |
return mcq_generation
|
|
|
1 |
+
import requests
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
from helper import generate_access_token
|
5 |
+
|
6 |
+
def generate_mcq_questions(grade, board, subject, topics, number_of_questions, multiple_answer, single_answer,
|
7 |
+
easy, medium, hard, remember, understand, apply, analyze, evaluate, create,
|
8 |
+
hint, curricular_goal, competency, lo, lob, difficulty_level, bloom_taxonomy,
|
9 |
+
solution_sheet):
|
10 |
+
|
11 |
+
data = {
|
12 |
+
"institution_id": "string",
|
13 |
+
"teacher_id": "string",
|
14 |
+
"board": board,
|
15 |
+
"grade": grade,
|
16 |
+
"subject": subject,
|
17 |
+
"topics": topics.split(", "),
|
18 |
+
"number_of_questions": number_of_questions,
|
19 |
+
"question_type_distribution_percentage": {
|
20 |
+
"multiple_answer": multiple_answer,
|
21 |
+
"single_answer": single_answer,
|
22 |
+
},
|
23 |
+
"difficulty_distribution_percentage": {
|
24 |
+
"easy": easy,
|
25 |
+
"medium": medium,
|
26 |
+
"hard": hard
|
27 |
+
},
|
28 |
+
"blooms_taxonomy_distribution_percentage": {
|
29 |
+
"Remember": remember,
|
30 |
+
"Understand": understand,
|
31 |
+
"Apply": apply,
|
32 |
+
"Analyze": analyze,
|
33 |
+
"Evaluate": evaluate,
|
34 |
+
"Create": create
|
35 |
+
},
|
36 |
+
"question_tagging_options": {
|
37 |
+
"Hint": hint,
|
38 |
+
"Curricular_Goal": curricular_goal,
|
39 |
+
"Competency": competency,
|
40 |
+
"LO": lo,
|
41 |
+
"LOB": lob,
|
42 |
+
"Difficulty_level": difficulty_level,
|
43 |
+
"Bloom_Taxonomy": bloom_taxonomy
|
44 |
+
},
|
45 |
+
"solution_sheet": solution_sheet
|
46 |
+
}
|
47 |
+
|
48 |
+
print(data)
|
49 |
+
|
50 |
+
access_token = generate_access_token()
|
51 |
+
|
52 |
+
if access_token is None:
|
53 |
+
return {"Error": "Failed to generate access token"}
|
54 |
+
|
55 |
+
response = requests.post("http://20.193.151.200:8080/v1/k12/generate/mcqs",
|
56 |
+
headers={
|
57 |
+
"accept": "application/json",
|
58 |
+
"content-type": "application/json",
|
59 |
+
"Authorization": f"{access_token}"},
|
60 |
+
json=data)
|
61 |
+
|
62 |
+
if(str(response.status_code)[0] != '2'):
|
63 |
+
return {"Error": f"{response.status_code}"}
|
64 |
+
|
65 |
+
return response.json()
|
66 |
+
|
67 |
+
def get_mcq_questions(request_id):
|
68 |
+
|
69 |
+
access_token = generate_access_token()
|
70 |
+
|
71 |
+
if access_token is None:
|
72 |
+
return {"Error": "Failed to generate access token"}
|
73 |
+
|
74 |
+
url = f"http://20.193.151.200:8080/v1/k12/generate/mcqs/{request_id}"
|
75 |
+
headers = {"accept": "application/json",
|
76 |
+
"Authorization": access_token}
|
77 |
+
|
78 |
+
response = requests.get(url, headers=headers)
|
79 |
+
|
80 |
+
if response.status_code == 200:
|
81 |
+
return response.json()
|
82 |
+
else:
|
83 |
+
return {"Error" : f"{response.status_code}"}
|
84 |
+
|
85 |
+
def post_interface():
|
86 |
+
|
87 |
+
with gr.Blocks() as post_page:
|
88 |
+
grade = gr.Textbox(label="Grade", value="6")
|
89 |
+
board = gr.Textbox(label="Board", value="NCERT")
|
90 |
+
subject = gr.Textbox(label="Subject", value="Science")
|
91 |
+
topics = gr.Textbox(label="Topics (comma-separated)", value="Light")
|
92 |
+
number_of_questions = gr.Number(label="Number of Questions", value=20)
|
93 |
+
|
94 |
+
multiple_answer = gr.Slider(label="Multiple Answer Questions (%)", minimum=0, maximum=100, value=100)
|
95 |
+
single_answer = gr.Slider(label="Single Answer Questions (%)", minimum=0, maximum=100, value=0)
|
96 |
+
|
97 |
+
easy = gr.Slider(label="Easy Questions (%)", minimum=0, maximum=100, value=0)
|
98 |
+
medium = gr.Slider(label="Medium Questions (%)", minimum=0, maximum=100, value=0)
|
99 |
+
hard = gr.Slider(label="Hard Questions (%)", minimum=0, maximum=100, value=0)
|
100 |
+
|
101 |
+
remember = gr.Slider(label="Remember (%)", minimum=0, maximum=100, value=0)
|
102 |
+
understand = gr.Slider(label="Understand (%)", minimum=0, maximum=100, value=0)
|
103 |
+
apply = gr.Slider(label="Apply (%)", minimum=0, maximum=100, value=0)
|
104 |
+
analyze = gr.Slider(label="Analyze (%)", minimum=0, maximum=100, value=0)
|
105 |
+
evaluate = gr.Slider(label="Evaluate (%)", minimum=0, maximum=100, value=0)
|
106 |
+
create = gr.Slider(label="Create (%)", minimum=0, maximum=100, value=0)
|
107 |
+
|
108 |
+
hint = gr.Radio(label="Hint", choices=["Yes", "No"], value="No")
|
109 |
+
curricular_goal = gr.Radio(label="Curricular Goal", choices=["Yes", "No"], value="No")
|
110 |
+
competency = gr.Radio(label="Competency", choices=["Yes", "No"], value="No")
|
111 |
+
lo = gr.Radio(label="LO", choices=["Yes", "No"], value="No")
|
112 |
+
lob = gr.Radio(label="LOB", choices=["Yes", "No"], value="No")
|
113 |
+
difficulty_level = gr.Radio(label="Difficulty Level", choices=["Yes", "No"], value="No")
|
114 |
+
bloom_taxonomy = gr.Radio(label="Bloom Taxonomy", choices=["Yes", "No"], value="No")
|
115 |
+
|
116 |
+
solution_sheet = gr.Radio(label="Solution Sheet", choices=["Yes", "No"], value="Yes")
|
117 |
+
|
118 |
+
submit_button = gr.Button("Invoke Request")
|
119 |
+
|
120 |
+
submit_button.click(generate_mcq_questions,
|
121 |
+
inputs= [grade, board, subject, topics, number_of_questions, multiple_answer, single_answer,
|
122 |
+
easy, medium, hard, remember, understand, apply, analyze, evaluate, create,
|
123 |
+
hint, curricular_goal, competency, lo, lob, difficulty_level, bloom_taxonomy,
|
124 |
+
solution_sheet],
|
125 |
+
outputs=gr.JSON())
|
126 |
+
|
127 |
+
return post_page
|
128 |
+
|
129 |
+
def get_interface():
|
130 |
+
|
131 |
+
with gr.Blocks() as get_page:
|
132 |
+
|
133 |
+
interface = gr.Interface(
|
134 |
+
fn=get_mcq_questions,
|
135 |
+
inputs=gr.Textbox(label="Enter Request ID"),
|
136 |
+
outputs="json",
|
137 |
+
)
|
138 |
+
|
139 |
+
return get_page
|
140 |
+
|
141 |
+
def mcq_generation():
|
142 |
+
gr.Markdown("# MCQ Generation")
|
143 |
+
with gr.Blocks() as mcq_generation:
|
144 |
+
with gr.Tabs():
|
145 |
+
with gr.TabItem("POST"):
|
146 |
+
post_interface()
|
147 |
+
with gr.TabItem("GET"):
|
148 |
+
get_interface()
|
149 |
+
|
150 |
return mcq_generation
|