File size: 447 Bytes
7507a36
524f780
dbc2790
e116825
0116c46
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
from transformers import pipeline

summarizer = pipeline("summarization", model="t5-base")

text = "This is a long text that needs summarization."

# Dynamically adjust max_length based on input length
input_length = len(text.split())  # Approximate token count
max_length = min(50, int(input_length * 0.8))  # 80% of input length

summary = summarizer(text, max_length=max_length, min_length=5, do_sample=False)
print(summary[0]["summary_text"])