350016z commited on
Commit
d84cd5b
·
verified ·
1 Parent(s): 3747568

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -17
app.py CHANGED
@@ -45,7 +45,7 @@ def save_to_json(entry: dict, json_file: Path):
45
  f.write("\n")
46
  # scheduler.push_to_hub(commit_message=f"更新檔案 {json_file.name}")
47
 
48
- def save_current(source, target, rater_selector, error_span, correction_text, category, subcategory, severity, other):
49
  global annotations_file
50
  if category != "Non-translation":
51
  category_value = f"{category}/{subcategory}"
@@ -57,21 +57,21 @@ def save_current(source, target, rater_selector, error_span, correction_text, ca
57
  "target": target,
58
  "rater": rater_selector,
59
  "error_span": error_span,
60
- "correction_text": correction_text,
61
  "category": category_value,
62
  "severity": severity,
63
  "other": other if other else "",
64
  }
65
  save_to_json(new_entry, annotations_file)
66
- return source, target, "", "", f"當前資料已保存到 {annotations_file.name},請繼續標記!"
67
 
68
- def save_and_next(source, target, rater_selector, error_span, correction_text, category, subcategory, severity, other, score):
69
  global current_index, data, score_file
70
  new_entry = {
71
- "source": source,
72
- "target": target,
73
- "rater": rater_selector,
74
  "score": score,
 
75
  }
76
  save_to_json(new_entry, score_file)
77
 
@@ -129,16 +129,19 @@ with gr.Blocks() as demo:
129
  with gr.Row():
130
  source = gr.Textbox(label="原始文本", lines=5, interactive=False)
131
  target = gr.Textbox(label="翻譯文本", lines=5, interactive=False)
132
- with gr.Row():
133
- error_span = gr.Textbox(label="錯誤區間", lines=2, placeholder="請複製並貼上翻譯中的錯誤文本 (如無錯誤則不需)")
134
- correction_text = gr.Textbox(label="正確內容", lines=2, placeholder="輸入修正後的正確內容 (如無錯誤則不需)")
135
 
136
  with gr.Row(variant='panel', equal_height=True):
137
- severity = gr.Radio(label="錯誤嚴重程度", choices=["No-error", "Minor", "Major"], value="No-error")
138
- category = gr.Dropdown(label="錯誤類別", choices=list(categories.keys()), value="No-error")
139
- subcategory = gr.Dropdown(label="子類別", choices=categories["No-error"], value=None)
140
- other = gr.Textbox(label="其他子類別", placeholder="若無法歸類,請填寫其他")
141
- save_current_button = gr.Button("保存並繼續標記當前資料")
 
 
 
142
 
143
  def update_subcategories(selected_category):
144
  subcategories = categories[selected_category]
@@ -150,14 +153,15 @@ with gr.Blocks() as demo:
150
  category.change(update_subcategories, inputs=[category], outputs=[subcategory])
151
 
152
  with gr.Row(variant='panel', equal_height=True):
 
153
  score = gr.Slider(label="翻譯評分", minimum=0, maximum=100, step=1, value=50)
154
  save_next_button = gr.Button("保存並顯示下一筆")
155
 
156
  status = gr.Textbox(label="當前狀態", lines=1, interactive=False)
157
 
158
  file_selector.change(update_file_selection, inputs=[file_selector], outputs=[source, target, error_span, correction_text, status])
159
- save_current_button.click(save_current, inputs=[source, target, rater_selector, error_span, correction_text, category, subcategory, severity, other], outputs=[source, target, error_span, correction_text, status])
160
- save_next_button.click(save_and_next, inputs=[source, target, rater_selector, error_span, correction_text, category, subcategory, severity, other, score], outputs=[source, target, error_span, correction_text, status])
161
 
162
  original, translated = get_current_text()
163
  source.value = original
 
45
  f.write("\n")
46
  # scheduler.push_to_hub(commit_message=f"更新檔案 {json_file.name}")
47
 
48
+ def save_current(source, target, rater_selector, error_span, category, subcategory, severity, other):
49
  global annotations_file
50
  if category != "Non-translation":
51
  category_value = f"{category}/{subcategory}"
 
57
  "target": target,
58
  "rater": rater_selector,
59
  "error_span": error_span,
 
60
  "category": category_value,
61
  "severity": severity,
62
  "other": other if other else "",
63
  }
64
  save_to_json(new_entry, annotations_file)
65
+ return source, target, "", f"當前資料已保存到 {annotations_file.name},請繼續標記!"
66
 
67
+ def save_and_next(source, target, correction_text, score, rater_selector):
68
  global current_index, data, score_file
69
  new_entry = {
70
+ "src": source,
71
+ "mt": target,
72
+ "ref": correction_text,
73
  "score": score,
74
+ "rater": rater_selector,
75
  }
76
  save_to_json(new_entry, score_file)
77
 
 
129
  with gr.Row():
130
  source = gr.Textbox(label="原始文本", lines=5, interactive=False)
131
  target = gr.Textbox(label="翻譯文本", lines=5, interactive=False)
132
+ # with gr.Row():
133
+ # error_span = gr.Textbox(label="錯誤區間", lines=2, placeholder="請複製並貼上翻譯中的錯誤文本 (如無錯誤則不需)")
134
+ # correction_text = gr.Textbox(label="正確內容", lines=2, placeholder="輸入修正後的正確內容 (如無錯誤則不需)")
135
 
136
  with gr.Row(variant='panel', equal_height=True):
137
+ with gr.column(scale=1):
138
+ error_span = gr.Textbox(label="錯誤區間", lines=2, placeholder="請輸入翻譯中的文本錯誤區間 (如無錯誤則不需)")
139
+ with gr.column(scale=1):
140
+ severity = gr.Radio(label="錯誤嚴重程度", choices=["No-error", "Minor", "Major"], value="No-error")
141
+ category = gr.Dropdown(label="錯誤類別", choices=list(categories.keys()), value="No-error")
142
+ subcategory = gr.Dropdown(label="子類別", choices=categories["No-error"], value=None)
143
+ other = gr.Textbox(label="其他子類別", placeholder="若無法歸類,請填寫其他")
144
+ save_current_button = gr.Button("保存並繼續標記當前資料")
145
 
146
  def update_subcategories(selected_category):
147
  subcategories = categories[selected_category]
 
153
  category.change(update_subcategories, inputs=[category], outputs=[subcategory])
154
 
155
  with gr.Row(variant='panel', equal_height=True):
156
+ correction_text = gr.Textbox(label="正確內容", lines=2, placeholder="請輸入完整正確的翻譯 (如無錯誤則不需)")
157
  score = gr.Slider(label="翻譯評分", minimum=0, maximum=100, step=1, value=50)
158
  save_next_button = gr.Button("保存並顯示下一筆")
159
 
160
  status = gr.Textbox(label="當前狀態", lines=1, interactive=False)
161
 
162
  file_selector.change(update_file_selection, inputs=[file_selector], outputs=[source, target, error_span, correction_text, status])
163
+ save_current_button.click(save_current, inputs=[source, target, rater_selector, error_span, category, subcategory, severity, other], outputs=[source, target, error_span, status])
164
+ save_next_button.click(save_and_next, inputs=[source, target, correction_text, score, rater_selector], outputs=[source, target, error_span, correction_text, status])
165
 
166
  original, translated = get_current_text()
167
  source.value = original