Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Create a title and a text input for the user to enter the text
|
5 |
+
st.title('Sentiment Analysis App')
|
6 |
+
text = st.text_input('Enter text here')
|
7 |
+
|
8 |
+
# Create a dropdown for the user to select the pre-trained model
|
9 |
+
model_name = st.selectbox(
|
10 |
+
'Select a pre-trained model',
|
11 |
+
['distilbert-base-uncased', 'distilbert-base-cased', 'bert-base-uncased', 'bert-base-cased',
|
12 |
+
'cardiffnlp/twitter-roberta-base-sentiment-latest',
|
13 |
+
'cardiffnlp/twitter-xlm-roberta-base-sentiment',
|
14 |
+
'j-hartmann/emotion-english-distilroberta-base',
|
15 |
+
'ProsusAI/finbert'
|
16 |
+
]
|
17 |
+
)
|
18 |
+
|
19 |
+
# Create a button to perform the sentiment analysis
|
20 |
+
if st.button('Analyze Sentiment'):
|
21 |
+
# Load the selected model
|
22 |
+
model = pipeline('sentiment-analysis', model=model_name)
|
23 |
+
|
24 |
+
# Perform sentiment analysis on the input text
|
25 |
+
result = model(text)[0]
|
26 |
+
|
27 |
+
# Print the sentiment label and score
|
28 |
+
st.write(f'Sentiment: {result["label"]}')
|
29 |
+
st.write(f'Score: {result["score"]}')
|
30 |
+
|
31 |
+
|
32 |
+
|