File size: 830 Bytes
6bae696 | 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 | ---
license: unlicense
---
from transformers import pipeline
import PyPDF2
def summarize_pdf(pdf_path):
"""Summarizes the content of a given PDF file.
Args:
pdf_path: The path to the PDF file to be summarized.
Returns:
A list of dictionaries containing the summary text.
"""
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
with open(pdf_path, 'rb') as pdf_file:
pdf_reader = PyPDF2.PdfReader(pdf_file)
text = ""
for page_num in range(len(pdf_reader.pages)):
page = pdf_reader.pages[page_num]
text += page.extract_text()
summary = summarizer(text, max_length=130, min_length=30, do_sample=False)
return summary
# Example usage:
pdf_path = "path/to/your/pdf.pdf" # Replace with the actual PDF file path
summary = summarize_pdf(pdf_path)
print(summary)
|