Live demo | Full example on GitHub
Adding AI to an app often means an account, an API key, a bill for every request, and sending your users' data to someone else's server.
For many jobs you need none of that. A small model can run on the visitor's own device, in the browser, from C#.
We will build a page that names what is in a photo. The photo is never uploaded. You need the .NET 10 SDK and a browser.
The model
A model is a file. This one is MobileNetV2, a 14 MB image recognition network from the ONNX Model Zoo (Apache-2.0). It knows 1,000 kinds of things, from dog breeds to kitchen tools.
SpawnDev.ILGPU.ML reads the file and runs it on the GPU. It uses WebGPU when the browser has it, then WebGL, then WebAssembly.
Set up
dotnet new blazorwasm -o ImageAI --empty cd ImageAI dotnet add package SpawnDev.ILGPU.ML dotnet add package SpawnDev.SpawnJS dotnet add package SpawnDev.SpawnJS.Blazor
Enter fullscreen mode
Exit fullscreen mode
Download mobilenetv2-7.onnx into wwwroot .…