aliabd commited on
Commit
c021ad9
·
1 Parent(s): 2a0c6b2

Create new file

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # URL: https://huggingface.co/spaces/gradio/sentiment-analysis
2
+ # imports
3
+ import gradio as gr
4
+ import nltk
5
+ from nltk.sentiment.vader import SentimentIntensityAnalyzer
6
+
7
+ # load and set up model
8
+ nltk.download("vader_lexicon")
9
+ sid = SentimentIntensityAnalyzer()
10
+
11
+ # define core function
12
+ def sentiment_analysis(text):
13
+ scores = sid.polarity_scores(text)
14
+ del scores["compound"]
15
+ return scores
16
+
17
+ # define an interface with a textbox input, a label output, and interpretation
18
+ demo = gr.Interface(
19
+ fn=sentiment_analysis,
20
+ inputs=gr.Textbox(placeholder="Enter a positive or negative sentence here..."),
21
+ outputs="label",
22
+ interpretation="default")
23
+
24
+ # launch
25
+ demo.launch()