HongBenXian commited on
Commit
de83125
·
verified ·
1 Parent(s): c05a433

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
+ 这是一个工具,它会在Hugging Face Hub上返回特定任务的下载量最高的模型。
9
+ 它返回的是检查点的名称。"""
10
+ inputs = {'task': {'type': 'string', 'description': '任务类别(如文本分类、深度估计等)'}}
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