Skip to content

A sophisticated yet simple Python tool that goes beyond traditional text summarization by preserving the emotional context of your content. Built as a single, self-contained file for maximum portability and ease of use.

Notifications You must be signed in to change notification settings

swamy18/emotion-aware-summarizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 

Repository files navigation

Emotion-Aware Text Summarizer 🧠✨

Python PyTorch License Code Style PRs Welcome

An intelligent text summarization tool that preserves the emotional tone and sentiment of your original content using state-of-the-art NLP models.

🎯 Overview

The Emotion-Aware Text Summarizer is a sophisticated Python tool that goes beyond traditional summarization by maintaining the emotional context of your text. Built with reliability and simplicity in mind, it leverages powerful transformer models to deliver high-quality, sentiment-preserving summaries.

✨ Key Features

  • 🎭 Emotion Preservation: Analyzes and maintains the original emotional tone (positive, negative, neutral)
  • πŸš€ State-of-the-Art Summarization: Powered by BART-large-CNN for superior text understanding
  • ⚑ GPU Acceleration: Automatic CUDA detection for enhanced performance
  • πŸ“š Hierarchical Processing: Intelligent chunking for long documents with coherent output
  • πŸ”§ Flexible Input: Support for both direct text input and file processing
  • πŸ’» CLI-First Design: Clean command-line interface with comprehensive options
  • 🌍 Multi-Language Ready: Basic support for non-English text (English optimized)

πŸ› οΈ Installation

Prerequisites

  • Python 3.8 or higher
  • pip package manager
  • CUDA-compatible GPU (optional, for acceleration)

Quick Install

# Clone the repository
git clone https://github.com/swamy18/emotion-aware-summarizer.git
cd emotion-aware-summarizer

# Install dependencies
pip install -r requirements.txt

# Or install manually
pip install torch transformers textblob tqdm

Development Setup

# Install with development dependencies
pip install -e ".[dev]"

# Install pre-commit hooks (recommended)
pre-commit install

πŸš€ Quick Start

Basic Usage

# Summarize a file
python summarizer.py --input article.txt --output summary.txt --max-length 150

# Summarize text directly
python summarizer.py --text "Your amazing text here!" --max-length 100

# Quick summary to console
python summarizer.py -i document.txt

Advanced Examples

# Process large document with custom parameters
python summarize.py \
    --input large_document.txt \
    --output summary.txt \
    --max-length 300 \
    --preserve-emotion

# Batch processing (coming soon)
python summarize.py --batch-dir ./documents --output-dir ./summaries

πŸ“– Usage Guide

Command Line Options

Option Short Description Default
--input -i Path to input text file -
--text -t Direct text input (alternative to --input) -
--output -o Output file path (optional) Console output
--max-length -l Maximum words in summary 150

Input Validation

The tool automatically handles various input scenarios:

  • βœ… Empty input detection
  • βœ… Minimum length validation (30 words)
  • βœ… Maximum file size limits (5MB default)
  • βœ… Encoding detection and handling
  • βœ… Format validation

πŸ§ͺ Testing

Manual Testing Examples

# Test edge cases
python summarizer.py --text ""  # Empty input handling
python summarizer.py --text "Short text."  # Minimum length check

# Test large files
python summarizer.py --input large_file.txt  # Size limit validation (5MB max)

# Test non-English content
python summarizer.py --text "La vida es bella y el sol brilla."

# Test emotional content
python summarizer.py --text "This is absolutely terrible and disappointing!" --max-length 30
python summarizer.py --text "I'm so incredibly happy and excited about this!" --max-length 30

Automated Testing

# Run basic functionality test
python -c "
import subprocess
result = subprocess.run(['python', 'summarizer.py', '--text', 'This is a simple test.'], 
                       capture_output=True, text=True)
print('βœ… Basic test passed' if result.returncode == 0 else '❌ Test failed')
"

# Performance test with timing
time python summarizer.py --input large_document.txt --max-length 200

πŸ—οΈ Architecture

Project Structure

emotion-aware-summarizer/
β”œβ”€β”€ summarizer.py           # 🎯 Main application (single file!)
β”œβ”€β”€ requirements.txt        # Python dependencies
β”œβ”€β”€ LICENSE                # MIT License
β”œβ”€β”€ README.md              # This file
└── examples/              # Sample text files for testing
    β”œβ”€β”€ positive_article.txt
    β”œβ”€β”€ negative_review.txt
    └── neutral_news.txt

Note: This is a single-file application - all functionality is contained in summarizer.py for simplicity and ease of deployment!

