Clef-flash running locally on a live webcam feed

Luis CatacoraOct 131 stars on GitHubWeek 40 final: #121

Run Cloudflare's clef-flash decision model locally on your webcam

lucataco/clef-webcamReadme
# clef-flash on your webcam

Run [clef-flash](https://huggingface.co/Cloudflare/clef-flash), Cloudflare's open-weight decision model, locally on a Mac and turn your webcam into typed decisions with probabilities.

A decision model doesn't generate text. You give it a state (here, a webcam frame) and a schema of questions, and it returns a probability for every allowed answer in one forward pass. [Read the announcement](https://blog.cloudflare.com/clef-decision-models/).

## Quickstart

You need an Apple Silicon Mac with 32 GB+ of memory (the model is ~19 GB) and [uv](https://docs.astral.sh/uv/).

```sh
uv sync
uv run hf download Cloudflare/clef-flash --local-dir models/clef-flash
uv run uvicorn server:app --port 8787
```

Open http://localhost:8787 and allow camera access.

## Controls

| Key | Action |
| --- | --- |
| `E` | Edit the questions. They apply live, no retraining |
| `space` | Pause |
| `shift` + `R` | Reset to the default questions |

## Asking your own questions

Questions use the same schema as `@cf/cloudflare/clef` on Workers AI (and Jev / SystemOne):

```json
{
  "wearing_glasses": { "type": "noul", "instructions": "Wearing glasses?" },
  "mood": { "type": "choice", "criteria": { "happy": null, "neutral": null, "tired": null } },
  "energy": { "type": "score", "criteria": ["low", "medium", "high"] }
}
```

- `noul`: yes or no
- `choice`: pick one option. Descriptions are optional (`null`)
- `score`: an ordered scale

Latency grows with prompt length, so short instructions and few options keep it snappy.

## Performance

Measured on an M5 Max with `uv run python bench.py`, which also checks that the optimized model gives the same answers as the reference:

| Request | transformers on MPS | This repo |
| --- | --- | --- |
| Text, 3 questions | 566 ms | 155 ms |
| Webcam frame, 3 questions | 840 ms | 250 ms |

On a Mac, Qwen3.5's linear-attention layers fall back to a slow reference implementation, because the fast kernels are CUDA-only. Most of that time goes to `torch.linalg.solve_triangular`. [`mps_kernels.py`](mps_kernels.py) computes the same thing with batched block inversion, which Apple GPUs handle well. It is patched in automatically on MPS and CPU, and left alone on CUDA.

## Files

| File | |
| --- | --- |
| `server.py` | API: webcam frame + questions → decisions |
| `index.html` | The live demo page |
| `clef.py` | Model loading and timing |
| `mps_kernels.py` | Faster linear attention for Apple Silicon |
| `bench.py` | Speed and accuracy check |

`joint_schema_model.py` (Clef's reference inference code) is downloaded with the model.

## Settings

| Variable | Default | |
| --- | --- | --- |
| `CLEF_MODEL_DIR` | `models/clef-flash` | Where the model lives |
| `CLEF_MAX_SIDE` | `336` | Longest side of the frame sent to the model, in pixels |

## License

This code is [Apache 2.0](LICENSE) licensed, and so is the [clef-flash model](https://huggingface.co/Cloudflare/clef-flash).
Preview of Clef-flash running locally on a live webcam feed
See all
  1. Cloudflare just released Clef, an open-weight decision model that uses the exact same API as Jev, so we ran 200 real comments from our channel through both and had Claude Opus 5.5 referee the results. Jev was faster and cheaper, but Clef came within 3 points on accuracy and…

  2. #jev #clef #ai Jev just got some serious open-source competition. Meet Clef, a new model that beats Jev on the benchmarks. It's built on Qwen-3.8 27B, and there's a faster Flash version based on Qwen-3.5-9B for when speed matters most. Best of all, it understands images, which…

    CoderOneYouTube19.6K views
  3. Thirty-eight point eight milliseconds — a median, not a best case. Cloudflare published it for Clef-flash, one of two open-source decision models it announced on October 1, 2026. In the same latency table, Jev from Typesafe AI sits at 524.1 ms. Roughly thirteen times. A…

  4. Cloudflare just entered the decision model war. Clef and Clef-flash are open-source AI models that answer typed questions in milliseconds — no text generation at all. We break down the benchmarks vs TypeSafe's Jev, the API, the RL fine-tuning platform, and the pricing catch…

The Monday email

  • The week's best AI builds and who made them
  • New model releases and what people built with them
  • No spam. One click to leave.

Sign in once and you're on the list.