Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,7 @@
|
|
1 |
-
'''
|
2 |
-
AWS Exam Simulator v.05
|
3 |
-
Program Developed by Ruslan Magana Vsevolovna
|
4 |
-
The purpose of this program is help to practice the questions of AWS Exams.
|
5 |
-
'''
|
6 |
import gradio as gr
|
7 |
from tool import * # Assuming this module contains your exam data and text-to-speech functionality
|
8 |
from backend1 import *
|
9 |
|
10 |
-
|
11 |
# Global variable to store the currently selected set of exam questions
|
12 |
selected_questions = []
|
13 |
|
@@ -18,18 +12,23 @@ Select an exam from the dropdown menu below and start testing your skills. You c
|
|
18 |
|
19 |
# --- FUNCTION DEFINITIONS ---
|
20 |
|
21 |
-
def start_exam(exam_choice, audio_enabled):
|
22 |
"""Starts the exam by selecting questions, setting up UI."""
|
23 |
global selected_questions
|
24 |
selected_questions = select_exam_vce(exam_choice)
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
26 |
return (
|
27 |
# Hide start screen elements
|
28 |
gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False),
|
29 |
-
gr.update(visible=False),
|
30 |
# Show quiz elements
|
31 |
gr.update(visible=True), question, gr.update(choices=options, visible=True), gr.update(visible=True),
|
32 |
-
gr.update(visible=True), gr.update(visible=True), gr.update(visible=True),
|
33 |
gr.update(visible=True), None # None for the audio stop signal
|
34 |
)
|
35 |
|
@@ -98,8 +97,7 @@ def return_home():
|
|
98 |
return (
|
99 |
# Show start screen elements
|
100 |
gr.update(visible=True), gr.update(visible=True), gr.update(visible=True), gr.update(visible=True),
|
101 |
-
gr.update(visible=True),
|
102 |
-
# Hide quiz elements
|
103 |
gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False),
|
104 |
gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), "", "", gr.update(visible=False), gr.update(visible=False),
|
105 |
gr.update(visible=False) # Hide explain button
|
@@ -109,9 +107,10 @@ with gr.Blocks() as demo:
|
|
109 |
# Home page elements
|
110 |
title = gr.Markdown(value="**AWS Exam Simulator (Quiz)**")
|
111 |
description = gr.Markdown(value=description_str)
|
112 |
-
exam_selector = gr.Dropdown(label="Select an exam", choices=exams, value=
|
113 |
-
audio_checkbox = gr.Checkbox(label="Enable Audio", value=True)
|
114 |
-
|
|
|
115 |
|
116 |
# Quiz elements (initially hidden)
|
117 |
question_state = gr.State(0)
|
@@ -134,7 +133,9 @@ with gr.Blocks() as demo:
|
|
134 |
with gr.Row():
|
135 |
gr.Column([description])
|
136 |
with gr.Row():
|
137 |
-
gr.Column([exam_selector
|
|
|
|
|
138 |
with gr.Row():
|
139 |
gr.Column([start_button])
|
140 |
|
@@ -154,10 +155,17 @@ with gr.Blocks() as demo:
|
|
154 |
with gr.Row():
|
155 |
gr.Column([home_button])
|
156 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
# Connect the start button to start the exam
|
158 |
start_button.click(
|
159 |
fn=start_exam,
|
160 |
-
inputs=[exam_selector, audio_checkbox],
|
161 |
outputs=[
|
162 |
title, description, exam_selector, start_button,
|
163 |
audio_checkbox, # Ensure the checkbox visibility is updated
|
@@ -172,7 +180,7 @@ with gr.Blocks() as demo:
|
|
172 |
next_button.click(fn=handle_next, inputs=[question_state, audio_checkbox], outputs=[question_text, choices, question_state, result_text, question_audio, explanation_text])
|
173 |
prev_button.click(fn=handle_previous, inputs=[question_state, audio_checkbox], outputs=[question_text, choices, question_state, result_text, question_audio, explanation_text])
|
174 |
|
175 |
-
explain_button.click(fn=show_explanation, inputs=[question_state], outputs=[explanation_text, result_text, explanation_text])
|
176 |
|
177 |
home_button.click(fn=return_home, inputs=None, outputs=[
|
178 |
title, description, exam_selector, start_button,
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from tool import * # Assuming this module contains your exam data and text-to-speech functionality
|
3 |
from backend1 import *
|
4 |
|
|
|
5 |
# Global variable to store the currently selected set of exam questions
|
6 |
selected_questions = []
|
7 |
|
|
|
12 |
|
13 |
# --- FUNCTION DEFINITIONS ---
|
14 |
|
15 |
+
def start_exam(exam_choice, start_question, audio_enabled):
|
16 |
"""Starts the exam by selecting questions, setting up UI."""
|
17 |
global selected_questions
|
18 |
selected_questions = select_exam_vce(exam_choice)
|
19 |
+
|
20 |
+
if start_question >= len(selected_questions):
|
21 |
+
start_question = 0 # Default to the first question if the input exceeds available questions
|
22 |
+
|
23 |
+
question, options, audio_path = display_question(start_question, audio_enabled)
|
24 |
+
|
25 |
return (
|
26 |
# Hide start screen elements
|
27 |
gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False),
|
28 |
+
gr.update(visible=False), # Hide the audio_checkbox
|
29 |
# Show quiz elements
|
30 |
gr.update(visible=True), question, gr.update(choices=options, visible=True), gr.update(visible=True),
|
31 |
+
gr.update(visible=True), gr.update(visible=True), gr.update(visible=True), start_question, "", audio_path, gr.update(visible=True),
|
32 |
gr.update(visible=True), None # None for the audio stop signal
|
33 |
)
|
34 |
|
|
|
97 |
return (
|
98 |
# Show start screen elements
|
99 |
gr.update(visible=True), gr.update(visible=True), gr.update(visible=True), gr.update(visible=True),
|
100 |
+
gr.update(visible=True), # Show the audio_checkbox
|
|
|
101 |
gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False),
|
102 |
gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), "", "", gr.update(visible=False), gr.update(visible=False),
|
103 |
gr.update(visible=False) # Hide explain button
|
|
|
107 |
# Home page elements
|
108 |
title = gr.Markdown(value="**AWS Exam Simulator (Quiz)**")
|
109 |
description = gr.Markdown(value=description_str)
|
110 |
+
exam_selector = gr.Dropdown(label="Select an exam", choices=exams, value=None)
|
111 |
+
audio_checkbox = gr.Checkbox(label="Enable Audio", value=True, visible=False)
|
112 |
+
start_question_slider = gr.Slider(minimum=0, maximum=50, step=1, label="Select starting question", visible=False) # Slider for selecting the starting question
|
113 |
+
start_button = gr.Button("Start Exam", visible=False)
|
114 |
|
115 |
# Quiz elements (initially hidden)
|
116 |
question_state = gr.State(0)
|
|
|
133 |
with gr.Row():
|
134 |
gr.Column([description])
|
135 |
with gr.Row():
|
136 |
+
gr.Column([exam_selector])
|
137 |
+
with gr.Row():
|
138 |
+
gr.Column([audio_checkbox, start_question_slider])
|
139 |
with gr.Row():
|
140 |
gr.Column([start_button])
|
141 |
|
|
|
155 |
with gr.Row():
|
156 |
gr.Column([home_button])
|
157 |
|
158 |
+
# Show settings after exam selection
|
159 |
+
def show_settings(exam_choice):
|
160 |
+
return gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
|
161 |
+
|
162 |
+
# Connect exam selection to display settings section
|
163 |
+
exam_selector.change(fn=show_settings, inputs=[exam_selector], outputs=[audio_checkbox, start_question_slider, start_button])
|
164 |
+
|
165 |
# Connect the start button to start the exam
|
166 |
start_button.click(
|
167 |
fn=start_exam,
|
168 |
+
inputs=[exam_selector, start_question_slider, audio_checkbox],
|
169 |
outputs=[
|
170 |
title, description, exam_selector, start_button,
|
171 |
audio_checkbox, # Ensure the checkbox visibility is updated
|
|
|
180 |
next_button.click(fn=handle_next, inputs=[question_state, audio_checkbox], outputs=[question_text, choices, question_state, result_text, question_audio, explanation_text])
|
181 |
prev_button.click(fn=handle_previous, inputs=[question_state, audio_checkbox], outputs=[question_text, choices, question_state, result_text, question_audio, explanation_text])
|
182 |
|
183 |
+
explain_button.click(fn=show_explanation, inputs=[question_state], outputs=[explanation_text, result_text, explanation_text])
|
184 |
|
185 |
home_button.click(fn=return_home, inputs=None, outputs=[
|
186 |
title, description, exam_selector, start_button,
|