Repository navigation
Expand file tree
/
Copy pathapp.py
More file actions
90 lines (57 loc) · 2.04 KB
/
Copy pathapp.py
File metadata and controls
90 lines (57 loc) · 2.04 KB
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
#!/usr/bin/env python
# coding: utf-8
# In[ ]:
from flask import Flask
from flask import request
from flask import render_template
import numpy as np
from matplotlib import pyplot as plt
import os
import spacy
from spacy.lang.en.stop_words import STOP_WORDS
from string import punctuation
import en_core_web_sm
app = Flask(__name__)
@app.route('/')
def my_form():
return render_template("index.html")
@app.route('/', methods=['GET','POST'])
def my_form_post():
data = request.form['message']
print(data)
stopwords = list(STOP_WORDS)
doc1=data
nlp = en_core_web_sm.load()
docx = nlp(doc1)
mytokens = [token.text for token in docx]
word_freq={}
for word in docx:
if word.text not in stopwords:
if word.text not in word_freq.keys():
word_freq[word.text]=1;
else:
word_freq[word.text]+=1;
max_freq=max(word_freq.values())
for word in word_freq:
word_freq[word]=(word_freq[word]/max_freq)
sentence_list = [ sentence for sentence in docx.sents]
[w.text.lower() for t in sentence_list for w in t ]
sentence_scores={}
for sentence in sentence_list:
for word in sentence:
if word.text in word_freq.keys():
if len(sentence.text.split(' ')) < 30:
if sentence not in sentence_scores.keys():
sentence_scores[sentence] = word_freq[word.text]
else:
sentence_scores[sentence] += word_freq[word.text]
from heapq import nlargest
sum_sentences = nlargest(8, sentence_scores, key=sentence_scores.get)
final_sentences = [ w.text for w in sum_sentences ]
summary = ' '.join(final_sentences)
print(len(doc1))
print(len(summary))
return render_template('output.html', message = summary)
if __name__ == '__main__':
app.run()
# In[ ]: