Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -95,11 +95,9 @@ def update_quiz_components(quiz_data):
|
|
| 95 |
radio_updates.append(radio_update)
|
| 96 |
return radio_updates + [gr.update(value="Please select answers and click 'Check Score'.", visible=True)]
|
| 97 |
|
| 98 |
-
def
|
| 99 |
print(f"Received radio_values: {radio_values}") # Debug print
|
| 100 |
print(f"Received quiz_data: {quiz_data}") # Debug print
|
| 101 |
-
if not quiz_data or not quiz_data.items:
|
| 102 |
-
return "Please generate a quiz first."
|
| 103 |
user_answer_list = [answer for answer in radio_values if answer is not None]
|
| 104 |
correct_answers = [item.correct_answer for item in quiz_data.items[:10]]
|
| 105 |
print(f"User answers: {user_answer_list}") # Debug print
|
|
@@ -157,10 +155,10 @@ with gr.Blocks(title="Quiz Maker", theme=colorful_theme) as QUIZBOT:
|
|
| 157 |
outputs=question_radios + [quiz_msg]
|
| 158 |
)
|
| 159 |
|
| 160 |
-
# Register the click event for Check Score with explicit
|
| 161 |
check_score_btn.click(
|
| 162 |
-
fn=
|
| 163 |
-
inputs=question_radios + [quiz_data_state], #
|
| 164 |
outputs=[score_output],
|
| 165 |
api_name="check_score"
|
| 166 |
)
|
|
|
|
| 95 |
radio_updates.append(radio_update)
|
| 96 |
return radio_updates + [gr.update(value="Please select answers and click 'Check Score'.", visible=True)]
|
| 97 |
|
| 98 |
+
def collect_answers_and_calculate(*radio_values, quiz_data):
|
| 99 |
print(f"Received radio_values: {radio_values}") # Debug print
|
| 100 |
print(f"Received quiz_data: {quiz_data}") # Debug print
|
|
|
|
|
|
|
| 101 |
user_answer_list = [answer for answer in radio_values if answer is not None]
|
| 102 |
correct_answers = [item.correct_answer for item in quiz_data.items[:10]]
|
| 103 |
print(f"User answers: {user_answer_list}") # Debug print
|
|
|
|
| 155 |
outputs=question_radios + [quiz_msg]
|
| 156 |
)
|
| 157 |
|
| 158 |
+
# Register the click event for Check Score with explicit unpacking
|
| 159 |
check_score_btn.click(
|
| 160 |
+
fn=collect_answers_and_calculate,
|
| 161 |
+
inputs=question_radios + [quiz_data_state], # Unpack 10 radio values + 1 quiz_data
|
| 162 |
outputs=[score_output],
|
| 163 |
api_name="check_score"
|
| 164 |
)
|