Sina Media Lab commited on
Commit
764cfc6
Β·
1 Parent(s): 929abf5
Files changed (1) hide show
  1. app.py +27 -24
app.py CHANGED
@@ -1,7 +1,11 @@
1
  import streamlit as st
2
  import importlib
 
3
  from fpdf import FPDF
4
 
 
 
 
5
  # List of available modules with shorter names and icons
6
  module_names = {
7
  "Bases": "presentation_bases",
@@ -49,7 +53,7 @@ def generate_pdf_report():
49
  pdf.multi_cell(0, 10, f"Q{idx+1}: {question}")
50
  for option in options:
51
  if option == correct:
52
- pdf.multi_cell(0, 10, f"βœ”οΈ {option} (Correct)")
53
  elif option == selected:
54
  pdf.multi_cell(0, 10, f"✘ {option} (Your Choice)")
55
  else:
@@ -57,19 +61,18 @@ def generate_pdf_report():
57
  pdf.multi_cell(0, 10, f"Explanation: {explanation}")
58
  pdf.ln(10)
59
 
60
- return pdf.output(dest='S').encode('latin-1', 'replace')
61
 
62
- # Debugging information
63
- st.write("### Debugging Information")
64
- st.write(f"Current Module: {st.session_state.current_module}")
65
- st.write(f"Question Count: {st.session_state.question_count}")
66
- st.write(f"Correct Count: {st.session_state.correct_count}")
67
- st.write(f"Submitted: {st.session_state.submitted}")
68
- st.write(f"Current Question: {st.session_state.current_question}")
69
- st.write(f"Options: {st.session_state.options}")
70
- st.write(f"Selected Answer: {st.session_state.selected_answer}")
71
- st.write(f"Correct Answer: {st.session_state.correct_answer}")
72
- st.write(f"Explanation: {st.session_state.explanation}")
73
 
74
  # Streamlit interface
75
  st.sidebar.title("Quiz Modules")
@@ -83,7 +86,7 @@ if module_name:
83
  st.session_state.question_queue = []
84
  st.session_state.current_question = None
85
  st.session_state.submitted = False
86
- st.write("Module changed. Resetting session state.")
87
 
88
  module_file = module_names[module_name]
89
  try:
@@ -107,13 +110,13 @@ if module_name:
107
  st.session_state.selected_answer = question_data[2]
108
  st.session_state.correct_answer = question_data[3]
109
  st.session_state.explanation = question_data[4]
110
- st.write("Navigated to previous question.")
111
 
112
  if st.session_state.current_question is None or st.session_state.submitted:
113
  st.session_state.current_question, st.session_state.options, st.session_state.correct_answer, st.session_state.explanation = generate_question()
114
  st.session_state.submitted = False
115
  st.session_state.selected_answer = None
116
- st.write("Generated new question.")
117
 
118
  if st.session_state.question_count > 0:
119
  correct_percentage = (st.session_state.correct_count / st.session_state.question_count) * 100
@@ -135,13 +138,13 @@ if module_name:
135
 
136
  if st.session_state.selected_answer == st.session_state.correct_answer:
137
  st.session_state.correct_count += 1
138
- st.success("βœ”οΈ Correct!")
139
  else:
140
  st.error("✘ Incorrect.")
141
 
142
- st.write("Answer submitted.")
143
- st.write(f"Selected Answer: {st.session_state.selected_answer}")
144
- st.write(f"Correct Answer: {st.session_state.correct_answer}")
145
 
146
  # Explanation with proper width
147
  st.markdown(
@@ -157,7 +160,7 @@ if module_name:
157
  if st.session_state.submitted:
158
  if st.button("➑️ Next"):
159
  st.session_state.current_question = None
160
- st.write("Navigated to next question.")
161
 
162
  # Display the "Download PDF Report" button after at least one question has been answered
163
  if st.session_state.question_count > 0:
@@ -168,11 +171,11 @@ if module_name:
168
  file_name="quiz_report.pdf",
169
  mime="application/pdf"
170
  )
171
- st.write("PDF report generated.")
172
 
173
  except ModuleNotFoundError as e:
174
  st.error(f"The module '{module_name}' was not found. Please select another module.")
175
- st.write(f"Error: {e}")
176
  except Exception as e:
177
  st.error(f"An unexpected error occurred: {str(e)}")
178
- st.write(f"Error: {str(e)}")
 
1
  import streamlit as st
2
  import importlib
3
+ import logging
4
  from fpdf import FPDF
5
 
6
+ # Configure logging
7
+ logging.basicConfig(level=logging.INFO)
8
+
9
  # List of available modules with shorter names and icons
10
  module_names = {
11
  "Bases": "presentation_bases",
 
53
  pdf.multi_cell(0, 10, f"Q{idx+1}: {question}")
54
  for option in options:
55
  if option == correct:
56
+ pdf.multi_cell(0, 10, f"βœ” {option} (Correct)")
57
  elif option == selected:
58
  pdf.multi_cell(0, 10, f"✘ {option} (Your Choice)")
59
  else:
 
61
  pdf.multi_cell(0, 10, f"Explanation: {explanation}")
62
  pdf.ln(10)
63
 
64
+ return pdf.output(dest='S').encode('utf-8')
65
 
66
+ # Logging for debugging
67
+ logging.info(f"Current Module: {st.session_state.current_module}")
68
+ logging.info(f"Question Count: {st.session_state.question_count}")
69
+ logging.info(f"Correct Count: {st.session_state.correct_count}")
70
+ logging.info(f"Submitted: {st.session_state.submitted}")
71
+ logging.info(f"Current Question: {st.session_state.current_question}")
72
+ logging.info(f"Options: {st.session_state.options}")
73
+ logging.info(f"Selected Answer: {st.session_state.selected_answer}")
74
+ logging.info(f"Correct Answer: {st.session_state.correct_answer}")
75
+ logging.info(f"Explanation: {st.session_state.explanation}")
 
76
 
77
  # Streamlit interface
78
  st.sidebar.title("Quiz Modules")
 
86
  st.session_state.question_queue = []
87
  st.session_state.current_question = None
88
  st.session_state.submitted = False
89
+ logging.info("Module changed. Resetting session state.")
90
 
91
  module_file = module_names[module_name]
92
  try:
 
110
  st.session_state.selected_answer = question_data[2]
111
  st.session_state.correct_answer = question_data[3]
112
  st.session_state.explanation = question_data[4]
113
+ logging.info("Navigated to previous question.")
114
 
115
  if st.session_state.current_question is None or st.session_state.submitted:
116
  st.session_state.current_question, st.session_state.options, st.session_state.correct_answer, st.session_state.explanation = generate_question()
117
  st.session_state.submitted = False
118
  st.session_state.selected_answer = None
119
+ logging.info("Generated new question.")
120
 
121
  if st.session_state.question_count > 0:
122
  correct_percentage = (st.session_state.correct_count / st.session_state.question_count) * 100
 
138
 
139
  if st.session_state.selected_answer == st.session_state.correct_answer:
140
  st.session_state.correct_count += 1
141
+ st.success("βœ” Correct!")
142
  else:
143
  st.error("✘ Incorrect.")
144
 
145
+ logging.info("Answer submitted.")
146
+ logging.info(f"Selected Answer: {st.session_state.selected_answer}")
147
+ logging.info(f"Correct Answer: {st.session_state.correct_answer}")
148
 
149
  # Explanation with proper width
150
  st.markdown(
 
160
  if st.session_state.submitted:
161
  if st.button("➑️ Next"):
162
  st.session_state.current_question = None
163
+ logging.info("Navigated to next question.")
164
 
165
  # Display the "Download PDF Report" button after at least one question has been answered
166
  if st.session_state.question_count > 0:
 
171
  file_name="quiz_report.pdf",
172
  mime="application/pdf"
173
  )
174
+ logging.info("PDF report generated.")
175
 
176
  except ModuleNotFoundError as e:
177
  st.error(f"The module '{module_name}' was not found. Please select another module.")
178
+ logging.error(f"Error: {e}")
179
  except Exception as e:
180
  st.error(f"An unexpected error occurred: {str(e)}")
181
+ logging.error(f"Error: {str(e)}")