A simple, beginner-friendly command-line tool that summarizes text files by extracting the most important sentences. This tool helps you quickly understand the main points of large text documents without reading the entire content.
- Easy to Use: Simple command-line interface with clear instructions
- Customizable: Choose how many sentences you want in your summary
- Smart Extraction: Automatically identifies and extracts key sentences
- Error Handling: Gracefully handles missing files, empty files, and permission errors
- Clean Output: Displays summary with statistics (original length, summary length, reduction percentage)
- No Dependencies: Uses only Python standard library - no external packages required!
- Python 3.6 or higher
- Clone or download this repository
- Navigate to the
AI Text Summarizerfolder - No additional packages to install!
Summarize a text file with default settings (3 sentences):
python main.py yourfile.txtSpecify how many sentences you want in the summary:
python main.py yourfile.txt --sentences 5Or use the short form:
python main.py yourfile.txt -s 2# Summarize an article with 3 sentences
python main.py article.txt
# Summarize a story with 5 sentences
python main.py story.txt --sentences 5
# Quick summary with just 1 sentence
python main.py document.txt -s 1- File Reading: The tool reads your text file using UTF-8 encoding
- Text Processing: Removes extra whitespace and normalizes the text
- Sentence Extraction: Intelligently splits the text into sentences using punctuation marks (., !, ?)
- Summary Generation: Selects the first N sentences based on your preference
- Output Display: Shows the summary with helpful statistics
======================================================================
TEXT SUMMARY
======================================================================
This is the first sentence of the document. This is the second
sentence with important information. Here is the third sentence
that concludes the main idea.
----------------------------------------------------------------------
Original length: 1247 characters
Summary length: 156 characters
Reduction: 87.5%
======================================================================
The tool handles common errors gracefully:
- File not found: Clear message indicating the file doesn't exist
- Empty file: Informs you when the file is empty or contains only whitespace
- Permission denied: Alerts you if the file can't be read due to permissions
- Invalid arguments: Validates that the number of sentences is at least 1
Create a test file to try the summarizer:
echo "Python is a high-level programming language. It is known for its simplicity and readability. Python is widely used in web development, data science, and automation. The language was created by Guido van Rossum in 1991. Today, Python is one of the most popular programming languages in the world." > test.txt
python main.py test.txtPotential improvements for future versions:
- AI-powered summarization using NLP techniques
- Support for multiple file formats (PDF, DOCX, etc.)
- Keyword extraction
- Summary quality scoring
- Export summary to file
Feel free to fork this project and submit pull requests for any improvements!
This project is open source and available for educational purposes.
Created by Dimas D. Angga as a contribution to the Python-Scripts repository.