Spaces:
Runtime error
Runtime error
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" | |
) | |
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'] |