license:unlicense region:us
---
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)
