$npx -y skills add AlexAI-MCP/hermes-CCC --skill huggingface-hubHuggingFace Hub — download models/datasets, upload artifacts, search, and manage tokens via CLI and Python API.
| 1 | # HuggingFace Hub |
| 2 | |
| 3 | Download models and datasets, upload artifacts, and manage your Hub presence via CLI and Python API. |
| 4 | |
| 5 | ## Setup |
| 6 | |
| 7 | ```bash |
| 8 | pip install huggingface_hub datasets transformers |
| 9 | huggingface-cli login # paste your token from hf.co/settings/tokens |
| 10 | ``` |
| 11 | |
| 12 | Or set env var: |
| 13 | ```bash |
| 14 | export HF_TOKEN=hf_... |
| 15 | ``` |
| 16 | |
| 17 | --- |
| 18 | |
| 19 | ## Download Models |
| 20 | |
| 21 | ```bash |
| 22 | # Download entire model to cache (~/.cache/huggingface/) |
| 23 | huggingface-cli download meta-llama/Llama-3.1-8B-Instruct |
| 24 | |
| 25 | # Download to specific directory |
| 26 | huggingface-cli download Qwen/Qwen2.5-7B-Instruct --local-dir ./models/qwen |
| 27 | |
| 28 | # Download specific file only |
| 29 | huggingface-cli download microsoft/phi-4 config.json |
| 30 | |
| 31 | # Download GGUF quantized model |
| 32 | huggingface-cli download bartowski/Llama-3.1-8B-Instruct-GGUF \ |
| 33 | Llama-3.1-8B-Instruct-Q4_K_M.gguf --local-dir ./models/ |
| 34 | ``` |
| 35 | |
| 36 | Python API: |
| 37 | ```python |
| 38 | from huggingface_hub import snapshot_download, hf_hub_download |
| 39 | |
| 40 | # Full model |
| 41 | snapshot_download("meta-llama/Llama-3.1-8B-Instruct", local_dir="./models/llama") |
| 42 | |
| 43 | # Single file |
| 44 | hf_hub_download("meta-llama/Llama-3.1-8B-Instruct", "config.json", local_dir="./") |
| 45 | ``` |
| 46 | |
| 47 | --- |
| 48 | |
| 49 | ## Download Datasets |
| 50 | |
| 51 | ```bash |
| 52 | # CLI |
| 53 | huggingface-cli download --repo-type dataset HuggingFaceH4/ultrachat_200k |
| 54 | |
| 55 | # Python (preferred) |
| 56 | from datasets import load_dataset |
| 57 | |
| 58 | dataset = load_dataset("HuggingFaceH4/ultrachat_200k") |
| 59 | dataset["train_sft"].to_json("./data/train.jsonl") |
| 60 | ``` |
| 61 | |
| 62 | --- |
| 63 | |
| 64 | ## Upload Models |
| 65 | |
| 66 | ```bash |
| 67 | # Upload directory |
| 68 | huggingface-cli upload your-username/my-model ./local-model-dir |
| 69 | |
| 70 | # Upload specific file |
| 71 | huggingface-cli upload your-username/my-model ./model.safetensors |
| 72 | |
| 73 | # Create repo first if needed |
| 74 | huggingface-cli repo create my-new-model --type model |
| 75 | ``` |
| 76 | |
| 77 | Python API: |
| 78 | ```python |
| 79 | from huggingface_hub import HfApi |
| 80 | |
| 81 | api = HfApi() |
| 82 | api.upload_folder( |
| 83 | folder_path="./fine-tuned-model", |
| 84 | repo_id="your-username/my-fine-tuned-model", |
| 85 | repo_type="model", |
| 86 | ) |
| 87 | ``` |
| 88 | |
| 89 | --- |
| 90 | |
| 91 | ## Search Models |
| 92 | |
| 93 | ```bash |
| 94 | # CLI search |
| 95 | huggingface-cli search models --filter task=text-generation --filter language=ko |
| 96 | |
| 97 | # Python API |
| 98 | from huggingface_hub import list_models |
| 99 | |
| 100 | models = list_models( |
| 101 | task="text-generation", |
| 102 | language="ko", |
| 103 | sort="downloads", |
| 104 | limit=10, |
| 105 | ) |
| 106 | for m in models: |
| 107 | print(m.id, m.downloads) |
| 108 | ``` |
| 109 | |
| 110 | --- |
| 111 | |
| 112 | ## Cache Management |
| 113 | |
| 114 | ```bash |
| 115 | # Show cache info |
| 116 | huggingface-cli cache info |
| 117 | |
| 118 | # List cached repos |
| 119 | huggingface-cli cache scan |
| 120 | |
| 121 | # Delete specific cached model |
| 122 | huggingface-cli cache evict --model meta-llama/Llama-3.1-8B-Instruct |
| 123 | |
| 124 | # Cache location |
| 125 | echo ~/.cache/huggingface/hub/ |
| 126 | ``` |
| 127 | |
| 128 | Custom cache dir: |
| 129 | ```bash |
| 130 | export HF_HOME=/path/to/custom/cache |
| 131 | ``` |
| 132 | |
| 133 | --- |
| 134 | |
| 135 | ## Model Cards |
| 136 | |
| 137 | ```bash |
| 138 | # Read model card |
| 139 | python -c "from huggingface_hub import ModelCard; print(ModelCard.load('Qwen/Qwen2.5-7B-Instruct'))" |
| 140 | ``` |
| 141 | |
| 142 | --- |
| 143 | |
| 144 | ## Spaces |
| 145 | |
| 146 | ```bash |
| 147 | # Deploy a Gradio/Streamlit app to Spaces |
| 148 | huggingface-cli upload your-username/my-space ./app --repo-type space |
| 149 | |
| 150 | # Check Space status |
| 151 | huggingface-cli space info your-username/my-space |
| 152 | ``` |
| 153 | |
| 154 | --- |
| 155 | |
| 156 | ## Token Management |
| 157 | |
| 158 | ```bash |
| 159 | # Who am I? |
| 160 | huggingface-cli whoami |
| 161 | |
| 162 | # List tokens |
| 163 | huggingface-cli token list |
| 164 | |
| 165 | # Revoke |
| 166 | huggingface-cli token revoke TOKEN_NAME |
| 167 | ``` |
| 168 | |
| 169 | --- |
| 170 | |
| 171 | ## Gated Models (Llama, Gemma, etc.) |
| 172 | |
| 173 | 1. Go to hf.co/model-card and accept terms |
| 174 | 2. Use a token with read access: `huggingface-cli login` |
| 175 | 3. Download normally — gate is checked server-side |
| 176 | |
| 177 | ```python |
| 178 | # Check if you have access |
| 179 | from huggingface_hub import model_info |
| 180 | info = model_info("meta-llama/Llama-3.1-8B-Instruct") |
| 181 | print(info.gated) # False if you have access |
| 182 | ``` |