Crealink's picture
Extend README with clear browser walkthrough manual
f02188b verified
|
Raw History Blame Contribute Delete
7.25 kB

A newer version of the Gradio SDK is available: 6.29.1

Upgrade
metadata
title: Spaces as Agent Tools
emoji: πŸ€–
colorFrom: blue
colorTo: purple
sdk: gradio
sdk_version: 5.33.0
app_file: app.py
pinned: false
license: mit
tags:
  - agents
  - mcp
  - spaces-api
  - demo
short_description: Use any HF Space as a coding agent tool via agents.md

πŸ€– Spaces as Agent Tools

Every Gradio Space on Hugging Face exposes a plain-text agents.md that coding agents (Claude Code, Codex, OpenCode, Pi, etc.) can call directly β€” no client library, no hardcoded integration.

This Space is both a live demo you can use in the browser and a reference guide you can copy into your agent.


πŸ–₯️ Browser Walkthrough

What you need

Step-by-step

1. Open the Space

Go to β–Ά Open the demo in your browser.

You'll see three tabs at the top: πŸ” Explore a Space, ⛓️ Chain: Text β†’ Image β†’ 3D, and πŸ“‹ curl Reference.


2. πŸ” Explore a Space (works immediately β€” no token needed)

This tab lets you inspect any Gradio Space's agent interface.

  1. The Space ID field is pre-filled with black-forest-labs/flux-klein-9b-kv
  2. Click πŸ” Explore
  3. You'll see three things:
    • agents.md β€” the exact 4-line text a coding agent reads to know how to call this Space
    • curl command β€” copy-paste this into Claude Code, Codex, or any terminal
    • API Endpoints β€” every function the Space exposes, with parameter names, types, and defaults

Try it: Click one of the example buttons below the input (e.g. microsoft/TRELLIS.2 or Qwen/Qwen3-ASR) to explore other Spaces.

Tip: You can type any Gradio Space ID here β€” not just the examples. Try one of your own Spaces!


3. ⛓️ Chain: Text β†’ Image β†’ 3D (requires one-time token setup)

This tab demonstrates chaining two Spaces β€” the same thing a coding agent does behind the scenes, but visible step by step.

One-time setup (2 minutes):

Since this demo calls GPU-powered Spaces on your behalf, it needs your Hugging Face token.

  1. Create a token (if you don't have one):

    • Go to huggingface.co/settings/tokens
    • Click Create new token
    • Name it anything (e.g. "spaces-demo")
    • Type: Read is enough
    • Click Create token and copy it
  2. Add the token to this Space:

    • Go to βš™οΈ Space Settings
    • Scroll down to Variables and secrets
    • Click New secret
    • Name: HF_TOKEN
    • Value: paste your token
    • Click Save
    • The Space will restart automatically (takes ~30 seconds)

Using the chain demo:

  1. Switch to the ⛓️ Chain: Text β†’ Image β†’ 3D tab
  2. Type a prompt (or keep the default: "a glowing crystal dragon perched on a rocky mountain peak")
  3. Click πŸš€ Generate
  4. Watch the pipeline log at the bottom as it:
    • Calls FLUX Klein 9B to generate an image from your text
    • Sends that image to TRELLIS.2 for background removal
    • Generates a 3D model from the image
    • Extracts a downloadable .GLB mesh
  5. The generated image appears on the left, the 3D preview on the right, and the GLB download below

⏱️ The full pipeline takes about 1–3 minutes depending on queue times.

πŸ’‘ This is the exact same REST protocol (POST β†’ poll SSE) that a coding agent uses. The log shows you every step.


4. πŸ“‹ curl Reference (no token needed)

This tab is a full copy-paste cheatsheet. It covers:

  • How to read any Space's agents.md
  • How to inspect the API schema
  • How to submit a job and poll for results
  • How to chain FLUX β†’ TRELLIS.2 end to end
  • A Python gradio_client alternative
  • Authentication tiers and quotas

For coding agent users: Copy the curl commands from this tab directly into your agent's context.


πŸ”‘ How agents.md works

Every Gradio Space automatically exposes a URL:

https://huggingface.co/spaces/{owner}/{name}/agents.md

The response is always 4 lines of plain text:

To use this application (owner/name: description):
API schema: GET https://owner-name.hf.space/gradio_api/info
Call endpoint: POST https://owner-name.hf.space/gradio_api/call/{endpoint} {"data": [...]}
Poll result: GET https://owner-name.hf.space/gradio_api/call/{endpoint}/{event_id}
Auth: Bearer $HF_TOKEN

A coding agent reads this, fetches the schema to learn the parameters, and then makes standard HTTP calls. That's it.


πŸ”— From any Space's UI

You don't need this demo to use agent tools. On any compatible Space page:

  1. Look for the Agents button in the Space header
  2. Click it β†’ the curl command is copied to your clipboard
  3. Paste it into your coding agent (Claude Code, Codex, OpenCode, etc.)

⛓️ Chaining β€” why this is powerful

An agent can compose Spaces like building blocks:

Step Space Input Output
1 FLUX Klein 9B text prompt image
2 TRELLIS.2 image 3D model (.GLB)

The image URL from step 1 is passed directly as input to step 2. No file download, no SDK, no glue code β€” just HTTP.

Other possible chains:

  • Text β†’ Image β†’ Video (FLUX β†’ video generation Space)
  • Audio β†’ Text β†’ Translation (ASR Space β†’ translation Space)
  • Image β†’ Caption β†’ Image (captioning Space β†’ image gen Space)

πŸ“‹ Popular Spaces to try

Space What it does Try it
FLUX Klein 9B Text β†’ Image curl https://huggingface.co/spaces/black-forest-labs/flux-klein-9b-kv/agents.md
FLUX.2 Klein 9B Text β†’ Image (v2) curl https://huggingface.co/spaces/black-forest-labs/FLUX.2-klein-9B/agents.md
TRELLIS.2 Image β†’ 3D Model curl https://huggingface.co/spaces/microsoft/TRELLIS.2/agents.md
Qwen3 ASR Audio β†’ Text curl https://huggingface.co/spaces/Qwen/Qwen3-ASR/agents.md
Z-Image Turbo Text β†’ Image (fast) curl https://huggingface.co/spaces/mrfakename/Z-Image-Turbo/agents.md

Find more on huggingface.co/spaces β€” any Gradio Space has an agents.md.


πŸ” Authentication tiers

Tier ZeroGPU quota How to get it
No token 2 min/day β€”
Free account 3.5 min/day Sign up
PRO account 25 min/day Upgrade

Get your token at: huggingface.co/settings/tokens