forked from Ayushverma135/SentixAnalyzer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
54 lines (42 loc) · 1.44 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
43
44
45
46
47
48
49
50
51
52
53
54
from flask import Flask, render_template,request,url_for
from flask_bootstrap import Bootstrap
import nltk
nltk.download()
from nltk.corpus import brown
# brown.words()
# NLP Packages
from textblob import TextBlob,Word
import random
import time
app = Flask(__name__)
Bootstrap(app)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/analyse',methods=['POST'])
def analyse():
start = time.time()
if request.method == 'POST':
rawtext = request.form['rawtext']
#NLP Stuff
blob = TextBlob(rawtext)
received_text2 = blob
blob_sentiment,blob_subjectivity = blob.sentiment.polarity ,blob.sentiment.subjectivity
number_of_tokens = len(list(blob.words))
# Extracting Main Points
nouns = list()
for word, tag in blob.tags:
if tag == 'NN':
nouns.append(word.lemmatize())
len_of_words = len(nouns)
rand_words = random.sample(nouns,len(nouns))
final_word = list()
for item in rand_words:
word = Word(item).pluralize()
final_word.append(word)
summary = final_word
end = time.time()
final_time = end-start
return render_template('index.html',received_text = received_text2,number_of_tokens=number_of_tokens,blob_sentiment=blob_sentiment,blob_subjectivity=blob_subjectivity,summary=summary,final_time=final_time)
if __name__ == '__main__':
app.run(debug=True)