create method
Future<Object>
create({
- required ModelSource source,
- int cpuThreadNum = 4,
- CpuPower cpuPower = CpuPower.high,
- bool useOpenCL = false,
override
Loads models and returns an opaque engine handle.
Implementation
@override
Future<Object> create({
required ModelSource source,
int cpuThreadNum = 4,
CpuPower cpuPower = CpuPower.high,
bool useOpenCL = false,
}) async {
final bundled = switch (source) {
BundledModelSource s => s,
FilePathsModelSource() => throw UnsupportedError(
'Web only supports ModelSource.bundled. paddleocr-js fetches models '
'itself — no file paths needed.',
),
};
await _waitForSdk();
// onnxruntime-web can't infer its WASM path when paddleocr-js is bundled
// into a single script, so point it at the published CDN build.
final options = _Options(
lang: bundled.lang,
ocrVersion: bundled.version,
ortOptions: _OrtOptions(
wasmPaths: 'https://cdn.jsdelivr.net/npm/onnxruntime-web@1.24.3/dist/',
),
);
final ocr = await _paddleOcrSdk.create(options).toDart;
return ocr;
}