Commit
·
f90c3a5
1
Parent(s):
387bdf8
Update app.py
Browse files
app.py
CHANGED
@@ -3,16 +3,26 @@ from transformers import pipeline
|
|
3 |
|
4 |
# Title and Subtitle
|
5 |
st.title('Sentiment Analysis App')
|
|
|
6 |
|
7 |
-
|
8 |
-
text=st.text_area('Enter your text')
|
9 |
|
10 |
if text:
|
11 |
-
|
|
|
|
|
12 |
|
13 |
-
#
|
14 |
-
sentiment_label = "
|
15 |
|
16 |
-
# Display
|
|
|
17 |
st.write(f'Sentiment: {sentiment_label}')
|
18 |
-
st.write(f'Probability: {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
# Title and Subtitle
|
5 |
st.title('Sentiment Analysis App')
|
6 |
+
st.subheader('Enter text to analyze sentiment')
|
7 |
|
8 |
+
# Text input box
|
9 |
+
text = st.text_area('Enter your text')
|
10 |
|
11 |
if text:
|
12 |
+
# Analyze sentiment using the model
|
13 |
+
pipe = pipeline(model="dancingninjas/sentiment-analysis-nlp")
|
14 |
+
results = pipe(text)
|
15 |
|
16 |
+
# Determine sentiment label
|
17 |
+
sentiment_label = "Positive" if results[0]['label'] == 'LABEL_1' else "Negative"
|
18 |
|
19 |
+
# Display sentiment label and probability
|
20 |
+
st.subheader('Sentiment Analysis Result:')
|
21 |
st.write(f'Sentiment: {sentiment_label}')
|
22 |
+
st.write(f'Probability: {results[0]["score"]:.4f}')
|
23 |
+
|
24 |
+
# Visualize the sentiment with an emoji
|
25 |
+
if sentiment_label == 'Positive':
|
26 |
+
st.write('😃')
|
27 |
+
else:
|
28 |
+
st.write('😔')
|