ysharma HF Staff commited on
Commit
5ff721f
·
verified ·
1 Parent(s): 8924e29

Workflow1111 — Automatic1111-style diffusion studio on gr.Workflow

Browse files
Files changed (2) hide show
  1. README.md +29 -17
  2. nodes.py +10 -5
README.md CHANGED
@@ -349,32 +349,44 @@ endpoint list with parameter names and types.
349
 
350
  The Space holds **no** `HF_TOKEN` secret. In the browser, the Sign-in button
351
  supplies your token through OAuth; every other caller sends it on the request.
352
- Two hooks make that work:
 
 
 
353
 
354
- * every node that talks to Inference Providers declares a `request: gr.Request`
355
- parameter, and `_hf_token()` in `nodes.py` resolves the token in this order:
356
- OAuth session → `X-HF-Token` header `X-HF-Authorization: Bearer` header
357
- `Authorization: Bearer` header server `HF_TOKEN` local `hf auth login`;
358
- * `app.py` extends gradio's own `_resolve_token` (used for `model` and `space`
359
- nodes, which gradio runs itself) with the same header fallback.
360
-
361
- `gradio_client` sends your token as `X-HF-Authorization` (it renames the
362
- `Authorization` header so the Hub proxy never sees it), so the ordinary
363
- `token=` argument just works — and so does the locally saved `hf auth login`
364
- token, which the client sends by default:
365
 
366
  ```python
367
  from gradio_client import Client
368
 
369
- client = Client("https://ysharma-workflow1111.hf.space") # uses `hf auth login` token
370
- client = Client("https://ysharma-workflow1111.hf.space", token="hf_...")
371
- prompt = client.predict("an orange cat with a yellow hat", api_name="/generated_prompt")
 
 
 
 
 
 
 
 
 
372
  ```
373
 
374
- From the terminal (needs `typer>=0.15`; `gradio info <url>` prints the payload shapes):
 
 
 
 
 
 
375
 
376
  ```bash
377
- gradio predict https://ysharma-workflow1111.hf.space /generated_prompt '{"in_0": "an orange cat with a yellow hat"}'
378
  ```
379
 
380
  MCP clients forward custom headers verbatim, so use `X-HF-Token` there
 
349
 
350
  The Space holds **no** `HF_TOKEN` secret. In the browser, the Sign-in button
351
  supplies your token through OAuth; every other caller sends it on the request.
352
+ Two hooks make that work: each node that hits Inference Providers takes a
353
+ `request: gr.Request` parameter and reads the token in `nodes.py`
354
+ (`_hf_token`), and `app.py` extends gradio's own `_resolve_token` (used for the
355
+ `model`/`space` nodes gradio runs itself) with the same fallback.
356
 
357
+ **Which header to send.** On a Space the Hub proxy passes `X-HF-Token` and
358
+ `Authorization: Bearer` through to the app but **strips `x-hf-authorization`**.
359
+ `gradio_client`'s `token=` argument (and therefore `gradio predict --token`)
360
+ sends the token *as* `x-hf-authorization`, so that path does **not**
361
+ authenticate against this Space use `X-HF-Token` instead:
 
 
 
 
 
 
362
 
363
  ```python
364
  from gradio_client import Client
365
 
366
+ # WORKS token sent as X-HF-Token
367
+ client = Client("https://ysharma-workflow1111.hf.space", headers={"X-HF-Token": "hf_..."})
368
+ client.predict("an orange cat with a yellow hat", api_name="/generated_prompt")
369
+
370
+ # does NOT work on a Space — token goes out as x-hf-authorization (stripped by the proxy)
371
+ # client = Client("https://ysharma-workflow1111.hf.space", token="hf_...")
372
+ ```
373
+
374
+ curl works with either header:
375
+
376
+ ```bash
377
+ curl -s -X POST https://ysharma-workflow1111.hf.space/gradio_api/call/generated_prompt -H "X-HF-Token: hf_..." -H "Content-Type: application/json" -d '{"data": ["an orange cat with a yellow hat"]}'
378
  ```
379
 
380
+ **From the `gradio` CLI.** `gradio info <url>` prints every endpoint's payload
381
+ shape and needs no token. `gradio predict` runs a call, but its only auth knob
382
+ is `--token`, which the proxy strips (above) — so `gradio predict` can reach
383
+ this Space's token-free plumbing but cannot authenticate the model nodes. For a
384
+ scripted authenticated call, use the `gradio_client` `headers={"X-HF-Token"}`
385
+ snippet or curl instead. (`gradio info`/`predict` need `typer>=0.15`; older
386
+ typer crashes with `Type not yet supported: str | None`.)
387
 
388
  ```bash
389
+ gradio info https://ysharma-workflow1111.hf.space
390
  ```
391
 
392
  MCP clients forward custom headers verbatim, so use `X-HF-Token` there
nodes.py CHANGED
@@ -632,11 +632,16 @@ def _caller_hf_token(request):
632
  without the Space holding a token of its own. Two spellings are accepted:
633
 
634
  * ``X-HF-Token: hf_...`` (custom header, e.g. MCP configs)
635
- * ``X-HF-Authorization: Bearer hf_...`` (what ``gradio_client`` and the
636
- ``gradio predict`` CLI send for ``token=`` / ``--token`` / the locally
637
- saved ``hf auth login`` token the client renames ``Authorization``
638
- to this so the Hub proxy never sees it)
639
- * ``Authorization: Bearer hf_...`` (plain HTTP callers)
 
 
 
 
 
640
  """
641
  headers = getattr(request, "headers", None)
642
  if not headers:
 
632
  without the Space holding a token of its own. Two spellings are accepted:
633
 
634
  * ``X-HF-Token: hf_...`` (custom header, e.g. MCP configs)
635
+ * ``Authorization: Bearer hf_...`` (plain HTTP callers, e.g. curl)
636
+ * ``X-HF-Authorization: Bearer hf_...`` (what ``gradio_client`` / the
637
+ ``gradio predict`` CLI send for ``token=`` / ``--token``)
638
+
639
+ NOTE: on Hugging Face Spaces the reverse proxy STRIPS ``x-hf-authorization``
640
+ before it reaches the app, so ``gradio_client(token=...)`` and
641
+ ``gradio predict --token`` do NOT authenticate here — pass ``X-HF-Token``
642
+ (``gradio_client(headers=...)``) or a raw ``Authorization: Bearer`` instead.
643
+ The header is still honored when this app runs OUTSIDE a Space (local / any
644
+ host without that proxy), which is why it stays in the list.
645
  """
646
  headers = getattr(request, "headers", None)
647
  if not headers: