-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsummarize_file.py
33 lines (29 loc) · 1.06 KB
/
summarize_file.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
import pdfplumber
import summarizer
def summary_file(filename, dictfile):
print('opening filename in summarizing',filename)
if filename.lower().endswith('.txt'):
print('opening text file txt')
try:
with open(filename, 'rt', encoding="utf8") as f:
print('reading file')
text = f.read()
except Exception as e:
print('Terjadi kesalahan dalam membuka file : ',e)
else:
print('nggak mau wkwkwkwkwk')
elif(filename.lower().endswith('.pdf')):
print('pdf',filename)
with pdfplumber.open(filename) as pdf:
total_pages = len(pdf.pages)
text = ''
for page in range(total_pages):
print('extracting pdf page ',page)
loaded_page = pdf.pages[page]
text +=loaded_page.extract_text()
with open(dictfile, 'rt') as f:
dictionary = f.read()
print('SEKARANG BUAT SUMMARY')
summary = summarizer.summarize(text, dictionary)
print('summary',summary)
return summary