|
| 1 | +--- |
| 2 | +name: huggingface-spaces |
| 3 | +description: Find and call Hugging Face Spaces to generate AI artifacts (images, audio, 3D models, etc). Uses semantic search to discover Spaces, then calls their Gradio APIs. |
| 4 | +user-invocable: true |
| 5 | +allowed-tools: Bash WebFetch Read Write |
| 6 | +argument-hint: <prompt describing what to generate> |
| 7 | +--- |
| 8 | + |
| 9 | +# Hugging Face Spaces Tool |
| 10 | + |
| 11 | +You have access to thousands of AI apps hosted on Hugging Face Spaces. Use them to generate artifacts like images, audio, 3D models, videos, text, and more. |
| 12 | + |
| 13 | +## Authentication |
| 14 | + |
| 15 | +Install the latest `hf` CLI and log in: |
| 16 | + |
| 17 | +```bash |
| 18 | +curl -LsSf https://hf.co/cli/install.sh | bash |
| 19 | +hf auth login |
| 20 | +``` |
| 21 | + |
| 22 | +Always include the user's HF token in API requests: |
| 23 | +- **REST calls**: `Authorization: Bearer $(hf auth token)` |
| 24 | +- **Python client**: `Client("space-url", hf_token=subprocess.check_output(["hf", "auth", "token"]).decode().strip())` |
| 25 | + |
| 26 | +## Workflow |
| 27 | + |
| 28 | +### Step 1: Find the right Space |
| 29 | + |
| 30 | +Use the `hf` CLI to search for a Space matching the user's request: |
| 31 | + |
| 32 | +```bash |
| 33 | +hf spaces search --sdk gradio "<search query>" |
| 34 | +``` |
| 35 | + |
| 36 | +- Always filter by `--sdk gradio` (only Gradio spaces have callable APIs) |
| 37 | +- The output lists Space IDs sorted by relevance with descriptions |
| 38 | +- Prefer spaces that are running and have high trending scores |
| 39 | +- The space domain is derived from the `id`: `owner-spacename.hf.space` (replace `/` with `-`, lowercase) |
| 40 | + |
| 41 | +### Step 2: Call the Space |
| 42 | + |
| 43 | +Fetch the Space's `agents.md` and follow its instructions to call the Space: |
| 44 | + |
| 45 | +```bash |
| 46 | +curl https://huggingface.co/spaces/<owner>/<spacename>/agents.md |
| 47 | +``` |
| 48 | + |
| 49 | +This returns a Markdown document with everything needed to call the Space: available endpoints, parameters, input/output types, and usage examples — purpose-built for agents like this one. |
| 50 | + |
| 51 | +### Step 3: Handle the output |
| 52 | + |
| 53 | +- **Files (images, audio, 3D models)**: Download from the returned URL and save locally |
| 54 | +- **Open/play the result**: Use `open <file>` (macOS) or `afplay <file>` (audio) |
| 55 | +- File URLs from Gradio look like: `https://<space>.hf.space/gradio_api/file=<path>` |
| 56 | + |
| 57 | +## Tips |
| 58 | + |
| 59 | +- Read `agents.md` carefully — it often documents exact parameter names, accepted values, and example calls |
| 60 | +- For the Python client, use `handle_file("/path/to/file")` or `handle_file("https://url")` for file/image inputs |
| 61 | +- ZeroGPU spaces have usage quotas — if you get "GPU quota exceeded", wait or try another space |
| 62 | +- Multi-step pipelines (e.g., image-to-3D) often require session state — use the Python client |
| 63 | +- If a user provides a specific Space URL, skip the search step and use it directly |
| 64 | + |
| 65 | +## Examples |
| 66 | + |
| 67 | +**User says**: "generate an image of a sunset" |
| 68 | +1. Search: `hf spaces search --sdk gradio "text to image generation"` |
| 69 | +2. Pick a top result (e.g., `mrfakename/Z-Image-Turbo`) |
| 70 | +3. Fetch `agents.md`, follow its instructions, download and open the result |
| 71 | + |
| 72 | +**User says**: "convert this image to 3D" |
| 73 | +1. Search: `hf spaces search --sdk gradio "image to 3d model"` |
| 74 | +2. Pick a result (e.g., a Trellis space) |
| 75 | +3. Fetch `agents.md` and follow its instructions |
| 76 | + |
| 77 | +**User says**: "say hello world in speech" |
| 78 | +1. Search: `hf spaces search --sdk gradio "text to speech"` |
| 79 | +2. Pick a TTS space, call the generate endpoint, download and play the audio |
0 commit comments