A Python project demonstrating text summarization using Hugging Face Transformers and LangChain.
This project leverages the facebook/bart-large-cnn model for summarization, with support for Apple Silicon (MPS) acceleration on macOS.
This project demonstrates how to:
- Set up a Python environment
- Install dependencies
- Run a transformer-based summarization model (
facebook/bart-large-cnn)
It supports Apple Silicon (M1/M2) acceleration via MPS (Metal Performance Shaders) with CPU fallback.
- Python: 3.11 or 3.12 (
⚠️ Python 3.13 may have compatibility issues) - Git: For cloning and managing the repository
- PyCharm (optional): Recommended IDE
- macOS: Instructions tailored for Apple Silicon (M1/M2)
# Create virtual environment with Python 3.11
python3.11 -m venv .venv
# Activate the environment
source .venv/bin/activate
# If Python 3.11 is not installed
brew install python@3.11# Install dependencies from requirements file
pip install -r Requirements.txtRequirements.txt includes:
torch>=2.0.0
transformers>=4.45.2
huggingface_hub>=0.34.4
If outdated, install manually:
pip install torch transformers huggingface_hubFor Apple Silicon:
pip install torch torchvision torchaudioPyTorch on M1/M2 automatically uses MPS if available, falling back to CPU. No CUDA is required on macOS.
Check PyTorch installation:
python -c "import torch; print(torch.__version__)"import torch
print(f"MPS Available: {torch.backends.mps.is_available()}")
print(f"Device: {'mps' if torch.backends.mps.is_available() else 'cpu'}")✅ Expected output on M1/M2:
MPS Available: True
Device: mps
python Main.pyInput text (sample article):
The quick brown fox jumps over the lazy dog. The fox was fast and agile...
Output (summarized):
A fox quickly jumps over a lazy dog, showing agility and speed.
- Main.py – Summarization script using
facebook/bart-large-cnn - Requirements.txt – Project dependencies
- .gitignore – Ignores
.venv/,.DS_Store,.idea/, etc. - HFT.txt – Optional project notes (can be removed)
- README.md – Documentation
- MPS not available? → Update PyTorch and macOS, or fallback to CPU.
- Python version issues? → Use Python 3.11.
- Dependencies conflict? → Recreate virtual environment and reinstall.
Contributions are welcome! Fork this repo, make your changes, and open a pull request.
MIT License
Copyright (c) 2025 Somesh diwan
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.