Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -95,13 +95,12 @@ 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 calculate_score(
|
| 99 |
-
print(f"Received
|
| 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 |
-
|
| 104 |
-
user_answer_list = [answer for answer in user_answers if answer is not None]
|
| 105 |
correct_answers = [item.correct_answer for item in quiz_data.items[:10]]
|
| 106 |
print(f"User answers: {user_answer_list}") # Debug print
|
| 107 |
print(f"Correct answers: {correct_answers}") # Debug print
|
|
@@ -158,16 +157,16 @@ with gr.Blocks(title="Quiz Maker", theme=colorful_theme) as QUIZBOT:
|
|
| 158 |
outputs=question_radios + [quiz_msg]
|
| 159 |
)
|
| 160 |
|
| 161 |
-
# Register the click event for Check Score with explicit input
|
| 162 |
check_score_btn.click(
|
| 163 |
fn=calculate_score,
|
| 164 |
-
inputs=
|
| 165 |
outputs=[score_output],
|
| 166 |
api_name="check_score"
|
| 167 |
)
|
| 168 |
|
| 169 |
if __name__ == "__main__":
|
| 170 |
-
QUIZBOT.queue().launch(server_name="0.0.0.0", server_port=7860)# import gradio as gr
|
| 171 |
# from pathlib import Path
|
| 172 |
# from sentence_transformers import CrossEncoder
|
| 173 |
# import numpy as np
|
|
|
|
| 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 calculate_score(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 |
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
|
| 106 |
print(f"Correct answers: {correct_answers}") # Debug print
|
|
|
|
| 157 |
outputs=question_radios + [quiz_msg]
|
| 158 |
)
|
| 159 |
|
| 160 |
+
# Register the click event for Check Score with explicit input mapping
|
| 161 |
check_score_btn.click(
|
| 162 |
fn=calculate_score,
|
| 163 |
+
inputs=question_radios + [quiz_data_state], # Pass all radio values and quiz_data_state
|
| 164 |
outputs=[score_output],
|
| 165 |
api_name="check_score"
|
| 166 |
)
|
| 167 |
|
| 168 |
if __name__ == "__main__":
|
| 169 |
+
QUIZBOT.queue().launch(server_name="0.0.0.0", server_port=7860))# import gradio as gr
|
| 170 |
# from pathlib import Path
|
| 171 |
# from sentence_transformers import CrossEncoder
|
| 172 |
# import numpy as np
|