Harshavarma04's picture
Update app.py
f60aa84 verified
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()