Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -123,13 +123,25 @@ if uploaded_files or manual_input:
|
|
| 123 |
if st.button("Generate MCQs"):
|
| 124 |
mcqs = []
|
| 125 |
for chunk in text_chunks:
|
| 126 |
-
|
| 127 |
{"role": "system", "content": "Generate multiple-choice questions for a lesson."},
|
| 128 |
{"role": "user", "content": f"Context: {chunk}\n\nGenerate {num_questions} MCQs as a JSON array."}
|
| 129 |
-
])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
st.write("### Multiple Choice Questions")
|
| 131 |
-
for mcq in mcqs:
|
| 132 |
-
st.write(f"**{
|
|
|
|
|
|
|
| 133 |
|
| 134 |
elif task == "Adapt Lesson for Grades":
|
| 135 |
grade = st.slider("Select Grade:", 1, 16, 9)
|
|
|
|
| 123 |
if st.button("Generate MCQs"):
|
| 124 |
mcqs = []
|
| 125 |
for chunk in text_chunks:
|
| 126 |
+
response = process_with_groq([
|
| 127 |
{"role": "system", "content": "Generate multiple-choice questions for a lesson."},
|
| 128 |
{"role": "user", "content": f"Context: {chunk}\n\nGenerate {num_questions} MCQs as a JSON array."}
|
| 129 |
+
])
|
| 130 |
+
try:
|
| 131 |
+
# Parse the JSON response to a list of MCQs
|
| 132 |
+
mcqs_data = json.loads(response)
|
| 133 |
+
if isinstance(mcqs_data, list): # Check if the response is a valid JSON array
|
| 134 |
+
mcqs.extend(mcqs_data)
|
| 135 |
+
else:
|
| 136 |
+
st.error(f"Invalid MCQs response: {response}")
|
| 137 |
+
except json.JSONDecodeError:
|
| 138 |
+
st.error(f"Error decoding JSON response: {response}")
|
| 139 |
+
|
| 140 |
st.write("### Multiple Choice Questions")
|
| 141 |
+
for idx, mcq in enumerate(mcqs):
|
| 142 |
+
st.write(f"**Q{idx + 1}:** {mcq['question']}")
|
| 143 |
+
for option in mcq['options']:
|
| 144 |
+
st.write(f"- {option}")
|
| 145 |
|
| 146 |
elif task == "Adapt Lesson for Grades":
|
| 147 |
grade = st.slider("Select Grade:", 1, 16, 9)
|