JabrilJacobs commited on
Commit
6c9b377
·
verified ·
1 Parent(s): 0a87477

Update tools.py

Browse files
Files changed (1) hide show
  1. tools.py +12 -23
tools.py CHANGED
@@ -1,28 +1,17 @@
1
  from smolagents import DuckDuckGoSearchTool
2
- from smolagents import Tool
3
  import random
4
  from huggingface_hub import list_models
5
 
6
- class HubStatsTool(Tool):
7
- name = "hub_stats"
8
- description = "Fetches the most downloaded model from a specific author on the Hugging Face Hub."
9
- inputs = {
10
- "author": {
11
- "type": "string",
12
- "description": "The username of the model author/organization to find models from."
13
- }
14
- }
15
- output_type = "string"
16
 
17
- def forward(self, author: str):
18
- try:
19
- # List models from the specified author, sorted by downloads
20
- models = list(list_models(author=author, sort="downloads", direction=-1, limit=1))
21
-
22
- if models:
23
- model = models[0]
24
- return f"The most downloaded model by {author} is {model.id} with {model.downloads:,} downloads."
25
- else:
26
- return f"No models found for author {author}."
27
- except Exception as e:
28
- return f"Error fetching models for {author}: {str(e)}"
 
1
  from smolagents import DuckDuckGoSearchTool
 
2
  import random
3
  from huggingface_hub import list_models
4
 
5
+ def get_hub_stats(author: str) -> str:
6
+ """Fetches the most downloaded model from a specific author on the Hugging Face Hub."""
7
+ try:
8
+ # List models from the specified author, sorted by downloads
9
+ models = list(list_models(author=author, sort="downloads", direction=-1, limit=1))
 
 
 
 
 
10
 
11
+ if models:
12
+ model = models[0]
13
+ return f"The most downloaded model by {author} is {model.id} with {model.downloads:,} downloads."
14
+ else:
15
+ return f"No models found for author {author}."
16
+ except Exception as e:
17
+ return f"Error fetching models for {author}: {str(e)}"