Scaper_search / summarizer.py
gaur3009's picture
Update summarizer.py
7474f2b verified
raw
history blame contribute delete
653 Bytes
from transformers import pipeline
from functools import lru_cache
# Load CPU-friendly summarization model
summarizer = pipeline(
"summarization",
model="sshleifer/distilbart-cnn-12-6",
framework="pt"
)
@lru_cache(maxsize=200)
def summarize_text(text, max_length=100):
"""Efficient summarization with caching"""
if not text or len(text) < 100:
return text
# Truncate to model capacity
truncated = text[:1024]
return summarizer(
truncated,
max_length=max_length,
min_length=30,
do_sample=False, # Faster without sampling
truncation=True
)[0]['summary_text']