Spaces:
Runtime error
Runtime error
Merge branch 'main' of https://huggingface.co/spaces/polyglot-edu/generative-ai-for-ed
Browse files
demo.py
CHANGED
@@ -122,6 +122,8 @@ def generate_exercise(state):
|
|
122 |
except KeyError as e:
|
123 |
raise gr.Error(f"Missing key: {e}")
|
124 |
|
|
|
|
|
125 |
step3 = requests.post(
|
126 |
BASE_URL + "Exercises/GenerateExercise",
|
127 |
headers={"ApiKey": API_KEY, "SetupModel": str(SETUP_MODEL)},
|
@@ -176,7 +178,7 @@ def on_url_change(url, state):
|
|
176 |
state = state | material
|
177 |
state['material_url'] = url
|
178 |
|
179 |
-
lo_component = gr.Dropdown(label="Learning Objective", choices=[], value="placeholder", interactive=
|
180 |
|
181 |
return [gr.Radio(label="Topic", choices=topics, interactive=True), lo_component, state]
|
182 |
|
@@ -332,13 +334,13 @@ with gr.Blocks(title="Educational AI", css=css) as demo:
|
|
332 |
|
333 |
with gr.Column(scale=3):
|
334 |
language_component = gr.Dropdown(languages, label="Exercise Language", value="English")
|
335 |
-
topic_component = gr.Radio(label="Topic", choices=["placeholder"], interactive=
|
336 |
-
lo_component = gr.Dropdown(label="Learning Objective", choices=[], value="placeholder", interactive=
|
337 |
question_type_component = gr.Dropdown(label="Question Type", choices=type_of_exercise, type="index", value=0)
|
338 |
|
339 |
-
correct_answers_component = gr.Number(value=1, minimum=1, maximum=3, step=1, label="Number of correct answers", visible=False)
|
340 |
-
easy_distractors_component = gr.Number(value=1, minimum=0, maximum=8, step=1, label="Number of easy distractors", visible=False)
|
341 |
-
distractors_component = gr.Number(value=1, minimum=0, maximum=8, step=1, label="Number of distractors", visible=False)
|
342 |
|
343 |
generate_btn = gr.Button("Generate Question")
|
344 |
|
@@ -372,9 +374,9 @@ with gr.Blocks(title="Educational AI", css=css) as demo:
|
|
372 |
question_type_component.change(lambda x: make_visible(3, x in [type_of_exercise.index(y) for y in ["Multiple Choice", "Single Choice", "Fill in the Blanks"]]), [question_type_component], [correct_answers_component, easy_distractors_component, distractors_component])
|
373 |
|
374 |
# exercise-specific settings
|
375 |
-
correct_answers_component.change(lambda x, old_state: old_state | {"correctAnswersNumber": x}, [correct_answers_component, state], [state])
|
376 |
-
easy_distractors_component.change(lambda x, old_state: old_state | {"easyDistractorsNumber": x}, [correct_answers_component, state], [state])
|
377 |
-
distractors_component.change(lambda x, old_state: old_state | {"distractorsNumber": x}, [correct_answers_component, state], [state])
|
378 |
|
379 |
# on like/dislike
|
380 |
like_btn.click(like)
|
|
|
122 |
except KeyError as e:
|
123 |
raise gr.Error(f"Missing key: {e}")
|
124 |
|
125 |
+
print(json)
|
126 |
+
|
127 |
step3 = requests.post(
|
128 |
BASE_URL + "Exercises/GenerateExercise",
|
129 |
headers={"ApiKey": API_KEY, "SetupModel": str(SETUP_MODEL)},
|
|
|
178 |
state = state | material
|
179 |
state['material_url'] = url
|
180 |
|
181 |
+
lo_component = gr.Dropdown(label="Learning Objective", choices=[], value="placeholder", interactive=True)
|
182 |
|
183 |
return [gr.Radio(label="Topic", choices=topics, interactive=True), lo_component, state]
|
184 |
|
|
|
334 |
|
335 |
with gr.Column(scale=3):
|
336 |
language_component = gr.Dropdown(languages, label="Exercise Language", value="English")
|
337 |
+
topic_component = gr.Radio(label="Topic", choices=["placeholder"], interactive=True)
|
338 |
+
lo_component = gr.Dropdown(label="Learning Objective", choices=[], value="placeholder", interactive=True)
|
339 |
question_type_component = gr.Dropdown(label="Question Type", choices=type_of_exercise, type="index", value=0)
|
340 |
|
341 |
+
correct_answers_component = gr.Number(value=1, minimum=1, maximum=3, step=1, label="Number of correct answers", visible=False, interactive=True)
|
342 |
+
easy_distractors_component = gr.Number(value=1, minimum=0, maximum=8, step=1, label="Number of easy distractors", visible=False, interactive=True)
|
343 |
+
distractors_component = gr.Number(value=1, minimum=0, maximum=8, step=1, label="Number of distractors", visible=False, interactive=True)
|
344 |
|
345 |
generate_btn = gr.Button("Generate Question")
|
346 |
|
|
|
374 |
question_type_component.change(lambda x: make_visible(3, x in [type_of_exercise.index(y) for y in ["Multiple Choice", "Single Choice", "Fill in the Blanks"]]), [question_type_component], [correct_answers_component, easy_distractors_component, distractors_component])
|
375 |
|
376 |
# exercise-specific settings
|
377 |
+
correct_answers_component.change(lambda x, old_state: old_state | {"correctAnswersNumber": int(x)}, [correct_answers_component, state], [state])
|
378 |
+
easy_distractors_component.change(lambda x, old_state: old_state | {"easyDistractorsNumber": int(x)}, [correct_answers_component, state], [state])
|
379 |
+
distractors_component.change(lambda x, old_state: old_state | {"distractorsNumber": int(x)}, [correct_answers_component, state], [state])
|
380 |
|
381 |
# on like/dislike
|
382 |
like_btn.click(like)
|