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": tokenizer=AutoTokenizer.from_pretrained(“cardiffnlp/twitter-xlm-roberta-base-sentiment”, use_fast=False) classifier = pipeline("sentiment-analysis", model="cardiffnlp/twitter-xlm-roberta-base-sentiment", tokenizer) 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})')