File size: 3,001 Bytes
e813be9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import streamlit as st
import torch
from transformers import AutoTokenizer
from semviqa.SER.qatc_model import QATCForQuestionAnswering

# Load QATC Model
@st.cache_resource()
def load_qatc_model():
    tokenizer = AutoTokenizer.from_pretrained("xuandin/semviqa-qatc-vimrc-viwikifc")
    model = QATCForQuestionAnswering.from_pretrained("xuandin/semviqa-qatc-vimrc-viwikifc")
    return tokenizer, model

# Streamlit UI Configuration
st.set_page_config(page_title="SemViQA Demo", layout="wide")

# Improved UI Design
st.markdown("""

    <style>

        .big-title {

            font-size: 36px;

            font-weight: bold;

            color: #4A90E2;

            text-align: center;

        }

        .sub-title {

            font-size: 20px;

            color: #666;

            text-align: center;

        }

        .stButton>button {

            background-color: #4CAF50;

            color: white;

            font-size: 16px;

            width: 100%;

            border-radius: 8px;

            padding: 10px;

        }

        .stTextArea textarea {

            font-size: 16px;

        }

        .result-box {

            background-color: #f9f9f9;

            padding: 20px;

            border-radius: 10px;

            box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1);

        }

    </style>

""", unsafe_allow_html=True)

st.markdown("<p class='big-title'>πŸ” SemViQA: A Semantic Question Answering System for Vietnamese Information Fact-Checking</p>", unsafe_allow_html=True)
st.markdown("<p class='sub-title'>Enter a claim and context to verify its accuracy</p>", unsafe_allow_html=True)

# Sidebar - Configuration Settings
st.sidebar.header("βš™οΈ Settings")
tfidf_threshold = st.sidebar.slider("πŸ”§ TF-IDF Threshold", 0.0, 1.0, 0.5, 0.01)
length_ratio_threshold = st.sidebar.slider("πŸ“ Length Ratio Threshold", 0.1, 1.0, 0.5, 0.01)
qatc_model = st.sidebar.selectbox("πŸ€– Select QATC Model", ["xuandin/semviqa-qatc-vimrc-viwikifc"])

# User Input Fields
claim = st.text_area("✍️ Enter Claim", "Vietnam is a country in Southeast Asia.")
context = st.text_area("πŸ“– Enter Context", "Vietnam is a country located in Southeast Asia, covering an area of over 331,000 kmΒ² with a population of more than 98 million people.")

if st.button("πŸ”Ž Verify"):
    tokenizer, model = load_qatc_model()
    inputs = tokenizer(claim, context, return_tensors="pt", truncation=True, max_length=512)
    
    with torch.no_grad():
        outputs = model(**inputs)
    
    start_idx = torch.argmax(outputs.start_logits)
    end_idx = torch.argmax(outputs.end_logits)
    tokens = inputs["input_ids"][0][start_idx : end_idx + 1]
    evidence_result = tokenizer.decode(tokens, skip_special_tokens=True)
    
    st.markdown("""

        <div class='result-box'>

            <h3>πŸ“Œ Result</h3>

            <p><strong>πŸ” Evidence:</strong> {}</p>

        </div>

    """.format(evidence_result), unsafe_allow_html=True)