Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -201,7 +201,7 @@ class ClaimGenerator:
|
|
201 |
|
202 |
2. *Mượn cấu trúc và n-gram đặc trưng của SUPPORTED để tạo sự đánh lừa*
|
203 |
- Sử dụng n-gram đặc trưng của SUPPORTED:
|
204 |
-
- "một số", "
|
205 |
- "trong lịch sử", "của người dân", "khoảng thời gian"
|
206 |
- Tạo câu có cấu trúc giống SUPPORTED nhưng thay đổi thông tin cốt lõi.
|
207 |
- Ví dụ: "Trong lịch sử phát triển của [Title], một số yếu tố đã dẫn đến..." (dùng cụm từ SUPPORTED)
|
@@ -494,7 +494,7 @@ class ClaimGenerator:
|
|
494 |
'results': results
|
495 |
}
|
496 |
|
497 |
-
def process_dataframe_with_claims(df: pd.DataFrame) -> pd.DataFrame:
|
498 |
"""Process each summary in the DataFrame and generate claims with fallback handling."""
|
499 |
all_rows = []
|
500 |
progress_bar = st.progress(0)
|
@@ -503,7 +503,7 @@ def process_dataframe_with_claims(df: pd.DataFrame) -> pd.DataFrame:
|
|
503 |
context = row['Summary']
|
504 |
title = row['Title']
|
505 |
|
506 |
-
for claim_type in
|
507 |
generator = ClaimGenerator(claim_type)
|
508 |
result = generator.generate_hard_claims(context, title, predict)
|
509 |
|
@@ -710,6 +710,7 @@ def create_id(topic, stt):
|
|
710 |
# Generate unique ID
|
711 |
topic_num = chars_to_nums(topic_abbr)
|
712 |
return f'uit_{topic_num}_{stt}'
|
|
|
713 |
def wikipedia_scrape(title_input, stt, filename):
|
714 |
try:
|
715 |
page = wikipedia.page(title_input)
|
@@ -783,25 +784,36 @@ def main():
|
|
783 |
st.subheader("Danh sách bài viết từ Wikipedia:")
|
784 |
st.dataframe(df, use_container_width=True)
|
785 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
786 |
# Add automatic claim generation for all summaries
|
787 |
if st.button("Tạo Claims cho tất cả bài viết"):
|
788 |
-
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
-
|
802 |
-
|
803 |
-
|
804 |
-
|
|
|
|
|
|
|
805 |
|
806 |
# Original download option for basic DataFrame
|
807 |
csv = convert_df_to_csv(df)
|
|
|
201 |
|
202 |
2. *Mượn cấu trúc và n-gram đặc trưng của SUPPORTED để tạo sự đánh lừa*
|
203 |
- Sử dụng n-gram đặc trưng của SUPPORTED:
|
204 |
+
- "một số", "so với", "đối với", "lãnh thổ", "thế kỷ"
|
205 |
- "trong lịch sử", "của người dân", "khoảng thời gian"
|
206 |
- Tạo câu có cấu trúc giống SUPPORTED nhưng thay đổi thông tin cốt lõi.
|
207 |
- Ví dụ: "Trong lịch sử phát triển của [Title], một số yếu tố đã dẫn đến..." (dùng cụm từ SUPPORTED)
|
|
|
494 |
'results': results
|
495 |
}
|
496 |
|
497 |
+
def process_dataframe_with_claims(df: pd.DataFrame, selected_claim_types: List[str]) -> pd.DataFrame:
|
498 |
"""Process each summary in the DataFrame and generate claims with fallback handling."""
|
499 |
all_rows = []
|
500 |
progress_bar = st.progress(0)
|
|
|
503 |
context = row['Summary']
|
504 |
title = row['Title']
|
505 |
|
506 |
+
for claim_type in selected_claim_types:
|
507 |
generator = ClaimGenerator(claim_type)
|
508 |
result = generator.generate_hard_claims(context, title, predict)
|
509 |
|
|
|
710 |
# Generate unique ID
|
711 |
topic_num = chars_to_nums(topic_abbr)
|
712 |
return f'uit_{topic_num}_{stt}'
|
713 |
+
|
714 |
def wikipedia_scrape(title_input, stt, filename):
|
715 |
try:
|
716 |
page = wikipedia.page(title_input)
|
|
|
784 |
st.subheader("Danh sách bài viết từ Wikipedia:")
|
785 |
st.dataframe(df, use_container_width=True)
|
786 |
|
787 |
+
# Add claim type selection
|
788 |
+
claim_types = ["SUPPORTED", "REFUTED", "NEI"]
|
789 |
+
selected_claim_types = st.multiselect(
|
790 |
+
"Chọn loại claim cần tạo:",
|
791 |
+
claim_types,
|
792 |
+
default=claim_types
|
793 |
+
)
|
794 |
+
|
795 |
# Add automatic claim generation for all summaries
|
796 |
if st.button("Tạo Claims cho tất cả bài viết"):
|
797 |
+
if not selected_claim_types:
|
798 |
+
st.error("Vui lòng chọn ít nhất một loại claim để tạo.")
|
799 |
+
else:
|
800 |
+
with st.spinner("Đang tạo claims cho tất cả bài viết..."):
|
801 |
+
|
802 |
+
# Process the DataFrame and generate claims
|
803 |
+
df_with_claims = process_dataframe_with_claims(df, selected_claim_types)
|
804 |
+
|
805 |
+
st.subheader("Bảng dữ liệu với Claims:")
|
806 |
+
st.dataframe(df_with_claims, use_container_width=True)
|
807 |
+
|
808 |
+
# Download options
|
809 |
+
csv = convert_df_to_csv(df_with_claims)
|
810 |
+
claims_filename = f"uit_{uploaded_file.name.split('.')[0]}_with_claims.csv"
|
811 |
+
st.download_button(
|
812 |
+
label="Download CSV với Claims",
|
813 |
+
data=csv,
|
814 |
+
file_name=claims_filename,
|
815 |
+
mime="text/csv",
|
816 |
+
)
|
817 |
|
818 |
# Original download option for basic DataFrame
|
819 |
csv = convert_df_to_csv(df)
|