File size: 845 Bytes
3e56582
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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")