EdBoy2202 commited on
Commit
ed51c97
·
verified ·
1 Parent(s): 7165b5a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -10
app.py CHANGED
@@ -79,17 +79,16 @@ def parse_quiz_content(quiz_content):
79
  continue
80
 
81
  if parsing_question_text:
82
- if re.match(r'^Question\s+\d+:', line, re.IGNORECASE): # Check for "Question 1:", "Question 2:", etc.
83
- if len(lines) > line_index + 1: # Check if there's a line after "Question N:"
84
- question_text = lines[line_index + 1].strip() # Take the next line as question text
 
85
  parsing_question_text = False # Stop parsing question text, move to options
86
- else:
87
- st.warning(f"Warning: Question label '{line}' found, but no question text followed.")
88
- question_text = "" # No question text found after label
89
- parsing_question_text = False # Move to options parsing even if question text missing
90
  else:
91
- # If the line is not "Question N:", and we are still parsing question text,
92
- # it might be the question text itself (in case of format variation)
93
  question_text = line # Consider this line as question text
94
  parsing_question_text = False # Move to options parsing
95
 
@@ -107,7 +106,7 @@ def parse_quiz_content(quiz_content):
107
  st.write(f"- Options: {options}")
108
 
109
 
110
- if question_text: # Only add question if we successfully extracted question text
111
  questions.append({'question': question_text, 'options': options})
112
  else:
113
  st.warning(f"Warning: Could not parse question text for block (potential issue in question {question_number}). Block content:\n{block}")
 
79
  continue
80
 
81
  if parsing_question_text:
82
+ if re.match(r'^Question\s+\d+:\s*(.+)', line, re.IGNORECASE): # Check for "Question N:" and capture question text on same line
83
+ match = re.match(r'^Question\s+\d+:\s*(.+)', line, re.IGNORECASE)
84
+ if match:
85
+ question_text = match.group(1).strip() # Extract question text from the same line
86
  parsing_question_text = False # Stop parsing question text, move to options
87
+ else: # Should not happen, but for robustness
88
+ question_text = ""
89
+ parsing_question_text = False
 
90
  else:
91
+ # Fallback: If line doesn't start with "Question N:", consider it as question text
 
92
  question_text = line # Consider this line as question text
93
  parsing_question_text = False # Move to options parsing
94
 
 
106
  st.write(f"- Options: {options}")
107
 
108
 
109
+ if question_text: # Only add question if we successfully extracted question text (and it's not empty)
110
  questions.append({'question': question_text, 'options': options})
111
  else:
112
  st.warning(f"Warning: Could not parse question text for block (potential issue in question {question_number}). Block content:\n{block}")