MoritzLaurer HF staff commited on
Commit
1d50778
·
verified ·
1 Parent(s): 7e672cc

Upload tool

Browse files
Files changed (3) hide show
  1. app.py +7 -0
  2. requirements.txt +2 -0
  3. tool.py +21 -0
app.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ from smolagents import launch_gradio_demo
2
+ from typing import Optional
3
+ from tool import HFModelDownloadsTool
4
+
5
+ tool = HFModelDownloadsTool()
6
+
7
+ launch_gradio_demo(tool)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ huggingface_hub
2
+ smolagents
tool.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from smolagents.tools import Tool
2
+ import huggingface_hub
3
+
4
+ class HFModelDownloadsTool(Tool):
5
+ name = "model_download_counter"
6
+ description = """
7
+ This is a tool that returns the most downloaded model of a given task on the Hugging Face Hub.
8
+ It returns the name of the checkpoint."""
9
+ inputs = {'task': {'type': 'string', 'description': 'the task category (such as text-classification, depth-estimation, etc)'}}
10
+ output_type = "string"
11
+
12
+ def forward(self, task: str):
13
+ from huggingface_hub import list_models
14
+
15
+ model = next(iter(list_models(filter=task, sort="downloads", direction=-1)))
16
+ return model.id
17
+
18
+
19
+ def __init__(self, *args, **kwargs):
20
+ self.is_initialized = False
21
+