Update app.py
Browse files
app.py
CHANGED
@@ -125,15 +125,26 @@ def parse_quiz_content(quiz_content):
|
|
125 |
question_number += 1 # Increment expected question number
|
126 |
|
127 |
|
128 |
-
# --- Answer Key Parsing (
|
129 |
-
|
|
|
|
|
130 |
for line in answer_lines:
|
131 |
line = line.strip()
|
132 |
-
match = re.match(r'(\d+)\.\s*([A-D])', line)
|
|
|
|
|
133 |
if match:
|
134 |
question_num = int(match.group(1)) - 1
|
135 |
correct_answer = match.group(2)
|
136 |
answer_key_dict[question_num] = correct_answer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
|
138 |
# Basic validation
|
139 |
if not questions or not answer_key_dict:
|
@@ -143,10 +154,11 @@ def parse_quiz_content(quiz_content):
|
|
143 |
st.warning(f"Number of questions parsed ({len(questions)}) does not match number of answers in answer key ({len(answer_key_dict)}). Parsing might be incomplete.")
|
144 |
|
145 |
|
146 |
-
# Combine parsed questions and answer key into quiz_data
|
147 |
quiz_data_list = []
|
148 |
for i, q_data in enumerate(questions):
|
149 |
correct_answer = answer_key_dict.get(i)
|
|
|
150 |
if correct_answer:
|
151 |
quiz_data_list.append({
|
152 |
'question': q_data['question'],
|
@@ -154,9 +166,12 @@ def parse_quiz_content(quiz_content):
|
|
154 |
'correct_answer': correct_answer
|
155 |
})
|
156 |
else:
|
157 |
-
st.warning(f"Could not find correct answer for question {i+1} in the answer key.")
|
158 |
return None, None
|
159 |
|
|
|
|
|
|
|
160 |
return quiz_data_list, answer_key_dict
|
161 |
|
162 |
|
|
|
125 |
question_number += 1 # Increment expected question number
|
126 |
|
127 |
|
128 |
+
# --- Answer Key Parsing (Added Debugging Prints) ---
|
129 |
+
st.write("### Debugging: Answer Key Section Raw:") # Print raw answer key section
|
130 |
+
st.code(answer_key_section) # Display raw answer key in code block
|
131 |
+
answer_lines = answer_key_section.strip().split('\n')
|
132 |
for line in answer_lines:
|
133 |
line = line.strip()
|
134 |
+
match = re.match(r'(\d+)\.\s*([A-D])\)', line) # Try to match with closing parenthesis first
|
135 |
+
if not match: # If no match with parenthesis, try without
|
136 |
+
match = re.match(r'(\d+)\.\s*([A-D])', line)
|
137 |
if match:
|
138 |
question_num = int(match.group(1)) - 1
|
139 |
correct_answer = match.group(2)
|
140 |
answer_key_dict[question_num] = correct_answer
|
141 |
+
st.write(f"Debugging: Answer Key - Parsed Answer: Question {question_num+1}, Answer: {correct_answer}") # Print parsed answer
|
142 |
+
else:
|
143 |
+
st.warning(f"Warning: Could not parse answer key line: '{line}'") # Warning for unparsed answer key lines
|
144 |
+
|
145 |
+
st.write("### Debugging: Parsed Answer Key Dictionary:") # Print the answer key dictionary
|
146 |
+
st.write(answer_key_dict)
|
147 |
+
|
148 |
|
149 |
# Basic validation
|
150 |
if not questions or not answer_key_dict:
|
|
|
154 |
st.warning(f"Number of questions parsed ({len(questions)}) does not match number of answers in answer key ({len(answer_key_dict)}). Parsing might be incomplete.")
|
155 |
|
156 |
|
157 |
+
# Combine parsed questions and answer key into quiz_data (Added Debugging Print)
|
158 |
quiz_data_list = []
|
159 |
for i, q_data in enumerate(questions):
|
160 |
correct_answer = answer_key_dict.get(i)
|
161 |
+
st.write(f"Debugging: Creating quiz_data_list - Question Index: {i}, Correct Answer from dict: '{correct_answer}'") # Print during quiz_data_list creation
|
162 |
if correct_answer:
|
163 |
quiz_data_list.append({
|
164 |
'question': q_data['question'],
|
|
|
166 |
'correct_answer': correct_answer
|
167 |
})
|
168 |
else:
|
169 |
+
st.warning(f"Warning: Could not find correct answer for question {i+1} in the answer key.")
|
170 |
return None, None
|
171 |
|
172 |
+
st.write("### Debugging: Final Parsed Quiz Data:") # Print the final parsed quiz data
|
173 |
+
st.write(quiz_data_list)
|
174 |
+
|
175 |
return quiz_data_list, answer_key_dict
|
176 |
|
177 |
|