jarvis_gaia_agent / tools /hub_stats.py
onisj's picture
feat(advance): Deploy corrected app.py and tools fo advance functions
4701375
raw
history blame
709 Bytes
from langchain_core.tools import tool
from huggingface_hub import list_models
import logging
logger = logging.getLogger(__name__)
@tool
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)}"