Spaces:
Starting
Starting
from langchain_core.tools import tool | |
from huggingface_hub import list_models | |
import logging | |
logger = logging.getLogger(__name__) | |
async def hub_stats_tool(author: str) -> str: | |
"""Fetch the most downloaded model from a specific author on Hugging Face Hub.""" | |
try: | |
models = list(list_models(author=author, sort="downloads", direction=-1, limit=1)) | |
if models: | |
model = models[0] | |
return f"The most downloaded model by {author} is {model.id} with {model.downloads:,} downloads." | |
return f"No models found for author {author}." | |
except Exception as e: | |
logger.error(f"Error fetching models for {author}: {e}") | |
return f"Error: {str(e)}" |