/
SlavikPuz
/
Lab7
Обзор
Документация
Войти
/
SlavikPuz
/
Lab7
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
app/summarizer.py
33 строки
792 B
Андрей Афанасьев
fix whitespace
02 июн 2026, 18:49
02 июн 2026, 18:49
7ad2db4
Код
Авторство
О чём код?
from transformers import pipeline MODEL_NAME = "sshleifer/distilbart-cnn-12-6" def get_summarizer(): """Create and return Hugging Face summarization pipeline.""" return pipeline("summarization", model=MODEL_NAME) def summarize_text( text: str, max_length: int = 60, min_length: int = 15, ) -> str: """Summarize input text using Hugging Face model.""" if not isinstance(text, str): raise TypeError("Input text must be a string.") if not text.strip(): raise ValueError("Input text cannot be empty.") summarizer = get_summarizer() result = summarizer( text, max_length=max_length, min_length=min_length, do_sample=False, ) return result[0]["summary_text"]