Update app.py
Browse files
app.py
CHANGED
@@ -65,14 +65,18 @@ def parse_quiz_content(quiz_content):
|
|
65 |
|
66 |
for block in blocks:
|
67 |
block = block.strip()
|
68 |
-
if not block: # Skip completely empty blocks
|
|
|
69 |
continue
|
70 |
|
|
|
71 |
lines = block.split('\n')
|
72 |
question_text = ""
|
73 |
options = {}
|
74 |
parsing_question_text = True # Flag to indicate we are parsing question text
|
75 |
question_label_found = False # Flag to track if "Question N:" label was found
|
|
|
|
|
76 |
|
77 |
for line_index, line in enumerate(lines):
|
78 |
line = line.strip()
|
@@ -85,6 +89,7 @@ def parse_quiz_content(quiz_content):
|
|
85 |
if len(lines) > line_index + 1: # Check if there's a line after "Question N:"
|
86 |
question_text = lines[line_index + 1].strip() # Take the *next* line as question text
|
87 |
parsing_question_text = False # Stop parsing question text, move to options
|
|
|
88 |
else:
|
89 |
st.warning(f"Warning: Question label '{line}' found, but no question text followed.")
|
90 |
question_text = "" # No question text found after label
|
@@ -94,6 +99,7 @@ def parse_quiz_content(quiz_content):
|
|
94 |
# consider this line as question text (for the very first line if no label)
|
95 |
question_text = line
|
96 |
parsing_question_text = False # Move to options parsing
|
|
|
97 |
|
98 |
|
99 |
elif re.match(r'^[A-D]\)\s(.+)', line): # Parse options
|
@@ -102,17 +108,19 @@ def parse_quiz_content(quiz_content):
|
|
102 |
option_letter = match.group(1)
|
103 |
option_text = match.group(2).strip()
|
104 |
options[option_letter] = option_text
|
|
|
|
|
105 |
|
106 |
# --- DEBUGGING PRINT: Print question text and options for each block ---
|
107 |
st.write(f"#### Debugging: Block {question_number} - Parsed Data:")
|
108 |
st.write(f"- Question Text: '{question_text}'")
|
109 |
st.write(f"- Options: {options}")
|
|
|
110 |
|
111 |
-
|
112 |
-
if question_text: # Only add question if we successfully extracted question text (and it's not empty)
|
113 |
questions.append({'question': question_text, 'options': options})
|
114 |
else:
|
115 |
-
st.warning(f"Warning: Could not parse question text for block (potential issue in question {question_number}). Block content:\n{block}")
|
116 |
|
117 |
question_number += 1 # Increment expected question number
|
118 |
|
|
|
65 |
|
66 |
for block in blocks:
|
67 |
block = block.strip()
|
68 |
+
if not block or len(block) < 5: # Skip completely empty blocks or very short blocks (less than 5 chars)
|
69 |
+
st.write(f"Debugging: Skipping very short or empty block: '{block}'") # Debugging skip message
|
70 |
continue
|
71 |
|
72 |
+
|
73 |
lines = block.split('\n')
|
74 |
question_text = ""
|
75 |
options = {}
|
76 |
parsing_question_text = True # Flag to indicate we are parsing question text
|
77 |
question_label_found = False # Flag to track if "Question N:" label was found
|
78 |
+
block_has_question_content = False # Flag to check if block has any question content
|
79 |
+
|
80 |
|
81 |
for line_index, line in enumerate(lines):
|
82 |
line = line.strip()
|
|
|
89 |
if len(lines) > line_index + 1: # Check if there's a line after "Question N:"
|
90 |
question_text = lines[line_index + 1].strip() # Take the *next* line as question text
|
91 |
parsing_question_text = False # Stop parsing question text, move to options
|
92 |
+
block_has_question_content = True # Mark that we found question content
|
93 |
else:
|
94 |
st.warning(f"Warning: Question label '{line}' found, but no question text followed.")
|
95 |
question_text = "" # No question text found after label
|
|
|
99 |
# consider this line as question text (for the very first line if no label)
|
100 |
question_text = line
|
101 |
parsing_question_text = False # Move to options parsing
|
102 |
+
block_has_question_content = True # Mark that we found question content
|
103 |
|
104 |
|
105 |
elif re.match(r'^[A-D]\)\s(.+)', line): # Parse options
|
|
|
108 |
option_letter = match.group(1)
|
109 |
option_text = match.group(2).strip()
|
110 |
options[option_letter] = option_text
|
111 |
+
block_has_question_content = True # Mark that we found option content
|
112 |
+
|
113 |
|
114 |
# --- DEBUGGING PRINT: Print question text and options for each block ---
|
115 |
st.write(f"#### Debugging: Block {question_number} - Parsed Data:")
|
116 |
st.write(f"- Question Text: '{question_text}'")
|
117 |
st.write(f"- Options: {options}")
|
118 |
+
st.write(f"- Block has question content: {block_has_question_content}") # Debugging flag
|
119 |
|
120 |
+
if question_text and block_has_question_content: # Only add question if we successfully extracted question text AND block has content
|
|
|
121 |
questions.append({'question': question_text, 'options': options})
|
122 |
else:
|
123 |
+
st.warning(f"Warning: Could not parse question text OR no question content found for block (potential issue in question {question_number}). Block content:\n{block}")
|
124 |
|
125 |
question_number += 1 # Increment expected question number
|
126 |
|