Amelia-James commited on
Commit
3caaaa1
·
verified ·
1 Parent(s): ce8e40e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -45,19 +45,22 @@ def generate_mcqs_from_text(user_text):
45
  # Function to parse the MCQs and correct answers
46
  def parse_mcqs_and_answers(mcqs_and_answers):
47
  try:
48
- # Try splitting on "Correct Answers:"
49
- parts = mcqs_and_answers.split("Correct Answers:")
50
- if len(parts) != 2:
51
  raise ValueError("Could not find 'Correct Answers:' in the response.")
52
 
53
- # Separate MCQs and correct answers
54
- mcqs = parts[0].strip()
 
 
 
55
  correct_answers = {}
56
- for line in parts[1].strip().splitlines():
57
  if line.startswith("Question"):
58
  q, ans = line.split(":")
59
  correct_answers[q.strip()] = ans.strip()
60
-
61
  return mcqs, correct_answers
62
  except Exception as e:
63
  st.error(f"Failed to parse response: {e}")
@@ -66,7 +69,6 @@ def parse_mcqs_and_answers(mcqs_and_answers):
66
 
67
  # Function to evaluate user answers
68
  def evaluate_answers(mcqs, user_answers):
69
- # Here we assume the user_answers is a dictionary of answers for each question
70
  prompt = f"""
71
  Here are the user's answers to the following multiple-choice questions.
72
  Please evaluate them as an experienced teacher, providing feedback on correctness,
 
45
  # Function to parse the MCQs and correct answers
46
  def parse_mcqs_and_answers(mcqs_and_answers):
47
  try:
48
+ # Split based on the "Correct Answers" section
49
+ correct_answers_start = mcqs_and_answers.find("Correct Answers")
50
+ if correct_answers_start == -1:
51
  raise ValueError("Could not find 'Correct Answers:' in the response.")
52
 
53
+ # Extract MCQs and correct answers
54
+ mcqs = mcqs_and_answers[:correct_answers_start].strip()
55
+ correct_answers_section = mcqs_and_answers[correct_answers_start:].strip()
56
+
57
+ # Extract the correct answers
58
  correct_answers = {}
59
+ for line in correct_answers_section.splitlines():
60
  if line.startswith("Question"):
61
  q, ans = line.split(":")
62
  correct_answers[q.strip()] = ans.strip()
63
+
64
  return mcqs, correct_answers
65
  except Exception as e:
66
  st.error(f"Failed to parse response: {e}")
 
69
 
70
  # Function to evaluate user answers
71
  def evaluate_answers(mcqs, user_answers):
 
72
  prompt = f"""
73
  Here are the user's answers to the following multiple-choice questions.
74
  Please evaluate them as an experienced teacher, providing feedback on correctness,