Model Architecture

  • Summarization: BART-large-CNN (Facebook AI) - State-of-the-art transformer model
  • Sentiment Analysis: TextBlob - Fast, lightweight sentiment detection
  • Text Processing: Intelligent word-based chunking for long documents
  • Hardware: Automatic CPU/GPU detection with CUDA optimization
  • Memory Management: Smart lazy loading and GPU cache cleanup

Key Technical Features

  • Lazy Loading: Models load only when needed, improving startup time
  • Chunked Processing: Handles documents larger than model limits
  • Hierarchical Summarization: Summarizes chunks, then summarizes summaries
  • Emotion-Guided Generation: Uses sentiment-aware prefixes for tone preservation
  • Error Recovery: Graceful handling of model failures and edge cases

⚑ Performance

Document Size Processing Time* Memory Usage**
< 1KB ~0.5s ~200MB
1-10KB ~2-5s ~300MB
10-100KB ~10-30s ~500MB
100KB-1MB ~30-120s ~800MB

* Times measured on RTX 3080, varies by hardware
** Peak memory usage during processing

πŸ”„ Roadmap

Current Features βœ…

  • Single-file implementation for easy deployment
  • Emotion-aware summarization with TextBlob
  • BART-large-CNN integration
  • GPU acceleration with automatic detection
  • Intelligent chunking for long documents
  • File size validation (5MB limit)
  • Comprehensive error handling
  • Progress bars for model loading and processing

Upcoming Enhancements πŸš€

  • Web interface using Flask
  • Batch processing built-in command
  • Configuration file support (YAML/JSON)
  • Additional emotion models (VADER, RoBERTa)
  • Docker containerization
  • Output format options (JSON, XML, HTML)

Future Vision 🌟

  • REST API with FastAPI
  • Multiple summarization models (T5, Pegasus)
  • Custom emotion training capabilities
  • Real-time processing for streaming text
  • Multi-language emotion detection
  • Plugin architecture for custom models

🀝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Workflow

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Add tests for new functionality
  5. Ensure all tests pass (pytest)
  6. Commit your changes (git commit -m 'Add amazing feature')
  7. Push to the branch (git push origin feature/amazing-feature)
  8. Open a Pull Request

Code Style

We use Black for code formatting and isort for import sorting.

# Format code
black summarizer/
isort summarizer/

# Check linting
flake8 summarizer/

πŸ› Known Issues & Limitations

  • Emotion Detection: TextBlob may miss nuanced emotions like sarcasm
  • Language Support: Optimized for English; other languages may have reduced accuracy
  • Memory Usage: Large documents (>1MB) require significant RAM
  • Processing Time: Very long texts may take considerable time on CPU-only systems

πŸ“š Examples & Tutorials

Example 1: News Article Summarization

# For integration into other Python projects
import subprocess
import json

def summarize_with_emotion(text, max_length=150):
    """Helper function to use the summarizer in other Python code."""
    result = subprocess.run([
        'python', 'summarizer.py', 
        '--text', text, 
        '--max-length', str(max_length)
    ], capture_output=True, text=True)
    
    if result.returncode == 0:
        return result.stdout
    else:
        raise Exception(f"Summarization failed: {result.stderr}")

# Example usage
news_text = """
The latest breakthrough in artificial intelligence has researchers excited about the potential 
applications. Scientists have developed a new model that can understand context better than 
ever before, leading to more accurate and helpful AI assistants...
"""

summary = summarize_with_emotion(news_text, max_length=100)
print(summary)

Example 2: Batch Processing Script

import os
import subprocess
from pathlib import Path

def process_directory(input_dir, output_dir, max_length=150):
    """Process all .txt files in a directory."""
    input_path = Path(input_dir)
    output_path = Path(output_dir)
    output_path.mkdir(exist_ok=True)
    
    for txt_file in input_path.glob("*.txt"):
        output_file = output_path / f"{txt_file.stem}_summary.txt"
        
        subprocess.run([
            'python', 'summarizer.py',
            '--input', str(txt_file),
            '--output', str(output_file),
            '--max-length', str(max_length)
        ])
        
        print(f"βœ… Processed: {txt_file.name}")

# Usage
process_directory("./articles", "./summaries")

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

πŸ“ž Support


Made by [Swami Gadila]

If this project helped you, please consider giving it a ⭐!

About

A sophisticated yet simple Python tool that goes beyond traditional text summarization by preserving the emotional context of your content. Built as a single, self-contained file for maximum portability and ease of use.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages