"""
Text Summarizer
Generated by Eden via recursive self-improvement
2025-10-28 09:38:03.332328
"""

from transformers import pipeline

class TextSummarizer:
    """
    A class for generating summaries of text content using a pre-trained model.
    
    Methods:
        __init__(): Initializes the summarizer with a specified model.
        summarize(text: str, max_length: int = 100) -> str:
            Generates a summary from the given text.
            
    Example usage:
        summarizer = TextSummarizer()
        summary = summarizer.summarize("Your input text here.")
    """

    def __init__(self):
        self.summarizer = pipeline(
            "summarization",
            model="facebook/bart-large-cnn",
            device=0 if torch.cuda.is_available() else -1
        )

    def summarize(self, text: str, max_length: int = 100) -> str:
        """
        Generates a summary of the input text.
        
        Args:
            text (str): The text to be summarized.
            max_length (int, optional): Maximum length of the summary in tokens. Defaults to 100.
            
        Returns:
            str: The generated summary.
            
        Raises:
            ValueError: If the input text is empty or too long for summarization.
        """
        if not text.strip():
            raise ValueError("Input text cannot be empty.")
        
        try:
            summary = self.summarizer(text, max_length=max_length)
            return summary[0]['summary_text']
        except Exception as e:
            raise RuntimeError(f"Summarization failed: {str(e)}")

# Example usage
if __name__ == "__main__":
    # Initialize the summarizer
    summarizer = TextSummarizer()
    
    # Single text summarization
    input_text_single = "The European Union is a political and economic union of 27 European countries. It was established by the Maastricht Treaty in 1993."
    print("Single text summary:")
    print(summarizer.summarize(input_text_single))
    
    # Batch summarization example (though current implementation handles single texts)
    input_texts = [
        "The quick brown fox jumps over the lazy dog. This pangram contains every letter of the English alphabet at least once.",
        "Python is a versatile programming language that supports multiple programming paradigms, including functional and object-oriented programming."
    ]
    
    print("\nBatch summarization (each text will be summarized individually):")
    for text in input_texts:
        print(f"\nOriginal text: {text[:50]}...")
        try:
            summary = summarizer.summarize(text)
            print(f"Summary: {summary}")
        except Exception as e:
            print(f"Error summarizing text: {str(e)}")