Sina Media Lab commited on
Commit
a862f0d
Β·
1 Parent(s): 7b6a611
Files changed (1) hide show
  1. app.py +48 -38
app.py CHANGED
@@ -88,6 +88,26 @@ if module_name:
88
  st.title(title)
89
  st.write(description)
90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  if st.session_state.current_question is None or st.session_state.submitted:
92
  st.session_state.current_question, st.session_state.options, st.session_state.correct_answer, st.session_state.explanation = generate_question()
93
  st.session_state.submitted = False
@@ -101,49 +121,39 @@ if module_name:
101
  f"""
102
  <div style='border: 2px solid #ccc; padding: 15px; background-color: #f9f9f9;'>
103
  <strong>Question {st.session_state.question_count + 1}:</strong> {st.session_state.current_question}
 
 
104
  </div>
105
  """,
106
  unsafe_allow_html=True
107
  )
108
 
109
- st.session_state.selected_answer = st.radio("Choose an answer:", st.session_state.options)
110
-
111
- col1, col2, col3 = st.columns([1, 1, 3])
112
- with col1:
113
- if st.session_state.question_count > 0:
114
- if st.button("⬅️ Prev"):
115
- navigate_question("prev")
116
- with col2:
117
- if st.button("Submit"):
118
- st.session_state.submitted = True
119
- st.session_state.question_queue.append((
120
- st.session_state.current_question,
121
- st.session_state.options,
122
- st.session_state.selected_answer,
123
- st.session_state.correct_answer,
124
- st.session_state.explanation
125
- ))
126
-
127
- if st.session_state.selected_answer == st.session_state.correct_answer:
128
- st.session_state.correct_count += 1
129
- st.success("βœ… Correct!")
130
- else:
131
- st.error("❌ Incorrect.")
132
- st.write(f"**Explanation:** {st.session_state.explanation}")
133
- st.session_state.current_question = None
134
-
135
- if st.session_state.submitted:
136
- with col3:
137
- if st.button("➑️ Next"):
138
- navigate_question("next")
139
- if st.session_state.question_count > 0:
140
- pdf = generate_pdf_report()
141
- st.download_button(
142
- label="Download PDF Report πŸ“„",
143
- data=pdf,
144
- file_name="quiz_report.pdf",
145
- mime="application/pdf"
146
- )
147
 
148
  except ModuleNotFoundError:
149
  st.error(f"The module '{module_name}' was not found. Please select another module.")
 
88
  st.title(title)
89
  st.write(description)
90
 
91
+ # Navigation and PDF Download buttons
92
+ col_nav_1, col_nav_2, col_pdf = st.columns([1, 1, 2])
93
+ with col_nav_1:
94
+ if st.session_state.question_count > 0:
95
+ if st.button("⬅️ Prev"):
96
+ navigate_question("prev")
97
+ with col_nav_2:
98
+ if st.session_state.submitted:
99
+ if st.button("➑️ Next"):
100
+ navigate_question("next")
101
+ with col_pdf:
102
+ if st.session_state.question_count > 0:
103
+ pdf = generate_pdf_report()
104
+ st.download_button(
105
+ label="Download PDF Report πŸ“„",
106
+ data=pdf,
107
+ file_name="quiz_report.pdf",
108
+ mime="application/pdf"
109
+ )
110
+
111
  if st.session_state.current_question is None or st.session_state.submitted:
112
  st.session_state.current_question, st.session_state.options, st.session_state.correct_answer, st.session_state.explanation = generate_question()
113
  st.session_state.submitted = False
 
121
  f"""
122
  <div style='border: 2px solid #ccc; padding: 15px; background-color: #f9f9f9;'>
123
  <strong>Question {st.session_state.question_count + 1}:</strong> {st.session_state.current_question}
124
+ <br>
125
+ {st.radio("Choose an answer:", st.session_state.options)}
126
  </div>
127
  """,
128
  unsafe_allow_html=True
129
  )
130
 
131
+ if st.button("Submit"):
132
+ st.session_state.submitted = True
133
+ st.session_state.question_queue.append((
134
+ st.session_state.current_question,
135
+ st.session_state.options,
136
+ st.session_state.selected_answer,
137
+ st.session_state.correct_answer,
138
+ st.session_state.explanation
139
+ ))
140
+
141
+ if st.session_state.selected_answer == st.session_state.correct_answer:
142
+ st.session_state.correct_count += 1
143
+ st.success("βœ… Correct!")
144
+ else:
145
+ st.error("❌ Incorrect.")
146
+
147
+ # Explanation with proper width
148
+ st.markdown(
149
+ f"""
150
+ <div style='border: 2px solid #ccc; padding: 15px; background-color: #f0f0f0;'>
151
+ <strong>Explanation:</strong> {st.session_state.explanation}
152
+ </div>
153
+ """,
154
+ unsafe_allow_html=True
155
+ )
156
+ st.session_state.current_question = None
 
 
 
 
 
 
 
 
 
 
 
 
157
 
158
  except ModuleNotFoundError:
159
  st.error(f"The module '{module_name}' was not found. Please select another module.")