Sina Media Lab commited on
Commit
9124e0f
Β·
1 Parent(s): 795b9ba
Files changed (1) hide show
  1. app.py +32 -21
app.py CHANGED
@@ -25,6 +25,8 @@ if 'question_queue' not in st.session_state:
25
  st.session_state.question_queue = []
26
  if 'submitted' not in st.session_state:
27
  st.session_state.submitted = False
 
 
28
 
29
  def generate_pdf_report():
30
  pdf = FPDF()
@@ -59,9 +61,6 @@ if module_name:
59
  # Show module title and description
60
  st.title(title)
61
  st.write(description)
62
-
63
- # Add spacing to ensure question visibility on Hugging Face
64
- st.markdown("<br><br>", unsafe_allow_html=True)
65
 
66
  if st.session_state.submitted:
67
  st.session_state.submitted = False
@@ -79,32 +78,44 @@ if module_name:
79
  else:
80
  st.error("❌ Incorrect.")
81
  st.write(f"**Explanation:** {st.session_state.explanation}")
82
-
83
  if st.session_state.question_count > 0:
84
  correct_percentage = (st.session_state.correct_count / st.session_state.question_count) * 100
85
  st.write(f"**Correct Answers:** {st.session_state.correct_count}/{st.session_state.question_count} ({correct_percentage:.2f}%)")
86
 
87
- st.session_state.current_question, options, st.session_state.correct_answer, st.session_state.explanation = generate_question()
88
- st.write(f"**Question {st.session_state.question_count + 1}:** {st.session_state.current_question}")
89
- st.session_state.selected_answer = st.radio("Choose an answer:", options)
 
90
 
91
- col1, col2, col3 = st.columns(3)
92
- if col1.button("Submit"):
93
- st.session_state.submitted = True
94
- st.experimental_rerun()
95
-
96
- if st.session_state.question_count > 0:
97
  with col2:
98
- if st.button("Next Question"):
 
99
  st.experimental_rerun()
100
 
 
 
 
 
 
 
 
 
 
101
  with col3:
102
- pdf = generate_pdf_report()
103
- st.download_button(
104
- label="Download PDF Report πŸ“„",
105
- data=pdf,
106
- file_name="quiz_report.pdf",
107
- mime="application/pdf"
108
- )
 
 
109
  except ModuleNotFoundError:
110
  st.error(f"The module '{module_name}' was not found. Please select another module.")
 
25
  st.session_state.question_queue = []
26
  if 'submitted' not in st.session_state:
27
  st.session_state.submitted = False
28
+ if 'selected_answer' not in st.session_state:
29
+ st.session_state.selected_answer = None
30
 
31
  def generate_pdf_report():
32
  pdf = FPDF()
 
61
  # Show module title and description
62
  st.title(title)
63
  st.write(description)
 
 
 
64
 
65
  if st.session_state.submitted:
66
  st.session_state.submitted = False
 
78
  else:
79
  st.error("❌ Incorrect.")
80
  st.write(f"**Explanation:** {st.session_state.explanation}")
81
+
82
  if st.session_state.question_count > 0:
83
  correct_percentage = (st.session_state.correct_count / st.session_state.question_count) * 100
84
  st.write(f"**Correct Answers:** {st.session_state.correct_count}/{st.session_state.question_count} ({correct_percentage:.2f}%)")
85
 
86
+ if not st.session_state.submitted:
87
+ st.session_state.current_question, options, st.session_state.correct_answer, st.session_state.explanation = generate_question()
88
+ st.write(f"**Question {st.session_state.question_count + 1}:** {st.session_state.current_question}")
89
+ st.session_state.selected_answer = st.radio("Choose an answer:", options)
90
 
91
+ col1, col2 = st.columns([1, 5])
92
+ with col1:
93
+ if st.button("⬅️ Prev"):
94
+ # Logic for previous question (if applicable)
95
+ pass
 
96
  with col2:
97
+ if st.button("Submit"):
98
+ st.session_state.submitted = True
99
  st.experimental_rerun()
100
 
101
+ if st.session_state.submitted:
102
+ col1, col2, col3 = st.columns([1, 1, 3])
103
+ with col1:
104
+ if st.button("⬅️ Prev"):
105
+ # Logic for previous question (if applicable)
106
+ pass
107
+ with col2:
108
+ if st.button("➑️ Next"):
109
+ st.experimental_rerun()
110
  with col3:
111
+ if st.session_state.question_count > 0:
112
+ pdf = generate_pdf_report()
113
+ st.download_button(
114
+ label="Download PDF Report πŸ“„",
115
+ data=pdf,
116
+ file_name="quiz_report.pdf",
117
+ mime="application/pdf"
118
+ )
119
+
120
  except ModuleNotFoundError:
121
  st.error(f"The module '{module_name}' was not found. Please select another module.")