|
Download README.md from TmbAI/PDF-Summarizer: direct link, hf CLI and curl.
- Browser
- Download file 830 Bytes
-
https://huggingface.co/TmbAI/PDF-Summarizer/resolve/main/README.md
- Command line
-
hf download hf://TmbAI/PDF-Summarizer/README.md
-
curl -L -o README.md https://huggingface.co/TmbAI/PDF-Summarizer/resolve/main/README.md
830 Bytes
| 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) | |