Benjy's picture
Update app.py
8c5fe37 verified
raw
history blame
1.18 kB
import streamlit as st
from transformers import pipeline
# Load the sentiment analysis pipeline
sentiment_pipeline = pipeline("sentiment-analysis")
# Streamlit UI
st.title("Sentiment Analysis")
st.write("Enter text below to analyse the sentiment.")
st.write("You can copy and paste a comment from social media for example.")
st.write("Usage idea: Companies can now reach those unhappy customers who leave unhappy comments on social media before they leave a bad review.")
st.write("You can then gather a list of names for your customer services team to prioritise and make that crucial early contact.")
st.write("Be proactive, not reactive")
# Text input
user_input = st.text_area("Text input")
# Button to perform sentiment analysis
if st.button("Analyse Sentiment"):
if user_input:
# Perform sentiment analysis
results = sentiment_pipeline(user_input)
# Display the results
sentiment = results[0]['label']
score = results[0]['score']
confidence_percentage = score * 100
st.write(f"Sentiment: {sentiment} (Confidence: {confidence_percentage:.2f}%)")
else:
st.write("Please enter some text to proceed.")