Spaces:
Running
Running
Delete tools.py
Browse files
tools.py
DELETED
|
@@ -1,61 +0,0 @@
|
|
| 1 |
-
from smolagents import Tool, DuckDuckGoSearchTool
|
| 2 |
-
from huggingface_hub import list_models
|
| 3 |
-
import random
|
| 4 |
-
|
| 5 |
-
# Export DuckDuckGoSearchTool for use in other modules
|
| 6 |
-
__all__ = ['DuckDuckGoSearchTool', 'WeatherInfoTool', 'HubStatsTool', 'search_tool', 'weather_info_tool', 'hub_stats_tool']
|
| 7 |
-
|
| 8 |
-
# Initialize the DuckDuckGo search tool
|
| 9 |
-
search_tool = DuckDuckGoSearchTool()
|
| 10 |
-
|
| 11 |
-
class WeatherInfoTool(Tool):
|
| 12 |
-
name = "weather_info"
|
| 13 |
-
description = "Fetches dummy weather information for a given location."
|
| 14 |
-
inputs = {
|
| 15 |
-
"location": {
|
| 16 |
-
"type": "string",
|
| 17 |
-
"description": "The location to get weather information for."
|
| 18 |
-
}
|
| 19 |
-
}
|
| 20 |
-
output_type = "string"
|
| 21 |
-
|
| 22 |
-
def forward(self, location: str):
|
| 23 |
-
# Dummy weather data
|
| 24 |
-
weather_conditions = [
|
| 25 |
-
{"condition": "Rainy", "temp_c": 15},
|
| 26 |
-
{"condition": "Clear", "temp_c": 25},
|
| 27 |
-
{"condition": "Windy", "temp_c": 20}
|
| 28 |
-
]
|
| 29 |
-
# Randomly select a weather condition
|
| 30 |
-
data = random.choice(weather_conditions)
|
| 31 |
-
return f"Weather in {location}: {data['condition']}, {data['temp_c']}°C"
|
| 32 |
-
|
| 33 |
-
# Initialize the tool
|
| 34 |
-
weather_info_tool = WeatherInfoTool()
|
| 35 |
-
|
| 36 |
-
class HubStatsTool(Tool):
|
| 37 |
-
name = "hub_stats"
|
| 38 |
-
description = "Fetches the most downloaded model from a specific author on the Hugging Face Hub."
|
| 39 |
-
inputs = {
|
| 40 |
-
"author": {
|
| 41 |
-
"type": "string",
|
| 42 |
-
"description": "The username of the model author/organization to find models from."
|
| 43 |
-
}
|
| 44 |
-
}
|
| 45 |
-
output_type = "string"
|
| 46 |
-
|
| 47 |
-
def forward(self, author: str):
|
| 48 |
-
try:
|
| 49 |
-
# List models from the specified author, sorted by downloads
|
| 50 |
-
models = list(list_models(author=author, sort="downloads", direction=-1, limit=1))
|
| 51 |
-
|
| 52 |
-
if models:
|
| 53 |
-
model = models[0]
|
| 54 |
-
return f"The most downloaded model by {author} is {model.id} with {model.downloads:,} downloads."
|
| 55 |
-
else:
|
| 56 |
-
return f"No models found for author {author}."
|
| 57 |
-
except Exception as e:
|
| 58 |
-
return f"Error fetching models for {author}: {str(e)}"
|
| 59 |
-
|
| 60 |
-
# Initialize the tool
|
| 61 |
-
hub_stats_tool = HubStatsTool()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|