kevineen commited on
Commit
2f845c0
1 Parent(s): cf30d79

readme修正 5段階評価button並び順修正

Browse files
Files changed (5) hide show
  1. .gitignore +4 -2
  2. README.md +12 -0
  3. app.py +46 -30
  4. huggingface_dataset.txt +8 -8
  5. run.py +48 -34
.gitignore CHANGED
@@ -162,5 +162,7 @@ cython_debug/
162
  #.idea/
163
 
164
  user_annotation/*
165
-
166
- backup.py
 
 
 
162
  #.idea/
163
 
164
  user_annotation/*
165
+ run.py
166
+ backup.py
167
+ huggingface_dataset.txt
168
+ note.txt
README.md CHANGED
@@ -8,6 +8,18 @@ app_file: app.py
8
  pinned: false
9
  license: unknown
10
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  hf_oauth: true
12
  # optional, default duration is 8 hours/480 minutes. Max duration is 30 days/43200 minutes.
13
  hf_oauth_expiration_minutes: 480
 
8
  pinned: false
9
  license: unknown
10
 
11
+ language:
12
+ - ja
13
+
14
+ datasets:
15
+ - team-hatakeyama-phase2/annotation_tanuki_phase2
16
+ - hatakeyama-llm-team/AutoGeneratedJapaneseQA
17
+ - hatakeyama-llm-team/AutoGeneratedJapaneseQA-other
18
+ - kanhatakeyama/ChatbotArenaJaMixtral8x22b
19
+ - kanhatakeyama/OrcaJaMixtral8x22b
20
+ - kanhatakeyama/LogicalDatasetsByMixtral8x22b
21
+ - kanhatakeyama/AutoMultiTurnByMixtral8x22b
22
+
23
  hf_oauth: true
24
  # optional, default duration is 8 hours/480 minutes. Max duration is 30 days/43200 minutes.
25
  hf_oauth_expiration_minutes: 480
app.py CHANGED
@@ -104,6 +104,7 @@ answer_text_2 = gr.State("") # answer_2 回答
104
  # 未整理
105
  # データ読み込み ========================================
106
 
 
107
  def dataset_load_fn() -> Tuple[
108
  str,
109
  str,
@@ -228,6 +229,8 @@ def save_annotation(
228
  # UI処理 ========================================
229
 
230
  # ユーザー名表示
 
 
231
  def hello(profile: gr.OAuthProfile | None) -> Tuple[str, str]:
232
  if profile is None:
233
  return "プライベートデータセット取得のためにログインしてください。", who.value
@@ -289,7 +292,8 @@ with gr.Blocks(theme=theme_, css=load_css()) as demo:
289
  with gr.Column():
290
  with gr.Row(equal_height=True):
291
  good_btn = gr.Button("良い", interactive=False)
292
- unknown_btn = gr.Button("分からない", interactive=False) # 「分からない」ボタンを追加
 
293
  bad_btn = gr.Button("悪い", interactive=False)
294
 
295
  gr_question_text_1 = gr.Textbox(
@@ -306,11 +310,11 @@ with gr.Blocks(theme=theme_, css=load_css()) as demo:
306
  label="質問: ", lines=5, interactive=False)
307
 
308
  with gr.Row() as score_btn:
309
- gr_score_1 = gr.Button("1: 低品質", interactive=False)
310
- gr_score_2 = gr.Button("2: 悪い", interactive=False)
311
- gr_score_3 = gr.Button("3: 普通", interactive=False)
312
- gr_score_4 = gr.Button("4: 良い", interactive=False)
313
  gr_score_5 = gr.Button("5: 高品質", interactive=False)
 
 
 
 
314
 
315
  gr_answer_text_3 = gr.Textbox(
316
  label="回答: 訂正して頂けると品質が上がります。", lines=20, interactive=True)
@@ -319,7 +323,7 @@ with gr.Blocks(theme=theme_, css=load_css()) as demo:
319
  def score_button_clicked(button_value):
320
  good.value = False
321
  bad.value = False
322
- unknown_quality.value = False # 「分からない」の状態をリセット
323
  score.value = button_value
324
 
325
  gr_data_load_btn.click(
@@ -349,6 +353,34 @@ with gr.Blocks(theme=theme_, css=load_css()) as demo:
349
  ) -> Tuple[gr.update, gr.update, gr.update, gr.update]:
350
 
351
  # good/bad/unknown と score の状態を更新
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
352
  if score_value is not None: # 5段階評価の場合
353
  good.value = False
354
  bad.value = False
@@ -359,7 +391,7 @@ with gr.Blocks(theme=theme_, css=load_css()) as demo:
359
  bad.value = not is_good if not is_unknown else False
360
  unknown_quality.value = is_unknown # 「分からない」の状態を設定
361
 
362
- # 変更を検知 (5段階評価の場合も処理するように変更)
363
  if input_ans_1 is not None and initial_answer_text_1.value != input_ans_1:
364
  is_proofreading_1.value = True
365
  answer_text_1.value = input_ans_1
@@ -372,18 +404,7 @@ with gr.Blocks(theme=theme_, css=load_css()) as demo:
372
  else:
373
  answer_text_2.value = ""
374
 
375
- # 表示更新
376
- # indexを進める
377
- select_idx.value += 1
378
-
379
- df = select_dataset.value["train"]
380
-
381
- # ループさせるか、エラー処理を行う
382
- if select_idx.value >= len(df):
383
- select_idx.value = 0
384
-
385
- # データセットに追加
386
- # 元のindex番号(dataset_id)を指定して保存
387
  save_annotation(
388
  select_dropdown_dataset.value,
389
  # datasetIdは元のindex番号を使用
@@ -399,17 +420,12 @@ with gr.Blocks(theme=theme_, css=load_css()) as demo:
399
  answer_text_2.value
400
  )
401
 
402
- # Nextデータ初期化
403
  is_proofreading_1.value = False
404
  is_proofreading_2.value = False
405
  initial_answer_text_1.value = df.iloc[select_idx.value]["answer"]
406
  initial_answer_text_2.value = df.iloc[select_idx.value]["answer"]
407
 
408
- return gr.update(value=df.iloc[select_idx.value]["question"]), \
409
- gr.update(value=df.iloc[select_idx.value]["answer"]), \
410
- gr.update(value=df.iloc[select_idx.value]["question"]), \
411
- gr.update(value=df.iloc[select_idx.value]["answer"])
412
-
413
  def good_click(input_ans_1, input_ans_3):
414
  return update_annotation(input_ans_1=input_ans_1, input_ans_3=input_ans_3, is_good=True, is_unknown=False)
415
 
@@ -458,15 +474,15 @@ with gr.Blocks(theme=theme_, css=load_css()) as demo:
458
  )
459
 
460
  # 5段階評価ボタンのクリックイベント
461
- gr_score_1.click(lambda x: update_annotation(input_ans_1=x, input_ans_3=x, is_unknown=False, score_value=1),
462
  inputs=[gr_answer_text_3], outputs=[gr_question_text_1, gr_answer_text_1, gr_question_text_3, gr_answer_text_3])
463
- gr_score_2.click(lambda x: update_annotation(input_ans_1=x, input_ans_3=x, is_unknown=False, score_value=2),
464
  inputs=[gr_answer_text_3], outputs=[gr_question_text_1, gr_answer_text_1, gr_question_text_3, gr_answer_text_3])
465
- gr_score_3.click(lambda x: update_annotation(input_ans_1=x, input_ans_3=x, is_unknown=False, score_value=3),
466
  inputs=[gr_answer_text_3], outputs=[gr_question_text_1, gr_answer_text_1, gr_question_text_3, gr_answer_text_3])
467
- gr_score_4.click(lambda x: update_annotation(input_ans_1=x, input_ans_3=x, is_unknown=False, score_value=4),
468
  inputs=[gr_answer_text_3], outputs=[gr_question_text_1, gr_answer_text_1, gr_question_text_3, gr_answer_text_3])
469
- gr_score_5.click(lambda x: update_annotation(input_ans_1=x, input_ans_3=x, is_unknown=False, score_value=5),
470
  inputs=[gr_answer_text_3], outputs=[gr_question_text_1, gr_answer_text_1, gr_question_text_3, gr_answer_text_3])
471
 
472
  # TODO Tab切り替えで、アノテ済みの一覧を表示する
 
104
  # 未整理
105
  # データ読み込み ========================================
106
 
107
+
108
  def dataset_load_fn() -> Tuple[
109
  str,
110
  str,
 
229
  # UI処理 ========================================
230
 
231
  # ユーザー名表示
232
+
233
+
234
  def hello(profile: gr.OAuthProfile | None) -> Tuple[str, str]:
235
  if profile is None:
236
  return "プライベートデータセット取得のためにログインしてください。", who.value
 
292
  with gr.Column():
293
  with gr.Row(equal_height=True):
294
  good_btn = gr.Button("良い", interactive=False)
295
+ unknown_btn = gr.Button(
296
+ "分からない", interactive=False) # 「分からない」ボタンを追加
297
  bad_btn = gr.Button("悪い", interactive=False)
298
 
299
  gr_question_text_1 = gr.Textbox(
 
310
  label="質問: ", lines=5, interactive=False)
311
 
312
  with gr.Row() as score_btn:
 
 
 
 
313
  gr_score_5 = gr.Button("5: 高品質", interactive=False)
314
+ gr_score_4 = gr.Button("4: 良い", interactive=False)
315
+ gr_score_3 = gr.Button("3: 普通", interactive=False)
316
+ gr_score_2 = gr.Button("2: 悪い", interactive=False)
317
+ gr_score_1 = gr.Button("1: 低品質", interactive=False)
318
 
319
  gr_answer_text_3 = gr.Textbox(
320
  label="回答: 訂正して頂けると品質が上がります。", lines=20, interactive=True)
 
323
  def score_button_clicked(button_value):
324
  good.value = False
325
  bad.value = False
326
+ unknown_quality.value = False # 「分からない」の状態をリセット
327
  score.value = button_value
328
 
329
  gr_data_load_btn.click(
 
353
  ) -> Tuple[gr.update, gr.update, gr.update, gr.update]:
354
 
355
  # good/bad/unknown と score の状態を更新
356
+ update_evaluation_state(is_good, is_unknown, score_value)
357
+
358
+ # 変更を検知 (5段階評価の場合も処理するように変更)
359
+ update_answer_state(input_ans_1, input_ans_3)
360
+
361
+ # 表示更新
362
+ # indexを進める
363
+ select_idx.value += 1
364
+
365
+ df = select_dataset.value["train"]
366
+
367
+ # ループさせるか、エラー処理を行う
368
+ if select_idx.value >= len(df):
369
+ select_idx.value = 0
370
+
371
+ # データセットに追加
372
+ # 元のindex番号(dataset_id)を指定して保存
373
+ save_annotation_data(df)
374
+
375
+ # Nextデータ初期化
376
+ initialize_next_data(df)
377
+
378
+ return gr.update(value=df.iloc[select_idx.value]["question"]), \
379
+ gr.update(value=df.iloc[select_idx.value]["answer"]), \
380
+ gr.update(value=df.iloc[select_idx.value]["question"]), \
381
+ gr.update(value=df.iloc[select_idx.value]["answer"])
382
+
383
+ def update_evaluation_state(is_good, is_unknown, score_value):
384
  if score_value is not None: # 5段階評価の場合
385
  good.value = False
386
  bad.value = False
 
391
  bad.value = not is_good if not is_unknown else False
392
  unknown_quality.value = is_unknown # 「分からない」の状態を設定
393
 
394
+ def update_answer_state(input_ans_1, input_ans_3):
395
  if input_ans_1 is not None and initial_answer_text_1.value != input_ans_1:
396
  is_proofreading_1.value = True
397
  answer_text_1.value = input_ans_1
 
404
  else:
405
  answer_text_2.value = ""
406
 
407
+ def save_annotation_data(df):
 
 
 
 
 
 
 
 
 
 
 
408
  save_annotation(
409
  select_dropdown_dataset.value,
410
  # datasetIdは元のindex番号を使用
 
420
  answer_text_2.value
421
  )
422
 
423
+ def initialize_next_data(df):
424
  is_proofreading_1.value = False
425
  is_proofreading_2.value = False
426
  initial_answer_text_1.value = df.iloc[select_idx.value]["answer"]
427
  initial_answer_text_2.value = df.iloc[select_idx.value]["answer"]
428
 
 
 
 
 
 
429
  def good_click(input_ans_1, input_ans_3):
430
  return update_annotation(input_ans_1=input_ans_1, input_ans_3=input_ans_3, is_good=True, is_unknown=False)
431
 
 
474
  )
475
 
476
  # 5段階評価ボタンのクリックイベント
477
+ gr_score_1.click(lambda x: update_annotation(input_ans_1=x, is_unknown=False, score_value=1),
478
  inputs=[gr_answer_text_3], outputs=[gr_question_text_1, gr_answer_text_1, gr_question_text_3, gr_answer_text_3])
479
+ gr_score_2.click(lambda x: update_annotation(input_ans_1=x, is_unknown=False, score_value=2),
480
  inputs=[gr_answer_text_3], outputs=[gr_question_text_1, gr_answer_text_1, gr_question_text_3, gr_answer_text_3])
481
+ gr_score_3.click(lambda x: update_annotation(input_ans_1=x, is_unknown=False, score_value=3),
482
  inputs=[gr_answer_text_3], outputs=[gr_question_text_1, gr_answer_text_1, gr_question_text_3, gr_answer_text_3])
483
+ gr_score_4.click(lambda x: update_annotation(input_ans_1=x, is_unknown=False, score_value=4),
484
  inputs=[gr_answer_text_3], outputs=[gr_question_text_1, gr_answer_text_1, gr_question_text_3, gr_answer_text_3])
485
+ gr_score_5.click(lambda x: update_annotation(input_ans_1=x, is_unknown=False, score_value=5),
486
  inputs=[gr_answer_text_3], outputs=[gr_question_text_1, gr_answer_text_1, gr_question_text_3, gr_answer_text_3])
487
 
488
  # TODO Tab切り替えで、アノテ済みの一覧を表示する
huggingface_dataset.txt CHANGED
@@ -59,6 +59,13 @@ fileSize 116MB
59
  - question string
60
  - answer string
61
 
 
 
 
 
 
 
 
62
  # kevineen/Tanuki-Phase2-annotation-dataset
63
  - index int64
64
  - datetime string
@@ -72,11 +79,4 @@ fileSize 116MB
72
  - is_proofreading_1 bool
73
  - answer_text_1 string
74
  - is_proofreading_2 bool
75
- - answer_text_2 string
76
-
77
- # susumuota/SyntheticTextWikiTranslate-askllm-v1
78
- - mode string
79
- - url string
80
- - ja string
81
- - eng string
82
- - askllm_score float64
 
59
  - question string
60
  - answer string
61
 
62
+ # susumuota/SyntheticTextWikiTranslate-askllm-v1
63
+ - mode string
64
+ - url string
65
+ - ja string
66
+ - eng string
67
+ - askllm_score float64
68
+
69
  # kevineen/Tanuki-Phase2-annotation-dataset
70
  - index int64
71
  - datetime string
 
79
  - is_proofreading_1 bool
80
  - answer_text_1 string
81
  - is_proofreading_2 bool
82
+ - answer_text_2 string
 
 
 
 
 
 
 
run.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  import os
2
  from dotenv import load_dotenv
3
 
@@ -103,7 +105,6 @@ answer_text_2 = gr.State("") # answer_2 回答
103
 
104
  # 未整理
105
  # データ読み込み ========================================
106
-
107
  def dataset_load_fn() -> Tuple[
108
  str,
109
  str,
@@ -163,7 +164,7 @@ annotation_file = Path("user_annotation/") / f"data_{uuid.uuid4()}.json"
163
  annotated_folder = annotation_file.parent
164
 
165
  scheduler = CommitScheduler(
166
- repo_id=output_dataset[0],
167
  repo_type="dataset",
168
  folder_path=annotated_folder,
169
  path_in_repo="data", # Spaceの場合の保存先フォルダー
@@ -172,8 +173,6 @@ scheduler = CommitScheduler(
172
  )
173
 
174
  # CommitScheduler (HFへのデータアップロード
175
-
176
-
177
  def save_annotation(
178
  dataset_name: str,
179
  dataset_id: int,
@@ -230,6 +229,8 @@ def save_annotation(
230
  # UI処理 ========================================
231
 
232
  # ユーザー名表示
 
 
233
  def hello(profile: gr.OAuthProfile | None) -> Tuple[str, str]:
234
  if profile is None:
235
  return "プライベートデータセット取得のためにログインしてください。", who.value
@@ -291,7 +292,8 @@ with gr.Blocks(theme=theme_, css=load_css()) as demo:
291
  with gr.Column():
292
  with gr.Row(equal_height=True):
293
  good_btn = gr.Button("良い", interactive=False)
294
- unknown_btn = gr.Button("分からない", interactive=False) # 「分からない」ボタンを追加
 
295
  bad_btn = gr.Button("悪い", interactive=False)
296
 
297
  gr_question_text_1 = gr.Textbox(
@@ -308,11 +310,11 @@ with gr.Blocks(theme=theme_, css=load_css()) as demo:
308
  label="質問: ", lines=5, interactive=False)
309
 
310
  with gr.Row() as score_btn:
311
- gr_score_1 = gr.Button("1: 低品質", interactive=False)
312
- gr_score_2 = gr.Button("2: 悪い", interactive=False)
313
- gr_score_3 = gr.Button("3: 普通", interactive=False)
314
- gr_score_4 = gr.Button("4: 良い", interactive=False)
315
  gr_score_5 = gr.Button("5: 高品質", interactive=False)
 
 
 
 
316
 
317
  gr_answer_text_3 = gr.Textbox(
318
  label="回答: 訂正して頂けると品質が上がります。", lines=20, interactive=True)
@@ -321,7 +323,7 @@ with gr.Blocks(theme=theme_, css=load_css()) as demo:
321
  def score_button_clicked(button_value):
322
  good.value = False
323
  bad.value = False
324
- unknown_quality.value = False # 「分からない」の状態をリセット
325
  score.value = button_value
326
 
327
  gr_data_load_btn.click(
@@ -351,6 +353,34 @@ with gr.Blocks(theme=theme_, css=load_css()) as demo:
351
  ) -> Tuple[gr.update, gr.update, gr.update, gr.update]:
352
 
353
  # good/bad/unknown と score の状態を更新
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
354
  if score_value is not None: # 5段階評価の場合
355
  good.value = False
356
  bad.value = False
@@ -361,7 +391,7 @@ with gr.Blocks(theme=theme_, css=load_css()) as demo:
361
  bad.value = not is_good if not is_unknown else False
362
  unknown_quality.value = is_unknown # 「分からない」の状態を設定
363
 
364
- # 変更を検知 (5段階評価の場合も処理するように変更)
365
  if input_ans_1 is not None and initial_answer_text_1.value != input_ans_1:
366
  is_proofreading_1.value = True
367
  answer_text_1.value = input_ans_1
@@ -374,18 +404,7 @@ with gr.Blocks(theme=theme_, css=load_css()) as demo:
374
  else:
375
  answer_text_2.value = ""
376
 
377
- # 表示更新
378
- # indexを進める
379
- select_idx.value += 1
380
-
381
- df = select_dataset.value["train"]
382
-
383
- # ループさせるか、エラー処理を行う
384
- if select_idx.value >= len(df):
385
- select_idx.value = 0
386
-
387
- # データセットに追加
388
- # 元のindex番号(dataset_id)を指定して保存
389
  save_annotation(
390
  select_dropdown_dataset.value,
391
  # datasetIdは元のindex番号を使用
@@ -401,17 +420,12 @@ with gr.Blocks(theme=theme_, css=load_css()) as demo:
401
  answer_text_2.value
402
  )
403
 
404
- # Nextデータ初期化
405
  is_proofreading_1.value = False
406
  is_proofreading_2.value = False
407
  initial_answer_text_1.value = df.iloc[select_idx.value]["answer"]
408
  initial_answer_text_2.value = df.iloc[select_idx.value]["answer"]
409
 
410
- return gr.update(value=df.iloc[select_idx.value]["question"]), \
411
- gr.update(value=df.iloc[select_idx.value]["answer"]), \
412
- gr.update(value=df.iloc[select_idx.value]["question"]), \
413
- gr.update(value=df.iloc[select_idx.value]["answer"])
414
-
415
  def good_click(input_ans_1, input_ans_3):
416
  return update_annotation(input_ans_1=input_ans_1, input_ans_3=input_ans_3, is_good=True, is_unknown=False)
417
 
@@ -460,15 +474,15 @@ with gr.Blocks(theme=theme_, css=load_css()) as demo:
460
  )
461
 
462
  # 5段階評価ボタンのクリックイベント
463
- gr_score_1.click(lambda x: update_annotation(input_ans_1=x, input_ans_3=x, is_unknown=False, score_value=1),
464
  inputs=[gr_answer_text_3], outputs=[gr_question_text_1, gr_answer_text_1, gr_question_text_3, gr_answer_text_3])
465
- gr_score_2.click(lambda x: update_annotation(input_ans_1=x, input_ans_3=x, is_unknown=False, score_value=2),
466
  inputs=[gr_answer_text_3], outputs=[gr_question_text_1, gr_answer_text_1, gr_question_text_3, gr_answer_text_3])
467
- gr_score_3.click(lambda x: update_annotation(input_ans_1=x, input_ans_3=x, is_unknown=False, score_value=3),
468
  inputs=[gr_answer_text_3], outputs=[gr_question_text_1, gr_answer_text_1, gr_question_text_3, gr_answer_text_3])
469
- gr_score_4.click(lambda x: update_annotation(input_ans_1=x, input_ans_3=x, is_unknown=False, score_value=4),
470
  inputs=[gr_answer_text_3], outputs=[gr_question_text_1, gr_answer_text_1, gr_question_text_3, gr_answer_text_3])
471
- gr_score_5.click(lambda x: update_annotation(input_ans_1=x, input_ans_3=x, is_unknown=False, score_value=5),
472
  inputs=[gr_answer_text_3], outputs=[gr_question_text_1, gr_answer_text_1, gr_question_text_3, gr_answer_text_3])
473
 
474
  # TODO Tab切り替えで、アノテ済みの一覧を表示する
 
1
+ # gradio run.pyでHotReload開発
2
+
3
  import os
4
  from dotenv import load_dotenv
5
 
 
105
 
106
  # 未整理
107
  # データ読み込み ========================================
 
108
  def dataset_load_fn() -> Tuple[
109
  str,
110
  str,
 
164
  annotated_folder = annotation_file.parent
165
 
166
  scheduler = CommitScheduler(
167
+ repo_id=output_dataset[1],
168
  repo_type="dataset",
169
  folder_path=annotated_folder,
170
  path_in_repo="data", # Spaceの場合の保存先フォルダー
 
173
  )
174
 
175
  # CommitScheduler (HFへのデータアップロード
 
 
176
  def save_annotation(
177
  dataset_name: str,
178
  dataset_id: int,
 
229
  # UI処理 ========================================
230
 
231
  # ユーザー名表示
232
+
233
+
234
  def hello(profile: gr.OAuthProfile | None) -> Tuple[str, str]:
235
  if profile is None:
236
  return "プライベートデータセット取得のためにログインしてください。", who.value
 
292
  with gr.Column():
293
  with gr.Row(equal_height=True):
294
  good_btn = gr.Button("良い", interactive=False)
295
+ unknown_btn = gr.Button(
296
+ "分からない", interactive=False) # 「分からない」ボタンを追加
297
  bad_btn = gr.Button("悪い", interactive=False)
298
 
299
  gr_question_text_1 = gr.Textbox(
 
310
  label="質問: ", lines=5, interactive=False)
311
 
312
  with gr.Row() as score_btn:
 
 
 
 
313
  gr_score_5 = gr.Button("5: 高品質", interactive=False)
314
+ gr_score_4 = gr.Button("4: 良い", interactive=False)
315
+ gr_score_3 = gr.Button("3: 普通", interactive=False)
316
+ gr_score_2 = gr.Button("2: 悪い", interactive=False)
317
+ gr_score_1 = gr.Button("1: 低品質", interactive=False)
318
 
319
  gr_answer_text_3 = gr.Textbox(
320
  label="回答: 訂正して頂けると品質が上がります。", lines=20, interactive=True)
 
323
  def score_button_clicked(button_value):
324
  good.value = False
325
  bad.value = False
326
+ unknown_quality.value = False # 「分からない」の状態をリセット
327
  score.value = button_value
328
 
329
  gr_data_load_btn.click(
 
353
  ) -> Tuple[gr.update, gr.update, gr.update, gr.update]:
354
 
355
  # good/bad/unknown と score の状態を更新
356
+ update_evaluation_state(is_good, is_unknown, score_value)
357
+
358
+ # 変更を検知 (5段階評価の場合も処理するように変更)
359
+ update_answer_state(input_ans_1, input_ans_3)
360
+
361
+ # 表示更新
362
+ # indexを進める
363
+ select_idx.value += 1
364
+
365
+ df = select_dataset.value["train"]
366
+
367
+ # ループさせるか、エラー処理を行う
368
+ if select_idx.value >= len(df):
369
+ select_idx.value = 0
370
+
371
+ # データセットに追加
372
+ # 元のindex番号(dataset_id)を指定して保存
373
+ save_annotation_data(df)
374
+
375
+ # Nextデータ初期化
376
+ initialize_next_data(df)
377
+
378
+ return gr.update(value=df.iloc[select_idx.value]["question"]), \
379
+ gr.update(value=df.iloc[select_idx.value]["answer"]), \
380
+ gr.update(value=df.iloc[select_idx.value]["question"]), \
381
+ gr.update(value=df.iloc[select_idx.value]["answer"])
382
+
383
+ def update_evaluation_state(is_good, is_unknown, score_value):
384
  if score_value is not None: # 5段階評価の場合
385
  good.value = False
386
  bad.value = False
 
391
  bad.value = not is_good if not is_unknown else False
392
  unknown_quality.value = is_unknown # 「分からない」の状態を設定
393
 
394
+ def update_answer_state(input_ans_1, input_ans_3):
395
  if input_ans_1 is not None and initial_answer_text_1.value != input_ans_1:
396
  is_proofreading_1.value = True
397
  answer_text_1.value = input_ans_1
 
404
  else:
405
  answer_text_2.value = ""
406
 
407
+ def save_annotation_data(df):
 
 
 
 
 
 
 
 
 
 
 
408
  save_annotation(
409
  select_dropdown_dataset.value,
410
  # datasetIdは元のindex番号を使用
 
420
  answer_text_2.value
421
  )
422
 
423
+ def initialize_next_data(df):
424
  is_proofreading_1.value = False
425
  is_proofreading_2.value = False
426
  initial_answer_text_1.value = df.iloc[select_idx.value]["answer"]
427
  initial_answer_text_2.value = df.iloc[select_idx.value]["answer"]
428
 
 
 
 
 
 
429
  def good_click(input_ans_1, input_ans_3):
430
  return update_annotation(input_ans_1=input_ans_1, input_ans_3=input_ans_3, is_good=True, is_unknown=False)
431
 
 
474
  )
475
 
476
  # 5段階評価ボタンのクリックイベント
477
+ gr_score_1.click(lambda x: update_annotation(input_ans_1=x, is_unknown=False, score_value=1),
478
  inputs=[gr_answer_text_3], outputs=[gr_question_text_1, gr_answer_text_1, gr_question_text_3, gr_answer_text_3])
479
+ gr_score_2.click(lambda x: update_annotation(input_ans_1=x, is_unknown=False, score_value=2),
480
  inputs=[gr_answer_text_3], outputs=[gr_question_text_1, gr_answer_text_1, gr_question_text_3, gr_answer_text_3])
481
+ gr_score_3.click(lambda x: update_annotation(input_ans_1=x, is_unknown=False, score_value=3),
482
  inputs=[gr_answer_text_3], outputs=[gr_question_text_1, gr_answer_text_1, gr_question_text_3, gr_answer_text_3])
483
+ gr_score_4.click(lambda x: update_annotation(input_ans_1=x, is_unknown=False, score_value=4),
484
  inputs=[gr_answer_text_3], outputs=[gr_question_text_1, gr_answer_text_1, gr_question_text_3, gr_answer_text_3])
485
+ gr_score_5.click(lambda x: update_annotation(input_ans_1=x, is_unknown=False, score_value=5),
486
  inputs=[gr_answer_text_3], outputs=[gr_question_text_1, gr_answer_text_1, gr_question_text_3, gr_answer_text_3])
487
 
488
  # TODO Tab切り替えで、アノテ済みの一覧を表示する