Spaces:
Runtime error
Runtime error
File size: 1,701 Bytes
e222a8f 9708554 e222a8f bccb162 e222a8f 2d6a0fb e222a8f 2d6a0fb 12cd16d c092532 d454322 bccb162 2d6a0fb e222a8f 9cb70e4 e826273 d0973ee e826273 |
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
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":
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(str(resultf[0]['label']) + ": " + str(resultf[0]['score']))
# st.write(str(resultf[1]['label']) + ": " + str(resultf[1]['score']))
# st.write(str(resultf[2]['label']) + ": " + str(resultf[2]['score']))
# 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})') |