dayuian commited on
Commit
af8e5d3
·
verified ·
1 Parent(s): b2dbf5f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -5
app.py CHANGED
@@ -119,7 +119,7 @@ with gr.Blocks(css="""
119
  value="common3000",
120
  label="選擇單字庫"
121
  )
122
- quiz_num_slider = gr.Slider(minimum=1, maximum=10, value=2, step=1, label="題目數量")
123
 
124
  quiz_generate_button = gr.Button("📄 生成試卷")
125
  quiz_submit_button = gr.Button("✅ 提交試卷")
@@ -133,13 +133,27 @@ with gr.Blocks(css="""
133
  questions = generate_fill_in_blank_exam(source, num)
134
  quiz_questions_state.value = questions
135
 
136
- radios = render_exam_interface(questions)
 
 
 
 
 
 
 
 
 
137
  return radios
138
 
139
  def submit_exam(*user_answers):
140
  questions = quiz_questions_state.value
141
- score_html = check_exam(user_answers, questions)
142
- return score_html
 
 
 
 
 
143
 
144
  quiz_generate_button.click(
145
  display_exam,
@@ -153,4 +167,4 @@ with gr.Blocks(css="""
153
  outputs=quiz_score_display
154
  )
155
 
156
- demo.launch()
 
119
  value="common3000",
120
  label="選擇單字庫"
121
  )
122
+ quiz_num_slider = gr.Slider(minimum=1, maximum=5, value=2, step=1, label="題目數量")
123
 
124
  quiz_generate_button = gr.Button("📄 生成試卷")
125
  quiz_submit_button = gr.Button("✅ 提交試卷")
 
133
  questions = generate_fill_in_blank_exam(source, num)
134
  quiz_questions_state.value = questions
135
 
136
+ radios = []
137
+ for i, q in enumerate(questions):
138
+ radios.append(
139
+ gr.Radio(
140
+ choices=q['options'],
141
+ label=f"第 {i + 1} 題:{q['sentence']}",
142
+ interactive=True
143
+ )
144
+ )
145
+
146
  return radios
147
 
148
  def submit_exam(*user_answers):
149
  questions = quiz_questions_state.value
150
+ score, results = check_exam(user_answers, questions)
151
+ result_html = f"<p><strong>分數:</strong> {score}</p>"
152
+
153
+ for res in results:
154
+ result_html += f"<p>{res['question']}<br> 你的答案:{res['user_answer']} <br> 正確答案:{res['correct_answer']} <br> {'✅' if res['is_correct'] else '❌'}</p>"
155
+
156
+ return result_html
157
 
158
  quiz_generate_button.click(
159
  display_exam,
 
167
  outputs=quiz_score_display
168
  )
169
 
170
+ demo.launch()