-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
124 lines (107 loc) · 3.94 KB
/
Copy pathapp.py
File metadata and controls
124 lines (107 loc) · 3.94 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
from urllib.request import urlopen
from flask import Flask, app,render_template,request
import os
from bert import bert
from bs4 import BeautifulSoup
from sumy_sum import sumy_summarization
from sq2sq import sq2sq
from werkzeug.utils import secure_filename
from werkzeug.datastructures import FileStorage
from PyPDF2 import PdfFileReader,PdfFileWriter
#from rogoue_score import score_sum
# from pandas.compat import StringIO
app = Flask(__name__, static_url_path="", static_folder="static")
#app.config['UPLOAD_FOLDER']= 'C:/Users/abhim/Documents/Python/sum_new/static/'
UPLOAD_FOLDER = os.path.dirname(os.path.abspath(__file__)) +'/uploads/'
# DOWNLOAD_FOLDER = os.path.dirname(os.path.abspath(__file__))
# app.config['DOWNLOAD_FOLDER'] = DOWNLOAD_FOLDER
@app.route('/', methods=['GET', 'POST'])
def fun():
summary=''
if request.method=='POST':
word = request.form['word']
word=int(word)
text = request.form['text']
summary=bert(text,word)
print(summary)
return render_template('index.html',summary=summary)
else:
return render_template('index.html')
@app.route('/link', methods=['GET', 'POST'])
def link():
summary=''
if request.method=='POST':
url = request.form['link']
word=request.form['word']
word=int(word)
page = urlopen(url)
soup = BeautifulSoup(page)
fetched_text = ' '.join(map(lambda p:p.text,soup.find_all('p')))
#max_value = sent_tokenize(fetched_text)
summary = bert(fetched_text, word)
return render_template('link.html',summary=summary)
@app.route('/pdf', methods=['GET', 'POST'])
def pdf():
summary=''
if request.method=='POST':
word = request.form['word']
word=int(word)
#file_pdf = request.files['file']
f = request.files['file']
filename=secure_filename(f.filename)
f.save(os.path.join(UPLOAD_FOLDER,filename))
pdffileobj=open(os.path.join(UPLOAD_FOLDER,filename),'rb')
pdfreader=PdfFileReader(pdffileobj)
x=pdfreader.numPages
text=''
count=0
while (count < 5 and count < x):
pageobj=pdfreader.getPage(count)
text= text + pageobj.extractText()
count+=1
print(text,count)
pdffileobj.close()
print(text)
#print(type(file_pdf))
#print(file_pdf.read())
# rsrcmgr = PDFResourceManager()
# sio = StringIO()
# codec = 'utf-8'
# laparams = LAParams()
# device = TextConverter(rsrcmgr, sio, laparams=laparams)
# interpreter = PDFPageInterpreter(rsrcmgr, device)
# # Extract text
# fp = open("C:/Users/abhim/Documents/Python/sum_new/static/"+ f.filename, 'rb')
# for page in PDFPage.get_pages(fp):
# interpreter.process_page(page)
# fp.close()
# # Get text from StringIO
# text = sio.getvalue()
summary=bert(text,word)
print(summary)
return render_template('pdf.html',summary=summary)
@app.route('/compare', methods=['GET', 'POST'])
def fu3():
summary=''
sumy_summary=''
spacy_summary=''
# score_bert=''
# score_spacy=''
# score_sumy=''
if request.method=='POST':
word = request.form['word']
word=int(word)
text = request.form['text']
summary=bert(text,word)
spacy_summary=sq2sq(text,word)
sumy_summary=sumy_summarization(text,word)
print(summary)
# score_bert=score_sum(text,summary)
# score_spacy=score_sum(text,spacy_summary)
# score_sumy=score_sum(text,spacy_summary)
return render_template('compare.html',summary=summary,sumy_summary=sumy_summary,spacy_summary=spacy_summary)
else:
return render_template('compare.html',summary=summary,sumy_summary=sumy_summary,spacy_summary=spacy_summary)
port = int(os.environ.get('PORT', 5000))
if __name__ == "__main__":
app.run(debug=True, port=port)