Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -35,6 +35,9 @@ y_pred = crf.predict(X_test)[0]
|
|
| 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):
|
| 40 |
return ["background-color: #FF9999" if not row["Is_Correct"] else "" for _ in row]
|
|
@@ -45,14 +48,13 @@ 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 |
-
# **🔹 Hiển thị bảng
|
| 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
|
| 56 |
num_rows="dynamic", # Cho phép thêm hàng ở bất kỳ đâu
|
| 57 |
key=f"edit_table_{sentence_id}"
|
| 58 |
)
|
|
@@ -62,8 +64,8 @@ if os.path.exists("corrected_data.csv"):
|
|
| 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
|
| 66 |
if st.button("Lưu chỉnh sửa"):
|
| 67 |
-
|
| 68 |
-
|
| 69 |
st.success("✅ Dữ liệu đã được lưu thành corrected_data.csv!")
|
|
|
|
| 35 |
sentence["Predicted_Chunk"] = y_pred
|
| 36 |
sentence["Is_Correct"] = sentence["Chunk"] == sentence["Predicted_Chunk"] # Kiểm tra dự đoán
|
| 37 |
|
| 38 |
+
# **Ẩn cột `Chunk` trong tất cả các bảng**
|
| 39 |
+
sentence_display = sentence.drop(columns=["Chunk"]) # Bỏ hiển thị cột `Chunk`
|
| 40 |
+
|
| 41 |
# Highlight lỗi: Màu đỏ nếu `Predicted_Chunk` sai
|
| 42 |
def highlight_errors(row):
|
| 43 |
return ["background-color: #FF9999" if not row["Is_Correct"] else "" for _ in row]
|
|
|
|
| 48 |
st.write(f"✅ **Số token đúng**: {num_correct} / {len(sentence)}")
|
| 49 |
st.write(f"❌ **Số token sai**: {num_wrong}")
|
| 50 |
|
| 51 |
+
# **🔹 Hiển thị bảng với highlight lỗi (ẨN `Chunk`)**
|
|
|
|
| 52 |
st.write("🔹 **Câu gốc (Highlight lỗi màu đỏ)**")
|
| 53 |
st.dataframe(sentence_display.style.apply(highlight_errors, axis=1))
|
| 54 |
|
| 55 |
+
# **🔹 Annotator chỉnh sửa `Predicted_Chunk` (ẨN `Chunk`)**
|
| 56 |
edited_df = st.data_editor(
|
| 57 |
+
sentence_display[["Token", "POS", "Predicted_Chunk"]], # Chỉ hiển thị các cột cần thiết
|
| 58 |
num_rows="dynamic", # Cho phép thêm hàng ở bất kỳ đâu
|
| 59 |
key=f"edit_table_{sentence_id}"
|
| 60 |
)
|
|
|
|
| 64 |
with open("corrected_data.csv", "rb") as file:
|
| 65 |
st.download_button("📥 Tải xuống corrected_data.csv", file, "corrected_data.csv")
|
| 66 |
|
| 67 |
+
# Lưu lại dữ liệu chỉnh sửa
|
| 68 |
if st.button("Lưu chỉnh sửa"):
|
| 69 |
+
sentence.update(edited_df) # Cập nhật lại dữ liệu chỉnh sửa vào dataframe gốc
|
| 70 |
+
sentence.to_csv("corrected_data.csv", index=False, encoding="utf-8", columns=["Token", "POS", "Predicted_Chunk"]) # Chỉ lưu các cột cần thiết
|
| 71 |
st.success("✅ Dữ liệu đã được lưu thành corrected_data.csv!")
|