Spaces:
Sleeping
Sleeping
Download tools/summarize_topic.py from Justchidi/smolagent_practice: direct link, hf CLI and curl.
- Browser
- Download file 914 Bytes
-
https://huggingface.co/spaces/Justchidi/smolagent_practice/resolve/main/tools/summarize_topic.py
- Command line
-
hf download hf://spaces/Justchidi/smolagent_practice/tools/summarize_topic.py
-
curl -L -o summarize_topic.py https://huggingface.co/spaces/Justchidi/smolagent_practice/resolve/main/tools/summarize_topic.py
914 Bytes
| from smolagents import Tool | |
| from typing import Any, Optional | |
| class SimpleTool(Tool): | |
| name = "summarize_topic" | |
| description = "This agent uses a web search tool to getch search results for the provided topic and the summarizes them and\nreturns the summary" | |
| inputs = {"topic":{"type":"string","description":"The topic to provide summary for"}} | |
| output_type = "string" | |
| def forward(self, topic: str) -> str: | |
| """ | |
| This agent uses a web search tool to getch search results for the provided topic and the summarizes them and | |
| returns the summary | |
| Args: | |
| topic: The topic to provide summary for | |
| """ | |
| from transformers import pipeline | |
| summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6") | |
| summary = summarizer(topic, max_length=100, min_length=30, do_sample=False) | |
| return summary[0]['summary_text'] |