gr.Server + client.submit() over WebRTC

From gradio-app/gradio#13965 (the Blocks version is here): the endpoints are ordinary @app.api() functions with transport="webrtc", the media marked by gr.VideoFrame / gr.AudioChunk type hints, and this plain HTML page calls them with client.submit(), passing a MediaStream. The media sent back arrives as a MediaStream in its output's slot of msg.data.

@app.api(name="flip", transport=gr.WebRTCOptions(rtc_configuration=turn_credentials))
def flip(frame: gr.VideoFrame, brightness: float) -> tuple[gr.VideoFrame, float]: ...

const job = client.submit("/flip", { frame: media, brightness: 1.0 });
for await (const msg of job) { if (msg.type === "data") { const [video, mean] = msg.data; ... } }
job.send_chunk({ data: [null, 1.5] });   // change brightness mid-stream
job.close_stream();

Sign in first: TURN credentials are issued with your own Hugging Face account.

Each endpoint allows one stream at a time, for at most 30 s; a second tab shows its place in line.

Video: flip(frame, brightness)

Brightness

Mean brightness: -

idle

Audio: Echo (an AsyncStreamHandler)

Frames received: -

idle

Receive: gradient(speed) (a generator)

Speed

Seconds: -

idle