Spaces:
Runtime error
Runtime error
import streamlit as st | |
from transformers import pipeline, AutoTokenizer | |
st.title('Sentiment Analyser App') | |
st.write('Welcome to my sentiment analysis app!') | |
model_options=["sentiment-analysis", "twitter-xlm-roberta-base-sentiment", "sentiment-roberta-large-english"] | |
form = st.form(key='sentiment-form') | |
model_type = form.selectbox(label="Select a model", options=model_options) | |
user_input = form.text_area(label='Enter your text to analyse', value="Hey how are you?") | |
submit = form.form_submit_button('Submit') | |
def classification(user_input, type): | |
if type=="sentiment-analysis": | |
classifier = pipeline("sentiment-analysis") | |
elif type=="twitter-xlm-roberta-base-sentiment": | |
path="cardiffnlp/twitter-xlm-roberta-base-sentiment" | |
classifier = pipeline("sentiment-analysis", model=path, tokenizer=path) | |
elif type=="sentiment-roberta-large-english-3-classes": | |
path="siebert/sentiment-roberta-large-english" | |
classifier = pipeline("sentiment-analysis", model=path) | |
result = classifier(user_input) | |
return result | |
if submit: | |
resultf = classification(user_input, model_type) | |
if model_type=="sentiment-roberta-large-english": | |
st.write(resultf[0][0] + ": " + resultf[0][1]) | |
else: | |
label = resultf[0]['label'] | |
score = resultf[0]['score'] | |
if (label == 'POSITIVE') or (label =='Positive') or (label =='positive'): | |
st.success(f'{label} sentiment (score: {score})') | |
else: | |
st.error(f'{label} sentiment (score: {score})') |