Hugging Face Hub Development Skill
When to Use This Skill
Trigger this skill when the user asks to:
- Make HTTP/curl requests to Hugging Face APIs
- Upload or download models/datasets using huggingface_hub Python library
- Use Inference Providers API (chat completion, text generation, image generation)
- Create or modify Gradio or Docker Spaces applications
- Work with GGUF models, PEFT/LoRA adapters, or quantization
- Load datasets with pandas, Polars, or DuckDB
- Set up webhooks, Jobs, or CI/CD automation
- Configure model cards, dataset cards, or Space YAML metadata
- Use @huggingface/hub or Transformers.js JavaScript packages
- Set up authentication, tokens, or security features
- Embed Spaces in websites or enable OAuth sign-in
Quick Reference
Authentication
# Python - Interactive login
from huggingface_hub import login
login() # Opens browser or prompts for token
# Python - Programmatic login
login(token="hf_xxx")
# Environment variable (recommended for CI/production)
# export HF_TOKEN="hf_xxx"
# CLI login
huggingface-cli login
# Set token directly
huggingface-cli login --token hf_xxx
Get tokens at: https://huggingface.co/settings/tokens
Download Files
from huggingface_hub import hf_hub_download, snapshot_download
# Single file
model_path = hf_hub_download(
repo_id="user/model",
filename="model.safetensors"
)
# Entire repository
local_dir = snapshot_download(repo_id="user/model")
# Specific revision
hf_hub_download(repo_id="user/model", filename="config.json", revision="v1.0")
# CLI download
huggingface-cli download HuggingFaceH4/zephyr-7b-beta
huggingface-cli download user/model model.safetensors
Upload Files
from huggingface_hub import upload_file, upload_folder, HfApi
# Single file
upload_file(
path_or_fileobj="model.safetensors",
path_in_repo="model.safetensors",
repo_id="user/model"
)
# Entire folder
upload_folder(
folder_path="./my_model",
repo_id="user/model"
)
# Using HfApi
api = HfApi()
api.create_repo(repo_id="user/new-model", repo_type="model")
api.upload_file(path_or_fileobj="model.pt", path_in_repo="model.pt", repo_id="user/new-model")
Inference Providers
import os
from huggingface_hub import InferenceClient
client = InferenceClient(api_key=os.environ["HF_TOKEN"])
# Chat completion (OpenAI-compatible)
response = client.chat.completions.create(
model="meta-llama/Llama-3.1-8B-Instruct",
messages=[{"role": "user", "content": "Hello!"}]
)
# Text generation
response = client.text_generation(
"The answer to the universe is",
model="meta-llama/Llama-3.1-8B-Instruct"
)
# Image generation
image = client.text_to_image(
"A serene mountain landscape at sunset",
model="black-forest-labs/FLUX.1-schnell"
)
curl:
curl https://router.huggingface.co/v1/chat/completions \
-H "Authorization: Bearer $HF_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"model": "meta-llama/Llama-3.1-8B-Instruct",
"messages": [{"role": "user", "content": "Hello!"}]
}'
Dataset Loading
import pandas as pd
import polars as pl
# Pandas with hf:// protocol
df = pd.read_parquet("hf://datasets/stanfordnlp/imdb/plain_text/train-00000-of-00001.parquet")
# Polars with hf:// protocol
df = pl.read_parquet("hf://datasets/stanfordnlp/imdb/plain_text/train-*.parquet")
# DuckDB
import duckdb
conn = duckdb.connect()
df = conn.execute("SELECT * FROM 'hf://datasets/stanfordnlp/imdb/plain_text/*.parquet' LIMIT 100").fetchdf()
Gradio Space (Minimal)
README.md:
---
title: My Space
emoji: 🚀
sdk: gradio
sdk_version: 5.0.0
app_file: app.py
---
app.py:
import gradio as gr
from transformers import pipeline
pipe = pipeline("text-classification", model="distilbert-base-uncased-finetuned-sst-2-english")
def classify(text):
result = pipe(text)[0]
return {result["label"]: result["score"]}
demo = gr.Interface(fn=classify, inputs="text", outputs="label")
demo.launch()
Space Configuration
---
title: My Application
emoji: 🤗
colorFrom: blue
colorTo: purple
sdk: gradio # gradio, docker, or static
sdk_version: 5.0.0
python_version: "3.10"
app_file: app.py
app_port: 7860 # Docker only
suggested_hardware: t4-small # or cpu-basic, a10g-small, etc.
pinned: true
models:
- openai-community/gpt2
datasets:
- mozilla-foundation/common_voice_13_0
hf_oauth: true # Enable HF OAuth
preload_from_hub:
- user/model config.json,model.safetensors
---
Hardware options:
- CPU:
cpu-basic, cpu-upgrade
- GPU:
t4-small, t4-medium, l4x1, l4x4, a10g-small, a10g-large, a100-large
- TPU:
v5e-1x1, v5e-2x2, v5e-2x4
Model Card Metadata
---
language:
- en
license: apache-2.0
library_name: transformers
pipeline_tag: text-classification
tags:
- nlp
- sentiment
datasets:
- stanfordnlp/imdb
base_model: bert-base-uncased
metrics:
- accuracy
---
Resources
Detailed documentation organized by topic:
references/
api-http.md - curl/HTTP API examples for all endpoints
python-sdk.md - huggingface_hub Python patterns (download, upload, HfApi)
javascript-sdk.md - @huggingface/hub and Transformers.js
inference-providers.md - InferenceClient and provider selection
models-advanced.md - GGUF, PEFT/LoRA, quantization formats
datasets-workflows.md - pandas, Polars, DuckDB data workflows
spaces-config.md - Complete YAML configuration reference
spaces-gradio.md - Building Gradio Spaces
spaces-docker.md - Docker Spaces with secrets and permissions
spaces-integration.md - Embedding, OAuth, MCP servers
automation.md - Webhooks, Jobs, GitHub Actions
security.md - Tokens, gating, scanning, SSO
models.md - Model repositories, cards, and uploading
datasets.md - Dataset repositories and configuration
enterprise.md - Enterprise Hub features
doc-syntax.md - Doc-builder markdown syntax
examples/
inference-curl.sh - Complete curl examples for all APIs
jupyter-pandas.py - Jupyter + pandas workflow
browser-transformersjs.html - Browser inference with Transformers.js
lora-peft-workflow.py - LoRA adapter find/load/merge workflow
webhooks-auto-retrain.py - Webhook automation for retraining
collections-api.py - Collections creation and management
offline-setup.py - Offline/air-gapped environment setup
space-embed-iframe.html - Embedding patterns for websites
gradio-image-classifier.py - Image classification with gr.Interface
gradio-chat-interface.py - Chat interface with HF model
upload-model.py - PyTorchModelHubMixin complete example
download-files.py - Various download patterns
model-card.md - Model card template with metadata
dataset-card.md - Dataset card template with metadata
patterns/
missing-features.md - iOS, Next.js, full offline workarounds
Best Practices
- Always use environment variables for tokens - Never hardcode
hf_xxx tokens
- Use
.safetensors format - Preferred over .bin for model weights
- Add comprehensive model cards - Include intended use, limitations, training data
- Pin SDK versions in Spaces - Ensure reproducibility
- Use
preload_from_hub - Speed up Space startup by preloading models
- Set appropriate hardware - Match compute needs to avoid OOM errors
- Use fine-grained tokens - Minimize scope for production apps
- Use Parquet for datasets - Much faster than CSV for large data
1---2name: huggingface-hub3description: Expert knowledge for the Hugging Face Hub ecosystem including HTTP/curl API usage, Python/JavaScript SDKs, Spaces apps (Gradio, Docker), model formats (GGUF, PEFT/LoRA), datasets (pandas, Polars, DuckDB), automation (webhooks, Jobs), and security features. Use when working with Hub APIs, huggingface_hub Python code, Spaces apps, inference providers, model/dataset repositories, or Hub automation.4---56# Hugging Face Hub Development Skill78## When to Use This Skill910Trigger this skill when the user asks to:11- Make HTTP/curl requests to Hugging Face APIs12- Upload or download models/datasets using huggingface_hub Python library13- Use Inference Providers API (chat completion, text generation, image generation)14- Create or modify Gradio or Docker Spaces applications15- Work with GGUF models, PEFT/LoRA adapters, or quantization16- Load datasets with pandas, Polars, or DuckDB17- Set up webhooks, Jobs, or CI/CD automation18- Configure model cards, dataset cards, or Space YAML metadata19- Use @huggingface/hub or Transformers.js JavaScript packages20- Set up authentication, tokens, or security features21- Embed Spaces in websites or enable OAuth sign-in2223## Quick Reference2425### Authentication2627```python28# Python - Interactive login29from huggingface_hub import login30login() # Opens browser or prompts for token3132# Python - Programmatic login33login(token="hf_xxx")3435# Environment variable (recommended for CI/production)36# export HF_TOKEN="hf_xxx"37```3839```bash40# CLI login41huggingface-cli login4243# Set token directly44huggingface-cli login --token hf_xxx45```4647Get tokens at: https://huggingface.co/settings/tokens4849### Download Files5051```python52from huggingface_hub import hf_hub_download, snapshot_download5354# Single file55model_path = hf_hub_download(56 repo_id="user/model",57 filename="model.safetensors"58)5960# Entire repository61local_dir = snapshot_download(repo_id="user/model")6263# Specific revision64hf_hub_download(repo_id="user/model", filename="config.json", revision="v1.0")65```6667```bash68# CLI download69huggingface-cli download HuggingFaceH4/zephyr-7b-beta70huggingface-cli download user/model model.safetensors71```7273### Upload Files7475```python76from huggingface_hub import upload_file, upload_folder, HfApi7778# Single file79upload_file(80 path_or_fileobj="model.safetensors",81 path_in_repo="model.safetensors",82 repo_id="user/model"83)8485# Entire folder86upload_folder(87 folder_path="./my_model",88 repo_id="user/model"89)9091# Using HfApi92api = HfApi()93api.create_repo(repo_id="user/new-model", repo_type="model")94api.upload_file(path_or_fileobj="model.pt", path_in_repo="model.pt", repo_id="user/new-model")95```9697### Inference Providers9899```python100import os101from huggingface_hub import InferenceClient102103client = InferenceClient(api_key=os.environ["HF_TOKEN"])104105# Chat completion (OpenAI-compatible)106response = client.chat.completions.create(107 model="meta-llama/Llama-3.1-8B-Instruct",108 messages=[{"role": "user", "content": "Hello!"}]109)110111# Text generation112response = client.text_generation(113 "The answer to the universe is",114 model="meta-llama/Llama-3.1-8B-Instruct"115)116117# Image generation118image = client.text_to_image(119 "A serene mountain landscape at sunset",120 model="black-forest-labs/FLUX.1-schnell"121)122```123124**curl:**125```bash126curl https://router.huggingface.co/v1/chat/completions \127 -H "Authorization: Bearer $HF_TOKEN" \128 -H "Content-Type: application/json" \129 -d '{130 "model": "meta-llama/Llama-3.1-8B-Instruct",131 "messages": [{"role": "user", "content": "Hello!"}]132 }'133```134135### Dataset Loading136137```python138import pandas as pd139import polars as pl140141# Pandas with hf:// protocol142df = pd.read_parquet("hf://datasets/stanfordnlp/imdb/plain_text/train-00000-of-00001.parquet")143144# Polars with hf:// protocol145df = pl.read_parquet("hf://datasets/stanfordnlp/imdb/plain_text/train-*.parquet")146147# DuckDB148import duckdb149conn = duckdb.connect()150df = conn.execute("SELECT * FROM 'hf://datasets/stanfordnlp/imdb/plain_text/*.parquet' LIMIT 100").fetchdf()151```152153### Gradio Space (Minimal)154155**README.md:**156```yaml157---158title: My Space159emoji: 🚀160sdk: gradio161sdk_version: 5.0.0162app_file: app.py163---164```165166**app.py:**167```python168import gradio as gr169from transformers import pipeline170171pipe = pipeline("text-classification", model="distilbert-base-uncased-finetuned-sst-2-english")172173def classify(text):174 result = pipe(text)[0]175 return {result["label"]: result["score"]}176177demo = gr.Interface(fn=classify, inputs="text", outputs="label")178demo.launch()179```180181### Space Configuration182183```yaml184---185title: My Application186emoji: 🤗187colorFrom: blue188colorTo: purple189sdk: gradio # gradio, docker, or static190sdk_version: 5.0.0191python_version: "3.10"192app_file: app.py193app_port: 7860 # Docker only194suggested_hardware: t4-small # or cpu-basic, a10g-small, etc.195pinned: true196models:197 - openai-community/gpt2198datasets:199 - mozilla-foundation/common_voice_13_0200hf_oauth: true # Enable HF OAuth201preload_from_hub:202 - user/model config.json,model.safetensors203---204```205206**Hardware options:**207- CPU: `cpu-basic`, `cpu-upgrade`208- GPU: `t4-small`, `t4-medium`, `l4x1`, `l4x4`, `a10g-small`, `a10g-large`, `a100-large`209- TPU: `v5e-1x1`, `v5e-2x2`, `v5e-2x4`210211### Model Card Metadata212213```yaml214---215language:216 - en217license: apache-2.0218library_name: transformers219pipeline_tag: text-classification220tags:221 - nlp222 - sentiment223datasets:224 - stanfordnlp/imdb225base_model: bert-base-uncased226metrics:227 - accuracy228---229```230231## Resources232233Detailed documentation organized by topic:234235### references/236- `api-http.md` - **curl/HTTP API examples** for all endpoints237- `python-sdk.md` - huggingface_hub Python patterns (download, upload, HfApi)238- `javascript-sdk.md` - @huggingface/hub and Transformers.js239- `inference-providers.md` - InferenceClient and provider selection240- `models-advanced.md` - **GGUF, PEFT/LoRA, quantization** formats241- `datasets-workflows.md` - **pandas, Polars, DuckDB** data workflows242- `spaces-config.md` - Complete YAML configuration reference243- `spaces-gradio.md` - Building Gradio Spaces244- `spaces-docker.md` - Docker Spaces with secrets and permissions245- `spaces-integration.md` - **Embedding, OAuth, MCP servers**246- `automation.md` - **Webhooks, Jobs, GitHub Actions**247- `security.md` - **Tokens, gating, scanning, SSO**248- `models.md` - Model repositories, cards, and uploading249- `datasets.md` - Dataset repositories and configuration250- `enterprise.md` - Enterprise Hub features251- `doc-syntax.md` - Doc-builder markdown syntax252253### examples/254- `inference-curl.sh` - **Complete curl examples** for all APIs255- `jupyter-pandas.py` - **Jupyter + pandas workflow**256- `browser-transformersjs.html` - **Browser inference** with Transformers.js257- `lora-peft-workflow.py` - **LoRA adapter** find/load/merge workflow258- `webhooks-auto-retrain.py` - **Webhook automation** for retraining259- `collections-api.py` - **Collections** creation and management260- `offline-setup.py` - **Offline/air-gapped** environment setup261- `space-embed-iframe.html` - **Embedding patterns** for websites262- `gradio-image-classifier.py` - Image classification with gr.Interface263- `gradio-chat-interface.py` - Chat interface with HF model264- `upload-model.py` - PyTorchModelHubMixin complete example265- `download-files.py` - Various download patterns266- `model-card.md` - Model card template with metadata267- `dataset-card.md` - Dataset card template with metadata268269### patterns/270- `missing-features.md` - **iOS, Next.js, full offline** workarounds271272## Best Practices2732741. **Always use environment variables for tokens** - Never hardcode `hf_xxx` tokens2752. **Use `.safetensors` format** - Preferred over `.bin` for model weights2763. **Add comprehensive model cards** - Include intended use, limitations, training data2774. **Pin SDK versions in Spaces** - Ensure reproducibility2785. **Use `preload_from_hub`** - Speed up Space startup by preloading models2796. **Set appropriate hardware** - Match compute needs to avoid OOM errors2807. **Use fine-grained tokens** - Minimize scope for production apps2818. **Use Parquet for datasets** - Much faster than CSV for large data