Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,32 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: unlicense
|
| 3 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: unlicense
|
| 3 |
+
---
|
| 4 |
+
from transformers import pipeline
|
| 5 |
+
import PyPDF2
|
| 6 |
+
|
| 7 |
+
def summarize_pdf(pdf_path):
|
| 8 |
+
"""Summarizes the content of a given PDF file.
|
| 9 |
+
|
| 10 |
+
Args:
|
| 11 |
+
pdf_path: The path to the PDF file to be summarized.
|
| 12 |
+
|
| 13 |
+
Returns:
|
| 14 |
+
A list of dictionaries containing the summary text.
|
| 15 |
+
"""
|
| 16 |
+
|
| 17 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 18 |
+
|
| 19 |
+
with open(pdf_path, 'rb') as pdf_file:
|
| 20 |
+
pdf_reader = PyPDF2.PdfReader(pdf_file)
|
| 21 |
+
text = ""
|
| 22 |
+
for page_num in range(len(pdf_reader.pages)):
|
| 23 |
+
page = pdf_reader.pages[page_num]
|
| 24 |
+
text += page.extract_text()
|
| 25 |
+
|
| 26 |
+
summary = summarizer(text, max_length=130, min_length=30, do_sample=False)
|
| 27 |
+
return summary
|
| 28 |
+
|
| 29 |
+
# Example usage:
|
| 30 |
+
pdf_path = "path/to/your/pdf.pdf" # Replace with the actual PDF file path
|
| 31 |
+
summary = summarize_pdf(pdf_path)
|
| 32 |
+
print(summary)
|