Spaces:
Running
Running
johnpaulbin
commited on
Commit
•
650e31e
1
Parent(s):
9679e18
Update app.py
Browse files
app.py
CHANGED
@@ -83,6 +83,17 @@ def handle_answer(answer, mock_index, score, incorrect_questions):
|
|
83 |
|
84 |
return gr.update(), gr.update(visible=False), gr.update(), gr.update(), gr.update(), gr.update(), mock_index, score, incorrect_questions
|
85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
def update_question(mock_index, score, incorrect_questions):
|
87 |
data = load_mocktest()
|
88 |
if mock_index >= len(data):
|
@@ -91,10 +102,6 @@ def update_question(mock_index, score, incorrect_questions):
|
|
91 |
question, ans1, ans2, ans3, ans4, correct = display_mock_question(mock_index, score, incorrect_questions)
|
92 |
return gr.update(value=question), gr.update(value=ans1, visible=True), gr.update(value=ans2, visible=True), gr.update(value=ans3, visible=True), gr.update(value=ans4, visible=True)
|
93 |
|
94 |
-
# Function to restart the test
|
95 |
-
def restart_test():
|
96 |
-
return 0, "", [], *display_mock_question(0, 0, []), gr.update(visible=False), gr.update(visible=True)
|
97 |
-
|
98 |
|
99 |
# Gradio interface
|
100 |
with gr.Blocks() as demo:
|
@@ -158,6 +165,14 @@ with gr.Blocks() as demo:
|
|
158 |
)
|
159 |
|
160 |
# Restart test button
|
161 |
-
restart_button.click(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
|
163 |
demo.launch()
|
|
|
83 |
|
84 |
return gr.update(), gr.update(visible=False), gr.update(), gr.update(), gr.update(), gr.update(), mock_index, score, incorrect_questions
|
85 |
|
86 |
+
def restart_test():
|
87 |
+
mock_index = 0
|
88 |
+
score = 0
|
89 |
+
incorrect_questions = []
|
90 |
+
data = load_mocktest()
|
91 |
+
if data:
|
92 |
+
question, ans1, ans2, ans3, ans4, _ = display_mock_question(mock_index, score, incorrect_questions)
|
93 |
+
return mock_index, score, incorrect_questions, question, ans1, ans2, ans3, ans4, gr.update(visible=False), gr.update(visible=False)
|
94 |
+
else:
|
95 |
+
return mock_index, score, incorrect_questions, "Error loading mock test data", "", "", "", "", gr.update(visible=False), gr.update(visible=False)
|
96 |
+
|
97 |
def update_question(mock_index, score, incorrect_questions):
|
98 |
data = load_mocktest()
|
99 |
if mock_index >= len(data):
|
|
|
102 |
question, ans1, ans2, ans3, ans4, correct = display_mock_question(mock_index, score, incorrect_questions)
|
103 |
return gr.update(value=question), gr.update(value=ans1, visible=True), gr.update(value=ans2, visible=True), gr.update(value=ans3, visible=True), gr.update(value=ans4, visible=True)
|
104 |
|
|
|
|
|
|
|
|
|
105 |
|
106 |
# Gradio interface
|
107 |
with gr.Blocks() as demo:
|
|
|
165 |
)
|
166 |
|
167 |
# Restart test button
|
168 |
+
restart_button.click(
|
169 |
+
restart_test,
|
170 |
+
inputs=[],
|
171 |
+
outputs=[mock_index, score, incorrect_questions, question_output, answer_1, answer_2, answer_3, answer_4, result_output, restart_button]
|
172 |
+
).then(
|
173 |
+
update_question,
|
174 |
+
inputs=[mock_index, score, incorrect_questions],
|
175 |
+
outputs=[question_output, answer_1, answer_2, answer_3, answer_4]
|
176 |
+
)
|
177 |
|
178 |
demo.launch()
|