Spaces:
Runtime error
Runtime error
File size: 1,152 Bytes
e222a8f 9708554 e222a8f 2d6a0fb e222a8f 2d6a0fb e222a8f 2d6a0fb 12cd16d c092532 2d6a0fb 1553f68 e222a8f 2d6a0fb d0973ee |
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 |
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"]
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)
result = classifier(user_input)[0]
return result
if submit:
resultf = classification(user_input, model_type)
label = resultf['label']
score = resultf['score']
if label == 'POSITIVE' or 'Positive':
st.success(f'{label} sentiment (score: {score})')
else:
st.error(f'{label} sentiment (score: {score})') |