Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -94,6 +94,7 @@ def perform_verification(claim, context, model_qatc, tokenizer_qatc, model_tc, t
|
|
94 |
torch.cuda.empty_cache()
|
95 |
gc.collect()
|
96 |
|
|
|
97 |
# Parallel classification using ThreadPoolExecutor
|
98 |
with ThreadPoolExecutor(max_workers=2) as executor:
|
99 |
future_tc = executor.submit(cached_classify_claim, claim, evidence, tc_model_name, False)
|
@@ -102,7 +103,6 @@ def perform_verification(claim, context, model_qatc, tokenizer_qatc, model_tc, t
|
|
102 |
prob3class, pred_tc = future_tc.result()
|
103 |
prob2class, pred_bc = future_bc.result()
|
104 |
|
105 |
-
verdict_start_time = time.time()
|
106 |
with torch.no_grad():
|
107 |
verdict = "NEI"
|
108 |
if pred_tc != 0:
|
@@ -137,7 +137,7 @@ def monitor_performance():
|
|
137 |
|
138 |
# Set page configuration
|
139 |
st.set_page_config(
|
140 |
-
page_title="SemViQA -
|
141 |
page_icon="🔍",
|
142 |
layout="wide",
|
143 |
initial_sidebar_state="expanded"
|
@@ -340,18 +340,18 @@ st.markdown("""
|
|
340 |
st.markdown("""
|
341 |
<div class="main-header">
|
342 |
<div class="main-title">SemViQA</div>
|
343 |
-
<div class="sub-title">
|
344 |
</div>
|
345 |
""", unsafe_allow_html=True)
|
346 |
|
347 |
# Sidebar
|
348 |
with st.sidebar:
|
349 |
-
st.markdown("### ⚙️
|
350 |
|
351 |
# Model selection
|
352 |
-
st.markdown("#### 🧠
|
353 |
qatc_model_name = st.selectbox(
|
354 |
-
"
|
355 |
[
|
356 |
"SemViQA/qatc-infoxlm-viwikifc",
|
357 |
"SemViQA/qatc-infoxlm-isedsc01",
|
@@ -361,7 +361,7 @@ with st.sidebar:
|
|
361 |
)
|
362 |
|
363 |
bc_model_name = st.selectbox(
|
364 |
-
"
|
365 |
[
|
366 |
"SemViQA/bc-xlmr-viwikifc",
|
367 |
"SemViQA/bc-xlmr-isedsc01",
|
@@ -373,7 +373,7 @@ with st.sidebar:
|
|
373 |
)
|
374 |
|
375 |
tc_model_name = st.selectbox(
|
376 |
-
"
|
377 |
[
|
378 |
"SemViQA/tc-xlmr-viwikifc",
|
379 |
"SemViQA/tc-xlmr-isedsc01",
|
@@ -385,40 +385,40 @@ with st.sidebar:
|
|
385 |
)
|
386 |
|
387 |
# Threshold settings
|
388 |
-
st.markdown("#### ⚖️
|
389 |
tfidf_threshold = st.slider(
|
390 |
-
"
|
391 |
0.0, 1.0, 0.5,
|
392 |
-
help="
|
393 |
)
|
394 |
|
395 |
length_ratio_threshold = st.slider(
|
396 |
-
"
|
397 |
0.1, 1.0, 0.5,
|
398 |
-
help="
|
399 |
)
|
400 |
|
401 |
# Display settings
|
402 |
-
st.markdown("#### 👁️
|
403 |
show_details = st.checkbox(
|
404 |
-
"
|
405 |
value=False,
|
406 |
-
help="
|
407 |
)
|
408 |
|
409 |
# Performance settings
|
410 |
-
st.markdown("#### ⚡
|
411 |
num_threads = st.slider(
|
412 |
-
"
|
413 |
1, psutil.cpu_count(),
|
414 |
psutil.cpu_count(logical=False),
|
415 |
-
help="
|
416 |
)
|
417 |
os.environ["OMP_NUM_THREADS"] = str(num_threads)
|
418 |
os.environ["MKL_NUM_THREADS"] = str(num_threads)
|
419 |
|
420 |
# Main content
|
421 |
-
tabs = st.tabs(["🔍
|
422 |
|
423 |
tokenizer_qatc, model_qatc = load_model(qatc_model_name, QATCForQuestionAnswering, device=DEVICE)
|
424 |
tokenizer_bc, model_bc = load_model(bc_model_name, ClaimModelForClassification, is_bc=True, device=DEVICE)
|
@@ -434,25 +434,25 @@ with tabs[0]:
|
|
434 |
col1, col2 = st.columns([2, 1])
|
435 |
|
436 |
with col1:
|
437 |
-
st.markdown("### 📝
|
438 |
claim = st.text_area(
|
439 |
-
"
|
440 |
"Chiến tranh với Campuchia đã kết thúc trước khi Việt Nam thống nhất.",
|
441 |
-
help="
|
442 |
)
|
443 |
|
444 |
context = st.text_area(
|
445 |
-
"
|
446 |
"Sau khi thống nhất, Việt Nam tiếp tục gặp khó khăn do sự sụp đổ và tan rã của đồng minh Liên Xô cùng Khối phía Đông, các lệnh cấm vận của Hoa Kỳ, chiến tranh với Campuchia, biên giới giáp Trung Quốc và hậu quả của chính sách bao cấp sau nhiều năm áp dụng. Năm 1986, Đảng Cộng sản ban hành cải cách đổi mới, tạo điều kiện hình thành kinh tế thị trường và hội nhập sâu rộng. Cải cách đổi mới kết hợp cùng quy mô dân số lớn đưa Việt Nam trở thành một trong những nước đang phát triển có tốc độ tăng trưởng thuộc nhóm nhanh nhất thế giới, được coi là Hổ mới châu Á dù cho vẫn gặp phải những thách thức như tham nhũng, tội phạm gia tăng, ô nhiễm môi trường và phúc lợi xã hội chưa đầy đủ. Ngoài ra, giới bất đồng chính kiến, chính phủ một số nước phương Tây và các tổ chức theo dõi nhân quyền có quan điểm chỉ trích hồ sơ nhân quyền của Việt Nam liên quan đến các vấn đề tôn giáo, kiểm duyệt truyền thông, hạn chế hoạt động ủng hộ nhân quyền cùng các quyền tự do dân sự.",
|
447 |
-
help="
|
448 |
)
|
449 |
|
450 |
-
verify_button = st.button("🔍
|
451 |
|
452 |
with col2:
|
453 |
-
st.markdown("### 📊
|
454 |
if verify_button:
|
455 |
-
with st.spinner("
|
456 |
# Preprocess texts
|
457 |
preprocessed_claim = preprocess_text(claim)
|
458 |
preprocessed_context = preprocess_text(context)
|
@@ -526,17 +526,17 @@ with tabs[0]:
|
|
526 |
|
527 |
st.markdown(f"""
|
528 |
<div class="result-box">
|
529 |
-
<h3>
|
530 |
-
<p><strong>
|
531 |
-
<p><strong>
|
532 |
<p class="verdict {verdict_class}">
|
533 |
{verdict_icons.get(res['verdict'], '')} {res['verdict']}
|
534 |
</p>
|
535 |
<div class="stats-box">
|
536 |
-
<p><strong>
|
537 |
-
<p><strong>
|
538 |
-
<p><strong>
|
539 |
-
<p><strong>
|
540 |
<ul>
|
541 |
<li>CPU: {res['performance_metrics']['cpu_percent']}%</li>
|
542 |
<li>RAM: {res['performance_metrics']['memory_percent']}%</li>
|
@@ -549,35 +549,35 @@ with tabs[0]:
|
|
549 |
|
550 |
# Download button with performance metrics
|
551 |
result_text = f"""
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
|
557 |
-
|
558 |
- CPU: {res['performance_metrics']['cpu_percent']}%
|
559 |
- RAM: {res['performance_metrics']['memory_percent']}%
|
560 |
{f"- GPU Memory: {res['performance_metrics'].get('gpu_memory_used', 'N/A'):.2f} MB" if DEVICE == "cuda" else ""}
|
561 |
"""
|
562 |
st.download_button(
|
563 |
-
"📥
|
564 |
data=result_text,
|
565 |
-
file_name="
|
566 |
mime="text/plain"
|
567 |
)
|
568 |
else:
|
569 |
-
st.info("
|
570 |
|
571 |
# --- Tab History ---
|
572 |
with tabs[1]:
|
573 |
-
st.markdown("### 📊
|
574 |
if 'history' in st.session_state and st.session_state.history:
|
575 |
# Download full history
|
576 |
history_df = pd.DataFrame(st.session_state.history)
|
577 |
st.download_button(
|
578 |
-
"📥
|
579 |
data=history_df.to_csv(index=False).encode('utf-8'),
|
580 |
-
file_name="
|
581 |
mime="text/csv"
|
582 |
)
|
583 |
|
@@ -585,42 +585,36 @@ with tabs[1]:
|
|
585 |
for idx, record in enumerate(reversed(st.session_state.history), 1):
|
586 |
st.markdown(f"""
|
587 |
<div class="result-box">
|
588 |
-
<h4>
|
589 |
-
<p><strong>
|
590 |
-
<p><strong>
|
591 |
-
<p><strong>
|
592 |
</div>
|
593 |
""", unsafe_allow_html=True)
|
594 |
else:
|
595 |
-
st.info("
|
596 |
|
597 |
# --- Tab Info ---
|
598 |
with tabs[2]:
|
599 |
st.markdown("""
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
<li><strong>SUPPORTED:</strong> Câu khẳng định được hỗ trợ bởi bằng chứng</li>
|
622 |
-
<li><strong>REFUTED:</strong> Câu khẳng định bị bác bỏ bởi bằng chứng</li>
|
623 |
-
<li><strong>NEI:</strong> Không đủ bằng chứng để kết luận</li>
|
624 |
-
</ul>
|
625 |
-
</div>
|
626 |
-
""", unsafe_allow_html=True)
|
|
|
94 |
torch.cuda.empty_cache()
|
95 |
gc.collect()
|
96 |
|
97 |
+
verdict_start_time = time.time()
|
98 |
# Parallel classification using ThreadPoolExecutor
|
99 |
with ThreadPoolExecutor(max_workers=2) as executor:
|
100 |
future_tc = executor.submit(cached_classify_claim, claim, evidence, tc_model_name, False)
|
|
|
103 |
prob3class, pred_tc = future_tc.result()
|
104 |
prob2class, pred_bc = future_bc.result()
|
105 |
|
|
|
106 |
with torch.no_grad():
|
107 |
verdict = "NEI"
|
108 |
if pred_tc != 0:
|
|
|
137 |
|
138 |
# Set page configuration
|
139 |
st.set_page_config(
|
140 |
+
page_title="SemViQA - A Semantic Question Answering System for Vietnamese Information Fact-Checking",
|
141 |
page_icon="🔍",
|
142 |
layout="wide",
|
143 |
initial_sidebar_state="expanded"
|
|
|
340 |
st.markdown("""
|
341 |
<div class="main-header">
|
342 |
<div class="main-title">SemViQA</div>
|
343 |
+
<div class="sub-title">A Semantic Question Answering System for Vietnamese Information Fact-Checking</div>
|
344 |
</div>
|
345 |
""", unsafe_allow_html=True)
|
346 |
|
347 |
# Sidebar
|
348 |
with st.sidebar:
|
349 |
+
st.markdown("### ⚙️ System Settings")
|
350 |
|
351 |
# Model selection
|
352 |
+
st.markdown("#### 🧠 Model Selection")
|
353 |
qatc_model_name = st.selectbox(
|
354 |
+
"QATC Model",
|
355 |
[
|
356 |
"SemViQA/qatc-infoxlm-viwikifc",
|
357 |
"SemViQA/qatc-infoxlm-isedsc01",
|
|
|
361 |
)
|
362 |
|
363 |
bc_model_name = st.selectbox(
|
364 |
+
"Binary Classification Model",
|
365 |
[
|
366 |
"SemViQA/bc-xlmr-viwikifc",
|
367 |
"SemViQA/bc-xlmr-isedsc01",
|
|
|
373 |
)
|
374 |
|
375 |
tc_model_name = st.selectbox(
|
376 |
+
"Three-Class Classification Model",
|
377 |
[
|
378 |
"SemViQA/tc-xlmr-viwikifc",
|
379 |
"SemViQA/tc-xlmr-isedsc01",
|
|
|
385 |
)
|
386 |
|
387 |
# Threshold settings
|
388 |
+
st.markdown("#### ⚖️ Analysis Thresholds")
|
389 |
tfidf_threshold = st.slider(
|
390 |
+
"Confidence Threshold",
|
391 |
0.0, 1.0, 0.5,
|
392 |
+
help="Adjust sensitivity in evidence search"
|
393 |
)
|
394 |
|
395 |
length_ratio_threshold = st.slider(
|
396 |
+
"Length Ratio Threshold",
|
397 |
0.1, 1.0, 0.5,
|
398 |
+
help="Adjust maximum evidence length"
|
399 |
)
|
400 |
|
401 |
# Display settings
|
402 |
+
st.markdown("#### 👁️ Display")
|
403 |
show_details = st.checkbox(
|
404 |
+
"Show Probability Details",
|
405 |
value=False,
|
406 |
+
help="Display detailed probability information"
|
407 |
)
|
408 |
|
409 |
# Performance settings
|
410 |
+
st.markdown("#### ⚡ Performance")
|
411 |
num_threads = st.slider(
|
412 |
+
"CPU Threads",
|
413 |
1, psutil.cpu_count(),
|
414 |
psutil.cpu_count(logical=False),
|
415 |
+
help="Adjust processing performance"
|
416 |
)
|
417 |
os.environ["OMP_NUM_THREADS"] = str(num_threads)
|
418 |
os.environ["MKL_NUM_THREADS"] = str(num_threads)
|
419 |
|
420 |
# Main content
|
421 |
+
tabs = st.tabs(["🔍 Verify", "📊 History", "ℹ️ Info"])
|
422 |
|
423 |
tokenizer_qatc, model_qatc = load_model(qatc_model_name, QATCForQuestionAnswering, device=DEVICE)
|
424 |
tokenizer_bc, model_bc = load_model(bc_model_name, ClaimModelForClassification, is_bc=True, device=DEVICE)
|
|
|
434 |
col1, col2 = st.columns([2, 1])
|
435 |
|
436 |
with col1:
|
437 |
+
st.markdown("### 📝 Input Information")
|
438 |
claim = st.text_area(
|
439 |
+
"Claim to Verify",
|
440 |
"Chiến tranh với Campuchia đã kết thúc trước khi Việt Nam thống nhất.",
|
441 |
+
help="Enter the claim to be verified"
|
442 |
)
|
443 |
|
444 |
context = st.text_area(
|
445 |
+
"Context",
|
446 |
"Sau khi thống nhất, Việt Nam tiếp tục gặp khó khăn do sự sụp đổ và tan rã của đồng minh Liên Xô cùng Khối phía Đông, các lệnh cấm vận của Hoa Kỳ, chiến tranh với Campuchia, biên giới giáp Trung Quốc và hậu quả của chính sách bao cấp sau nhiều năm áp dụng. Năm 1986, Đảng Cộng sản ban hành cải cách đổi mới, tạo điều kiện hình thành kinh tế thị trường và hội nhập sâu rộng. Cải cách đổi mới kết hợp cùng quy mô dân số lớn đưa Việt Nam trở thành một trong những nước đang phát triển có tốc độ tăng trưởng thuộc nhóm nhanh nhất thế giới, được coi là Hổ mới châu Á dù cho vẫn gặp phải những thách thức như tham nhũng, tội phạm gia tăng, ô nhiễm môi trường và phúc lợi xã hội chưa đầy đủ. Ngoài ra, giới bất đồng chính kiến, chính phủ một số nước phương Tây và các tổ chức theo dõi nhân quyền có quan điểm chỉ trích hồ sơ nhân quyền của Việt Nam liên quan đến các vấn đề tôn giáo, kiểm duyệt truyền thông, hạn chế hoạt động ủng hộ nhân quyền cùng các quyền tự do dân sự.",
|
447 |
+
help="Enter context or reference text"
|
448 |
)
|
449 |
|
450 |
+
verify_button = st.button("🔍 Verify", use_container_width=True)
|
451 |
|
452 |
with col2:
|
453 |
+
st.markdown("### 📊 Results")
|
454 |
if verify_button:
|
455 |
+
with st.spinner("Verifying..."):
|
456 |
# Preprocess texts
|
457 |
preprocessed_claim = preprocess_text(claim)
|
458 |
preprocessed_context = preprocess_text(context)
|
|
|
526 |
|
527 |
st.markdown(f"""
|
528 |
<div class="result-box">
|
529 |
+
<h3>Verification Results</h3>
|
530 |
+
<p><strong>Claim:</strong> {res['claim']}</p>
|
531 |
+
<p><strong>Evidence:</strong> {res['evidence']}</p>
|
532 |
<p class="verdict {verdict_class}">
|
533 |
{verdict_icons.get(res['verdict'], '')} {res['verdict']}
|
534 |
</p>
|
535 |
<div class="stats-box">
|
536 |
+
<p><strong>Evidence Extraction Time:</strong> {res['evidence_time']:.2f} seconds</p>
|
537 |
+
<p><strong>Classification Time:</strong> {res['verdict_time']:.2f} seconds</p>
|
538 |
+
<p><strong>Total Time:</strong> {res['total_time']:.2f} seconds</p>
|
539 |
+
<p><strong>Performance:</strong></p>
|
540 |
<ul>
|
541 |
<li>CPU: {res['performance_metrics']['cpu_percent']}%</li>
|
542 |
<li>RAM: {res['performance_metrics']['memory_percent']}%</li>
|
|
|
549 |
|
550 |
# Download button with performance metrics
|
551 |
result_text = f"""
|
552 |
+
Claim: {res['claim']}
|
553 |
+
Evidence: {res['evidence']}
|
554 |
+
Verdict: {res['verdict']}
|
555 |
+
Details: {res['details']}
|
556 |
|
557 |
+
Performance:
|
558 |
- CPU: {res['performance_metrics']['cpu_percent']}%
|
559 |
- RAM: {res['performance_metrics']['memory_percent']}%
|
560 |
{f"- GPU Memory: {res['performance_metrics'].get('gpu_memory_used', 'N/A'):.2f} MB" if DEVICE == "cuda" else ""}
|
561 |
"""
|
562 |
st.download_button(
|
563 |
+
"📥 Download Results",
|
564 |
data=result_text,
|
565 |
+
file_name="verification_results.txt",
|
566 |
mime="text/plain"
|
567 |
)
|
568 |
else:
|
569 |
+
st.info("Please enter information and click Verify to begin.")
|
570 |
|
571 |
# --- Tab History ---
|
572 |
with tabs[1]:
|
573 |
+
st.markdown("### 📊 Verification History")
|
574 |
if 'history' in st.session_state and st.session_state.history:
|
575 |
# Download full history
|
576 |
history_df = pd.DataFrame(st.session_state.history)
|
577 |
st.download_button(
|
578 |
+
"📥 Download Full History",
|
579 |
data=history_df.to_csv(index=False).encode('utf-8'),
|
580 |
+
file_name="verification_history.csv",
|
581 |
mime="text/csv"
|
582 |
)
|
583 |
|
|
|
585 |
for idx, record in enumerate(reversed(st.session_state.history), 1):
|
586 |
st.markdown(f"""
|
587 |
<div class="result-box">
|
588 |
+
<h4>Verification #{idx}</h4>
|
589 |
+
<p><strong>Claim:</strong> {record['claim']}</p>
|
590 |
+
<p><strong>Verdict:</strong> {verdict_icons.get(record['verdict'], '')} {record['verdict']}</p>
|
591 |
+
<p><strong>Time:</strong> {record['total_time']:.2f} seconds</p>
|
592 |
</div>
|
593 |
""", unsafe_allow_html=True)
|
594 |
else:
|
595 |
+
st.info("No verification history available.")
|
596 |
|
597 |
# --- Tab Info ---
|
598 |
with tabs[2]:
|
599 |
st.markdown("""
|
600 |
+
### ℹ️ About SemViQA
|
601 |
+
**Author:** [**Nam V. Nguyen**](https://github.com/DAVID-NGUYEN-S16), [**Dien X. Tran**](https://github.com/xndien2004), Thanh T. Tran, Anh T. Hoang, Tai V. Duong, Di T. Le, Phuc-Lu Le
|
602 |
+
|
603 |
+
SemViQA is a cutting-edge Vietnamese fact-checking system designed to combat misinformation. It leverages semantic-based evidence retrieval (SER) and a two-step verdict classification (TVC) approach to verify claims efficiently. By combining TF-IDF with a Question Answering Token Classifier (QATC), SemViQA improves accuracy while reducing inference time. Achieving state-of-the-art performance, it has set new benchmarks on ViWikiFC (80.82% accuracy) and ISE-DSC01 (78.97% accuracy) datasets. With its 7x speed boost, SemViQA is a powerful tool for ensuring information integrity in the Vietnamese language.
|
604 |
+
|
605 |
+
#### 🔍 How to Use
|
606 |
+
1. Enter the claim to verify
|
607 |
+
2. Enter context or reference text
|
608 |
+
3. Adjust parameters in Settings if needed
|
609 |
+
4. Click Verify button
|
610 |
+
|
611 |
+
#### ⚙️ Parameters
|
612 |
+
- **Confidence Threshold:** Adjust sensitivity in evidence search
|
613 |
+
- **Length Ratio Threshold:** An important parameter in the evidence retrieval process. It determines how text segments are processed when compared to the length of the claim to be verified.
|
614 |
+
- **CPU Threads:** Adjust processing performance
|
615 |
+
|
616 |
+
#### 📊 Results
|
617 |
+
- **SUPPORTED:** The claim is supported by evidence
|
618 |
+
- **REFUTED:** The claim is refuted by evidence
|
619 |
+
- **NEI:** Not enough information to conclude
|
620 |
+
""")
|
|
|
|
|
|
|
|
|
|
|
|