Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -124,31 +124,32 @@ if uploaded_files or manual_input:
|
|
| 124 |
mcqs = []
|
| 125 |
for chunk in text_chunks:
|
| 126 |
response = process_with_groq([
|
| 127 |
-
{"role": "system", "content": "
|
| 128 |
-
{"role": "user", "content": f"Context: {chunk}\n\nGenerate {num_questions} MCQs
|
| 129 |
])
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
|
|
|
| 152 |
|
| 153 |
st.write("### Multiple Choice Questions")
|
| 154 |
for idx, mcq in enumerate(mcqs):
|
|
|
|
| 124 |
mcqs = []
|
| 125 |
for chunk in text_chunks:
|
| 126 |
response = process_with_groq([
|
| 127 |
+
{"role": "system", "content": "You are an AI assistant generating multiple-choice questions. Please provide each MCQ in a clearly structured format with the following fields: question, options (list of options), and answer. Separate each question with a newline."},
|
| 128 |
+
{"role": "user", "content": f"Context: {chunk}\n\nGenerate {num_questions} MCQs in a structured format."}
|
| 129 |
])
|
| 130 |
+
|
| 131 |
+
# Check if the response contains a valid structure (e.g., 'Q1:', 'Options:')
|
| 132 |
+
if "Q" in response and "Options:" in response:
|
| 133 |
+
# Split the response into individual MCQs using a delimiter like 'Q' or a newline
|
| 134 |
+
mcq_blocks = response.split("\n")
|
| 135 |
+
for block in mcq_blocks:
|
| 136 |
+
if block.strip().startswith("Q"):
|
| 137 |
+
question = block.strip()
|
| 138 |
+
options = []
|
| 139 |
+
answer = ""
|
| 140 |
+
# Extract options and answer
|
| 141 |
+
for option_line in mcq_blocks:
|
| 142 |
+
if option_line.startswith("Options:"):
|
| 143 |
+
options = option_line[len("Options:"):].split(" ")
|
| 144 |
+
if option_line.startswith("Answer:"):
|
| 145 |
+
answer = option_line[len("Answer:"):].strip()
|
| 146 |
+
mcqs.append({
|
| 147 |
+
"question": question,
|
| 148 |
+
"options": options,
|
| 149 |
+
"answer": answer
|
| 150 |
+
})
|
| 151 |
+
else:
|
| 152 |
+
st.error(f"Failed to parse structured MCQs from the response: {response}")
|
| 153 |
|
| 154 |
st.write("### Multiple Choice Questions")
|
| 155 |
for idx, mcq in enumerate(mcqs):
|