Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -55,4 +55,26 @@ if uploaded_file:
|
|
| 55 |
question_data = generate_question_and_options(chunk)
|
| 56 |
try:
|
| 57 |
# Parse response into a question, options, and answer
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
question_data = generate_question_and_options(chunk)
|
| 56 |
try:
|
| 57 |
# Parse response into a question, options, and answer
|
| 58 |
+
lines = question_data.split("\n")
|
| 59 |
+
question = lines[0].replace("Question: ", "").strip()
|
| 60 |
+
options = [line.strip() for line in lines[1:5] if line.strip()]
|
| 61 |
+
answer = lines[-1].replace("Answer: ", "").strip()
|
| 62 |
+
|
| 63 |
+
if len(options) == 4: # Ensure exactly 4 options
|
| 64 |
+
quiz.append({"question": question, "options": options, "answer": answer})
|
| 65 |
+
except Exception as e:
|
| 66 |
+
st.warning(f"Failed to parse a question from: {chunk[:100]}...")
|
| 67 |
+
|
| 68 |
+
# Display the quiz
|
| 69 |
+
st.write("🎯 **Your Quiz:**")
|
| 70 |
+
for i, q in enumerate(quiz, 1):
|
| 71 |
+
st.markdown(f"### Question {i}: {q['question']}")
|
| 72 |
+
selected_option = st.radio(f"Select your answer for Question {i}:", q['options'], key=f"q{i}")
|
| 73 |
+
|
| 74 |
+
if st.button(f"Submit Answer for Question {i}", key=f"submit_q{i}"):
|
| 75 |
+
if selected_option == q['answer']:
|
| 76 |
+
st.success(f"🎉 Correct! The answer is: {q['answer']}", icon="✅")
|
| 77 |
+
else:
|
| 78 |
+
st.error(f"❌ Incorrect! The correct answer is: {q['answer']}", icon="🚫")
|
| 79 |
+
|
| 80 |
+
st.write("Thank you for taking the quiz! 🎓")
|