Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -129,6 +129,8 @@ def save_current(source, target, rater_selector, error_span, category, subcatego
|
|
129 |
"rater": rater_selector,
|
130 |
}
|
131 |
save_to_json(new_entry, annotations_file)
|
|
|
|
|
132 |
return "", f"當前資料已保存到 {annotations_file.name},請繼續標記!"
|
133 |
|
134 |
def save_and_next(source, target, score, rater_selector):
|
@@ -155,9 +157,10 @@ def save_and_next(source, target, score, rater_selector):
|
|
155 |
current_index += 1
|
156 |
if current_index < len(data):
|
157 |
next_source, next_target = get_current_text()
|
|
|
158 |
return next_source, next_target, "", str(current_index), f"分數已保存到 {score_file.name},請繼續下一筆!"
|
159 |
else:
|
160 |
-
return "已完成所有文本標記", "已完成所有文本標記", "",
|
161 |
|
162 |
def update_file_selection(selected_file):
|
163 |
global data_path, data, current_index, annotations_file, score_file
|
@@ -169,7 +172,9 @@ def update_file_selection(selected_file):
|
|
169 |
annotations_file = DATASET_DIR / f"{file_base_name}_annotations-{uuid4()}.json"
|
170 |
score_file = DATASET_DIR / f"{file_base_name}_score-{uuid4()}.json"
|
171 |
|
172 |
-
|
|
|
|
|
173 |
|
174 |
def update_index_selection(selected_index):
|
175 |
global current_index, data
|
@@ -177,6 +182,7 @@ def update_index_selection(selected_index):
|
|
177 |
selected_index = int(selected_index)
|
178 |
if selected_index in data["id"].values:
|
179 |
current_index = data.index[data["id"] == selected_index].tolist()[0]
|
|
|
180 |
return get_current_text() + (str(current_index), f"已跳轉至 id: {selected_index}")
|
181 |
except:
|
182 |
return "錯誤", "錯誤", str(current_index), "選擇的索引無效,請重新選擇"
|
|
|
129 |
"rater": rater_selector,
|
130 |
}
|
131 |
save_to_json(new_entry, annotations_file)
|
132 |
+
|
133 |
+
# [error_span, status]
|
134 |
return "", f"當前資料已保存到 {annotations_file.name},請繼續標記!"
|
135 |
|
136 |
def save_and_next(source, target, score, rater_selector):
|
|
|
157 |
current_index += 1
|
158 |
if current_index < len(data):
|
159 |
next_source, next_target = get_current_text()
|
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 |
+
# [source, target, error_span, index_selector, current_index_display, status]
|
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
|
|
|
182 |
selected_index = int(selected_index)
|
183 |
if selected_index in data["id"].values:
|
184 |
current_index = data.index[data["id"] == selected_index].tolist()[0]
|
185 |
+
# [source, target, current_index_display, status]
|
186 |
return get_current_text() + (str(current_index), f"已跳轉至 id: {selected_index}")
|
187 |
except:
|
188 |
return "錯誤", "錯誤", str(current_index), "選擇的索引無效,請重新選擇"
|