Spaces:
Runtime error
Runtime error
File size: 1,300 Bytes
1e6c35c 4d85e89 0885d54 1e6c35c 4d85e89 66a868b 9f4d605 c838257 4d85e89 552048c c838257 4d85e89 a0667b7 552048c 66a868b 552048c c838257 31cc01d 66a868b a3c2573 66a868b a0667b7 31cc01d a0667b7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
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)
|