kyled's picture
added senitment task
c838257
raw
history blame
1.3 kB
import streamlit as st
import transformers as t
import plotly.express as px
import pandas as pd
st.title("Phrase Feeling Analysis")
with st.spinner(text="Loading model..."):
classifier = t.pipeline("zero-shot-classification",
model="facebook/bart-large-mnli",
multi_class=True)
sentiment_task = t.pipeline("sentiment-analysis",
model="cardiffnlp/twitter-xlm-roberta-base-sentiment",
tokenizer="cardiffnlp/twitter-xlm-roberta-base-sentiment")
x = st.text_input("Enter your title here:")
candidate_labels = ['anger', 'sadness', 'fear', 'joy', 'interest',
'surprise', 'disgust', 'shame', 'compassion', 'other']
if x != "":
with st.spinner(text="Evaluating your input..."):
output = classifier(x, candidate_labels)
sentiment = sentiment_task(x)
st.write(str(sentiment))
ordered_results = []
for lbl in candidate_labels:
ind = output['labels'].index(lbl)
ordered_results.append(output['scores'][ind])
df = pd.DataFrame(dict(r=ordered_results, theta=candidate_labels))
fig = px.line_polar(df, r='r', theta='theta', line_close=True)
fig.update_traces(fill='toself')
st.plotly_chart(fig)