Spaces:
Running
Running
johnpaulbin
commited on
Commit
•
513dc9e
1
Parent(s):
4bfc410
Update app.py
Browse files
app.py
CHANGED
@@ -65,6 +65,7 @@ def display_mock_question(index, score, incorrect_questions):
|
|
65 |
|
66 |
return question, all_answers[0], all_answers[1], all_answers[2], all_answers[3], correct_answer
|
67 |
|
|
|
68 |
def handle_answer(index, answer, score, incorrect_questions):
|
69 |
data = load_mocktest()
|
70 |
correct_answer = data[index]["correct-answer"]
|
@@ -76,17 +77,12 @@ def handle_answer(index, answer, score, incorrect_questions):
|
|
76 |
|
77 |
index += 1
|
78 |
if index >= len(data):
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
else:
|
83 |
-
incorrect_str = "No questions to review."
|
84 |
-
|
85 |
-
return gr.update(visible=False), f"Your score: {score}/{len(data)}\n\n{incorrect_str}", gr.update(visible=True)
|
86 |
|
87 |
question, ans1, ans2, ans3, ans4, correct = display_mock_question(index, score, incorrect_questions)
|
88 |
-
return question, ans1, ans2, ans3, ans4,
|
89 |
-
|
90 |
|
91 |
# Function to restart the test
|
92 |
def restart_test():
|
@@ -129,10 +125,12 @@ with gr.Blocks() as demo:
|
|
129 |
incorrect_questions = gr.State([])
|
130 |
|
131 |
question_output = gr.Markdown(label="Question")
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
|
|
|
|
136 |
|
137 |
result_output = gr.Markdown(visible=False)
|
138 |
restart_button = gr.Button("Restart Test", visible=False)
|
@@ -141,13 +139,14 @@ with gr.Blocks() as demo:
|
|
141 |
demo.load(display_mock_question, inputs=[mock_index, score, incorrect_questions], outputs=[question_output, answer_1, answer_2, answer_3, answer_4])
|
142 |
|
143 |
# Handle answer selection
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
|
|
|
|
148 |
|
149 |
# Restart test button
|
150 |
restart_button.click(restart_test, inputs=[], outputs=[mock_index, score, incorrect_questions, question_output, answer_1, answer_2, answer_3, answer_4, result_output, restart_button])
|
151 |
-
|
152 |
# Launch the app
|
153 |
demo.launch()
|
|
|
65 |
|
66 |
return question, all_answers[0], all_answers[1], all_answers[2], all_answers[3], correct_answer
|
67 |
|
68 |
+
|
69 |
def handle_answer(index, answer, score, incorrect_questions):
|
70 |
data = load_mocktest()
|
71 |
correct_answer = data[index]["correct-answer"]
|
|
|
77 |
|
78 |
index += 1
|
79 |
if index >= len(data):
|
80 |
+
incorrect_str = "Questions to review:\n\n" + "\n\n".join(incorrect_questions) if incorrect_questions else "No questions to review."
|
81 |
+
result = f"Your score: {score}/{len(data)}\n\n{incorrect_str}"
|
82 |
+
return gr.update(visible=False), result, gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), score, incorrect_questions
|
|
|
|
|
|
|
|
|
83 |
|
84 |
question, ans1, ans2, ans3, ans4, correct = display_mock_question(index, score, incorrect_questions)
|
85 |
+
return gr.update(value=question), ans1, ans2, ans3, ans4, gr.update(visible=False), gr.update(visible=False), score, incorrect_questions
|
|
|
86 |
|
87 |
# Function to restart the test
|
88 |
def restart_test():
|
|
|
125 |
incorrect_questions = gr.State([])
|
126 |
|
127 |
question_output = gr.Markdown(label="Question")
|
128 |
+
with gr.Row():
|
129 |
+
answer_1 = gr.Button("Answer 1")
|
130 |
+
answer_2 = gr.Button("Answer 2")
|
131 |
+
with gr.Row():
|
132 |
+
answer_3 = gr.Button("Answer 3")
|
133 |
+
answer_4 = gr.Button("Answer 4")
|
134 |
|
135 |
result_output = gr.Markdown(visible=False)
|
136 |
restart_button = gr.Button("Restart Test", visible=False)
|
|
|
139 |
demo.load(display_mock_question, inputs=[mock_index, score, incorrect_questions], outputs=[question_output, answer_1, answer_2, answer_3, answer_4])
|
140 |
|
141 |
# Handle answer selection
|
142 |
+
for answer_btn in [answer_1, answer_2, answer_3, answer_4]:
|
143 |
+
answer_btn.click(
|
144 |
+
handle_answer,
|
145 |
+
inputs=[mock_index, answer_btn, score, incorrect_questions],
|
146 |
+
outputs=[question_output, answer_1, answer_2, answer_3, answer_4, result_output, restart_button, score, incorrect_questions]
|
147 |
+
)
|
148 |
|
149 |
# Restart test button
|
150 |
restart_button.click(restart_test, inputs=[], outputs=[mock_index, score, incorrect_questions, question_output, answer_1, answer_2, answer_3, answer_4, result_output, restart_button])
|
|
|
151 |
# Launch the app
|
152 |
demo.launch()
|