NghiTran1009 commited on
Commit
aeb7075
·
verified ·
1 Parent(s): 9fac977

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import joblib
4
+
5
+ # Load mô hình CRF đã train
6
+ @st.cache_resource
7
+ def load_model():
8
+ return joblib.load("chunking_crf_model.pkl")
9
+
10
+ crf = load_model()
11
+
12
+ # Hàm trích xuất feature
13
+ def extract_features(sentence):
14
+ return [{"word": token, "pos": pos} for token, pos in zip(sentence["Token"], sentence["POS"])]
15
+
16
+ # Load dữ liệu test
17
+ df_test = pd.read_csv("chunking_test.csv")
18
+
19
+ # Nhóm theo câu
20
+ sentences = [group for _, group in df_test.groupby("Sentence_ID")]
21
+
22
+ # Giao diện web
23
+ st.title("📝 Tool Annotator - Chỉnh sửa dữ liệu chunking")
24
+
25
+ # Chọn câu để annotate
26
+ sentence_id = st.selectbox("Chọn câu", range(len(sentences)))
27
+ sentence = sentences[sentence_id]
28
+
29
+ # Hiển thị dữ liệu ban đầu
30
+ st.write("🔹 **Câu gốc**")
31
+ st.table(sentence)
32
+
33
+ # Dự đoán bằng mô hình
34
+ X_test = [extract_features(sentence)]
35
+ y_pred = crf.predict(X_test)[0]
36
+
37
+ # Thêm cột dự đoán vào dataframe
38
+ sentence["Predicted_Chunk"] = y_pred
39
+
40
+ # Hiển thị dữ liệu dự đoán
41
+ st.write("🔹 **Dữ liệu dự đoán**")
42
+ edited_df = st.data_editor(sentence, key="edit_table")
43
+
44
+ # Lưu lại kết quả chỉnh sửa
45
+ if st.button("Lưu chỉnh sửa"):
46
+ edited_df.to_csv("corrected_data.csv", index=False, encoding="utf-8")
47
+ st.success("✅ Dữ liệu đã được lưu thành corrected_data.csv!")