Spaces:
Running
Running
Upload 2 files
Browse files- app.py +80 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import torch
|
3 |
+
from transformers import AutoTokenizer
|
4 |
+
from semviqa.SER.qatc_model import QATCForQuestionAnswering
|
5 |
+
|
6 |
+
# Load QATC Model
|
7 |
+
@st.cache_resource()
|
8 |
+
def load_qatc_model():
|
9 |
+
tokenizer = AutoTokenizer.from_pretrained("xuandin/semviqa-qatc-vimrc-viwikifc")
|
10 |
+
model = QATCForQuestionAnswering.from_pretrained("xuandin/semviqa-qatc-vimrc-viwikifc")
|
11 |
+
return tokenizer, model
|
12 |
+
|
13 |
+
# Streamlit UI Configuration
|
14 |
+
st.set_page_config(page_title="SemViQA Demo", layout="wide")
|
15 |
+
|
16 |
+
# Improved UI Design
|
17 |
+
st.markdown("""
|
18 |
+
<style>
|
19 |
+
.big-title {
|
20 |
+
font-size: 36px;
|
21 |
+
font-weight: bold;
|
22 |
+
color: #4A90E2;
|
23 |
+
text-align: center;
|
24 |
+
}
|
25 |
+
.sub-title {
|
26 |
+
font-size: 20px;
|
27 |
+
color: #666;
|
28 |
+
text-align: center;
|
29 |
+
}
|
30 |
+
.stButton>button {
|
31 |
+
background-color: #4CAF50;
|
32 |
+
color: white;
|
33 |
+
font-size: 16px;
|
34 |
+
width: 100%;
|
35 |
+
border-radius: 8px;
|
36 |
+
padding: 10px;
|
37 |
+
}
|
38 |
+
.stTextArea textarea {
|
39 |
+
font-size: 16px;
|
40 |
+
}
|
41 |
+
.result-box {
|
42 |
+
background-color: #f9f9f9;
|
43 |
+
padding: 20px;
|
44 |
+
border-radius: 10px;
|
45 |
+
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1);
|
46 |
+
}
|
47 |
+
</style>
|
48 |
+
""", unsafe_allow_html=True)
|
49 |
+
|
50 |
+
st.markdown("<p class='big-title'>π SemViQA: A Semantic Question Answering System for Vietnamese Information Fact-Checking</p>", unsafe_allow_html=True)
|
51 |
+
st.markdown("<p class='sub-title'>Enter a claim and context to verify its accuracy</p>", unsafe_allow_html=True)
|
52 |
+
|
53 |
+
# Sidebar - Configuration Settings
|
54 |
+
st.sidebar.header("βοΈ Settings")
|
55 |
+
tfidf_threshold = st.sidebar.slider("π§ TF-IDF Threshold", 0.0, 1.0, 0.5, 0.01)
|
56 |
+
length_ratio_threshold = st.sidebar.slider("π Length Ratio Threshold", 0.1, 1.0, 0.5, 0.01)
|
57 |
+
qatc_model = st.sidebar.selectbox("π€ Select QATC Model", ["xuandin/semviqa-qatc-vimrc-viwikifc"])
|
58 |
+
|
59 |
+
# User Input Fields
|
60 |
+
claim = st.text_area("βοΈ Enter Claim", "Vietnam is a country in Southeast Asia.")
|
61 |
+
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.")
|
62 |
+
|
63 |
+
if st.button("π Verify"):
|
64 |
+
tokenizer, model = load_qatc_model()
|
65 |
+
inputs = tokenizer(claim, context, return_tensors="pt", truncation=True, max_length=512)
|
66 |
+
|
67 |
+
with torch.no_grad():
|
68 |
+
outputs = model(**inputs)
|
69 |
+
|
70 |
+
start_idx = torch.argmax(outputs.start_logits)
|
71 |
+
end_idx = torch.argmax(outputs.end_logits)
|
72 |
+
tokens = inputs["input_ids"][0][start_idx : end_idx + 1]
|
73 |
+
evidence_result = tokenizer.decode(tokens, skip_special_tokens=True)
|
74 |
+
|
75 |
+
st.markdown("""
|
76 |
+
<div class='result-box'>
|
77 |
+
<h3>π Result</h3>
|
78 |
+
<p><strong>π Evidence:</strong> {}</p>
|
79 |
+
</div>
|
80 |
+
""".format(evidence_result), unsafe_allow_html=True)
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
torch
|
3 |
+
transformers
|
4 |
+
semviqa
|