File size: 1,302 Bytes
5d2636d
f468f30
5d2636d
 
426d602
 
 
 
 
 
 
 
 
 
 
 
 
9e87fa4
426d602
 
 
 
 
 
 
 
 
9e87fa4
426d602
 
 
 
 
 
 
 
9e87fa4
426d602
 
 
 
 
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
import streamlit as st
import nltk
from nltk.sentiment.vader import SentimentIntensityAnalyzer

# Ensure the VADER lexicon is downloaded
nltk.download('vader_lexicon')

class SentimentAnalyzer:
    def __init__(self):
        self.analyzer = SentimentIntensityAnalyzer()

    def analyze_sentiment(self, sentence):
        return self.analyzer.polarity_scores(sentence)

def fool():
    analyzer = SentimentAnalyzer()

    st.title("Sentiment Analysis App using VADER")
    st.write("Enter a sentence to analyze its sentiment:")

    # Input text box for user input
    sentence = st.text_input("Input sentence:")

    if st.button("Analyze"):
        if sentence:
            # Perform sentiment analysis
            result = analyzer.analyze_sentiment(sentence)
            
            # Interpret sentiment label
            compound_score = result['compound']
            if compound_score >= 0.05:
                sentiment_type = 'Positive'
            elif compound_score <= -0.05:
                sentiment_type = 'Negative'
            else:
                sentiment_type = 'Neutral'
            
            # Display sentiment analysis result
            st.write(f"Sentiment: {sentiment_type}, Score: {compound_score:.4f}")

# Call fool function directly if the script is executed
fool()