semviqa-demo / app.py
xuandin's picture
Upload 2 files
e813be9 verified
raw
history blame
3 kB
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)