Spaces:
Sleeping
Sleeping
import streamlit as st | |
import torch | |
from transformers import AutoTokenizer | |
from semviqa.SER.qatc_model import QATCForQuestionAnswering | |
# Load QATC Model | |
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) | |