File size: 817 Bytes
483dd11 f90c3a5 483dd11 f90c3a5 483dd11 f90c3a5 c06f677 f90c3a5 c06f677 f90c3a5 c06f677 f90c3a5 |
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 |
import streamlit as st
from transformers import pipeline
# Title and Subtitle
st.title('Sentiment Analysis App')
st.subheader('Enter text to analyze sentiment')
# Text input box
text = st.text_area('Enter your text')
if text:
# Analyze sentiment using the model
pipe = pipeline(model="dancingninjas/sentiment-analysis-nlp")
results = pipe(text)
# Determine sentiment label
sentiment_label = "Positive" if results[0]['label'] == 'LABEL_1' else "Negative"
# Display sentiment label and probability
st.subheader('Sentiment Analysis Result:')
st.write(f'Sentiment: {sentiment_label}')
st.write(f'Probability: {results[0]["score"]:.4f}')
# Visualize the sentiment with an emoji
if sentiment_label == 'Positive':
st.write('π')
else:
st.write('π')
|