Pruthul's picture
Upload app.py
03b7383
raw history blame
No virus
1.01 kB
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"]}')