Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -75,7 +75,7 @@ st.title("EduAI Assistant for Teachers")
|
|
| 75 |
st.markdown("""
|
| 76 |
Welcome to your AI-powered teaching assistant!
|
| 77 |
- Upload lesson files or input text.
|
| 78 |
-
- Perform actions like summarizing topics, generating
|
| 79 |
""")
|
| 80 |
|
| 81 |
if uploaded_files or manual_input:
|
|
@@ -128,15 +128,28 @@ if uploaded_files or manual_input:
|
|
| 128 |
{"role": "user", "content": f"Context: {chunk}\n\nGenerate {num_questions} MCQs as a JSON array."}
|
| 129 |
])
|
| 130 |
try:
|
| 131 |
-
#
|
| 132 |
mcqs_data = json.loads(response)
|
| 133 |
-
if isinstance(mcqs_data, list): #
|
| 134 |
mcqs.extend(mcqs_data)
|
| 135 |
else:
|
| 136 |
st.error(f"Invalid MCQs response: {response}")
|
| 137 |
except json.JSONDecodeError:
|
| 138 |
-
|
| 139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
st.write("### Multiple Choice Questions")
|
| 141 |
for idx, mcq in enumerate(mcqs):
|
| 142 |
st.write(f"**Q{idx + 1}:** {mcq['question']}")
|
|
|
|
| 75 |
st.markdown("""
|
| 76 |
Welcome to your AI-powered teaching assistant!
|
| 77 |
- Upload lesson files or input text.
|
| 78 |
+
- Perform actions like summarizing topics, generating assignments/quizzez/short questions, generating learning resources and adapting lessons.
|
| 79 |
""")
|
| 80 |
|
| 81 |
if uploaded_files or manual_input:
|
|
|
|
| 128 |
{"role": "user", "content": f"Context: {chunk}\n\nGenerate {num_questions} MCQs as a JSON array."}
|
| 129 |
])
|
| 130 |
try:
|
| 131 |
+
# Try to parse the response as JSON
|
| 132 |
mcqs_data = json.loads(response)
|
| 133 |
+
if isinstance(mcqs_data, list): # Ensure it's a valid JSON array
|
| 134 |
mcqs.extend(mcqs_data)
|
| 135 |
else:
|
| 136 |
st.error(f"Invalid MCQs response: {response}")
|
| 137 |
except json.JSONDecodeError:
|
| 138 |
+
# If the response is not valid JSON, treat it as plain text
|
| 139 |
+
st.warning(f"Error decoding JSON response. Attempting to extract MCQs from text.")
|
| 140 |
+
|
| 141 |
+
# Extract questions manually from the response (basic heuristic approach)
|
| 142 |
+
lines = response.split('\n')
|
| 143 |
+
for line in lines:
|
| 144 |
+
if line.startswith('Q'):
|
| 145 |
+
mcqs.append({'question': line.strip(), 'options': []})
|
| 146 |
+
elif line.startswith('-'):
|
| 147 |
+
if mcqs:
|
| 148 |
+
mcqs[-1]['options'].append(line.strip())
|
| 149 |
+
|
| 150 |
+
if not mcqs:
|
| 151 |
+
st.error(f"Failed to extract MCQs from the response: {response}")
|
| 152 |
+
|
| 153 |
st.write("### Multiple Choice Questions")
|
| 154 |
for idx, mcq in enumerate(mcqs):
|
| 155 |
st.write(f"**Q{idx + 1}:** {mcq['question']}")
|