akdeniz27's picture
Update app.py
a6b9335
raw
history blame
3.13 kB
# Zero-Shot Text Classification with Multilingual T5 (mT5)
import streamlit as st
import plotly.graph_objects as go
from mT5Model import runModel
text_1 = """Bilim insanları Botsvana’da Covid-19’un şu ana kadar en çok mutasyona uğramış varyantını tespit etti. \
Resmi olarak B.1.1.529 koduyla bilinen bu varyantı ise “Nu varyantı” adı verildi. Uzmanlar bu varyant içerisinde \
tam 32 farklı mutasyon tespit edildiğini açıklarken, bu virüsün corona virüsü aşılarına karşı daha dirençli olabileceğini duyurdu."""
text_2 = """Lionel Messi starred as Argentina progressed to the quarter-finals of the World Cup with a 2-1 win over Australia. \
Messi marked the 1,000th senior game of his career with a measured finish for the breakthrough goal late in the first half, and \
Mat Ryan's error allowed Julian Alvarez to double the advantage early in the second."""
@st.cache(allow_output_mutation=True)
def list2text(label_list):
labels = ""
for label in label_list:
labels = labels + label + ","
labels = labels[:-1]
return labels
label_list_1 = ["dünya", "ekonomi", "kültür", "sağlık", "siyaset", "spor", "teknoloji"]
label_list_2 = ["world", "economy", "culture", "health", "politics", "sport", "technology"]
st.title("Multilingual Zero-Shot Text Classification with mT5")
model_name = "alan-turing-institute/mt5-large-finetuned-mnli-xtreme-xnli"
st.sidebar.write("For details of used model:")
st.sidebar.write("https://huggingface.co/alan-turing-institute/mt5-large-finetuned-mnli-xtreme-xnli")
st.sidebar.write("For Xtreme XNLI Dataset:")
st.sidebar.write("https://www.tensorflow.org/datasets/catalog/xtreme_xnli")
st.subheader("Select Text and Label List")
st.text_area("Text #1", text_1, height=128)
st.text_area("Text #2", text_2, height=128)
st.write(f"Label List #1: {list2text(label_list_1)}")
st.write(f"Label List #2: {list2text(label_list_2)}")
text = st.radio("Select Text", ("Text #1", "Text #2", "New Text"))
labels = st.radio("Select Label List", ("Label List #1", "Label List #2", "New Label List"))
if text == "Text #1": sequence_to_classify = text_1
elif text == "Text #2": sequence_to_classify = text_2
elif text == "New Text":
sequence_to_classify = st.text_area("New Text", value="", height=128)
if labels == "Label List #1": candidate_labels = label_list_1
elif labels == "Label List #2": candidate_labels = label_list_2
elif labels == "New Label List":
candidate_labels = st.text_area("New Label List (Pls Input as comma-separated)", value="", height=16).split(",")
hypothesis_template = "Bu yazı {} konusundadır."
Run_Button = st.button("Run", key=None)
if Run_Button == True:
with st.spinner('Model is running...'):
output = runModel(model_name, sequence_to_classify, candidate_labels, hypothesis_template)
output_labels = list(output.keys())
output_scores = list(output.values())
st.header("Result")
fig = go.Figure([go.Bar(x=output_labels, y=output_scores)])
st.plotly_chart(fig, use_container_width=False, sharing="streamlit")
st.success('Done!')