🎥 Make videos programmatically with React
import type * as OnnxRuntimeNode from 'onnxruntime-node';
import {importNodeModule} from './import-node-module';
// A 130-byte multiplication model from ONNX Runtime's test fixtures.
// https://github.com/microsoft/onnxruntime/blob/main/onnxruntime/test/testdata/mul_1.onnx
// Creating a session is enough to make the WebGPU execution provider request an
// adapter, without downloading a Whisper model or running inference.
const webGpuProbeModel = new Uint8Array([
0x08, 0x03, 0x12, 0x06, 0x63, 0x68, 0x65, 0x6e, 0x74, 0x61, 0x3a, 0x70, 0x0a,
0x15, 0x0a, 0x01, 0x58, 0x0a, 0x01, 0x57, 0x12, 0x01, 0x59, 0x1a, 0x05, 0x6d,
0x75, 0x6c, 0x5f, 0x31, 0x22, 0x03, 0x4d, 0x75, 0x6c, 0x12, 0x08, 0x6d, 0x75,
0x6c, 0x20, 0x74, 0x65, 0x73, 0x74, 0x2a, 0x23, 0x08, 0x03, 0x08, 0x02, 0x10,
0x01, 0x22, 0x18, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00,
0x40, 0x40, 0x00, 0x00, 0x80, 0x40, 0x00, 0x00, 0xa0, 0x40, 0x00, 0x00, 0xc0,
0x40, 0x42, 0x01, 0x57, 0x5a, 0x13, 0x0a, 0x01, 0x58, 0x12, 0x0e, 0x0a, 0x0c,
0x08, 0x01, 0x12, 0x08, 0x0a, 0x02, 0x08, 0x03, 0x0a, 0x02, 0x08, 0x02, 0x62,
0x13, 0x0a, 0x01, 0x59, 0x12, 0x0e, 0x0a, 0x0c, 0x08, 0x01, 0x12, 0x08, 0x0a,
0x02, 0x08, 0x03, 0x0a, 0x02, 0x08, 0x02, 0x42, 0x04, 0x0a, 0x00, 0x10, 0x07,
]);
export const probeNodeWebGpu = async (): Promise<void> => {
// Keep the native Node.js addon out of browser bundles.
const {InferenceSession} =
await importNodeModule<typeof OnnxRuntimeNode>('onnxruntime-node');
const session = await InferenceSession.create(webGpuProbeModel, {
executionProviders: ['webgpu'],
});
await session.release();
};