Update app.py
Browse files
app.py
CHANGED
@@ -72,6 +72,7 @@ def parse_quiz_content(quiz_content):
|
|
72 |
question_text = ""
|
73 |
options = {}
|
74 |
parsing_question_text = True # Flag to indicate we are parsing question text
|
|
|
75 |
|
76 |
for line_index, line in enumerate(lines):
|
77 |
line = line.strip()
|
@@ -79,17 +80,19 @@ def parse_quiz_content(quiz_content):
|
|
79 |
continue
|
80 |
|
81 |
if parsing_question_text:
|
82 |
-
if re.match(r'^Question\s+\d
|
83 |
-
|
84 |
-
if
|
85 |
-
question_text =
|
86 |
parsing_question_text = False # Stop parsing question text, move to options
|
87 |
-
else:
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
|
|
|
|
93 |
parsing_question_text = False # Move to options parsing
|
94 |
|
95 |
|
@@ -240,10 +243,6 @@ if topic:
|
|
240 |
else:
|
241 |
st.error("Failed to generate quiz content. Please try again or check your API key.")
|
242 |
|
243 |
-
except Exception as e:
|
244 |
-
st.error(f"An error occurred: {e}")
|
245 |
-
st.error("Please check your API key and network connection. If the problem persists, try a different topic or try again later.")
|
246 |
-
|
247 |
# Quiz Display Logic
|
248 |
if st.session_state.quiz_data:
|
249 |
if not st.session_state.quiz_completed:
|
|
|
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()
|
|
|
80 |
continue
|
81 |
|
82 |
if parsing_question_text:
|
83 |
+
if re.match(r'^Question\s+\d+:', line, re.IGNORECASE): # Check for "Question N:"
|
84 |
+
question_label_found = True # Mark label as found
|
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
|
91 |
+
parsing_question_text = False # Move to options parsing even if question text missing
|
92 |
+
elif not question_label_found:
|
93 |
+
# If no "Question N:" label found yet in this block, and we are still parsing question text,
|
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 |
|
|
|
243 |
else:
|
244 |
st.error("Failed to generate quiz content. Please try again or check your API key.")
|
245 |
|
|
|
|
|
|
|
|
|
246 |
# Quiz Display Logic
|
247 |
if st.session_state.quiz_data:
|
248 |
if not st.session_state.quiz_completed:
|