Spaces:
Runtime error
Runtime error
Update tools/summarizer.py
Browse files- tools/summarizer.py +13 -15
tools/summarizer.py
CHANGED
|
@@ -1,21 +1,19 @@
|
|
| 1 |
from smolagents import tool
|
| 2 |
-
from transformers import pipeline
|
| 3 |
-
|
| 4 |
-
# load once globally (uses a small summarization model from Hugging Face)
|
| 5 |
-
summarizer_pipeline = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 6 |
|
| 7 |
@tool
|
| 8 |
def summarizer(text: str, max_length: int = 100, min_length: int = 30) -> str:
|
| 9 |
-
"""Summarize a long piece of text into a shorter version.
|
| 10 |
Args:
|
| 11 |
-
text: The text
|
| 12 |
-
max_length: Maximum length of the summary.
|
| 13 |
-
min_length: Minimum length of the summary.
|
| 14 |
"""
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
| 1 |
from smolagents import tool
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
@tool
|
| 4 |
def summarizer(text: str, max_length: int = 100, min_length: int = 30) -> str:
|
| 5 |
+
"""Summarize a long piece of text into a shorter version using the agent's own LLM.
|
| 6 |
Args:
|
| 7 |
+
text: The text to be summarized.
|
| 8 |
+
max_length: Maximum length of the summary (approximate).
|
| 9 |
+
min_length: Minimum length of the summary (approximate).
|
| 10 |
"""
|
| 11 |
+
# Here we don’t call transformers — just ask the model to summarize
|
| 12 |
+
prompt = (
|
| 13 |
+
f"Summarize the following text into a clear and concise version:\n\n"
|
| 14 |
+
f"{text}\n\n"
|
| 15 |
+
f"Constraints: summary should be between {min_length} and {max_length} words."
|
| 16 |
+
)
|
| 17 |
+
# The agent will handle this prompt automatically
|
| 18 |
+
return prompt
|
| 19 |
+
|