File size: 1,735 Bytes
53b7479
 
 
 
 
 
 
 
 
 
1fff55b
53b7479
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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.")