-
Notifications
You must be signed in to change notification settings - Fork 11
/
app.py
executable file
·34 lines (28 loc) · 874 Bytes
/
app.py
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
from flask import Flask, render_template, abort, request, jsonify
import nltk
from nltk.sentiment.vader import SentimentIntensityAnalyzer
app = Flask(__name__)
output = {}
def sentiment(sentence):
nltk.download('vader_lexicon')
sid = SentimentIntensityAnalyzer()
score = sid.polarity_scores(sentence)['compound']
if(score>0):
return "Positive"
else:
return "Negative"
@app.route("/", methods = ["GET","POST"])
def sentimentRequest():
if request.method == "POST":
sentence = request.form['q']
sent = sentiment(sentence)
output['sentiment'] = sent
return jsonify(output)
else:
sentence = request.args.get('q')
sent = sentiment(sentence)
print(sentence)
output['sentiment'] = sent
return jsonify(output)
if __name__ == "__main__":
app.run(debug=True)