datarefine / app.py
ghosthets's picture
Update app.py
bdd9d8b verified
import os
import json
from fastmcp import FastMCP
from huggingface_hub import HfApi, model_info
# Hugging Face token from Space secrets
HF_TOKEN = os.environ.get("HF_TOKEN")
hf_api = HfApi(token=HF_TOKEN) if HF_TOKEN else None
# FastMCP server setup
mcp = FastMCP("hf-tagging-bot")
@mcp.tool()
def get_current_tags(repo_id: str) -> str:
"""Get current tags from a HuggingFace model repository"""
if not hf_api:
return json.dumps({"error": "HF token not configured"})
try:
info = model_info(repo_id=repo_id, token=HF_TOKEN)
current_tags = info.tags if info.tags else []
return json.dumps({
"status": "success",
"repo_id": repo_id,
"current_tags": current_tags,
"count": len(current_tags),
})
except Exception as e:
return json.dumps({
"status": "error",
"repo_id": repo_id,
"error": str(e),
})
# Run MCP server only
if __name__ == "__main__":
mcp.run()