bexgboost commited on
Commit
b795523
·
verified ·
1 Parent(s): 61ea094

Upload tool

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