This repository contains a Python script that extracts text from a PDF file and generates a summarized version of the text using the Hugging Face Transformers library. It leverages the facebook/bart-large-cnn model for text summarization. The script is designed to handle larger PDFs by chunking the text and summarizing each chunk separately.
- Extracts text from PDF files: Uses the
PyPDF2library to extract text content from each page of the PDF. - Summarizes text: Utilizes Hugging Face's
facebook/bart-large-cnnmodel to summarize the extracted text into a concise version. - Handles large PDFs: Breaks large PDFs into smaller chunks to avoid memory issues and to summarize efficiently.
- Customizable parameters: Allows adjustment of chunk size and summary length.
To run the script, you need to have Python installed along with the required dependencies. You can install them using pip:
pip install PyPDF2 transformers textwrapAdditionally, you should have the torch library installed to use Hugging Face models:
pip install torch-
Clone the repository to your local machine:
git clone https://github.com/vg15o2/summarizer.git cd summarizer -
Replace the
file_pathvariable in the script with the path to your PDF file:file_path = r"your_pdf_file_path.pdf" # Replace with your PDF file path
-
Run the script:
python textsummarizer2.py
-
The script will output:
- The first 2000 characters of the extracted text (for preview).
- A summary of the extracted text.
- Chunk Size: You can change the
chunk_sizeparameter in thechunk_and_summarizefunction to adjust the size of each text chunk that is processed. - Summary Length: You can adjust the
max_lengthandmin_lengthin thesummarizerpipeline to control the length of the summary.