Spaces:
Runtime error
Runtime error
| # 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 | |