Spaces:
Runtime error
Runtime error
File size: 1,036 Bytes
1d96b34 | 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 28 29 30 31 32 33 34 35 | # modules/summarizer.py
from transformers import pipeline
from config.settings import SUMMARIZER_MODEL
# Load summarization pipeline
summarizer_pipeline = pipeline("summarization", model=SUMMARIZER_MODEL)
def summarize_texts(texts: list, max_length: int = 60, min_length: int = 20) -> list:
"""
Generate summaries for a list of texts.
Returns a list of dictionaries with original text and summary.
"""
results = []
for t in texts:
if t.strip():
try:
summary = summarizer_pipeline(
t,
max_length=max_length,
min_length=min_length,
do_sample=False
)[0]["summary_text"]
results.append({
"text": t,
"summary": summary
})
except Exception as e:
results.append({
"text": t,
"summary": f"ERROR: {str(e)}"
})
return results
|