Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -45,19 +45,22 @@ def generate_mcqs_from_text(user_text):
|
|
45 |
# Function to parse the MCQs and correct answers
|
46 |
def parse_mcqs_and_answers(mcqs_and_answers):
|
47 |
try:
|
48 |
-
#
|
49 |
-
|
50 |
-
if
|
51 |
raise ValueError("Could not find 'Correct Answers:' in the response.")
|
52 |
|
53 |
-
#
|
54 |
-
mcqs =
|
|
|
|
|
|
|
55 |
correct_answers = {}
|
56 |
-
for line in
|
57 |
if line.startswith("Question"):
|
58 |
q, ans = line.split(":")
|
59 |
correct_answers[q.strip()] = ans.strip()
|
60 |
-
|
61 |
return mcqs, correct_answers
|
62 |
except Exception as e:
|
63 |
st.error(f"Failed to parse response: {e}")
|
@@ -66,7 +69,6 @@ def parse_mcqs_and_answers(mcqs_and_answers):
|
|
66 |
|
67 |
# Function to evaluate user answers
|
68 |
def evaluate_answers(mcqs, user_answers):
|
69 |
-
# Here we assume the user_answers is a dictionary of answers for each question
|
70 |
prompt = f"""
|
71 |
Here are the user's answers to the following multiple-choice questions.
|
72 |
Please evaluate them as an experienced teacher, providing feedback on correctness,
|
|
|
45 |
# Function to parse the MCQs and correct answers
|
46 |
def parse_mcqs_and_answers(mcqs_and_answers):
|
47 |
try:
|
48 |
+
# Split based on the "Correct Answers" section
|
49 |
+
correct_answers_start = mcqs_and_answers.find("Correct Answers")
|
50 |
+
if correct_answers_start == -1:
|
51 |
raise ValueError("Could not find 'Correct Answers:' in the response.")
|
52 |
|
53 |
+
# Extract MCQs and correct answers
|
54 |
+
mcqs = mcqs_and_answers[:correct_answers_start].strip()
|
55 |
+
correct_answers_section = mcqs_and_answers[correct_answers_start:].strip()
|
56 |
+
|
57 |
+
# Extract the correct answers
|
58 |
correct_answers = {}
|
59 |
+
for line in correct_answers_section.splitlines():
|
60 |
if line.startswith("Question"):
|
61 |
q, ans = line.split(":")
|
62 |
correct_answers[q.strip()] = ans.strip()
|
63 |
+
|
64 |
return mcqs, correct_answers
|
65 |
except Exception as e:
|
66 |
st.error(f"Failed to parse response: {e}")
|
|
|
69 |
|
70 |
# Function to evaluate user answers
|
71 |
def evaluate_answers(mcqs, user_answers):
|
|
|
72 |
prompt = f"""
|
73 |
Here are the user's answers to the following multiple-choice questions.
|
74 |
Please evaluate them as an experienced teacher, providing feedback on correctness,
|