import streamlit as st from transformers import pipeline # Initialize the sentiment analysis pipeline sentiment_analyzer = pipeline("sentiment-analysis") # Streamlit UI st.title('Sentiment Analysis for Customer Reviews') # Get input text from the user reviews_text = st.text_area("Paste customer reviews here (multiple reviews separated by a newline; recommended-upto 15 reviews at a time):", height=200) # Button to process the sentiment if st.button("Analyze Sentiment"): if reviews_text: # Split the reviews into separate lines (assuming each line is a separate review) reviews = reviews_text.split("\n") # Analyze the sentiment of each review sentiment_scores = [] for review in reviews: sentiment = sentiment_analyzer(review)[0] sentiment_scores.append(sentiment['label']) # Count sentiment labels positive_count = sentiment_scores.count('POSITIVE') negative_count = sentiment_scores.count('NEGATIVE') neutral_count = sentiment_scores.count('NEUTRAL') # Determine the overall sentiment if positive_count > negative_count and positive_count > neutral_count: overall_sentiment = 'Positive' elif negative_count > positive_count and negative_count > neutral_count: overall_sentiment = 'Negative' else: overall_sentiment = 'Neutral' # Display results st.subheader(f"Overall Sentiment: {overall_sentiment}") st.write(f"Positive Reviews: {positive_count}") st.write(f"Negative Reviews: {negative_count}") st.write(f"Neutral Reviews: {neutral_count}") else: st.warning("Please paste some reviews to analyze.")