Spaces:
Build error
Build error
Update app.py
Browse files
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"
|
| 36 |
generated = generator(input_text, max_length=400, num_return_sequences=1)
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
#
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
| 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
|