Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -15,7 +15,8 @@ category_map = {
|
|
15 |
"流暢度": "Fluency",
|
16 |
"專有名詞": "Terminology",
|
17 |
"風格": "Style",
|
18 |
-
"在地化": "Locale"
|
|
|
19 |
}
|
20 |
subcategory_map = {
|
21 |
("正確性", "誤譯"): ("Accuracy", "Mistranslation"),
|
@@ -43,13 +44,15 @@ subcategory_map = {
|
|
43 |
("在地化", "日期格式"): ("Locale", "Date format"),
|
44 |
("在地化", "地址格式"): ("Locale", "Address format"),
|
45 |
("在地化", "其他"): ("Locale", "Other"),
|
|
|
46 |
}
|
47 |
categories_display = {
|
48 |
"正確性": ["誤譯", "多譯", "漏譯", "其他"],
|
49 |
"流暢度": ["文法", "拼字", "標點符號", "前後不一致", "語域", "其他"],
|
50 |
"專有名詞": ["使用不當", "不一致", "其他"],
|
51 |
"風格": ["用字尷尬", "其他"],
|
52 |
-
"在地化": ["貨幣格式", "時間格式", "姓名格式", "日期格式", "地址格式", "其他"]
|
|
|
53 |
}
|
54 |
|
55 |
severity_choices_display = ["輕微", "嚴重"]
|
@@ -73,7 +76,8 @@ category_display_map = {
|
|
73 |
"Locale": "在地化",
|
74 |
"Other": "其他",
|
75 |
"No-error": "無錯誤",
|
76 |
-
"Non-translation": "過多錯誤"
|
|
|
77 |
}
|
78 |
|
79 |
# ---------------------------下載CSV資料檔--------------------------------
|
@@ -337,62 +341,6 @@ def mark_as_too_many_errors(target):
|
|
337 |
get_error_dataframe(),
|
338 |
highlight_errors_in_text(target, current_errors)
|
339 |
)
|
340 |
-
|
341 |
-
# def save_current(source, target, rater_selector, error_span, category, subcategory, severity, other):
|
342 |
-
# global current_index, data, current_errors
|
343 |
-
# if len(current_errors) >= 5:
|
344 |
-
# return "", "您已標記超過 5 處錯誤,可直接按『過多錯誤』或繼續。"
|
345 |
-
|
346 |
-
# if error_span and error_span not in target:
|
347 |
-
# return "", "錯誤區間不存在於翻譯文本,請檢查!"
|
348 |
-
|
349 |
-
# # 轉英文
|
350 |
-
# cat_val, subcat_val = subcategory_map.get((category, subcategory), (category_map.get(category, "Other"), "Other"))
|
351 |
-
# severity_val = severity_map.get(severity, "Minor")
|
352 |
-
|
353 |
-
# if error_span:
|
354 |
-
# start = target.find(error_span)
|
355 |
-
# end = start + len(error_span)
|
356 |
-
|
357 |
-
# for err in current_errors:
|
358 |
-
# if err["start"] == start and err["end"] == end:
|
359 |
-
# return "", "此錯誤區間已標記過,請勿重複。"
|
360 |
-
|
361 |
-
# if subcat_val == "Other" and other.strip():
|
362 |
-
# subcat_val = other.strip()
|
363 |
-
|
364 |
-
# current_errors.append({
|
365 |
-
# "text": error_span,
|
366 |
-
# "severity": severity_val,
|
367 |
-
# "start": start,
|
368 |
-
# "end": end,
|
369 |
-
# "category": f"{cat_val}/{subcat_val}"
|
370 |
-
# })
|
371 |
-
# return "", f"已標記錯誤: {error_span} (範圍 {start}-{end})"
|
372 |
-
# else:
|
373 |
-
# return "", "尚未輸入錯誤區間,如無錯誤請按『完全正確』"
|
374 |
-
|
375 |
-
# def mark_as_correct():
|
376 |
-
# global current_errors
|
377 |
-
# current_errors.append({
|
378 |
-
# "text": "",
|
379 |
-
# "severity": "No-error",
|
380 |
-
# "start": 0,
|
381 |
-
# "end": 0,
|
382 |
-
# "category": "No-error"
|
383 |
-
# })
|
384 |
-
# return "", "標註為完全正確!", get_error_dataframe()
|
385 |
-
|
386 |
-
# def mark_as_too_many_errors():
|
387 |
-
# global current_errors
|
388 |
-
# current_errors.append({
|
389 |
-
# "text": "",
|
390 |
-
# "severity": "Major",
|
391 |
-
# "start": 0,
|
392 |
-
# "end": 0,
|
393 |
-
# "category": "Non-translation"
|
394 |
-
# })
|
395 |
-
# return "", "已標註為過多錯誤!", get_error_dataframe()
|
396 |
|
397 |
def save_and_next(source, target, score, rater_selector, alternative_translation):
|
398 |
global current_index, data, annotations_file, current_errors, annotation_history
|
@@ -663,7 +611,11 @@ with gr.Blocks(css="""
|
|
663 |
# ------------------- callback 綁定 -------------------
|
664 |
def update_subcats(selected_category):
|
665 |
subcats = categories_display[selected_category]
|
666 |
-
|
|
|
|
|
|
|
|
|
667 |
|
668 |
file_selector.change(
|
669 |
update_file_selection,
|
@@ -687,28 +639,6 @@ with gr.Blocks(css="""
|
|
687 |
inputs=[category],
|
688 |
outputs=[subcategory]
|
689 |
)
|
690 |
-
|
691 |
-
# correct_button.click(
|
692 |
-
# mark_as_correct,
|
693 |
-
# outputs=[error_span, status, error_table]
|
694 |
-
# )
|
695 |
-
# too_many_errors_button.click(
|
696 |
-
# mark_as_too_many_errors,
|
697 |
-
# outputs=[error_span, status, error_table]
|
698 |
-
# )
|
699 |
-
|
700 |
-
# # 按「保存並繼續標記」 -> 在同一句上加錯誤
|
701 |
-
# save_current_button.click(
|
702 |
-
# save_current,
|
703 |
-
# inputs=[source, target, rater_selector, error_span, category, subcategory, severity, other],
|
704 |
-
# outputs=[error_span, status]
|
705 |
-
# )
|
706 |
-
# # 再更新表格 & 高亮
|
707 |
-
# save_current_button.click(
|
708 |
-
# fn=lambda tgt: (get_error_dataframe(), highlight_errors_in_text(tgt, current_errors)),
|
709 |
-
# inputs=[target],
|
710 |
-
# outputs=[error_table, highlighted_target]
|
711 |
-
# )
|
712 |
|
713 |
# === 以下三個按鈕,皆一次更新表格與螢光區 ===
|
714 |
# 按「保存並繼續標記」 -> 在同一句上加錯誤並更新表格 & 高亮
|
|
|
15 |
"流暢度": "Fluency",
|
16 |
"專有名詞": "Terminology",
|
17 |
"風格": "Style",
|
18 |
+
"在地化": "Locale",
|
19 |
+
"純正性": "Purity"
|
20 |
}
|
21 |
subcategory_map = {
|
22 |
("正確性", "誤譯"): ("Accuracy", "Mistranslation"),
|
|
|
44 |
("在地化", "日期格式"): ("Locale", "Date format"),
|
45 |
("在地化", "地址格式"): ("Locale", "Address format"),
|
46 |
("在地化", "其他"): ("Locale", "Other"),
|
47 |
+
|
48 |
}
|
49 |
categories_display = {
|
50 |
"正確性": ["誤譯", "多譯", "漏譯", "其他"],
|
51 |
"流暢度": ["文法", "拼字", "標點符號", "前後不一致", "語域", "其他"],
|
52 |
"專有名詞": ["使用不當", "不一致", "其他"],
|
53 |
"風格": ["用字尷尬", "其他"],
|
54 |
+
"在地化": ["貨幣格式", "時間格式", "姓名格式", "日期格式", "地址格式", "其他"],
|
55 |
+
"純正性": []
|
56 |
}
|
57 |
|
58 |
severity_choices_display = ["輕微", "嚴重"]
|
|
|
76 |
"Locale": "在地化",
|
77 |
"Other": "其他",
|
78 |
"No-error": "無錯誤",
|
79 |
+
"Non-translation": "過多錯誤",
|
80 |
+
"Purity": "純正性"
|
81 |
}
|
82 |
|
83 |
# ---------------------------下載CSV資料檔--------------------------------
|
|
|
341 |
get_error_dataframe(),
|
342 |
highlight_errors_in_text(target, current_errors)
|
343 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
344 |
|
345 |
def save_and_next(source, target, score, rater_selector, alternative_translation):
|
346 |
global current_index, data, annotations_file, current_errors, annotation_history
|
|
|
611 |
# ------------------- callback 綁定 -------------------
|
612 |
def update_subcats(selected_category):
|
613 |
subcats = categories_display[selected_category]
|
614 |
+
if len(subcats) == 0:
|
615 |
+
# 沒有任何子類別 -> 傳回空的 choices
|
616 |
+
return gr.update(choices=[], value=None)
|
617 |
+
else:
|
618 |
+
return gr.update(choices=subcats, value=subcats[0])
|
619 |
|
620 |
file_selector.change(
|
621 |
update_file_selection,
|
|
|
639 |
inputs=[category],
|
640 |
outputs=[subcategory]
|
641 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
642 |
|
643 |
# === 以下三個按鈕,皆一次更新表格與螢光區 ===
|
644 |
# 按「保存並繼續標記」 -> 在同一句上加錯誤並更新表格 & 高亮
|