File size: 1,013 Bytes
03b7383
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from transformers import pipeline

# Create a title and a text input for the user to enter the text
st.title('Sentiment Analysis App')
text = st.text_input('Enter text here')

# Create a dropdown for the user to select the pre-trained model
model_name = st.selectbox(
    'Select a pre-trained model',
    ['distilbert-base-uncased', 'distilbert-base-cased', 'bert-base-uncased', 'bert-base-cased',
     'cardiffnlp/twitter-roberta-base-sentiment-latest',
     'cardiffnlp/twitter-xlm-roberta-base-sentiment',
     'j-hartmann/emotion-english-distilroberta-base',
     'ProsusAI/finbert'
     ]
)

# Create a button to perform the sentiment analysis
if st.button('Analyze Sentiment'):
    # Load the selected model
    model = pipeline('sentiment-analysis', model=model_name)

    # Perform sentiment analysis on the input text
    result = model(text)[0]

    # Print the sentiment label and score
    st.write(f'Sentiment: {result["label"]}')
    st.write(f'Score: {result["score"]}')