forked from msindev/Sentiment-Analysis-Flask-API
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.py
executable file
·32 lines (26 loc) · 839 Bytes
/
script.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
from flask import Flask, render_template, abort, request, jsonify
import nltk
from nltk.sentiment.vader import SentimentIntensityAnalyzer
app = Flask(__name__
output = {}
def sentiment(sentence):
sid = SentimentIntensityAnalyzer()
score = sid.polarity_scores(sentence)['compound']
if(score>0):
return "Positive"
else:
return "Negative"
@app.route("/", methods = ["GET","POST"])
def request():
if request.method == "POST":
sentence = request.form["sentiment_input"]
sentiment = sentiment(sentence)
output['sentiment'] = sentiment
return jsonify(output)
else:
sentence = request.args.get('sentiment_input')
sentiment = sentiment(sentence)
print(sentiment)
output['sentiment'] = sentiment
return {output}
app.run(debug=True)