350016z commited on
Commit
c1bca1d
·
verified ·
1 Parent(s): 52ef8e5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -58
app.py CHANGED
@@ -192,7 +192,6 @@ def get_error_dataframe():
192
  main_cat, sub_cat = cat_str.split("/", 1)
193
  main_cat_zh = category_display_map.get(main_cat, main_cat)
194
  # sub_cat -> e.g. "Mistranslation", "Addition", "Omission", ...
195
- # 這裡可逐一對照
196
  if sub_cat == "Mistranslation":
197
  sub_cat_zh = "誤譯"
198
  elif sub_cat == "Addition":
@@ -402,20 +401,15 @@ def update_index_selection(selected_display):
402
  )
403
 
404
  DEMO_EXPLANATION = """
405
- ## 翻譯標記工具:兩個 Tab
406
-
407
- **操作步驟:**
408
- 1. 在「基本設定」中,選擇要標註的檔案、標註人員,以及句子索引。
409
- 2. 切換到「錯誤標註」標籤頁 (Tab),若發現翻譯有錯,於該頁面中輸入「錯誤區間」並選擇類別/嚴重度等,最後點擊「保存並繼續標記當前資料」。
410
- - 若整句完全正確,可點擊「完全正確」
411
- - 若錯誤太多超過五處,可點擊「過多錯誤」
412
- 3. 切換到「評分與提交」標籤頁,於此頁拉動滑桿給分,若有更好的譯文可在「建議翻譯」中輸入,最後按「保存並顯示下一筆」送出本句並進入下一筆。
413
  """
414
 
415
  with gr.Blocks(css="""
416
- /* 整體字體與行距 */
417
  body {
418
- background-color: #FAFAFA;
419
  color: #333;
420
  margin: 0;
421
  padding: 0;
@@ -424,15 +418,16 @@ body {
424
  font-size: 15px;
425
  line-height: 1.4;
426
  }
427
- /* 按鈕分色,改用更柔和或深色系 */
 
428
  #correct_button {
429
- background-color: #2E7D32; /* 深綠 */
430
  color: white;
431
  font-size: 14px;
432
  margin-bottom: 5px;
433
  }
434
  #too_many_errors_button {
435
- background-color: #C62828; /* 深紅 */
436
  color: white;
437
  font-size: 14px;
438
  margin-bottom: 5px;
@@ -449,23 +444,23 @@ body {
449
  font-size: 14px;
450
  margin-bottom: 5px;
451
  }
452
- /* 螢光標示區的外框 */
453
- #highlight_box_group {
 
 
 
 
 
 
454
  border: 1px solid #aaa;
455
  padding: 10px;
456
  min-height: 80px;
457
  }
458
- /* 小面板 */
459
- .panel {
460
- border: 1px solid #ccc;
461
- padding: 10px;
462
- margin-bottom: 10px;
463
- }
464
  """) as demo:
465
  gr.Markdown(DEMO_EXPLANATION)
466
 
467
- # ------------------- 頂部:基本設定 -------------------
468
- with gr.Box():
469
  gr.Markdown("### 基本設定")
470
  with gr.Row():
471
  with gr.Column(scale=1):
@@ -489,16 +484,15 @@ body {
489
  value=str(data.loc[current_index, "id"]),
490
  interactive=False
491
  )
492
-
493
  with gr.Column(scale=4):
494
  source = gr.Textbox(label="原始文本", lines=4, interactive=False)
495
  with gr.Column(scale=4):
496
  target = gr.Textbox(label="翻譯文本", lines=4, interactive=False)
497
 
498
- # ------------------- 顯示螢光標示 錯誤紀錄 -------------------
499
  with gr.Row():
500
  with gr.Column(scale=5):
501
- with gr.Group(elem_id="highlight_box_group"):
502
  highlighted_target = gr.HTML(label="螢光標示區 (已標註的錯誤)")
503
  with gr.Column(scale=5):
