-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathapp.py
42 lines (30 loc) · 1.28 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
39
40
41
42
from flask import Flask, request, render_template
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import cosine_similarity
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
import nltk
from string import punctuation
import re
from nltk.corpus import stopwords
nltk.download('stopwords')
set(stopwords.words('english'))
app = Flask(__name__)
@app.route('/')
def my_form():
return render_template('form.html')
@app.route('/', methods=['POST'])
def my_form_post():
stop_words = stopwords.words('english')
#convert to lowercase
text1 = request.form['text1'].lower()
text_final = ''.join(c for c in text1 if not c.isdigit())
#remove punctuations
#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])
sa = SentimentIntensityAnalyzer()
dd = sa.polarity_scores(text=processed_doc1)
compound = round((1 + dd['compound'])/2, 2)
return render_template('form.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="127.0.0.1", port=5002, threaded=True)