Update app.py
Browse files
app.py
CHANGED
@@ -46,39 +46,28 @@ def parse_quiz_content(quiz_content):
|
|
46 |
question_section = quiz_parts[0].strip()
|
47 |
answer_key_section = quiz_parts[1].strip()
|
48 |
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
for block in blocks:
|
64 |
-
block = block.strip()
|
65 |
-
if not block:
|
66 |
-
continue
|
67 |
-
|
68 |
-
lines = block.split('\n')
|
69 |
-
# --- First line is question text (after removing bold markdown) ---
|
70 |
-
question_text = re.sub(r'\*\*|\*', '', lines[0]).strip()
|
71 |
-
|
72 |
-
options = {}
|
73 |
-
for line in lines[1:]:
|
74 |
-
line = line.strip()
|
75 |
-
if re.match(r'^[A-D]\.\s', line): # Options are like "A. Elephant"
|
76 |
option_letter = line[0]
|
77 |
-
option_text = line[2:].strip()
|
78 |
-
options[option_letter] = option_text
|
|
|
|
|
79 |
|
80 |
-
|
81 |
-
|
82 |
|
83 |
|
84 |
# --- Answer Key Parsing (No change needed) ---
|
|
|
46 |
question_section = quiz_parts[0].strip()
|
47 |
answer_key_section = quiz_parts[1].strip()
|
48 |
|
49 |
+
question_lines = question_section.strip().split('\n')
|
50 |
+
current_question = None
|
51 |
+
for line in question_lines:
|
52 |
+
line = line.strip()
|
53 |
+
if not line:
|
54 |
+
continue # Skip empty lines
|
55 |
+
|
56 |
+
if re.match(r'^\d+\.\s', line): # Start of a new question
|
57 |
+
if current_question: # Save previous question if exists
|
58 |
+
questions.append(current_question)
|
59 |
+
current_question = {'options': {}} # Start new question
|
60 |
+
current_question['question'] = re.sub(r'\*\*|\*', '', line).strip() # Question text, remove bold
|
61 |
+
elif re.match(r'^[A-D]\)\s', line) or re.match(r'^[A-D]\.\s', line): # Option line (handle both ')' and '.' after letter)
|
62 |
+
if current_question:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
option_letter = line[0]
|
64 |
+
option_text = line[2:].strip() # Remove "A) " or "A. "
|
65 |
+
current_question['options'][option_letter] = option_text
|
66 |
+
elif re.match(r'^\*\*.*?\*\*$', line) or re.match(r'^\*.*?\*$', line) : # Check for title again, just in case after split. Remove bold title if found in lines.
|
67 |
+
pass # Ignore title lines within question section if any.
|
68 |
|
69 |
+
if current_question: # Append the last question
|
70 |
+
questions.append(current_question)
|
71 |
|
72 |
|
73 |
# --- Answer Key Parsing (No change needed) ---
|