Spaces:
Runtime error
Runtime error
Commit
Β·
9fab710
1
Parent(s):
39e0d8c
final changes demo
Browse files
demo.py
CHANGED
@@ -35,7 +35,7 @@ BASE_URL = "https://skapi.polyglot-edu.com/"
|
|
35 |
|
36 |
levels = ["Primary School", "Middle School", "High School", "College", "Academy"]
|
37 |
languages = ["English", "Italian", "French", "German", "Spanish"]
|
38 |
-
type_of_exercise = ["Open Question", "Short Answer Question", "True or False", "Fill in the Blanks", "Single Choice", "Multiple Choice", "Debate", "Essay", "Brainstorming", "
|
39 |
bloom_levels = ["Remembering", "Understanding", "Applying", "Analyzing", "Evaluating", "Creating"]
|
40 |
|
41 |
def like():
|
@@ -65,7 +65,8 @@ def analyze_resource(url):
|
|
65 |
)
|
66 |
|
67 |
if response.status_code != 200:
|
68 |
-
raise gr.Error(f"Failed to analyze resource: {response.text}
|
|
|
69 |
|
70 |
return response.json()
|
71 |
|
@@ -82,7 +83,8 @@ def generate_learning_objective(topic, context, level):
|
|
82 |
)
|
83 |
|
84 |
if response.status_code != 200:
|
85 |
-
raise gr.Error(f"Failed to generate learning objective: {response.text}
|
|
|
86 |
|
87 |
return response.json()
|
88 |
|
@@ -93,7 +95,9 @@ def generate_exercise(state):
|
|
93 |
return key
|
94 |
return None
|
95 |
|
96 |
-
gr.Info(find_key(state["learningObjectiveList"], state['learningObjective']))
|
|
|
|
|
97 |
|
98 |
try:
|
99 |
_json = {
|
@@ -126,7 +130,8 @@ def generate_exercise(state):
|
|
126 |
)
|
127 |
|
128 |
if step3.status_code != 200:
|
129 |
-
raise gr.Error(f"Failed to generate exercise: {step3.text}
|
|
|
130 |
|
131 |
global firebase_current_ref
|
132 |
firebase_current_ref = firebase_data_ref.push({
|
@@ -150,7 +155,7 @@ def format_output(output, exercise_type):
|
|
150 |
return f"""<div class='markdown-body'><h3>Question:</h3><p>{output['Assignment']}</p><h3>Options:</h3><p>{
|
151 |
"<br/>".join(["β
" + x for x in output['Solutions']] + ["β" + x for x in output['Distractors'] + output["EasilyDiscardableDistractors"]])
|
152 |
}</p></div>"""
|
153 |
-
elif type_of_exercise[exercise_type] in ["Debate", "Essay", "Brainstorming", "
|
154 |
return f"<div class='markdown-body'><h3>Assignment:</h3><p>{output['Assignment']}</p></div>"
|
155 |
elif type_of_exercise[exercise_type] in ["Fill in the Blanks"]:
|
156 |
return f"""<div class='markdown-body'><h3>Paragraph:</h3><p>{output['Plus']}</p><h3>Question:</h3><p>{output['Assignment']}</p><h3>Options:</h3><p>{
|
@@ -200,6 +205,7 @@ body, html {
|
|
200 |
}
|
201 |
.row-content {
|
202 |
height: 90vh; /* Full height */
|
|
|
203 |
}
|
204 |
.column-content {
|
205 |
display: flex;
|
@@ -321,7 +327,7 @@ with gr.Blocks(title="Educational AI", css=css) as demo:
|
|
321 |
with gr.Row(elem_classes=["row-content"]):
|
322 |
with gr.Column(scale=3, elem_classes=["column-content"]):
|
323 |
level_component = gr.Dropdown(label="Level", choices=levels, value=levels[-1])
|
324 |
-
url_component = gr.Textbox(label="Input URL", placeholder="Enter URL here...")
|
325 |
iframe_component = gr.HTML("<iframe class='second-row' src='' allowfullscreen></iframe>")
|
326 |
|
327 |
with gr.Column(scale=3):
|
@@ -376,7 +382,6 @@ with gr.Blocks(title="Educational AI", css=css) as demo:
|
|
376 |
|
377 |
|
378 |
# on generate question
|
379 |
-
generate_btn.click(lambda: gr.Info("Generating question..."))
|
380 |
generate_btn.click(generate_exercise, [state], [output_component])
|
381 |
|
382 |
demo.launch(show_api=False)
|
|
|
35 |
|
36 |
levels = ["Primary School", "Middle School", "High School", "College", "Academy"]
|
37 |
languages = ["English", "Italian", "French", "German", "Spanish"]
|
38 |
+
type_of_exercise = ["Open Question", "Short Answer Question", "True or False", "Fill in the Blanks", "Single Choice", "Multiple Choice", "Debate", "Essay", "Brainstorming", "Knowledge Exposition"]
|
39 |
bloom_levels = ["Remembering", "Understanding", "Applying", "Analyzing", "Evaluating", "Creating"]
|
40 |
|
41 |
def like():
|
|
|
65 |
)
|
66 |
|
67 |
if response.status_code != 200:
|
68 |
+
raise gr.Error(f"""Failed to analyze resource: {response.text}
|
69 |
+
Please try again with different parameters""")
|
70 |
|
71 |
return response.json()
|
72 |
|
|
|
83 |
)
|
84 |
|
85 |
if response.status_code != 200:
|
86 |
+
raise gr.Error(f"""Failed to generate learning objective: {response.text}
|
87 |
+
Please try again with different parameters""")
|
88 |
|
89 |
return response.json()
|
90 |
|
|
|
95 |
return key
|
96 |
return None
|
97 |
|
98 |
+
gr.Info(f"Generating exercise with Bloom level: {find_key(state["learningObjectiveList"], state['learningObjective'])}")
|
99 |
+
|
100 |
+
print(state["correctAnswersNumber"], state["distractorsNumber"], state["easyDistractorsNumber"])
|
101 |
|
102 |
try:
|
103 |
_json = {
|
|
|
130 |
)
|
131 |
|
132 |
if step3.status_code != 200:
|
133 |
+
raise gr.Error(f"""Failed to generate exercise: {step3.text}
|
134 |
+
Please try again with different parameters""")
|
135 |
|
136 |
global firebase_current_ref
|
137 |
firebase_current_ref = firebase_data_ref.push({
|
|
|
155 |
return f"""<div class='markdown-body'><h3>Question:</h3><p>{output['Assignment']}</p><h3>Options:</h3><p>{
|
156 |
"<br/>".join(["β
" + x for x in output['Solutions']] + ["β" + x for x in output['Distractors'] + output["EasilyDiscardableDistractors"]])
|
157 |
}</p></div>"""
|
158 |
+
elif type_of_exercise[exercise_type] in ["Debate", "Essay", "Brainstorming", "Knowledge Exposition"]:
|
159 |
return f"<div class='markdown-body'><h3>Assignment:</h3><p>{output['Assignment']}</p></div>"
|
160 |
elif type_of_exercise[exercise_type] in ["Fill in the Blanks"]:
|
161 |
return f"""<div class='markdown-body'><h3>Paragraph:</h3><p>{output['Plus']}</p><h3>Question:</h3><p>{output['Assignment']}</p><h3>Options:</h3><p>{
|
|
|
205 |
}
|
206 |
.row-content {
|
207 |
height: 90vh; /* Full height */
|
208 |
+
overflow: auto; /* Scrollable content */
|
209 |
}
|
210 |
.column-content {
|
211 |
display: flex;
|
|
|
327 |
with gr.Row(elem_classes=["row-content"]):
|
328 |
with gr.Column(scale=3, elem_classes=["column-content"]):
|
329 |
level_component = gr.Dropdown(label="Level", choices=levels, value=levels[-1])
|
330 |
+
url_component = gr.Textbox(label="Input URL - Do not provide pages that are too long (e.g. Wikipedia pages) or too short, as they may not be analyzed correctly", placeholder="Enter URL here...")
|
331 |
iframe_component = gr.HTML("<iframe class='second-row' src='' allowfullscreen></iframe>")
|
332 |
|
333 |
with gr.Column(scale=3):
|
|
|
382 |
|
383 |
|
384 |
# on generate question
|
|
|
385 |
generate_btn.click(generate_exercise, [state], [output_component])
|
386 |
|
387 |
demo.launch(show_api=False)
|