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