-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
25 lines (21 loc) · 695 Bytes
/
app.py
File metadata and controls
25 lines (21 loc) · 695 Bytes
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
from flask import Flask, request, render_template
from textblob import TextBlob
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def index():
sentiment = None
polarity = None
text = ""
if request.method == 'POST':
text = request.form['text']
blob = TextBlob(text)
polarity = blob.sentiment.polarity
if polarity > 0:
sentiment = "Positive"
elif polarity < 0:
sentiment = "Negative"
else:
sentiment = "Neutral"
return render_template('index.html', sentiment=sentiment, polarity=polarity, text=text)
if __name__ == '__main__':
app.run(debug=True)