Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,7 +18,7 @@ def extract_features(sentence):
|
|
| 18 |
df_test = pd.read_csv("vi-chunk-test.csv")
|
| 19 |
|
| 20 |
# Nhóm dữ liệu theo câu
|
| 21 |
-
sentences = [group
|
| 22 |
|
| 23 |
# Giao diện Annotator
|
| 24 |
st.title("📝 Tool Annotator - Chỉnh sửa dữ liệu chunking")
|
|
@@ -33,7 +33,7 @@ y_pred = crf.predict(X_test)[0]
|
|
| 33 |
|
| 34 |
# Thêm nhãn dự đoán vào dataframe
|
| 35 |
sentence["Predicted_Chunk"] = y_pred
|
| 36 |
-
sentence["Is_Correct"] = sentence["
|
| 37 |
|
| 38 |
# Highlight lỗi: Màu đỏ nếu `Predicted_Chunk` sai
|
| 39 |
def highlight_errors(row):
|
|
@@ -45,13 +45,14 @@ num_wrong = len(sentence) - num_correct
|
|
| 45 |
st.write(f"✅ **Số token đúng**: {num_correct} / {len(sentence)}")
|
| 46 |
st.write(f"❌ **Số token sai**: {num_wrong}")
|
| 47 |
|
| 48 |
-
# **🔹
|
| 49 |
-
|
| 50 |
-
st.
|
|
|
|
| 51 |
|
| 52 |
# **🔹 Annotator chỉnh sửa `Predicted_Chunk`**
|
| 53 |
edited_df = st.data_editor(
|
| 54 |
-
|
| 55 |
num_rows="dynamic", # Cho phép thêm hàng ở bất kỳ đâu
|
| 56 |
key=f"edit_table_{sentence_id}"
|
| 57 |
)
|
|
@@ -61,7 +62,8 @@ if os.path.exists("corrected_data.csv"):
|
|
| 61 |
with open("corrected_data.csv", "rb") as file:
|
| 62 |
st.download_button("📥 Tải xuống corrected_data.csv", file, "corrected_data.csv")
|
| 63 |
|
| 64 |
-
# Lưu lại dữ liệu chỉnh sửa
|
| 65 |
if st.button("Lưu chỉnh sửa"):
|
| 66 |
-
|
|
|
|
| 67 |
st.success("✅ Dữ liệu đã được lưu thành corrected_data.csv!")
|
|
|
|
| 18 |
df_test = pd.read_csv("vi-chunk-test.csv")
|
| 19 |
|
| 20 |
# Nhóm dữ liệu theo câu
|
| 21 |
+
sentences = [group for _, group in df_test.groupby("Sentence_ID")]
|
| 22 |
|
| 23 |
# Giao diện Annotator
|
| 24 |
st.title("📝 Tool Annotator - Chỉnh sửa dữ liệu chunking")
|
|
|
|
| 33 |
|
| 34 |
# Thêm nhãn dự đoán vào dataframe
|
| 35 |
sentence["Predicted_Chunk"] = y_pred
|
| 36 |
+
sentence["Is_Correct"] = sentence["Chunk"] == sentence["Predicted_Chunk"] # Kiểm tra dự đoán
|
| 37 |
|
| 38 |
# Highlight lỗi: Màu đỏ nếu `Predicted_Chunk` sai
|
| 39 |
def highlight_errors(row):
|
|
|
|
| 45 |
st.write(f"✅ **Số token đúng**: {num_correct} / {len(sentence)}")
|
| 46 |
st.write(f"❌ **Số token sai**: {num_wrong}")
|
| 47 |
|
| 48 |
+
# **🔹 Hiển thị bảng đầy đủ (bao gồm `Chunk` nhưng không hiển thị trong Annotator)**
|
| 49 |
+
sentence_display = sentence.copy()
|
| 50 |
+
st.write("🔹 **Câu gốc (Highlight lỗi màu đỏ)**")
|
| 51 |
+
st.dataframe(sentence_display.style.apply(highlight_errors, axis=1))
|
| 52 |
|
| 53 |
# **🔹 Annotator chỉnh sửa `Predicted_Chunk`**
|
| 54 |
edited_df = st.data_editor(
|
| 55 |
+
sentence_display.drop(columns=["Chunk"]), # Ẩn cột `Chunk`
|
| 56 |
num_rows="dynamic", # Cho phép thêm hàng ở bất kỳ đâu
|
| 57 |
key=f"edit_table_{sentence_id}"
|
| 58 |
)
|
|
|
|
| 62 |
with open("corrected_data.csv", "rb") as file:
|
| 63 |
st.download_button("📥 Tải xuống corrected_data.csv", file, "corrected_data.csv")
|
| 64 |
|
| 65 |
+
# Lưu lại dữ liệu chỉnh sửa (bao gồm `Chunk`, nhưng không hiển thị)
|
| 66 |
if st.button("Lưu chỉnh sửa"):
|
| 67 |
+
sentence_display.update(edited_df) # Cập nhật lại dữ liệu chỉnh sửa
|
| 68 |
+
sentence_display.to_csv("corrected_data.csv", index=False, encoding="utf-8")
|
| 69 |
st.success("✅ Dữ liệu đã được lưu thành corrected_data.csv!")
|