-
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) · 665 Bytes
/
Copy pathapp.py
File metadata and controls
25 lines (21 loc) · 665 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__)
def analyze_sentiment(text):
blob = TextBlob(text)
polarity = blob.sentiment.polarity
if polarity > 0:
return "Positive"
elif polarity < 0:
return "Negative"
else:
return "Neutral"
@app.route("/", methods=["GET", "POST"])
def home():
if request.method == "POST":
text = request.form["text"]
sentiment = analyze_sentiment(text)
return render_template("index.html", sentiment=sentiment, text=text)
return render_template("index.html")
if __name__ == "__main__":
app.run(debug=True)