Penut commited on
Commit
ab1ba74
·
1 Parent(s): d7c9947

update app

Browse files
Files changed (1) hide show
  1. app.py +28 -6
app.py CHANGED
@@ -63,7 +63,7 @@ class App:
63
 
64
  def __init_record(self):
65
  with gr.Row():
66
- self.record = gr.TextArea(show_label=False)
67
 
68
  with gr.Row():
69
  self.again_btn = gr.Button("再次測驗")
@@ -81,12 +81,22 @@ class App:
81
  next_outs = [self.curr_item, self.question, self.question_list, self.answer]
82
  next_args = gr_args(self.next_question, next_inns, next_outs)
83
 
84
- check_inns = [self.answer, self.curr_item, self.correct, self.total]
85
- check_outs = [self.score, self.correct, self.total]
 
 
 
 
 
 
 
86
  check_args = gr_args(self.check, check_inns, check_outs)
 
87
 
88
  self.start_btn.click(**init_args).then(**reset_args).then(**next_args)
 
89
  self.answer.submit(**check_args).then(**next_args)
 
90
 
91
  def init_questions(self, chapters):
92
  question_list = [v for ch in chapters for v in self.vocab[ch]]
@@ -100,7 +110,7 @@ class App:
100
  return item, item["meaning"], question_list, None
101
  return None, None, None, None
102
 
103
- def check(self, answer, item, correct, total):
104
  total += 1
105
  if answer == item["kana"]:
106
  correct += 1
@@ -112,14 +122,26 @@ class App:
112
  kana = item["kana"]
113
  kanji = item["kanji"]
114
  meaning = item["meaning"]
115
- info = f"{correct}/{total} - 錯誤 {meaning} - {kana}"
 
116
  info += f" - {kanji}" if kanji is not None else ""
 
 
 
 
 
117
 
118
- return info, correct, total
 
 
 
119
 
120
  def reset_score(self):
121
  return "0/0", 0, 0
122
 
 
 
 
123
  def launch(self):
124
  self.app.launch()
125
 
 
63
 
64
  def __init_record(self):
65
  with gr.Row():
66
+ self.record = gr.TextArea(show_label=False, lines=15)
67
 
68
  with gr.Row():
69
  self.again_btn = gr.Button("再次測驗")
 
81
  next_outs = [self.curr_item, self.question, self.question_list, self.answer]
82
  next_args = gr_args(self.next_question, next_inns, next_outs)
83
 
84
+ check_inns = [
85
+ self.answer,
86
+ self.curr_item,
87
+ self.correct,
88
+ self.total,
89
+ self.record,
90
+ self.question_list,
91
+ ]
92
+ check_outs = [self.score, self.correct, self.total, self.record, self.tabs]
93
  check_args = gr_args(self.check, check_inns, check_outs)
94
+ back_args = gr_args(self.back_to_setting, None, self.tabs)
95
 
96
  self.start_btn.click(**init_args).then(**reset_args).then(**next_args)
97
+ self.again_btn.click(**init_args).then(**reset_args).then(**next_args)
98
  self.answer.submit(**check_args).then(**next_args)
99
+ self.back_to_setting_btn.click(**back_args)
100
 
101
  def init_questions(self, chapters):
102
  question_list = [v for ch in chapters for v in self.vocab[ch]]
 
110
  return item, item["meaning"], question_list, None
111
  return None, None, None, None
112
 
113
+ def check(self, answer, item, correct, total, record, question_list):
114
  total += 1
115
  if answer == item["kana"]:
116
  correct += 1
 
122
  kana = item["kana"]
123
  kanji = item["kanji"]
124
  meaning = item["meaning"]
125
+
126
+ info = f"錯誤 {meaning} - {kana}"
127
  info += f" - {kanji}" if kanji is not None else ""
128
+ record = f"{record}{info}\n"
129
+ info = f"{correct}/{total} - {info}"
130
+
131
+ if not question_list:
132
+ record = f"{record}\n此輪得分 - {correct}/{total}"
133
 
134
+ tab_idx = 1 if question_list else 2
135
+ tab_idx = gr.Tabs(selected=tab_idx)
136
+
137
+ return info, correct, total, record, tab_idx
138
 
139
  def reset_score(self):
140
  return "0/0", 0, 0
141
 
142
+ def back_to_setting(self):
143
+ return gr.Tabs(selected=0)
144
+
145
  def launch(self):
146
  self.app.launch()
147