import torch from transformers import pipeline MODEL_NAME = "sshleifer/distilbart-cnn-12-6" device = 0 if torch.cuda.is_available() else -1 summarizer = pipeline( "summarization", model=MODEL_NAME, device=device ) texts = [ ( "Artificial intelligence is transforming education by enabling personalized learning. " "Teachers can use AI-driven tools to understand student progress and tailor activities." ), ( "The James Webb Space Telescope has captured stunning new images of distant galaxies, " "providing insights into the early universe and the formation of cosmic structures." ) ] for text in texts: summary = summarizer(text, max_length=120, min_length=40, do_sample=False) print(f"Original: {text}\nSummary: {summary[0]['summary_text']}\n")