Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -247,6 +247,38 @@ class QuizApp:
|
|
247 |
print(f"Error generating questions: {e}")
|
248 |
return False, []
|
249 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
250 |
def update_questions(self, text: str, num_questions: int) -> Tuple[gr.update, gr.update, List[gr.update], List[Question], gr.update]:
|
251 |
"""
|
252 |
Event handler for generating new questions
|
|
|
247 |
print(f"Error generating questions: {e}")
|
248 |
return False, []
|
249 |
|
250 |
+
def calculate_score(self, answers: List[Optional[str]]) -> Tuple[float, bool, List[QuizFeedback]]:
|
251 |
+
"""
|
252 |
+
Calculate the quiz score and generate feedback
|
253 |
+
Returns (score, passed, feedback) tuple
|
254 |
+
"""
|
255 |
+
if not answers or not self.current_questions:
|
256 |
+
return 0, False, []
|
257 |
+
|
258 |
+
feedback = []
|
259 |
+
correct = 0
|
260 |
+
|
261 |
+
for question, answer in zip(self.current_questions, answers):
|
262 |
+
if answer is None:
|
263 |
+
feedback.append(QuizFeedback(False, None, question.options[question.correct_answer]))
|
264 |
+
continue
|
265 |
+
|
266 |
+
try:
|
267 |
+
selected_index = question.options.index(answer)
|
268 |
+
is_correct = selected_index == question.correct_answer
|
269 |
+
if is_correct:
|
270 |
+
correct += 1
|
271 |
+
feedback.append(QuizFeedback(
|
272 |
+
is_correct,
|
273 |
+
answer,
|
274 |
+
question.options[question.correct_answer]
|
275 |
+
))
|
276 |
+
except ValueError:
|
277 |
+
feedback.append(QuizFeedback(False, answer, question.options[question.correct_answer]))
|
278 |
+
|
279 |
+
score = (correct / len(self.current_questions)) * 100
|
280 |
+
return score, score >= 80, feedback
|
281 |
+
|
282 |
def update_questions(self, text: str, num_questions: int) -> Tuple[gr.update, gr.update, List[gr.update], List[Question], gr.update]:
|
283 |
"""
|
284 |
Event handler for generating new questions
|