Update tools.py
Browse files
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 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
"type": "string",
|
| 12 |
-
"description": "The username of the model author/organization to find models from."
|
| 13 |
-
}
|
| 14 |
-
}
|
| 15 |
-
output_type = "string"
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 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)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|