Harshavarma04 commited on
Commit
426d602
·
verified ·
1 Parent(s): 394062f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from nltk.sentiment.vader import SentimentIntensityAnalyzer
3
+ import nltk
4
+
5
+ # Ensure the VADER lexicon is downloaded
6
+ nltk.download('vader_lexicon')
7
+
8
+
9
+ class SentimentAnalyzer:
10
+ def __init__(self):
11
+ self.analyzer = SentimentIntensityAnalyzer()
12
+
13
+ def analyze_sentiment(self, sentence):
14
+ return self.analyzer.polarity_scores(sentence)
15
+
16
+
17
+ def fool():
18
+ analyzer = SentimentAnalyzer()
19
+
20
+ st.title("Sentiment Analysis App")
21
+ st.write("Enter a sentence to analyze its sentiment:")
22
+
23
+ # Input text box for user input
24
+ sentence = st.text_input("Input sentence:")
25
+
26
+ if st.button("Analyze"):
27
+ if sentence:
28
+ # Perform sentiment analysis
29
+ result = analyzer.analyze_sentiment(sentence)
30
+
31
+ # Interpret sentiment label
32
+ compound_score = result['compound']
33
+ if compound_score >= 0.05:
34
+ sentiment_type = 'Positive'
35
+ elif compound_score <= -0.05:
36
+ sentiment_type = 'Negative'
37
+ else:
38
+ sentiment_type = 'Neutral'
39
+
40
+ # Display sentiment analysis result
41
+ st.write(f"Sentiment: {sentiment_type}, Score: {compound_score:.4f}")
42
+
43
+
44
+ # Call fool function directly if the script is executed
45
+ fool()