react-native-executorch
Version:
An easy way to run AI models in React Native with ExecuTorch
19 lines (18 loc) • 803 B
JavaScript
;
import { ResourceFetcher } from '../../utils/ResourceFetcher';
import { ETError, getError } from '../../Error';
import { BaseModule } from '../BaseModule';
export class ImageEmbeddingsModule extends BaseModule {
async load(model, onDownloadProgressCallback = () => {}) {
const paths = await ResourceFetcher.fetch(onDownloadProgressCallback, model.modelSource);
if (paths === null || paths.length < 1) {
throw new Error('Download interrupted.');
}
this.nativeModule = global.loadImageEmbeddings(paths[0] || '');
}
async forward(imageSource) {
if (this.nativeModule == null) throw new Error(getError(ETError.ModuleNotLoaded));
return new Float32Array(await this.nativeModule.generate(imageSource));
}
}
//# sourceMappingURL=ImageEmbeddingsModule.js.map