Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
'''
|
2 |
-
AWS Exam Simulator v.03.
|
3 |
Program Developed by Ruslan Magana Vsevolovna
|
4 |
The purpose of this program is help to practice the questions of AWS Exams.
|
5 |
'''
|
@@ -31,18 +31,53 @@ def select_exam_vce(exam_name):
|
|
31 |
print(f"File {file_path} not found.")
|
32 |
return [] # Return an empty list to indicate no questions were found
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
# Global variable to store selected questions
|
48 |
selected_questions = []
|
@@ -188,11 +223,3 @@ 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")
|
|
|
1 |
'''
|
2 |
+
AWS Exam Simulator v.03.2
|
3 |
Program Developed by Ruslan Magana Vsevolovna
|
4 |
The purpose of this program is help to practice the questions of AWS Exams.
|
5 |
'''
|
|
|
31 |
print(f"File {file_path} not found.")
|
32 |
return [] # Return an empty list to indicate no questions were found
|
33 |
|
34 |
+
import time
|
35 |
+
import httpx
|
36 |
+
# Text-to-speech clients
|
37 |
+
client_1 = Client("ruslanmv/text-to-speech-fast")
|
38 |
+
client_2 = Client("ruslanmv/Text-To-Speech")
|
39 |
+
client_3 = Client("ruslanmv/Text-to-Voice-Transformers")
|
40 |
+
clients = [client_1, client_2, client_3]
|
41 |
+
# Text-to-speech function with rate limiting, retry mechanism, and client rotation
|
42 |
+
def text_to_speech(text, retries=3, delay=5):
|
43 |
+
client_index = 0 # Start with the first client
|
44 |
+
|
45 |
+
for attempt in range(retries):
|
46 |
+
try:
|
47 |
+
client = clients[client_index]
|
48 |
+
print(f"Attempt {attempt + 1}")
|
49 |
+
|
50 |
+
if client_index == 0:
|
51 |
+
result = client.predict(
|
52 |
+
language="English",
|
53 |
+
repo_id="csukuangfj/vits-piper-en_US-hfc_female-medium|1 speaker",
|
54 |
+
text=text,
|
55 |
+
sid="0",
|
56 |
+
speed=0.8,
|
57 |
+
api_name="/process"
|
58 |
+
)
|
59 |
+
else:
|
60 |
+
result = client.predict(
|
61 |
+
text=text,
|
62 |
+
api_name="/predict"
|
63 |
+
)
|
64 |
+
|
65 |
+
return result
|
66 |
+
|
67 |
+
except httpx.HTTPStatusError as e:
|
68 |
+
if e.response.status_code == 429:
|
69 |
+
print(f"Rate limit exceeded. Retrying in {delay} seconds...")
|
70 |
+
client_index = (client_index + 1) % len(clients) # Rotate to the next client
|
71 |
+
time.sleep(delay)
|
72 |
+
else:
|
73 |
+
raise e
|
74 |
+
|
75 |
+
print("Max retries exceeded. Could not process the request.")
|
76 |
+
return None
|
77 |
+
|
78 |
+
|
79 |
+
|
80 |
+
|
81 |
|
82 |
# Global variable to store selected questions
|
83 |
selected_questions = []
|
|
|
223 |
|
224 |
### Notes revision v0.3.1
|
225 |
#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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|