Spaces:
Running
Running
Update tool2.py
Browse files
tool2.py
CHANGED
@@ -39,14 +39,14 @@ def display_question(index, audio_enabled, selected_questions):
|
|
39 |
return "Question index out of range.", [], None
|
40 |
|
41 |
def get_explanation_and_answer(index, selected_questions):
|
42 |
-
"""Retrieves the explanation and correct answer for a given question index, handling missing
|
43 |
if 0 <= index < len(selected_questions):
|
44 |
question_data = selected_questions[index]
|
45 |
-
# Use get() with a default value to handle missing
|
46 |
explanation = question_data.get("explanation", "No explanation available.")
|
47 |
-
correct_answer = question_data
|
48 |
return explanation, correct_answer
|
49 |
-
return "No explanation available.", ""
|
50 |
|
51 |
# Text-to-speech function with rate limiting, retry mechanism, and client rotation
|
52 |
import time
|
|
|
39 |
return "Question index out of range.", [], None
|
40 |
|
41 |
def get_explanation_and_answer(index, selected_questions):
|
42 |
+
"""Retrieves the explanation and correct answer for a given question index, handling missing keys."""
|
43 |
if 0 <= index < len(selected_questions):
|
44 |
question_data = selected_questions[index]
|
45 |
+
# Use get() with a default value to handle missing keys
|
46 |
explanation = question_data.get("explanation", "No explanation available.")
|
47 |
+
correct_answer = question_data.get("answer", "No answer available.") # Also handle missing answer key
|
48 |
return explanation, correct_answer
|
49 |
+
return "No explanation available.", "No answer available."
|
50 |
|
51 |
# Text-to-speech function with rate limiting, retry mechanism, and client rotation
|
52 |
import time
|