File size: 1,783 Bytes
c127c63
76904a5
 
 
 
c127c63
 
 
 
76904a5
 
 
 
 
 
c127c63
 
76904a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
---
title: Transformers Playground
emoji: 🛝
colorFrom: yellow
colorTo: gray
sdk: gradio
sdk_version: 6.30.0
app_file: app.py
pinned: false
hf_oauth: true
hf_oauth_expiration_minutes: 480
hf_oauth_scopes:
  - jobs
  - read-repos
short_description: Copy official transformers snippets or run them on HF Jobs
---

# Transformers Playground

Pick any transformers model on the Hub, get the usage snippets from its
`model_doc` page (adapted to your checkpoint), copy them, or run them on
Hugging Face Jobs with your own account.

## How it works

- `indexer.py` sparse-clones `docs/source/en/model_doc` from transformers,
  extracts the `<hfoptions id="usage">` tabs and usage code blocks, drops
  training and quantization examples (v1 is inference only), and writes
  `snippets.json`.
- `app.py` matches a model's `config.json` `model_type` to its doc page,
  swaps the doc's checkpoint for the selected model, adds a generic
  `pipeline()` snippet from the model's task, and recommends the cheapest
  Jobs flavor that fits the weights (live prices from `list_jobs_hardware`).
- Runs go through `run_job` with the user's OAuth token, so each user pays
  for their own compute. Jobs need a PRO, Team or Enterprise account.

## Setup

1. Create the Space from these files. On first boot it builds the index
   itself (about 30 seconds).
2. Optional but recommended: publish the index as a dataset and refresh it
   nightly, then set a Space variable `INDEX_REPO=<you>/transformers-snippets`.

```bash
hf jobs scheduled run @daily python:3.12 --secrets HF_TOKEN -- bash -c \
  "pip install -q huggingface_hub && \
   curl -sL https://huggingface.co/spaces/<you>/transformers-playground/raw/main/indexer.py -o indexer.py && \
   python indexer.py --push <you>/transformers-snippets"
```