--- 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 `` 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=/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//transformers-playground/raw/main/indexer.py -o indexer.py && \ python indexer.py --push /transformers-snippets" ```