gardarjuto commited on
Commit
fcffb23
1 Parent(s): 5ab11e2

add question breakdown to score screen

Browse files
Files changed (1) hide show
  1. app.py +65 -4
app.py CHANGED
@@ -7,6 +7,7 @@ mpl.rcParams["figure.dpi"] = 300
7
 
8
  quiz = BenchmarkQuiz()
9
 
 
10
  def update_quiz_screen(question_data: QuestionData):
11
  quiz_state = quiz.state
12
  return {
@@ -31,11 +32,39 @@ def update_quiz_screen(question_data: QuestionData):
31
  }
32
 
33
 
34
- def update_score_screen(plot):
35
- return {
36
  score_screen: gr.update(visible=True),
37
  score_plot: gr.update(value=plot),
 
38
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
 
41
  def start_quiz_handler(benchmark_name):
@@ -58,7 +87,7 @@ def next_question_handler(answer_input, free_text_input):
58
  if result["completed"]:
59
  return {
60
  quiz_screen: gr.update(visible=False),
61
- **update_score_screen(result["plot"]),
62
  }
63
  else:
64
  return update_quiz_screen(result["question_data"])
@@ -78,8 +107,31 @@ def reset_quiz_handler():
78
  }
79
 
80
 
 
 
 
 
 
 
 
 
 
 
 
 
81
 
82
- with gr.Blocks(theme=gr.themes.Soft()) as demo:
 
 
 
 
 
 
 
 
 
 
 
83
  start_screen = gr.Column(visible=True)
84
  with start_screen:
85
  gr.Markdown("# Veldu mælipróf")
@@ -102,6 +154,12 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
102
  gr.Markdown(f"## Niðurstöður")
103
  score_plot = gr.Plot()
104
  reset_btn = gr.Button("Byrja upp á nýtt")
 
 
 
 
 
 
105
 
106
  for benchmark_name, button in benchmark_buttons.items():
107
  button.click(
@@ -133,6 +191,9 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
133
  next_button,
134
  previous_button,
135
  score_plot,
 
 
 
136
  ],
137
  )
138
 
 
7
 
8
  quiz = BenchmarkQuiz()
9
 
10
+
11
  def update_quiz_screen(question_data: QuestionData):
12
  quiz_state = quiz.state
13
  return {
 
32
  }
33
 
34
 
35
+ def update_score_screen(plot, results_data):
36
+ updates = {
37
  score_screen: gr.update(visible=True),
38
  score_plot: gr.update(value=plot),
39
+ results_container: gr.update(visible=True),
40
  }
41
+ for i, result in enumerate(results_data):
42
+ updates[result_cards[i]] = gr.update(
43
+ visible=True,
44
+ elem_classes=[
45
+ "correct-answer"
46
+ if result["points"] == 1.0
47
+ else "semi-correct-answer"
48
+ if result["points"] == 0.5
49
+ else "incorrect-answer"
50
+ ],
51
+ )
52
+ emoji = "✅" if result["points"] == 1.0 else "❌" if result["points"] == 0.0 else "🔶"
53
+
54
+ markdown_string = f"### {emoji} Spurning {result['question_num']}"
55
+ markdown_string += f"\n{result['question']}"
56
+ markdown_string += (
57
+ f"\n\nValkostir:\n"
58
+ + "\n".join([f"- {option}" for option in result["options"]])
59
+ if result["options"]
60
+ else ""
61
+ )
62
+ markdown_string += f"\n\n**Þitt svar:** {result['user_answer']}"
63
+ markdown_string += f"\n\n**Rétt svar:** {result['correct_answer']}"
64
+ markdown_string += f"\n\n**Stig:** {result['points']}"
65
+ updates[result_cards[i].children[0]] = gr.update(value=markdown_string)
66
+
67
+ return updates
68
 
69
 
70
  def start_quiz_handler(benchmark_name):
 
87
  if result["completed"]:
88
  return {
89
  quiz_screen: gr.update(visible=False),
90
+ **update_score_screen(result["plot"], result["results_data"]),
91
  }
92
  else:
93
  return update_quiz_screen(result["question_data"])
 
107
  }
108
 
109
 
110
+ demo = gr.Blocks(
111
+ theme=gr.themes.Soft(),
112
+ title="Mælipróf",
113
+ css="""
114
+ .correct-answer, .correct-answer .block {
115
+ background-color: #d4edda !important;
116
+ border-color: #c3e6cb !important;
117
+ }
118
+ .incorrect-answer, .incorrect-answer .block {
119
+ background-color: #f8d7da !important;
120
+ border-color: #f5c6cb !important;
121
+ }
122
 
123
+ .semi-correct-answer, .semi-correct-answer .block {
124
+ background-color: #fff3cd !important;
125
+ border-color: #ffeeba !important;
126
+ }
127
+ .correct-answer, .incorrect-answer, .semi-correct-answer {
128
+ border-radius: 5px;
129
+ padding: 10px;
130
+ margin-bottom: 10px;
131
+ }
132
+ """,
133
+ )
134
+ with demo:
135
  start_screen = gr.Column(visible=True)
136
  with start_screen:
137
  gr.Markdown("# Veldu mælipróf")
 
154
  gr.Markdown(f"## Niðurstöður")
155
  score_plot = gr.Plot()
156
  reset_btn = gr.Button("Byrja upp á nýtt")
157
+ results_container = gr.Column(visible=False)
158
+ with results_container:
159
+ result_cards = [gr.Group(visible=False) for _ in range(5)]
160
+ for card in result_cards:
161
+ with card:
162
+ gr.Markdown("")
163
 
164
  for benchmark_name, button in benchmark_buttons.items():
165
  button.click(
 
191
  next_button,
192
  previous_button,
193
  score_plot,
194
+ results_container,
195
+ *result_cards,
196
+ *[child for card in result_cards for child in card.children],
197
  ],
198
  )
199