504
  error_table = gr.Dataframe(
@@ -508,38 +502,37 @@ body {
508
  interactive=False
509
  )
510
 
511
- # ------------------- 分成兩個 Tab -------------------
512
- with gr.Tabs():
513
- # ---- Tab 1: 錯誤標註 ----
514
- with gr.Tab(label="錯誤標註"):
515
- gr.Markdown("#### 在此頁標註錯誤區間,或按「完全正確」「過多錯誤」")
516
  error_span = gr.Textbox(label="錯誤區間 (可複製『翻譯文本』貼上)", lines=2)
517
- with gr.Row():
518
- category = gr.Dropdown(
519
- label="錯誤類別",
520
- choices=list(categories_display.keys()),
521
- value="正確性"
522
- )
523
- subcategory = gr.Dropdown(
524
- label="子類別",
525
- choices=categories_display["正確性"],
526
- value="誤譯"
527
- )
528
- severity = gr.Dropdown(
529
- label="嚴重度",
530
- choices=severity_choices_display,
531
- value="輕微 (Minor)"
532
- )
533
- other = gr.Textbox(label="���他子類別(如選『其他』則在此填)")
534
 
535
- with gr.Row():
536
- save_current_button = gr.Button("保存並繼續標記當前資料", elem_id="save_current_button")
537
- correct_button = gr.Button("✔ 完全正確", elem_id="correct_button")
538
- too_many_errors_button = gr.Button("✖ 過多錯誤", elem_id="too_many_errors_button")
539
 
540
- # ---- Tab 2: 評分與提交 ----
541
- with gr.Tab(label="評分與提交"):
542
- gr.Markdown("#### 在此頁給分,若有更適合的譯文可提供建議,最後點『保存並顯示下一筆』")
 
543
  alternative_translation = gr.Textbox(
544
  label="建議翻譯(如有更好譯法可填)",
545
  lines=2
@@ -551,9 +544,8 @@ body {
551
  step=1,
552
  value=66
553
  )
554
- save_next_button = gr.Button("保存並顯示下一筆", elem_id="save_next_button")
555
 
556
- # ------------------- 最下方:狀態顯示 -------------------
557
  status = gr.Textbox(label="當前狀態", lines=1, interactive=False)
558
 
559
  # ------------------- 互動邏輯綁定 -------------------
 
192
  main_cat, sub_cat = cat_str.split("/", 1)
193
  main_cat_zh = category_display_map.get(main_cat, main_cat)
194
  # sub_cat -> e.g. "Mistranslation", "Addition", "Omission", ...
 
195
  if sub_cat == "Mistranslation":
196
  sub_cat_zh = "誤譯"
197
  elif sub_cat == "Addition":
 
401
  )
402
 
403
  DEMO_EXPLANATION = """
404
+ ## 翻譯標記工具 (無 Box 元件)
405
+
406
+ 此版本完全移除了 `gr.Box()`, 直接用 `gr.Group()`, `gr.Row()`, `gr.Column()` 加上簡單 CSS 來排版。
 
 
 
 
 
407
  """
408
 
409
  with gr.Blocks(css="""
410
+ /* 整體字體與背景 */
411
  body {
412
+ background-color: #F9F9F9;
413
  color: #333;
414
  margin: 0;
415
  padding: 0;
 
418
  font-size: 15px;
419
  line-height: 1.4;
420
  }
421
+
422
+ /* 自訂一些按鈕顏色 */
423
  #correct_button {
424
+ background-color: #2E7D32; /* */
425
  color: white;
426
  font-size: 14px;
427
  margin-bottom: 5px;
428
  }
429
  #too_many_errors_button {
430
+ background-color: #C62828; /* */
431
  color: white;
432
  font-size: 14px;
433
  margin-bottom: 5px;
 
444
  font-size: 14px;
445
  margin-bottom: 5px;
446
  }
447
+
448
+ /* group 來替代 box 的外框效果 */
449
+ #outer_panel {
450
+ border: 1px solid #ccc;
451
+ padding: 15px;
452
+ margin-bottom: 15px;
453
+ }
454
+ #highlight_panel {
455
  border: 1px solid #aaa;
456
  padding: 10px;
457
  min-height: 80px;
458
  }
 
 
 
 
 
 
459
  """) as demo:
460
  gr.Markdown(DEMO_EXPLANATION)
461
 
462
+ # ------------------- 頂部: 基本設定 + 文字顯示 -------------------
463
+ with gr.Group(elem_id="outer_panel"):
464
  gr.Markdown("### 基本設定")
465
  with gr.Row():
466
  with gr.Column(scale=1):
 
484
  value=str(data.loc[current_index, "id"]),
485
  interactive=False
486
  )
 
487
  with gr.Column(scale=4):
488
  source = gr.Textbox(label="原始文本", lines=4, interactive=False)
489
  with gr.Column(scale=4):
490
  target = gr.Textbox(label="翻譯文本", lines=4, interactive=False)
491
 
492
+ # ------------------- 中段: 螢光標記區 + 錯誤表格 -------------------
493
  with gr.Row():
494
  with gr.Column(scale=5):
495
+ with gr.Group(elem_id="highlight_panel"):
496
  highlighted_target = gr.HTML(label="螢光標示區 (已標註的錯誤)")
497
  with gr.Column(scale=5):
498
  error_table = gr.Dataframe(
 
502
  interactive=False
503
  )
504
 
505
+ # ------------------- 錯誤標註區 -------------------
506
+ with gr.Group(elem_id="outer_panel"):
507
+ gr.Markdown("### 錯誤標註")
508
+ with gr.Row():
 
509
  error_span = gr.Textbox(label="錯誤區間 (可複製『翻譯文本』貼上)", lines=2)
510
+ category = gr.Dropdown(
511
+ label="錯誤類別",
512
+ choices=list(categories_display.keys()),
513
+ value="正確性"
514
+ )
515
+ subcategory = gr.Dropdown(
516
+ label="子類別",
517
+ choices=categories_display["正確性"],
518
+ value="誤譯"
519
+ )
520
+ other = gr.Textbox(label="其他子類別(如選『其他』則填寫)")
521
+ severity = gr.Dropdown(
522
+ label="嚴重度",
523
+ choices=severity_choices_display,
524
+ value="輕微 (Minor)"
525
+ )
 
526
 
527
+ with gr.Row():
528
+ save_current_button = gr.Button("保存並繼續標記當前資料", elem_id="save_current_button")
529
+ correct_button = gr.Button("✔ 完全正確", elem_id="correct_button")
530
+ too_many_errors_button = gr.Button("✖ 過多錯誤", elem_id="too_many_errors_button")
531
 
532
+ # ------------------- 評分與提交 -------------------
533
+ with gr.Group(elem_id="outer_panel"):
534
+ gr.Markdown("### 評分與提交")
535
+ with gr.Row():
536
  alternative_translation = gr.Textbox(
537
  label="建議翻譯(如有更好譯法可填)",
538
  lines=2
 
544
  step=1,
545
  value=66
546
  )
547
+ save_next_button = gr.Button("保存並顯示下一筆", elem_id="save_next_button")
548
 
 
549
  status = gr.Textbox(label="當前狀態", lines=1, interactive=False)
550
 
551
  # ------------------- 互動邏輯綁定 -------------------