gary149/huggingface-hub-skill
Overview
This skill provides expert guidance for developing with the Hugging Face Hub ecosystem, covering HTTP/curl APIs, Python and JavaScript SDKs, Spaces apps (Gradio, Docker), model formats, datasets, automation, and security. It helps you upload/download repositories, run inference, configure Spaces, and automate workflows with practical examples and patterns. Use it when integrating Hub features into apps, CI/CD, or production pipelines.
How this skill works
The skill explains concrete API calls (curl and HTTP), SDK usage (huggingface_hub in Python and @huggingface/hub in JavaScript), and inference via InferenceClient. It shows repository operations (hf_hub_download, upload_file, snapshot_download), Space configuration (YAML and app files), dataset access (pandas, Polars, DuckDB), and formats like GGUF and PEFT/LoRA. It also covers automation (webhooks, Jobs), security (tokens, OAuth, scoping), and deployment considerations for reproducibility and resource selection.
When to use it
- You need to upload or download models, weights, or datasets programmatically.
- You want to call Hugging Face inference endpoints from server or curl.
- You are building or configuring a Space (Gradio or Docker) for deployment.
- You must load large datasets efficiently with Parquet via pandas/Polars/DuckDB.
- You plan LoRA/PEFT workflows, GGUF conversion, or model quantization.
- You need automation: webhooks, scheduled Jobs, or CI/CD integration.
Best practices
- Store HF tokens in environment variables and use fine-grained tokens for production.
- Prefer .safetensors for model weights and pin SDK versions in Spaces.
- Add thorough model and dataset cards documenting use, limitations, and data sources.
- Preload heavy models with preload_from_hub to reduce Space startup time.
- Choose hardware to match workload (avoid OOM by selecting appropriate GPU/CPU).
- Use Parquet for large dataset storage and query via DuckDB for interactive analysis.
Example use cases
- Use hf_hub_download to fetch a specific model file for local inference in a script.
- Create a Gradio Space that loads a pretrained transformer and serves a chat interface.
- Invoke the InferenceClient with curl for chat completions or image generation in CI.
- Deploy a LoRA adapter: find, load, merge, and upload the adapted model to the Hub.
- Trigger retraining with a webhook that launches a Job or GitHub Actions workflow.
FAQ
Set HF_TOKEN as an environment variable, use fine-grained tokens, and avoid committing tokens to source control.
Which format should I use for model weights?
Use .safetensors where possible for safety and speed; document the format in the model card.