Files
microduck/spaces/hello
Pierre Rouanet 4e3506b8d4 vision-demo receives the frames instead of pulling them, and six findings about Spaces
The Space is the other half of `media.stream`: FastAPI owns the server, the robot
dials `wss://…/frames`, `av` decodes the access units and OpenCV runs over each
picture — **on Hugging Face hardware**, which was the point of the whole exercise.
The browser only ever receives the processed frame as an image.

Its WebRTC consumer is gone, and with it `aiortc`, the DTLS cipher shim over one
of their private methods, and the ICE stack that could never complete from a data
centre. What is left is `gradio`, `fastapi`, `opencv`, `requests` and `av` — a
decoder rather than a transport.

Frames are filed per account: the endpoint is public, so the robot presents its
own token and this resolves it through `whoami-v2`, exactly as the rendezvous
does. Without that anybody could push frames into the demo and, worse, a visitor
could be shown a stranger's camera.

`fake_duck.py` is the robot's whole side in Python — registers as a producer,
answers `rpc` envelopes, pushes H.264 from the webcam — which is what makes a
deployed Space testable with no board. Verified from a phone on 4G: duck at home,
Space in a data centre, viewer on mobile data, no network in common.

**Six things about Docker Spaces that each cost a round trip**, written down
because none is guessable and every one presented as something else:

- **`SYSTEM=spaces` is what Gradio checks**, not `SPACE_ID`. `get_space()` is
  `os.getenv("SYSTEM") == "spaces"`, Hugging Face sets it for gradio-SDK Spaces
  and not for Docker ones, so Gradio installs its *mocked* OAuth routes and the
  mock raises without a local `hf auth login`. The module then fails at import.
- **`git` must be installed.** Their builder appends `git config --global` to
  every Docker Space; a `-slim` base dies with exit 127 *after* the image built
  fine, reported as a page of cache-miss noise naming one of their own steps.
- **The user must be `user` at `/home/user`.** Their appended layers assume it.
- **`gradio[oauth]`, not `gradio`** — the extra is what carries `itsdangerous`
  and `authlib`, and without them a Space with `hf_oauth: true` fails at import.
- **A crash reports one truncated line, and reading a Space's logs needs write
  access to it.** So `boot.py` imports the app in a `try` and *serves the
  traceback* on the expected port when it cannot; `/env` reports which platform
  variables arrived. Those two are what ended four rounds of blaming the port for
  an import error.
- **Safari drops the OAuth session cookie** as third-party, because a Space runs
  in an iframe. The token box is therefore always offered, and the Space's own
  `.hf.space` URL works too.

`spaces/hello` is the baseline that proved the platform rather than the app:
Docker, FastAPI, one WebSocket route, Gradio mounted, no OAuth. Publish it into a
Space that will not start and it says which of the four is at fault.

One efficiency fix that was mistaken for a Safari bug: the timer polled ten times
a second for a five-frame-a-second stream and re-shipped four hundred log lines
every second, so half the responses re-encoded a picture the page already had.
`render` returns `gr.skip()` when the frame has not changed — 19 of 20 idle polls
now send nothing.

Assisted-by: Claude:claude-opus-5[1m]
2026-09-08 18:21:09 +02:00
..

title, emoji, colorFrom, colorTo, sdk, app_port, pinned, short_description
title emoji colorFrom colorTo sdk app_port pinned short_description
hello duck 🦆 yellow indigo docker 7860 false Smallest Docker Space that has a WebSocket route and Gradio.

hello duck

A deliberately minimal Docker Space, published to find out which of four things breaks the real one: the container, a custom WebSocket route, Gradio mounted under FastAPI, or Hugging Face OAuth.

It has the first three and not OAuth, which is where the last crash was. Grow it back one piece at a time rather than debugging four at once.