opencode-skills-antigravity 1.0.39 → 1.0.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/bundled-skills/.antigravity-install-manifest.json +10 -1
  2. package/bundled-skills/docs/integrations/jetski-cortex.md +3 -3
  3. package/bundled-skills/docs/integrations/jetski-gemini-loader/README.md +1 -1
  4. package/bundled-skills/docs/maintainers/repo-growth-seo.md +3 -3
  5. package/bundled-skills/docs/maintainers/security-findings-triage-2026-03-29-refresh.csv +34 -0
  6. package/bundled-skills/docs/maintainers/security-findings-triage-2026-03-29-refresh.md +2 -0
  7. package/bundled-skills/docs/maintainers/skills-update-guide.md +1 -1
  8. package/bundled-skills/docs/sources/sources.md +2 -2
  9. package/bundled-skills/docs/users/bundles.md +1 -1
  10. package/bundled-skills/docs/users/claude-code-skills.md +1 -1
  11. package/bundled-skills/docs/users/gemini-cli-skills.md +1 -1
  12. package/bundled-skills/docs/users/getting-started.md +1 -1
  13. package/bundled-skills/docs/users/kiro-integration.md +1 -1
  14. package/bundled-skills/docs/users/usage.md +4 -4
  15. package/bundled-skills/docs/users/visual-guide.md +4 -4
  16. package/bundled-skills/hugging-face-cli/SKILL.md +192 -195
  17. package/bundled-skills/hugging-face-community-evals/SKILL.md +213 -0
  18. package/bundled-skills/hugging-face-community-evals/examples/.env.example +3 -0
  19. package/bundled-skills/hugging-face-community-evals/examples/USAGE_EXAMPLES.md +101 -0
  20. package/bundled-skills/hugging-face-community-evals/scripts/inspect_eval_uv.py +104 -0
  21. package/bundled-skills/hugging-face-community-evals/scripts/inspect_vllm_uv.py +306 -0
  22. package/bundled-skills/hugging-face-community-evals/scripts/lighteval_vllm_uv.py +297 -0
  23. package/bundled-skills/hugging-face-dataset-viewer/SKILL.md +120 -120
  24. package/bundled-skills/hugging-face-gradio/SKILL.md +304 -0
  25. package/bundled-skills/hugging-face-gradio/examples.md +613 -0
  26. package/bundled-skills/hugging-face-jobs/SKILL.md +25 -18
  27. package/bundled-skills/hugging-face-jobs/index.html +216 -0
  28. package/bundled-skills/hugging-face-jobs/references/hardware_guide.md +336 -0
  29. package/bundled-skills/hugging-face-jobs/references/hub_saving.md +352 -0
  30. package/bundled-skills/hugging-face-jobs/references/token_usage.md +570 -0
  31. package/bundled-skills/hugging-face-jobs/references/troubleshooting.md +475 -0
  32. package/bundled-skills/hugging-face-jobs/scripts/cot-self-instruct.py +718 -0
  33. package/bundled-skills/hugging-face-jobs/scripts/finepdfs-stats.py +546 -0
  34. package/bundled-skills/hugging-face-jobs/scripts/generate-responses.py +587 -0
  35. package/bundled-skills/hugging-face-model-trainer/SKILL.md +11 -12
  36. package/bundled-skills/hugging-face-model-trainer/references/gguf_conversion.md +296 -0
  37. package/bundled-skills/hugging-face-model-trainer/references/hardware_guide.md +283 -0
  38. package/bundled-skills/hugging-face-model-trainer/references/hub_saving.md +364 -0
  39. package/bundled-skills/hugging-face-model-trainer/references/local_training_macos.md +231 -0
  40. package/bundled-skills/hugging-face-model-trainer/references/reliability_principles.md +371 -0
  41. package/bundled-skills/hugging-face-model-trainer/references/trackio_guide.md +189 -0
  42. package/bundled-skills/hugging-face-model-trainer/references/training_methods.md +150 -0
  43. package/bundled-skills/hugging-face-model-trainer/references/training_patterns.md +203 -0
  44. package/bundled-skills/hugging-face-model-trainer/references/troubleshooting.md +282 -0
  45. package/bundled-skills/hugging-face-model-trainer/references/unsloth.md +313 -0
  46. package/bundled-skills/hugging-face-model-trainer/scripts/convert_to_gguf.py +424 -0
  47. package/bundled-skills/hugging-face-model-trainer/scripts/dataset_inspector.py +417 -0
  48. package/bundled-skills/hugging-face-model-trainer/scripts/estimate_cost.py +150 -0
  49. package/bundled-skills/hugging-face-model-trainer/scripts/train_dpo_example.py +106 -0
  50. package/bundled-skills/hugging-face-model-trainer/scripts/train_grpo_example.py +89 -0
  51. package/bundled-skills/hugging-face-model-trainer/scripts/train_sft_example.py +122 -0
  52. package/bundled-skills/hugging-face-model-trainer/scripts/unsloth_sft_example.py +512 -0
  53. package/bundled-skills/hugging-face-paper-publisher/SKILL.md +11 -4
  54. package/bundled-skills/hugging-face-paper-publisher/examples/example_usage.md +326 -0
  55. package/bundled-skills/hugging-face-paper-publisher/references/quick_reference.md +216 -0
  56. package/bundled-skills/hugging-face-paper-publisher/scripts/paper_manager.py +606 -0
  57. package/bundled-skills/hugging-face-paper-publisher/templates/arxiv.md +299 -0
  58. package/bundled-skills/hugging-face-paper-publisher/templates/ml-report.md +358 -0
  59. package/bundled-skills/hugging-face-paper-publisher/templates/modern.md +319 -0
  60. package/bundled-skills/hugging-face-paper-publisher/templates/standard.md +201 -0
  61. package/bundled-skills/hugging-face-papers/SKILL.md +241 -0
  62. package/bundled-skills/hugging-face-trackio/.claude-plugin/plugin.json +19 -0
  63. package/bundled-skills/hugging-face-trackio/SKILL.md +117 -0
  64. package/bundled-skills/hugging-face-trackio/references/alerts.md +196 -0
  65. package/bundled-skills/hugging-face-trackio/references/logging_metrics.md +206 -0
  66. package/bundled-skills/hugging-face-trackio/references/retrieving_metrics.md +251 -0
  67. package/bundled-skills/hugging-face-vision-trainer/SKILL.md +595 -0
  68. package/bundled-skills/hugging-face-vision-trainer/references/finetune_sam2_trainer.md +254 -0
  69. package/bundled-skills/hugging-face-vision-trainer/references/hub_saving.md +618 -0
  70. package/bundled-skills/hugging-face-vision-trainer/references/image_classification_training_notebook.md +279 -0
  71. package/bundled-skills/hugging-face-vision-trainer/references/object_detection_training_notebook.md +700 -0
  72. package/bundled-skills/hugging-face-vision-trainer/references/reliability_principles.md +310 -0
  73. package/bundled-skills/hugging-face-vision-trainer/references/timm_trainer.md +91 -0
  74. package/bundled-skills/hugging-face-vision-trainer/scripts/dataset_inspector.py +814 -0
  75. package/bundled-skills/hugging-face-vision-trainer/scripts/estimate_cost.py +217 -0
  76. package/bundled-skills/hugging-face-vision-trainer/scripts/image_classification_training.py +383 -0
  77. package/bundled-skills/hugging-face-vision-trainer/scripts/object_detection_training.py +710 -0
  78. package/bundled-skills/hugging-face-vision-trainer/scripts/sam_segmentation_training.py +382 -0
  79. package/bundled-skills/jq/SKILL.md +273 -0
  80. package/bundled-skills/odoo-edi-connector/SKILL.md +32 -10
  81. package/bundled-skills/odoo-woocommerce-bridge/SKILL.md +9 -5
  82. package/bundled-skills/tmux/SKILL.md +370 -0
  83. package/bundled-skills/transformers-js/SKILL.md +639 -0
  84. package/bundled-skills/transformers-js/references/CACHE.md +339 -0
  85. package/bundled-skills/transformers-js/references/CONFIGURATION.md +390 -0
  86. package/bundled-skills/transformers-js/references/EXAMPLES.md +605 -0
  87. package/bundled-skills/transformers-js/references/MODEL_ARCHITECTURES.md +167 -0
  88. package/bundled-skills/transformers-js/references/PIPELINE_OPTIONS.md +545 -0
  89. package/bundled-skills/transformers-js/references/TEXT_GENERATION.md +315 -0
  90. package/bundled-skills/viboscope/SKILL.md +64 -0
  91. package/package.json +1 -1
