Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -160,7 +160,7 @@ def save_and_next(source, target, score, rater_selector):
|
|
160 |
# [source, target, error_span, current_index_display, status]
|
161 |
return next_source, next_target, "", str(current_index), f"分數已保存到 {score_file.name},請繼續下一筆!"
|
162 |
else:
|
163 |
-
return "
|
164 |
|
165 |
def update_file_selection(selected_file):
|
166 |
global data_path, data, current_index, annotations_file, score_file
|
@@ -172,9 +172,8 @@ def update_file_selection(selected_file):
|
|
172 |
annotations_file = DATASET_DIR / f"{file_base_name}_annotations-{uuid4()}.json"
|
173 |
score_file = DATASET_DIR / f"{file_base_name}_score-{uuid4()}.json"
|
174 |
|
175 |
-
#
|
176 |
return get_current_text() + ("", get_all_ids(), str(current_index), f"已加載檔案:{selected_file}")
|
177 |
-
|
178 |
|
179 |
def update_index_selection(selected_index):
|
180 |
global current_index, data
|
@@ -236,33 +235,19 @@ with gr.Blocks() as demo:
|
|
236 |
category = gr.Dropdown(label="錯誤類別", choices=list(categories.keys()), value="No-error")
|
237 |
subcategory = gr.Dropdown(label="子類別", choices=categories["No-error"], value=None)
|
238 |
other = gr.Textbox(label="其他子類別", placeholder="若無法歸類,請填寫其他")
|
239 |
-
with gr.Row(equal_height=True):
|
240 |
-
severity = gr.Radio(label="錯誤嚴重程度", choices=["
|
241 |
-
|
242 |
-
|
243 |
-
with gr.Row(
|
244 |
-
with gr.Column(scale=
|
245 |
-
|
246 |
-
with gr.Column(scale=
|
247 |
-
|
248 |
-
|
249 |
-
status = gr.Textbox(label="當前狀態", lines=1, interactive=False)
|
250 |
-
|
251 |
-
def update_subcategories(selected_category):
|
252 |
-
subcategories = categories[selected_category]
|
253 |
-
if subcategories:
|
254 |
-
return gr.update(choices=subcategories, value=subcategories[0])
|
255 |
-
else:
|
256 |
-
return gr.update(choices=[], value=None)
|
257 |
-
|
258 |
-
file_selector.change(update_file_selection, inputs=[file_selector], outputs=[source, target, error_span, index_selector, current_index_display, status])
|
259 |
-
index_selector.change(update_index_selection, inputs=[index_selector], outputs=[source, target, current_index_display, status])
|
260 |
-
category.change(update_subcategories, inputs=[category], outputs=[subcategory])
|
261 |
-
save_current_button.click(save_current, inputs=[source, target, rater_selector, error_span, category, subcategory, severity, other], outputs=[error_span, status])
|
262 |
-
save_next_button.click(save_and_next, inputs=[source, target, score, rater_selector], outputs=[source, target, error_span, current_index_display, status])
|
263 |
|
264 |
-
|
265 |
-
|
266 |
-
|
|
|
267 |
|
268 |
demo.launch()
|
|
|
160 |
# [source, target, error_span, current_index_display, status]
|
161 |
return next_source, next_target, "", str(current_index), f"分數已保存到 {score_file.name},請繼續下一筆!"
|
162 |
else:
|
163 |
+
return "已完成所有文本標註", "已完成所有文本標註", "", "", f"所有標記已完成並保存到 {score_file.name}!"
|
164 |
|
165 |
def update_file_selection(selected_file):
|
166 |
global data_path, data, current_index, annotations_file, score_file
|
|
|
172 |
annotations_file = DATASET_DIR / f"{file_base_name}_annotations-{uuid4()}.json"
|
173 |
score_file = DATASET_DIR / f"{file_base_name}_score-{uuid4()}.json"
|
174 |
|
175 |
+
# 刷新index的選項
|
176 |
return get_current_text() + ("", get_all_ids(), str(current_index), f"已加載檔案:{selected_file}")
|
|
|
177 |
|
178 |
def update_index_selection(selected_index):
|
179 |
global current_index, data
|
|
|
235 |
category = gr.Dropdown(label="錯誤類別", choices=list(categories.keys()), value="No-error")
|
236 |
subcategory = gr.Dropdown(label="子類別", choices=categories["No-error"], value=None)
|
237 |
other = gr.Textbox(label="其他子類別", placeholder="若無法歸類,請填寫其他")
|
238 |
+
with gr.Row(equal_height=True):
|
239 |
+
severity = gr.Radio(label="錯誤嚴重程度", choices=["Minor", "Major"], value="Minor")
|
240 |
+
score = gr.Slider(minimum=0, maximum=100, value=100, step=1, label="分數")
|
241 |
+
|
242 |
+
with gr.Row(equal_height=True):
|
243 |
+
with gr.Column(scale=3):
|
244 |
+
save_btn = gr.Button("保存並顯示下一筆")
|
245 |
+
with gr.Column(scale=6):
|
246 |
+
save_status = gr.Textbox(label="狀態", interactive=False, lines=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
247 |
|
248 |
+
# Custom functions
|
249 |
+
file_selector.change(update_file_selection, inputs=[file_selector], outputs=[source, target, error_span, index_selector, current_index_display])
|
250 |
+
index_selector.change(update_index_selection, inputs=[index_selector], outputs=[source, target, current_index_display, save_status])
|
251 |
+
save_btn.click(save_and_next, inputs=[source, target, score, rater_selector], outputs=[source, target, error_span, current_index_display, save_status])
|
252 |
|
253 |
demo.launch()
|