pratikshahp commited on
Commit
e1b789e
·
verified ·
1 Parent(s): ece53ba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -15
app.py CHANGED
@@ -32,23 +32,28 @@ def generate_mcqs(text_chunks, num_questions=5):
32
  mcqs = []
33
 
34
  for chunk in text_chunks:
35
- input_text = f"Generate a multiple-choice question from the following text:\n\n{chunk}\n\nQuestion:"
36
  generated = generator(input_text, max_length=400, num_return_sequences=1)
37
- question_text = generated[0]["generated_text"].split("Question:")[1].strip()
38
-
39
- # Generate options for the question
40
- options_text = f"Generate four plausible multiple-choice options for the following question:\n\n{question_text}\nOptions:"
41
- options_generated = generator(options_text, max_length=200, num_return_sequences=1)
42
- options_list = options_generated[0]["generated_text"].split("Options:")[1].strip().split("\n")
43
- options = [f"Option {chr(65 + i)}: {option.strip()}" for i, option in enumerate(options_list[:4])]
44
-
45
- if len(options) < 4:
46
- continue
 
 
47
 
48
- correct_answer = options[0] # Placeholder for correct answer identification logic
49
-
50
- mcq_formatted = f"Q: {question_text}\n{options[0]}\n{options[1]}\n{options[2]}\n{options[3]}\nCorrect Answer: {correct_answer}"
51
- mcqs.append(mcq_formatted)
 
 
 
52
 
53
  if len(mcqs) >= num_questions:
54
  break
 
32
  mcqs = []
33
 
34
  for chunk in text_chunks:
35
+ input_text = f"Based on the following text, generate a multiple-choice question along with four plausible options and mark the correct answer:\n\n{chunk}\n\nQuestion:"
36
  generated = generator(input_text, max_length=400, num_return_sequences=1)
37
+ generated_text = generated[0]["generated_text"]
38
+
39
+ # Extract question and options
40
+ try:
41
+ question_part = generated_text.split("Question:")[1].strip()
42
+ question = question_part.split("Options:")[0].strip()
43
+ options_part = question_part.split("Options:")[1].strip()
44
+ options = options_part.split("\n")
45
+
46
+ # Ensure four options
47
+ if len(options) < 4:
48
+ continue
49
 
50
+ options = [f"Option {chr(65 + i)}: {option.strip()}" for i, option in enumerate(options[:4])]
51
+ correct_answer = options[0] # Placeholder for correct answer identification logic
52
+
53
+ mcq_formatted = f"Q: {question}\n{options[0]}\n{options[1]}\n{options[2]}\n{options[3]}\nCorrect Answer: {correct_answer}"
54
+ mcqs.append(mcq_formatted)
55
+ except:
56
+ continue
57
 
58
  if len(mcqs) >= num_questions:
59
  break