1 file was added to this release more than 14 days after its initial publication. Inspect the release files before installing.
# AiSummary
AiSummary is a lightweight Python library for text summarization, developed by **Mohammad Taha Gorji**. It provides two main summarization methods:
- **FastSummarizer**: A quick, frequency-based summarizer for English and Persian texts.
- **DeepSummarizer**: A deep-learning–based summarizer using BART (for English) and mT5 (for Persian), with automatic language detection and optional translation for other languages.
## PyPI
You can install the package from PyPI:
[AiSummary on PyPI](https://pypi.org/project/AiSummary)
---
## Features
- **FastSummarizer**
- Language-aware (detects English vs. Persian based on character heuristics).
- Ranks sentences by frequency score and selects top sentences.
- Iteratively shortens the summary until it fits under a maximum token/character limit.
- **DeepSummarizer**
- Detects input language (English, Persian, or others via `langdetect`).
- For English: uses a two-stage BART-based summarization (chunking + beam search).
- For Persian: uses a two-stage mT5-based summarization (hazm normalization + token chunking).
- For other languages: translates to English, summarizes, then translates back.
- Heavy models are loaded only on first invocation (lazy loading).
- Supports GPU (CUDA) if available.
- **Logging Control**
- Call `enable_logging(True)` or `enable_logging(False)` to toggle INFO-level logs.
---
## Installation
```bash
pip install AiSummary
Requirements
The essential dependencies (in install_requires) are:
torch>=1.10.0
transformers>=4.0.0
langdetect>=1.0.9
googletrans>=4.0.0-rc1
spacy>=3.0.0
hazm>=0.7.0
sentencepiece>=0.1.95
If you plan to use DeepSummarizer, make sure you have a compatible version of PyTorch and CUDA (if you intend to use GPU acceleration). For FastSummarizer, spaCy will automatically download the English model (en_core_web_sm) on first use if it is not already installed.
Usage
Below is a minimal example demonstrating how to use both summarizers.
from AiSummary import FastSummarizer, DeepSummarizer, enable_logging
text = '''This Text ! A long text'''
# Enable INFO-level logging (optional)
enable_logging(True)
# Fast summarization
fast_summary = FastSummarizer(text)
print("Fast summary:", fast_summary)
# Deep summarization
deep_summary = DeepSummarizer(text)
print("Deep summary:", deep_summary)
Examples
-
English text
from AiSummary import FastSummarizer, DeepSummarizer, enable_logging enable_logging(True) text_en = """ Artificial intelligence (AI) refers to the simulation of human intelligence in machines that are programmed to think like humans and mimic their actions. The term may also be applied to any machine that exhibits traits associated with a human mind such as learning and problem-solving. """ fast_summary_en = FastSummarizer(text_en, percentage=0.3) print("Fast summary (EN):", fast_summary_en) deep_summary_en = DeepSummarizer(text_en) print("Deep summary (EN):", deep_summary_en)
-
Persian text
from AiSummary import FastSummarizer, DeepSummarizer, enable_logging enable_logging(True) text_fa = """ هوش مصنوعی به شبیهسازی هوش انسان در ماشینها اشاره دارد که برای تفکر مانند انسان و تقلید از عملکردهای او برنامهریزی شدهاند. این اصطلاح ممکن است برای هر ماشینی که صفاتی مرتبط با ذهن انسان مانند یادگیری و حل مسئله را نشان میدهد نیز به کار رود. """ fast_summary_fa = FastSummarizer(text_fa, percentage=0.3) print("Fast summary (FA):", fast_summary_fa) deep_summary_fa = DeepSummarizer(text_fa) print("Deep summary (FA):", deep_summary_fa)
-
Other language (e.g., Spanish)
from AiSummary import FastSummarizer, DeepSummarizer, enable_logging enable_logging(True) text_es = """ La inteligencia artificial (IA) se refiere a la simulación de la inteligencia humana en máquinas programadas para pensar como humanos y emular sus acciones. El término también puede aplicarse a cualquier máquina que exhiba rasgos asociados con la mente humana, como el aprendizaje y la resolución de problemas. """ # FastSummarizer will treat it as English or Persian depending on character heuristics, # so for non-Latin scripts it may translate under the hood if detected as neither. fast_summary_es = FastSummarizer(text_es, percentage=0.3) print("Fast summary (ES):", fast_summary_es) deep_summary_es = DeepSummarizer(text_es) print("Deep summary (ES):", deep_summary_es)
Configuration
-
Logging By default, logging is set to WARNING level (no INFO logs). To see detailed INFO logs (e.g., model-loading steps, language detection), call:
from AiSummary import enable_logging enable_logging(True)
-
DeepSummarizer Parameters
DeepSummarizer(text: str, min1: int = 40, max1: int = 150, min2: int = 60, max2: int = 200) -> str
min1,max1: Minimum/maximum length (in tokens) for the first stage of summarization.min2,max2: Minimum/maximum length (in tokens) for the second (final) stage.
-
FastSummarizer Parameters
FastSummarizer(text: str, percentage: float = 0.2, max_tokens: int = 4000) -> str
percentage: Fraction of sentences (or scored segments) to include in the summary.max_tokens: Maximum length of the returned summary (in characters).
Project Structure
AiSummary/
├── summarizer.py # Core implementation (FastSummarizer, DeepSummarizer, logger)
├── README.md # This file
├── setup.py # Package metadata and dependencies
└── LICENSE # (Optional) License file if any
summarizer.py: Contains all the functions and lazy-loading logic.setup.py: Points toinstall_requires(PyPI dependencies) and metadata like author, version, etc.README.md: Documentation and examples.
License
This project is currently provided without a specific license. If you plan to use it in other projects, please contact Mohammad Taha Gorji for licensing details.
Metadata
Release files for AiSummary 1.0.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
File added late
1 file was uploaded more than 14 days after the first file in this release.
While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.
We recommend inspecting the release files before installing.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| AiSummary-1.0.8.tar.gz | 7.6 kB | Without provenance | Details |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aisummary-1.0.8-py3-none-any.whl | Python 3 | none | any | Details |
| AiSummary-1.0.8-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.2 kB
Release files / AiSummary-1.0.8.tar.gz
| Download URL | AiSummary-1.0.8.tar.gz |
|---|---|
| Size | 7.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9836f4759ee6e2364a2e85178ac37532a7991e33a95f77f9fe5833a4d228125b
|
|
BLAKE2b-256 checksum How to use checksums |
2f575ab9dc3045aea21b00daf22abec47852bfe1fe000b4096d257e0f0ad4aff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.1
|
Release files / aisummary-1.0.8-py3-none-any.whl
File added late
This file was uploaded more than 14 days after the first file in this release.
While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.
We recommend inspecting the release file before installing.
| Download URL | aisummary-1.0.8-py3-none-any.whl |
|---|---|
| Size | 2.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a9f7daccaeab675c923f609107560440e0ce822444453e6246509df68c429f9a
|
|
BLAKE2b-256 checksum How to use checksums |
3d21c877543795bb2695937c5c8b2cd680350b2a27fd46e4db93cf942f8012c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.9
|
Release files / AiSummary-1.0.8-py3-none-any.whl
| Download URL | AiSummary-1.0.8-py3-none-any.whl |
|---|---|
| Size | 7.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
957bef7dbe1a697ff0f035924ee749c72f664f340db873ae1c46f62153628d9e
|
|
BLAKE2b-256 checksum How to use checksums |
e72af7a69d4fcee76e91cb4b3877cf4cc3e377fb863bdf1ae84ecf610c356817
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.1
|
Security for AiSummary 1.0.8
Upload timing
File added late
1 file was uploaded more than 14 days after the first file in this release.
While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.