generated from Micky373/readme-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
90 lines (54 loc) · 2.55 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from flask import Flask, render_template,request,url_for
from flask_bootstrap import Bootstrap
# NLP Packages
from textblob import TextBlob,Word
import random
import time
app = Flask(__name__)
# Using bootstrap to initialize all the stylings
Bootstrap(app)
# This will be our home page and it will call the index.html file
@app.route('/')
def index():
return render_template('index.html')
# This is the route we call to perform our analysis and showing the result
@app.route('/analyse',methods=['POST'])
def analyse():
# Initializing time to check how much time was elapsed
start = time.time()
# Initializing the summary words to an empty string
summary = ''
if request.method == 'POST':
# Recieving the text from the front end
rawtext = request.form['rawtext']
#NLP using TextBlob
blob = TextBlob(rawtext)
received_text2 = blob
'''
Finding out the sentiment and subjectivity of the text.
Subjectivity (ranges from 0 to 1) : 0 is objective 1 is subjective
Sentiment (ranges from -1 to 1): -1 is very negative, 0 is neutral and 1 is positive sentiment
'''
blob_sentiment,blob_subjectivity = blob.sentiment.polarity ,blob.sentiment.subjectivity
# Finding out the number of words without punctuation and white spaces
number_of_tokens = len(list(blob.words))
# Extracting the main points by finding the nouns from the text
nouns = list()
for word, tag in blob.tags:
if tag == 'NN':
'''
Lemmatize method in TextBlob is used to find the rootword given a single word.
Example: Word('radii').lemmatize() will return 'radius'
Word('went').lemmatize() will return 'go'
'''
nouns.append(word.lemmatize())
rand_words = random.sample(nouns,len(nouns))
final_word = list()
for item in rand_words:
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)