Spaces:
Runtime error
Runtime error
Update tool2.py
Browse files
tool2.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
#
|
2 |
import json
|
3 |
import os
|
4 |
from gradio_client import Client
|
@@ -8,6 +8,11 @@ import time # Import the time module
|
|
8 |
# Load question sets from JSON files
|
9 |
def load_question_sets(directory='question_sets'):
|
10 |
question_sets = {}
|
|
|
|
|
|
|
|
|
|
|
11 |
for filename in os.listdir(directory):
|
12 |
if filename.endswith('.json'):
|
13 |
exam_name = filename[:-5] # Remove '.json' extension
|
@@ -95,9 +100,4 @@ def get_explanation_and_answer(index, selected_questions): # Added selected_ques
|
|
95 |
"""Retrieves explanation and correct answer for a question."""
|
96 |
explanation = selected_questions[index].get('explanation', 'No explanation available for this question.')
|
97 |
correct_answer = selected_questions[index].get('correct', 'No correct answer provided.')
|
98 |
-
return explanation, correct_answer
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
# backend1.py - No changes needed as per problem description, but ensure it's in the same directory and defines 'exams'
|
103 |
-
exams = list(question_sets_data.keys()) # backend1.py (simplified and corrected to use loaded exams)
|
|
|
1 |
+
# tool2.py
|
2 |
import json
|
3 |
import os
|
4 |
from gradio_client import Client
|
|
|
8 |
# Load question sets from JSON files
|
9 |
def load_question_sets(directory='question_sets'):
|
10 |
question_sets = {}
|
11 |
+
# Check if the directory exists before trying to list files
|
12 |
+
if not os.path.exists(directory):
|
13 |
+
print(f"Error: Directory '{directory}' not found.")
|
14 |
+
return {} # Return empty dictionary if directory is missing
|
15 |
+
|
16 |
for filename in os.listdir(directory):
|
17 |
if filename.endswith('.json'):
|
18 |
exam_name = filename[:-5] # Remove '.json' extension
|
|
|
100 |
"""Retrieves explanation and correct answer for a question."""
|
101 |
explanation = selected_questions[index].get('explanation', 'No explanation available for this question.')
|
102 |
correct_answer = selected_questions[index].get('correct', 'No correct answer provided.')
|
103 |
+
return explanation, correct_answer
|
|
|
|
|
|
|
|
|
|