@@ -0,0 +1,570 @@
1
+ # Token Usage Guide for Hugging Face Jobs
2
+
3
+ **⚠️ CRITICAL:** Proper token usage is essential for any job that interacts with the Hugging Face Hub.
4
+
5
+ ## Overview
6
+
7
+ Hugging Face tokens are authentication credentials that allow your jobs to interact with the Hub. They're required for:
8
+ - Pushing models/datasets to Hub
9
+ - Accessing private repositories
10
+ - Creating new repositories
11
+ - Using Hub APIs programmatically
12
+ - Any authenticated Hub operations
13
+
14
+ ## Token Types
15
+
16
+ ### Read Token
17
+ - **Permissions:** Download models/datasets, read private repos
18
+ - **Use case:** Jobs that only need to download/read content
19
+ - **Creation:** https://huggingface.co/settings/tokens
20
+
21
+ ### Write Token
22
+ - **Permissions:** Push models/datasets, create repos, modify content
23
+ - **Use case:** Jobs that need to upload results (most common)
24
+ - **Creation:** https://huggingface.co/settings/tokens
25
+ - **⚠️ Required for:** Pushing models, datasets, or any uploads
26
+
27
+ ### Organization Token
28
+ - **Permissions:** Act on behalf of an organization
29
+ - **Use case:** Jobs running under organization namespace
30
+ - **Creation:** Organization settings → Tokens
31
+
32
+ ## Providing Tokens to Jobs
33
+
34
+ ### Method 1: `hf_jobs` MCP tool with `$HF_TOKEN` (Recommended) ⭐
35
+
36
+ ```python
37
+ hf_jobs("uv", {
38
+ "script": "your_script.py",
39
+ "secrets": {"HF_TOKEN": "$HF_TOKEN"} # ✅ Automatic replacement
40
+ })
41
+ ```
42
+
43
+ **How it works:**
44
+ 1. `$HF_TOKEN` is a placeholder that gets replaced with your actual token
45
+ 2. Uses the token from your logged-in session (`hf auth login`)
46
+ 3. Token is encrypted server-side when passed as a secret
47
+ 4. Most secure and convenient method
48
+
49
+ **Benefits:**
50
+ - ✅ No token exposure in code
51
+ - ✅ Uses your current login session
52
+ - ✅ Automatically updated if you re-login
53
+ - ✅ Works seamlessly with MCP tools
54
+ - ✅ Token encrypted server-side
55
+
56
+ **Requirements:**
57
+ - Must be logged in: `hf auth login` or `hf_whoami()` works
58
+ - Token must have required permissions
59
+
60
+ **⚠️ CRITICAL:** `$HF_TOKEN` auto-replacement is an `hf_jobs` MCP tool feature ONLY. It does NOT work with `HfApi().run_uv_job()` — see Method 1b below.
61
+
62
+ ### Method 1b: `HfApi().run_uv_job()` with `get_token()` (Required for Python API)
63
+
64
+ ```python
65
+ from huggingface_hub import HfApi, get_token
66
+ api = HfApi()
67
+ api.run_uv_job(
68
+ script="your_script.py",
69
+ secrets={"HF_TOKEN": get_token()}, # ✅ Passes actual token value
70
+ )
71
+ ```
72
+
73
+ **How it works:**
74
+ 1. `get_token()` retrieves the token from your logged-in session
75
+ 2. The actual token value is passed to the `secrets` parameter
76
+ 3. Token is encrypted server-side
77
+
78
+ **Why `"$HF_TOKEN"` fails with `HfApi().run_uv_job()`:**
79
+ - The Python API passes the literal string `"$HF_TOKEN"` (9 characters) as the token
80
+ - The Jobs server receives this invalid string instead of a real token
81
+ - Result: `401 Unauthorized` errors when the script tries to authenticate
82
+ - You MUST use `get_token()` from `huggingface_hub` to get the real token
83
+
84
+ ### Method 2: Explicit Token (Not Recommended)
85
+
86
+ ```python
87
+ hf_jobs("uv", {
88
+ "script": "your_script.py",
89
+ "secrets": {"HF_TOKEN": "hf_abc123..."} # ⚠️ Hardcoded token
90
+ })
91
+ ```
92
+
93
+ **When to use:**
94
+ - Only if automatic token doesn't work
95
+ - Testing with a specific token
96
+ - Organization tokens (use with caution)
97
+
98
+ **Security concerns:**
99
+ - ❌ Token visible in code/logs
100
+ - ❌ Must manually update if token rotates
101
+ - ❌ Risk of token exposure
102
+ - ❌ Not recommended for production
103
+
104
+ ### Method 3: Environment Variable (Less Secure)
105
+
106
+ ```python
107
+ hf_jobs("uv", {
108
+ "script": "your_script.py",
109
+ "env": {"HF_TOKEN": "hf_abc123..."} # ⚠️ Less secure than secrets
110
+ })
111
+ ```
112
+
113
+ **Difference from secrets:**
114
+ - `env` variables are visible in job logs
115
+ - `secrets` are encrypted server-side
116
+ - Always prefer `secrets` for tokens
117
+
118
+ **When to use:**
119
+ - Only for non-sensitive configuration
120
+ - Never use for tokens (use `secrets` instead)
121
+
122
+ ## Using Tokens in Scripts
123
+
124
+ ### Accessing Tokens
125
+
126
+ Tokens passed via `secrets` are available as environment variables in your script:
127
+
128
+ ```python
129
+ import os
130
+
131
+ # Get token from environment
132
+ token = os.environ.get("HF_TOKEN")
133
+
134
+ # Verify token exists
135
+ if not token:
136
+ raise ValueError("HF_TOKEN not found in environment!")
137
+ ```
138
+
139
+ ### Using with Hugging Face Hub
140
+
141
+ **Option 1: Explicit token parameter**
142
+ ```python
143
+ from huggingface_hub import HfApi
144
+
145
+ api = HfApi(token=os.environ.get("HF_TOKEN"))
146
+ api.upload_file(...)
147
+ ```
148
+
149
+ **Option 2: Auto-detection (Recommended)**
150
+ ```python
151
+ from huggingface_hub import HfApi
152
+
153
+ # Automatically uses HF_TOKEN env var
154
+ api = HfApi() # ✅ Simpler, uses token from environment
155
+ api.upload_file(...)
156
+ ```
157
+
158
+ **Option 3: With transformers/datasets**
159
+ ```python
160
+ from transformers import AutoModel
161
+ from datasets import load_dataset
162
+
163
+ # Auto-detects HF_TOKEN from environment
164
+ model = AutoModel.from_pretrained("username/model")
165
+ dataset = load_dataset("username/dataset")
166
+
167
+ # For push operations, token is auto-detected
168
+ model.push_to_hub("username/new-model")
169
+ dataset.push_to_hub("username/new-dataset")
170
+ ```
171
+
172
+ ### Complete Example
173
+
174
+ ```python
175
+ # /// script
176
+ # dependencies = ["huggingface-hub", "datasets"]
177
+ # ///
178
+
179
+ import os
180
+ from huggingface_hub import HfApi
181
+ from datasets import Dataset
182
+
183
+ # Verify token is available
184
+ assert "HF_TOKEN" in os.environ, "HF_TOKEN required for Hub operations!"
185
+
186
+ # Use token for Hub operations
187
+ api = HfApi() # Auto-detects HF_TOKEN
188
+
189
+ # Create and push dataset
190
+ data = {"text": ["Hello", "World"]}
191
+ dataset = Dataset.from_dict(data)
192
+
193
+ # Push to Hub (token auto-detected)
194
+ dataset.push_to_hub("username/my-dataset")
195
+
196
+ print("✅ Dataset pushed successfully!")
197
+ ```
198
+
199
+ ## Token Verification
200
+
201
+ ### Check Authentication Locally
202
+
203
+ ```python
204
+ from huggingface_hub import whoami
205
+
206
+ try:
207
+ user_info = whoami()
208
+ print(f"✅ Logged in as: {user_info['name']}")
209
+ except Exception as e:
210
+ print(f"❌ Not authenticated: {e}")
211
+ ```
212
+
213
+ ### Verify Token in Job
214
+
215
+ ```python
216
+ import os
217
+
218
+ # Check token exists
219
+ if "HF_TOKEN" not in os.environ:
220
+ raise ValueError("HF_TOKEN not found in environment!")
221
+
222
+ token = os.environ["HF_TOKEN"]
223
+
224
+ # Verify token format (should start with "hf_")
225
+ if not token.startswith("hf_"):
226
+ raise ValueError(f"Invalid token format: {token[:10]}...")
227
+
228
+ # Test token works
229
+ from huggingface_hub import whoami
230
+ try:
231
+ user_info = whoami(token=token)
232
+ print(f"✅ Token valid for user: {user_info['name']}")
233
+ except Exception as e:
234
+ raise ValueError(f"Token validation failed: {e}")
235
+ ```
236
+
237
+ ## Common Token Issues
238
+
239
+ ### Error: 401 Unauthorized
240
+
241
+ **Symptoms:**
242
+ ```
243
+ 401 Client Error: Unauthorized for url: https://huggingface.co/api/...
244
+ ```
245
+
246
+ **Causes:**
247
+ 1. Token missing from job
248
+ 2. Token invalid or expired
249
+ 3. Token not passed correctly
250
+
251
+ **Solutions:**
252
+ 1. Add `secrets={"HF_TOKEN": "$HF_TOKEN"}` to job config
253
+ 2. Verify `hf_whoami()` works locally
254
+ 3. Re-login: `hf auth login`
255
+ 4. Check token hasn't expired
256
+
257
+ **Verification:**
258
+ ```python
259
+ # In your script
260
+ import os
261
+ assert "HF_TOKEN" in os.environ, "HF_TOKEN missing!"
262
+ ```
263
+
264
+ ### Error: 403 Forbidden
265
+
266
+ **Symptoms:**
267
+ ```
268
+ 403 Client Error: Forbidden for url: https://huggingface.co/api/...
269
+ ```
270
+
271
+ **Causes:**
272
+ 1. Token lacks required permissions (read-only token used for write)
273
+ 2. No access to private repository
274
+ 3. Organization permissions insufficient
275
+
276
+ **Solutions:**
277
+ 1. Ensure token has write permissions
278
+ 2. Check token type at https://huggingface.co/settings/tokens
279
+ 3. Verify access to target repository
280
+ 4. Use organization token if needed
281
+
282
+ **Check token permissions:**
283
+ ```python
284
+ from huggingface_hub import whoami
285
+
286
+ user_info = whoami()
287
+ print(f"User: {user_info['name']}")
288
+ print(f"Type: {user_info.get('type', 'user')}")
289
+ ```
290
+
291
+ ### Error: Token not found in environment
292
+
293
+ **Symptoms:**
294
+ ```
295
+ KeyError: 'HF_TOKEN'
296
+ ValueError: HF_TOKEN not found
297
+ ```
298
+
299
+ **Causes:**
300
+ 1. `secrets` not passed in job config
301
+ 2. Wrong key name (should be `HF_TOKEN`)
302
+ 3. Using `env` instead of `secrets`
303
+
304
+ **Solutions:**
305
+ 1. Use `secrets={"HF_TOKEN": "$HF_TOKEN"}` (not `env`)
306
+ 2. Verify key name is exactly `HF_TOKEN`
307
+ 3. Check job config syntax
308
+
309
+ **Correct configuration:**
310
+ ```python
311
+ # ✅ Correct
312
+ hf_jobs("uv", {
313
+ "script": "...",
314
+ "secrets": {"HF_TOKEN": "$HF_TOKEN"}
315
+ })
316
+
317
+ # ❌ Wrong - using env instead of secrets
318
+ hf_jobs("uv", {
319
+ "script": "...",
320
+ "env": {"HF_TOKEN": "$HF_TOKEN"} # Less secure
321
+ })
322
+
323
+ # ❌ Wrong - wrong key name
324
+ hf_jobs("uv", {
325
+ "script": "...",
326
+ "secrets": {"TOKEN": "$HF_TOKEN"} # Wrong key
327
+ })
328
+ ```
329
+
330
+ ### Error: Repository access denied
331
+
332
+ **Symptoms:**
333
+ ```
334
+ 403 Client Error: Forbidden
335
+ Repository not found or access denied
336
+ ```
337
+
338
+ **Causes:**
339
+ 1. Token doesn't have access to private repo
340
+ 2. Repository doesn't exist and can't be created
341
+ 3. Wrong namespace
342
+
343
+ **Solutions:**
344
+ 1. Use token from account with access
345
+ 2. Verify repo visibility (public vs private)
346
+ 3. Check namespace matches token owner
347
+ 4. Create repo first if needed
348
+
349
+ **Check repository access:**
350
+ ```python
351
+ from huggingface_hub import HfApi
352
+
353
+ api = HfApi()
354
+ try:
355
+ repo_info = api.repo_info("username/repo-name")
356
+ print(f"✅ Access granted: {repo_info.id}")
357
+ except Exception as e:
358
+ print(f"❌ Access denied: {e}")
359
+ ```
360
+
361
+ ## Token Security Best Practices
362
+
363
+ ### 1. Never Commit Tokens
364
+
365
+ **❌ Bad:**
366
+ ```python
367
+ # Never do this!
368
+ token = "hf_abc123xyz..."
369
+ api = HfApi(token=token)
370
+ ```
371
+
372
+ **✅ Good:**
373
+ ```python
374
+ # Use environment variable
375
+ token = os.environ.get("HF_TOKEN")
376
+ api = HfApi(token=token)
377
+ ```
378
+
379
+ ### 2. Use Secrets, Not Environment Variables
380
+
381
+ **❌ Bad:**
382
+ ```python
383
+ hf_jobs("uv", {
384
+ "script": "...",
385
+ "env": {"HF_TOKEN": "$HF_TOKEN"} # Visible in logs
386
+ })
387
+ ```
388
+
389
+ **✅ Good:**
390
+ ```python
391
+ hf_jobs("uv", {
392
+ "script": "...",
393
+ "secrets": {"HF_TOKEN": "$HF_TOKEN"} # Encrypted server-side
394
+ })
395
+ ```
396
+
397
+ ### 3. Use Automatic Token Replacement
398
+
399
+ **❌ Bad:**
400
+ ```python
401
+ hf_jobs("uv", {
402
+ "script": "...",
403
+ "secrets": {"HF_TOKEN": "hf_abc123..."} # Hardcoded
404
+ })
405
+ ```
406
+
407
+ **✅ Good:**
408
+ ```python
409
+ hf_jobs("uv", {
410
+ "script": "...",
411
+ "secrets": {"HF_TOKEN": "$HF_TOKEN"} # Automatic
412
+ })
413
+ ```
414
+
415
+ ### 4. Rotate Tokens Regularly
416
+
417
+ - Generate new tokens periodically
418
+ - Revoke old tokens
419
+ - Update job configurations
420
+ - Monitor token usage
421
+
422
+ ### 5. Use Minimal Permissions
423
+
424
+ - Create tokens with only needed permissions
425
+ - Use read tokens when write isn't needed
426
+ - Don't use admin tokens for regular jobs
427
+
428
+ ### 6. Don't Share Tokens
429
+
430
+ - Each user should use their own token
431
+ - Don't commit tokens to repositories
432
+ - Don't share tokens in logs or messages
433
+
434
+ ### 7. Monitor Token Usage
435
+
436
+ - Check token activity in Hub settings
437
+ - Review job logs for token issues
438
+ - Set up alerts for unauthorized access
439
+
440
+ ## Token Workflow Examples
441
+
442
+ ### Example 1: Push Model to Hub
443
+
444
+ ```python
445
+ hf_jobs("uv", {
446
+ "script": """
447
+ # /// script
448
+ # dependencies = ["transformers"]
449
+ # ///
450
+
451
+ import os
452
+ from transformers import AutoModel, AutoTokenizer
453
+
454
+ # Verify token
455
+ assert "HF_TOKEN" in os.environ, "HF_TOKEN required!"
456
+
457
+ # Load and process model
458
+ model = AutoModel.from_pretrained("base-model")
459
+ # ... process model ...
460
+
461
+ # Push to Hub (token auto-detected)
462
+ model.push_to_hub("username/my-model")
463
+ print("✅ Model pushed!")
464
+ """,
465
+ "flavor": "a10g-large",
466
+ "timeout": "2h",
467
+ "secrets": {"HF_TOKEN": "$HF_TOKEN"} # ✅ Token provided
468
+ })
469
+ ```
470
+
471
+ ### Example 2: Access Private Dataset
472
+
473
+ ```python
474
+ hf_jobs("uv", {
475
+ "script": """
476
+ # /// script
477
+ # dependencies = ["datasets"]
478
+ # ///
479
+
480
+ import os
481
+ from datasets import load_dataset
482
+
483
+ # Verify token
484
+ assert "HF_TOKEN" in os.environ, "HF_TOKEN required!"
485
+
486
+ # Load private dataset (token auto-detected)
487
+ dataset = load_dataset("private-org/private-dataset")
488
+ print(f"✅ Loaded {len(dataset)} examples")
489
+ """,
490
+ "flavor": "cpu-basic",
491
+ "timeout": "30m",
492
+ "secrets": {"HF_TOKEN": "$HF_TOKEN"} # ✅ Token provided
493
+ })
494
+ ```
495
+
496
+ ### Example 3: Create and Push Dataset
497
+
498
+ ```python
499
+ hf_jobs("uv", {
500
+ "script": """
501
+ # /// script
502
+ # dependencies = ["datasets", "huggingface-hub"]
503
+ # ///
504
+
505
+ import os
506
+ from datasets import Dataset
507
+ from huggingface_hub import HfApi
508
+
509
+ # Verify token
510
+ assert "HF_TOKEN" in os.environ, "HF_TOKEN required!"
511
+
512
+ # Create dataset
513
+ data = {"text": ["Sample 1", "Sample 2"]}
514
+ dataset = Dataset.from_dict(data)
515
+
516
+ # Push to Hub
517
+ api = HfApi() # Auto-detects HF_TOKEN
518
+ dataset.push_to_hub("username/my-dataset")
519
+ print("✅ Dataset pushed!")
520
+ """,
521
+ "flavor": "cpu-basic",
522
+ "timeout": "30m",
523
+ "secrets": {"HF_TOKEN": "$HF_TOKEN"} # ✅ Token provided
524
+ })
525
+ ```
526
+
527
+ ## Quick Reference
528
+
529
+ ### Token Checklist
530
+
531
+ Before submitting a job that uses Hub:
532
+
533
+ - [ ] Job includes `secrets={"HF_TOKEN": "$HF_TOKEN"}`
534
+ - [ ] Script checks for token: `assert "HF_TOKEN" in os.environ`
535
+ - [ ] Token has required permissions (read/write)
536
+ - [ ] User is logged in: `hf_whoami()` works
537
+ - [ ] Token not hardcoded in script
538
+ - [ ] Using `secrets` not `env` for token
539
+
540
+ ### Common Patterns
541
+
542
+ **Pattern 1: Auto-detect token**
543
+ ```python
544
+ from huggingface_hub import HfApi
545
+ api = HfApi() # Uses HF_TOKEN from environment
546
+ ```
547
+
548
+ **Pattern 2: Explicit token**
549
+ ```python
550
+ import os
551
+ from huggingface_hub import HfApi
552
+ api = HfApi(token=os.environ.get("HF_TOKEN"))
553
+ ```
554
+
555
+ **Pattern 3: Verify token**
556
+ ```python
557
+ import os
558
+ assert "HF_TOKEN" in os.environ, "HF_TOKEN required!"
559
+ ```
560
+
561
+ ## Key Takeaways
562
+
563
+ 1. **Always use `secrets={"HF_TOKEN": "$HF_TOKEN"}`** for Hub operations
564
+ 2. **Never hardcode tokens** in scripts or job configs
565
+ 3. **Verify token exists** in script before Hub operations
566
+ 4. **Use auto-detection** when possible (`HfApi()` without token parameter)
567
+ 5. **Check permissions** - ensure token has required access
568
+ 6. **Monitor token usage** - review activity regularly
569
+ 7. **Rotate tokens** - generate new tokens periodically
570
+