Alfred828 commited on
Commit
16d2cc0
·
verified ·
1 Parent(s): 422ae9b

Create tools/get_hub_stats.py

Browse files
Files changed (1) hide show
  1. tools/get_hub_stats.py +23 -0
tools/get_hub_stats.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from huggingface_hub import list_models
2
+ from pydantic import BaseModel, Field
3
+
4
+
5
+ class HubStatInput(BaseModel):
6
+ author: str = Field(description="author on the Hugging Face Hub")
7
+
8
+
9
+ def get_hub_stats(author: str) -> str:
10
+ """Fetches the most downloaded model from a specific author on the Hugging Face Hub."""
11
+ try:
12
+ # List models from the specified author, sorted by downloads
13
+ models = list(
14
+ list_models(author=author, sort="downloads", direction=-1, limit=1)
15
+ )
16
+
17
+ if models:
18
+ model = models[0]
19
+ return f"The most downloaded model by {author} is {model.id} with {model.downloads:,} downloads."
20
+ else:
21
+ return f"No models found for author {author}."
22
+ except Exception as e:
23
+ return f"Error fetching models for {author}: {str(e)}"