forked from bkanishka004/Journic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
38 lines (27 loc) · 1.15 KB
/
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
35
36
37
38
from flask import Flask, request, render_template
from nltk.corpus import stopwords
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
import nltk
nltk.download('stopwords')
app = Flask(__name__)
@app.route('/')
def my_index1():
return render_template('index1.html')
@app.route('/', methods=['POST'])
def my_index1_post():
stop_words = set(stopwords.words('english'))
text1 = request.form['text1'].lower()
# Remove digits
text_final = ''.join(c for c in text1 if not c.isdigit())
#hi
# Remove punctuation (if needed)
# text3 = ''.join(c for c in text2 if c not in punctuation)
# Remove stopwords
processed_doc1 = ' '.join([word for word in text_final.split() if word not in stop_words])
# Sentiment analysis
sa = SentimentIntensityAnalyzer()
dd = sa.polarity_scores(text=processed_doc1)
compound = round((1 + dd['compound'])/2, 2)
return render_template('index1.html', final=compound, text1=text_final, text2=dd['pos'], text5=dd['neg'], text4=compound, text3=dd['neu'])
if __name__ == "__main__":
app.run(debug=True, host="0.0.0.0", port=5000, threaded=True)