Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,11 @@
|
|
1 |
'''
|
2 |
-
AWS Exam Simulator v.
|
3 |
Program Developed by Ruslan Magana Vsevolovna
|
4 |
The purpose of this program is help to practice the questions of AWS Exams.
|
5 |
'''
|
6 |
-
|
7 |
import gradio as gr
|
8 |
from gradio_client import Client
|
9 |
import os
|
10 |
-
import re
|
11 |
import json
|
12 |
|
13 |
# Function to load question sets from a directory
|
@@ -22,7 +20,6 @@ def load_question_sets_vce(directory='questions'):
|
|
22 |
exams = load_question_sets_vce('questions/')
|
23 |
print("question_sets:", exams)
|
24 |
|
25 |
-
|
26 |
def select_exam_vce(exam_name):
|
27 |
file_path = os.path.join(os.getcwd(), 'questions', f'{exam_name}.json')
|
28 |
try:
|
@@ -34,13 +31,16 @@ def select_exam_vce(exam_name):
|
|
34 |
print(f"File {file_path} not found.")
|
35 |
return [] # Return an empty list to indicate no questions were found
|
36 |
|
37 |
-
|
38 |
# Text-to-speech function
|
|
|
39 |
def text_to_speech(text):
|
40 |
-
client = Client("ruslanmv/Text-To-Speech")
|
41 |
result = client.predict(
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
44 |
)
|
45 |
return result # result is already the path to the audio file
|
46 |
|
@@ -64,9 +64,7 @@ def display_question(index, audio_enabled):
|
|
64 |
if index < 0 or index >= len(selected_questions):
|
65 |
return "No more questions.", [], None
|
66 |
question_text_ = selected_questions[index]['question']
|
67 |
-
|
68 |
question_text = f"**Question {index + 1}:** {question_text_}" # Numbering added
|
69 |
-
|
70 |
choices_options = selected_questions[index]['options']
|
71 |
audio_path = text_to_speech(question_text_ + " " + " ".join(choices_options)) if audio_enabled else None
|
72 |
return question_text, choices_options, audio_path
|
@@ -111,7 +109,6 @@ def return_home():
|
|
111 |
gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), "", ""
|
112 |
)
|
113 |
|
114 |
-
|
115 |
description_str="""Developed by Ruslan Magana, this interactive quiz platform is designed to help you prepare and assess your knowledge in a variety of exams.
|
116 |
For more information about the developer, please visit [ruslanmv.com](https://ruslanmv.com/).
|
117 |
|
@@ -123,7 +120,7 @@ with gr.Blocks() as demo:
|
|
123 |
# Home page elements
|
124 |
title = gr.Markdown(value="**AWS Exam Simulator (Quiz)**")
|
125 |
description = gr.Markdown(value=description_str)
|
126 |
-
exam_selector = gr.Dropdown(label="Select an exam", choices=exams,value='CLF-C02-v1')
|
127 |
audio_checkbox = gr.Checkbox(label="Enable Audio", value=True)
|
128 |
start_button = gr.Button("Start Exam")
|
129 |
|
@@ -137,7 +134,8 @@ with gr.Blocks() as demo:
|
|
137 |
prev_button = gr.Button("Previous Question", visible=False)
|
138 |
home_button = gr.Button("Return to Home", visible=False)
|
139 |
question_audio = gr.Audio(visible=False, label="Question Audio", autoplay=True)
|
140 |
-
answer_audio = gr.Audio(visible=False,label="Answer Audio",autoplay=True)
|
|
|
141 |
# Layout for the home page
|
142 |
with gr.Row():
|
143 |
gr.Column([title])
|
@@ -187,3 +185,14 @@ with gr.Blocks() as demo:
|
|
187 |
])
|
188 |
|
189 |
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
'''
|
2 |
+
AWS Exam Simulator v.03.1
|
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 gradio_client import Client
|
8 |
import os
|
|
|
9 |
import json
|
10 |
|
11 |
# Function to load question sets from a directory
|
|
|
20 |
exams = load_question_sets_vce('questions/')
|
21 |
print("question_sets:", exams)
|
22 |
|
|
|
23 |
def select_exam_vce(exam_name):
|
24 |
file_path = os.path.join(os.getcwd(), 'questions', f'{exam_name}.json')
|
25 |
try:
|
|
|
31 |
print(f"File {file_path} not found.")
|
32 |
return [] # Return an empty list to indicate no questions were found
|
33 |
|
|
|
34 |
# Text-to-speech function
|
35 |
+
client = Client("ruslanmv/text-to-speech-fast")
|
36 |
def text_to_speech(text):
|
|
|
37 |
result = client.predict(
|
38 |
+
language="English",
|
39 |
+
repo_id="csukuangfj/vits-piper-en_US-hfc_female-medium|1 speaker",
|
40 |
+
text=text,
|
41 |
+
sid="0",
|
42 |
+
speed=0.8,
|
43 |
+
api_name="/process"
|
44 |
)
|
45 |
return result # result is already the path to the audio file
|
46 |
|
|
|
64 |
if index < 0 or index >= len(selected_questions):
|
65 |
return "No more questions.", [], None
|
66 |
question_text_ = selected_questions[index]['question']
|
|
|
67 |
question_text = f"**Question {index + 1}:** {question_text_}" # Numbering added
|
|
|
68 |
choices_options = selected_questions[index]['options']
|
69 |
audio_path = text_to_speech(question_text_ + " " + " ".join(choices_options)) if audio_enabled else None
|
70 |
return question_text, choices_options, audio_path
|
|
|
109 |
gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), "", ""
|
110 |
)
|
111 |
|
|
|
112 |
description_str="""Developed by Ruslan Magana, this interactive quiz platform is designed to help you prepare and assess your knowledge in a variety of exams.
|
113 |
For more information about the developer, please visit [ruslanmv.com](https://ruslanmv.com/).
|
114 |
|
|
|
120 |
# Home page elements
|
121 |
title = gr.Markdown(value="**AWS Exam Simulator (Quiz)**")
|
122 |
description = gr.Markdown(value=description_str)
|
123 |
+
exam_selector = gr.Dropdown(label="Select an exam", choices=exams, value='CLF-C02-v1')
|
124 |
audio_checkbox = gr.Checkbox(label="Enable Audio", value=True)
|
125 |
start_button = gr.Button("Start Exam")
|
126 |
|
|
|
134 |
prev_button = gr.Button("Previous Question", visible=False)
|
135 |
home_button = gr.Button("Return to Home", visible=False)
|
136 |
question_audio = gr.Audio(visible=False, label="Question Audio", autoplay=True)
|
137 |
+
answer_audio = gr.Audio(visible=False, label="Answer Audio", autoplay=True)
|
138 |
+
|
139 |
# Layout for the home page
|
140 |
with gr.Row():
|
141 |
gr.Column([title])
|
|
|
185 |
])
|
186 |
|
187 |
demo.launch()
|
188 |
+
|
189 |
+
### Notes revision v0.3.1
|
190 |
+
#In this revised code, JavaScript is used to stop any currently playing audio when a new audio is about to be played. The _js parameter is added to the click function of the buttons that play audio (answer_button, next_button, and prev_button) to ensure that no multiple audios are played simultaneously
|
191 |
+
#In this revised code we have removed the following apis
|
192 |
+
#client = Client("ruslanmv/Text-To-Speech")
|
193 |
+
#client = Client("ruslanmv/Text-to-Voice-Transformers")
|
194 |
+
#result = client.predict(
|
195 |
+
# text=text,
|
196 |
+
# api_name="/predict"
|
197 |
+
#)
|
198 |
+
# and added client = Client("ruslanmv/text-to-speech-fast")
|