react-native-executorch 0.5.6 → 0.5.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/libs/classes.jar +0 -0
- package/android/src/main/cpp/CMakeLists.txt +23 -14
- package/common/rnexecutorch/RnExecutorchInstaller.cpp +4 -21
- package/common/rnexecutorch/host_objects/ModelHostObject.h +67 -51
- package/common/rnexecutorch/models/llm/LLM.cpp +24 -1
- package/common/rnexecutorch/models/llm/LLM.h +4 -1
- package/common/rnexecutorch/threads/GlobalThreadPool.h +79 -0
- package/common/rnexecutorch/threads/HighPerformanceThreadPool.h +364 -0
- package/common/rnexecutorch/threads/utils/ThreadUtils.h +29 -0
- package/common/runner/runner.cpp +9 -3
- package/common/runner/runner.h +4 -3
- package/common/runner/text_token_generator.h +28 -10
- package/lib/Error.js +53 -0
- package/lib/ThreadPool.d.ts +10 -0
- package/lib/ThreadPool.js +28 -0
- package/lib/common/Logger.d.ts +8 -0
- package/lib/common/Logger.js +19 -0
- package/lib/constants/directories.js +2 -0
- package/lib/constants/llmDefaults.d.ts +6 -0
- package/lib/constants/llmDefaults.js +16 -0
- package/lib/constants/modelUrls.d.ts +223 -0
- package/lib/constants/modelUrls.js +322 -0
- package/lib/constants/ocr/models.d.ts +882 -0
- package/lib/constants/ocr/models.js +182 -0
- package/lib/constants/ocr/symbols.js +139 -0
- package/lib/constants/sttDefaults.d.ts +28 -0
- package/lib/constants/sttDefaults.js +68 -0
- package/lib/controllers/LLMController.d.ts +47 -0
- package/lib/controllers/LLMController.js +213 -0
- package/lib/controllers/OCRController.js +67 -0
- package/lib/controllers/SpeechToTextController.d.ts +56 -0
- package/lib/controllers/SpeechToTextController.js +349 -0
- package/lib/controllers/VerticalOCRController.js +70 -0
- package/lib/hooks/computer_vision/useClassification.d.ts +15 -0
- package/lib/hooks/computer_vision/useClassification.js +7 -0
- package/lib/hooks/computer_vision/useImageEmbeddings.d.ts +15 -0
- package/lib/hooks/computer_vision/useImageEmbeddings.js +7 -0
- package/lib/hooks/computer_vision/useImageSegmentation.d.ts +38 -0
- package/lib/hooks/computer_vision/useImageSegmentation.js +7 -0
- package/lib/hooks/computer_vision/useOCR.d.ts +20 -0
- package/lib/hooks/computer_vision/useOCR.js +41 -0
- package/lib/hooks/computer_vision/useObjectDetection.d.ts +15 -0
- package/lib/hooks/computer_vision/useObjectDetection.js +7 -0
- package/lib/hooks/computer_vision/useStyleTransfer.d.ts +15 -0
- package/lib/hooks/computer_vision/useStyleTransfer.js +7 -0
- package/lib/hooks/computer_vision/useVerticalOCR.d.ts +21 -0
- package/lib/hooks/computer_vision/useVerticalOCR.js +43 -0
- package/lib/hooks/general/useExecutorchModule.d.ts +13 -0
- package/lib/hooks/general/useExecutorchModule.js +7 -0
- package/lib/hooks/natural_language_processing/useLLM.d.ts +10 -0
- package/lib/hooks/natural_language_processing/useLLM.js +78 -0
- package/lib/hooks/natural_language_processing/useSpeechToText.d.ts +27 -0
- package/lib/hooks/natural_language_processing/useSpeechToText.js +49 -0
- package/lib/hooks/natural_language_processing/useTextEmbeddings.d.ts +16 -0
- package/lib/hooks/natural_language_processing/useTextEmbeddings.js +7 -0
- package/lib/hooks/natural_language_processing/useTokenizer.d.ts +17 -0
- package/lib/hooks/natural_language_processing/useTokenizer.js +52 -0
- package/lib/hooks/useModule.js +45 -0
- package/lib/hooks/useNonStaticModule.d.ts +20 -0
- package/lib/hooks/useNonStaticModule.js +49 -0
- package/lib/index.d.ts +48 -0
- package/lib/index.js +58 -0
- package/lib/module/controllers/LLMController.js +21 -2
- package/lib/module/controllers/LLMController.js.map +1 -1
- package/lib/module/hooks/natural_language_processing/useLLM.js +6 -2
- package/lib/module/hooks/natural_language_processing/useLLM.js.map +1 -1
- package/lib/module/modules/natural_language_processing/LLMModule.js +7 -2
- package/lib/module/modules/natural_language_processing/LLMModule.js.map +1 -1
- package/lib/module/types/llm.js.map +1 -1
- package/lib/modules/BaseModule.js +25 -0
- package/lib/modules/BaseNonStaticModule.js +14 -0
- package/lib/modules/computer_vision/ClassificationModule.d.ts +8 -0
- package/lib/modules/computer_vision/ClassificationModule.js +17 -0
- package/lib/modules/computer_vision/ImageEmbeddingsModule.d.ts +8 -0
- package/lib/modules/computer_vision/ImageEmbeddingsModule.js +17 -0
- package/lib/modules/computer_vision/ImageSegmentationModule.d.ts +11 -0
- package/lib/modules/computer_vision/ImageSegmentationModule.js +27 -0
- package/lib/modules/computer_vision/OCRModule.d.ts +14 -0
- package/lib/modules/computer_vision/OCRModule.js +17 -0
- package/lib/modules/computer_vision/ObjectDetectionModule.d.ts +9 -0
- package/lib/modules/computer_vision/ObjectDetectionModule.js +17 -0
- package/lib/modules/computer_vision/StyleTransferModule.d.ts +8 -0
- package/lib/modules/computer_vision/StyleTransferModule.js +17 -0
- package/lib/modules/computer_vision/VerticalOCRModule.d.ts +14 -0
- package/lib/modules/computer_vision/VerticalOCRModule.js +19 -0
- package/lib/modules/general/ExecutorchModule.d.ts +7 -0
- package/lib/modules/general/ExecutorchModule.js +14 -0
- package/lib/modules/natural_language_processing/LLMModule.d.ts +28 -0
- package/lib/modules/natural_language_processing/LLMModule.js +45 -0
- package/lib/modules/natural_language_processing/SpeechToTextModule.d.ts +24 -0
- package/lib/modules/natural_language_processing/SpeechToTextModule.js +36 -0
- package/lib/modules/natural_language_processing/TextEmbeddingsModule.d.ts +9 -0
- package/lib/modules/natural_language_processing/TextEmbeddingsModule.js +21 -0
- package/lib/modules/natural_language_processing/TokenizerModule.d.ts +12 -0
- package/lib/modules/natural_language_processing/TokenizerModule.js +30 -0
- package/lib/native/NativeETInstaller.js +2 -0
- package/lib/native/NativeOCR.js +2 -0
- package/lib/native/NativeVerticalOCR.js +2 -0
- package/lib/native/RnExecutorchModules.d.ts +7 -0
- package/lib/native/RnExecutorchModules.js +18 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/types/common.d.ts +32 -0
- package/lib/types/common.js +25 -0
- package/lib/types/imageSegmentation.js +26 -0
- package/lib/types/llm.d.ts +46 -0
- package/lib/types/llm.js +9 -0
- package/lib/types/objectDetection.js +94 -0
- package/lib/types/ocr.js +1 -0
- package/lib/types/stt.d.ts +94 -0
- package/lib/types/stt.js +85 -0
- package/lib/typescript/controllers/LLMController.d.ts +4 -2
- package/lib/typescript/controllers/LLMController.d.ts.map +1 -1
- package/lib/typescript/hooks/natural_language_processing/useLLM.d.ts.map +1 -1
- package/lib/typescript/modules/natural_language_processing/LLMModule.d.ts +4 -2
- package/lib/typescript/modules/natural_language_processing/LLMModule.d.ts.map +1 -1
- package/lib/typescript/types/llm.d.ts +7 -1
- package/lib/typescript/types/llm.d.ts.map +1 -1
- package/lib/utils/ResourceFetcher.d.ts +24 -0
- package/lib/utils/ResourceFetcher.js +305 -0
- package/lib/utils/ResourceFetcherUtils.d.ts +54 -0
- package/lib/utils/ResourceFetcherUtils.js +127 -0
- package/lib/utils/llm.d.ts +6 -0
- package/lib/utils/llm.js +72 -0
- package/lib/utils/stt.js +21 -0
- package/package.json +3 -1
- package/react-native-executorch.podspec +12 -31
- package/src/controllers/LLMController.ts +29 -5
- package/src/hooks/natural_language_processing/useLLM.ts +15 -1
- package/src/modules/natural_language_processing/LLMModule.ts +14 -2
- package/src/types/llm.ts +8 -0
- package/third-party/android/libs/cpuinfo/arm64-v8a/libcpuinfo.so +0 -0
- package/third-party/android/libs/executorch/arm64-v8a/libexecutorch.so +0 -0
- package/third-party/android/libs/executorch/x86_64/libexecutorch.so +0 -0
- package/third-party/android/libs/pthreadpool/arm64-v8a/libpthreadpool.so +0 -0
- package/third-party/android/libs/tokenizers-cpp/arm64-v8a/libsentencepiece.a +0 -0
- package/third-party/android/libs/tokenizers-cpp/arm64-v8a/libtokenizers_c.a +0 -0
- package/third-party/android/libs/tokenizers-cpp/arm64-v8a/libtokenizers_cpp.a +0 -0
- package/third-party/android/libs/tokenizers-cpp/x86_64/libsentencepiece.a +0 -0
- package/third-party/android/libs/tokenizers-cpp/x86_64/libtokenizers_c.a +0 -0
- package/third-party/android/libs/tokenizers-cpp/x86_64/libtokenizers_cpp.a +0 -0
- package/third-party/include/c10/macros/Export.h +2 -86
- package/third-party/include/c10/macros/Macros.h +28 -5
- package/third-party/include/c10/util/BFloat16-inl.h +1 -4
- package/third-party/include/c10/util/BFloat16.h +5 -8
- package/third-party/include/c10/util/Half.h +5 -0
- package/third-party/include/c10/util/bit_cast.h +1 -1
- package/third-party/include/c10/util/complex.h +639 -0
- package/third-party/include/c10/util/complex_math.h +399 -0
- package/third-party/include/c10/util/complex_utils.h +41 -0
- package/third-party/include/c10/util/irange.h +2 -2
- package/third-party/include/c10/util/overflows.h +95 -0
- package/third-party/include/executorch/ExecuTorchError.h +75 -0
- package/third-party/include/executorch/ExecuTorchModule.h +115 -11
- package/third-party/include/executorch/ExecuTorchTensor.h +731 -51
- package/third-party/include/executorch/ExecuTorchValue.h +61 -9
- package/third-party/include/executorch/extension/kernel_util/make_boxed_from_unboxed_functor.h +181 -0
- package/third-party/include/executorch/extension/kernel_util/meta_programming.h +108 -0
- package/third-party/include/executorch/extension/kernel_util/type_list.h +137 -0
- package/third-party/include/executorch/extension/module/bundled_module.h +131 -0
- package/third-party/include/executorch/extension/module/module.h +46 -20
- package/third-party/include/executorch/extension/threadpool/cpuinfo_utils.h +1 -3
- package/third-party/include/executorch/extension/threadpool/threadpool.h +1 -3
- package/third-party/include/executorch/extension/threadpool/threadpool_guard.h +35 -0
- package/third-party/include/executorch/runtime/backend/backend_execution_context.h +3 -3
- package/third-party/include/executorch/runtime/backend/backend_init_context.h +12 -6
- package/third-party/include/executorch/runtime/backend/backend_option_context.h +34 -0
- package/third-party/include/executorch/runtime/backend/interface.h +70 -9
- package/third-party/include/executorch/runtime/backend/options.h +206 -0
- package/third-party/include/executorch/runtime/core/evalue.h +19 -25
- package/third-party/include/executorch/runtime/core/event_tracer.h +32 -17
- package/third-party/include/executorch/runtime/core/event_tracer_hooks.h +23 -14
- package/third-party/include/executorch/runtime/core/exec_aten/exec_aten.h +32 -9
- package/third-party/include/executorch/runtime/core/exec_aten/util/dim_order_util.h +3 -2
- package/third-party/include/executorch/runtime/core/exec_aten/util/scalar_type_util.h +43 -75
- package/third-party/include/executorch/runtime/core/exec_aten/util/tensor_util.h +88 -87
- package/third-party/include/executorch/runtime/core/function_ref.h +100 -0
- package/third-party/include/executorch/runtime/core/named_data_map.h +14 -14
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/macros/Export.h +2 -86
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/macros/Macros.h +28 -5
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/BFloat16-inl.h +1 -4
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/BFloat16.h +5 -8
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/Half.h +5 -0
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/bit_cast.h +1 -1
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/complex.h +639 -0
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/complex_math.h +399 -0
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/complex_utils.h +41 -0
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/irange.h +2 -2
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/overflows.h +95 -0
- package/third-party/include/executorch/runtime/core/portable_type/c10/torch/headeronly/macros/Export.h +88 -0
- package/third-party/include/executorch/runtime/core/portable_type/complex.h +6 -29
- package/third-party/include/executorch/runtime/core/portable_type/tensor_impl.h +20 -0
- package/third-party/include/executorch/runtime/core/span.h +4 -0
- package/third-party/include/executorch/runtime/core/tag.h +19 -0
- package/third-party/include/executorch/runtime/core/tensor_layout.h +2 -2
- package/third-party/include/executorch/runtime/executor/method.h +15 -3
- package/third-party/include/executorch/runtime/executor/method_meta.h +34 -5
- package/third-party/include/executorch/runtime/executor/program.h +3 -4
- package/third-party/include/executorch/runtime/executor/pte_data_map.h +9 -8
- package/third-party/include/executorch/runtime/executor/tensor_parser.h +14 -13
- package/third-party/include/executorch/runtime/kernel/kernel_runtime_context.h +5 -5
- package/third-party/include/executorch/runtime/kernel/operator_registry.h +21 -19
- package/third-party/include/executorch/runtime/platform/compiler.h +8 -0
- package/third-party/include/executorch/runtime/platform/platform.h +126 -0
- package/third-party/include/headeronly/macros/Export.h +88 -0
- package/third-party/include/tokenizers-cpp/tokenizers_c.h +61 -0
- package/third-party/include/torch/headeronly/macros/Export.h +88 -0
- package/third-party/ios/ExecutorchLib.xcframework/Info.plist +43 -0
- package/third-party/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/ExecutorchLib +0 -0
- package/third-party/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/Info.plist +0 -0
- package/third-party/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/ExecutorchLib +0 -0
- package/third-party/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/Info.plist +0 -0
- package/third-party/ios/libs/cpuinfo/libcpuinfo.a +0 -0
- package/third-party/ios/libs/pthreadpool/physical-arm64-release/libpthreadpool.a +0 -0
- package/third-party/ios/libs/pthreadpool/simulator-arm64-debug/libpthreadpool.a +0 -0
- package/ios/libs/executorch/libbackend_coreml_ios.a +0 -0
- package/ios/libs/executorch/libbackend_coreml_simulator.a +0 -0
- package/ios/libs/executorch/libbackend_mps_ios.a +0 -0
- package/ios/libs/executorch/libbackend_mps_simulator.a +0 -0
- package/ios/libs/executorch/libbackend_xnnpack_ios.a +0 -0
- package/ios/libs/executorch/libbackend_xnnpack_simulator.a +0 -0
- package/ios/libs/executorch/libexecutorch_ios.a +0 -0
- package/ios/libs/executorch/libexecutorch_simulator.a +0 -0
- package/ios/libs/executorch/libkernels_custom_ios.a +0 -0
- package/ios/libs/executorch/libkernels_custom_simulator.a +0 -0
- package/ios/libs/executorch/libkernels_optimized_ios.a +0 -0
- package/ios/libs/executorch/libkernels_optimized_simulator.a +0 -0
- package/ios/libs/executorch/libkernels_portable_ios.a +0 -0
- package/ios/libs/executorch/libkernels_portable_simulator.a +0 -0
- package/ios/libs/executorch/libkernels_quantized_ios.a +0 -0
- package/ios/libs/executorch/libkernels_quantized_simulator.a +0 -0
- package/third-party/ios/ios.toolchain.cmake +0 -1122
- /package/{ios → third-party/ios}/libs/tokenizers-cpp/physical-arm64-release/libsentencepiece.a +0 -0
- /package/{ios → third-party/ios}/libs/tokenizers-cpp/physical-arm64-release/libtokenizers_c.a +0 -0
- /package/{ios → third-party/ios}/libs/tokenizers-cpp/physical-arm64-release/libtokenizers_cpp.a +0 -0
- /package/{ios → third-party/ios}/libs/tokenizers-cpp/simulator-arm64-debug/libsentencepiece.a +0 -0
- /package/{ios → third-party/ios}/libs/tokenizers-cpp/simulator-arm64-debug/libtokenizers_c.a +0 -0
- /package/{ios → third-party/ios}/libs/tokenizers-cpp/simulator-arm64-debug/libtokenizers_cpp.a +0 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { ETError, getError } from '../Error';
|
|
3
|
+
export const useModule = ({ module, loadArgs, preventLoad = false, }) => {
|
|
4
|
+
const [error, setError] = useState(null);
|
|
5
|
+
const [isReady, setIsReady] = useState(false);
|
|
6
|
+
const [isGenerating, setIsGenerating] = useState(false);
|
|
7
|
+
const [downloadProgress, setDownloadProgress] = useState(0);
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
const loadModule = async () => {
|
|
10
|
+
try {
|
|
11
|
+
setIsReady(false);
|
|
12
|
+
module.onDownloadProgress(setDownloadProgress);
|
|
13
|
+
await module.load(...loadArgs);
|
|
14
|
+
setIsReady(true);
|
|
15
|
+
}
|
|
16
|
+
catch (err) {
|
|
17
|
+
setError(err.message);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
if (!preventLoad) {
|
|
21
|
+
loadModule();
|
|
22
|
+
}
|
|
23
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
24
|
+
}, [...loadArgs, preventLoad]);
|
|
25
|
+
const forward = async (...input) => {
|
|
26
|
+
if (!isReady)
|
|
27
|
+
throw new Error(getError(ETError.ModuleNotLoaded));
|
|
28
|
+
if (isGenerating)
|
|
29
|
+
throw new Error(getError(ETError.ModelGenerating));
|
|
30
|
+
try {
|
|
31
|
+
setIsGenerating(true);
|
|
32
|
+
return await module.forward(...input);
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
setIsGenerating(false);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
return {
|
|
39
|
+
error,
|
|
40
|
+
isReady,
|
|
41
|
+
isGenerating,
|
|
42
|
+
downloadProgress,
|
|
43
|
+
forward,
|
|
44
|
+
};
|
|
45
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
interface Module {
|
|
2
|
+
load: (...args: any[]) => Promise<void>;
|
|
3
|
+
forward: (...args: any[]) => Promise<any>;
|
|
4
|
+
delete: () => void;
|
|
5
|
+
}
|
|
6
|
+
interface ModuleConstructor<M extends Module> {
|
|
7
|
+
new (): M;
|
|
8
|
+
}
|
|
9
|
+
export declare const useNonStaticModule: <M extends Module, LoadArgs extends Parameters<M["load"]>, ForwardArgs extends Parameters<M["forward"]>, ForwardReturn extends Awaited<ReturnType<M["forward"]>>>({ module, model, preventLoad, }: {
|
|
10
|
+
module: ModuleConstructor<M>;
|
|
11
|
+
model: LoadArgs[0];
|
|
12
|
+
preventLoad?: boolean;
|
|
13
|
+
}) => {
|
|
14
|
+
error: string | null;
|
|
15
|
+
isReady: boolean;
|
|
16
|
+
isGenerating: boolean;
|
|
17
|
+
downloadProgress: number;
|
|
18
|
+
forward: (...input: ForwardArgs) => Promise<ForwardReturn>;
|
|
19
|
+
};
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { useEffect, useState, useMemo } from 'react';
|
|
2
|
+
import { ETError, getError } from '../Error';
|
|
3
|
+
export const useNonStaticModule = ({ module, model, preventLoad = false, }) => {
|
|
4
|
+
const [error, setError] = useState(null);
|
|
5
|
+
const [isReady, setIsReady] = useState(false);
|
|
6
|
+
const [isGenerating, setIsGenerating] = useState(false);
|
|
7
|
+
const [downloadProgress, setDownloadProgress] = useState(0);
|
|
8
|
+
const moduleInstance = useMemo(() => new module(), [module]);
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
if (preventLoad)
|
|
11
|
+
return;
|
|
12
|
+
(async () => {
|
|
13
|
+
setDownloadProgress(0);
|
|
14
|
+
setError(null);
|
|
15
|
+
try {
|
|
16
|
+
setIsReady(false);
|
|
17
|
+
await moduleInstance.load(model, setDownloadProgress);
|
|
18
|
+
setIsReady(true);
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
setError(err.message);
|
|
22
|
+
}
|
|
23
|
+
})();
|
|
24
|
+
return () => {
|
|
25
|
+
moduleInstance.delete();
|
|
26
|
+
};
|
|
27
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
28
|
+
}, [moduleInstance, ...Object.values(model), preventLoad]);
|
|
29
|
+
const forward = async (...input) => {
|
|
30
|
+
if (!isReady)
|
|
31
|
+
throw new Error(getError(ETError.ModuleNotLoaded));
|
|
32
|
+
if (isGenerating)
|
|
33
|
+
throw new Error(getError(ETError.ModelGenerating));
|
|
34
|
+
try {
|
|
35
|
+
setIsGenerating(true);
|
|
36
|
+
return await moduleInstance.forward(...input);
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
setIsGenerating(false);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
return {
|
|
43
|
+
error,
|
|
44
|
+
isReady,
|
|
45
|
+
isGenerating,
|
|
46
|
+
downloadProgress,
|
|
47
|
+
forward,
|
|
48
|
+
};
|
|
49
|
+
};
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { SpeechToTextLanguage } from './types/stt';
|
|
2
|
+
declare global {
|
|
3
|
+
var loadStyleTransfer: (source: string) => any;
|
|
4
|
+
var loadImageSegmentation: (source: string) => any;
|
|
5
|
+
var loadClassification: (source: string) => any;
|
|
6
|
+
var loadObjectDetection: (source: string) => any;
|
|
7
|
+
var loadExecutorchModule: (source: string) => any;
|
|
8
|
+
var loadTokenizerModule: (source: string) => any;
|
|
9
|
+
var loadImageEmbeddings: (source: string) => any;
|
|
10
|
+
var loadTextEmbeddings: (modelSource: string, tokenizerSource: string) => any;
|
|
11
|
+
var loadLLM: (modelSource: string, tokenizerSource: string) => any;
|
|
12
|
+
var loadSpeechToText: (encoderSource: string, decoderSource: string, modelName: string) => any;
|
|
13
|
+
}
|
|
14
|
+
export * from './hooks/computer_vision/useClassification';
|
|
15
|
+
export * from './hooks/computer_vision/useObjectDetection';
|
|
16
|
+
export * from './hooks/computer_vision/useStyleTransfer';
|
|
17
|
+
export * from './hooks/computer_vision/useImageSegmentation';
|
|
18
|
+
export * from './hooks/computer_vision/useOCR';
|
|
19
|
+
export * from './hooks/computer_vision/useVerticalOCR';
|
|
20
|
+
export * from './hooks/computer_vision/useImageEmbeddings';
|
|
21
|
+
export * from './hooks/natural_language_processing/useLLM';
|
|
22
|
+
export * from './hooks/natural_language_processing/useSpeechToText';
|
|
23
|
+
export * from './hooks/natural_language_processing/useTextEmbeddings';
|
|
24
|
+
export * from './hooks/natural_language_processing/useTokenizer';
|
|
25
|
+
export * from './hooks/general/useExecutorchModule';
|
|
26
|
+
export * from './modules/computer_vision/ClassificationModule';
|
|
27
|
+
export * from './modules/computer_vision/ObjectDetectionModule';
|
|
28
|
+
export * from './modules/computer_vision/StyleTransferModule';
|
|
29
|
+
export * from './modules/computer_vision/ImageSegmentationModule';
|
|
30
|
+
export * from './modules/computer_vision/OCRModule';
|
|
31
|
+
export * from './modules/computer_vision/VerticalOCRModule';
|
|
32
|
+
export * from './modules/general/ExecutorchModule';
|
|
33
|
+
export * from './modules/computer_vision/ImageEmbeddingsModule';
|
|
34
|
+
export * from './modules/natural_language_processing/LLMModule';
|
|
35
|
+
export * from './modules/natural_language_processing/SpeechToTextModule';
|
|
36
|
+
export * from './modules/natural_language_processing/TextEmbeddingsModule';
|
|
37
|
+
export * from './modules/natural_language_processing/TokenizerModule';
|
|
38
|
+
export * from './utils/ResourceFetcher';
|
|
39
|
+
export * from './utils/llm';
|
|
40
|
+
export * from './types/objectDetection';
|
|
41
|
+
export * from './types/ocr';
|
|
42
|
+
export * from './types/imageSegmentation';
|
|
43
|
+
export * from './types/llm';
|
|
44
|
+
export { SpeechToTextLanguage };
|
|
45
|
+
export * from './constants/modelUrls';
|
|
46
|
+
export * from './constants/ocr/models';
|
|
47
|
+
export * from './constants/llmDefaults';
|
|
48
|
+
export { STREAMING_ACTION, MODES, AvailableModels, } from './constants/sttDefaults';
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { SpeechToTextLanguage } from './types/stt';
|
|
2
|
+
import { ETInstallerNativeModule } from './native/RnExecutorchModules';
|
|
3
|
+
// eslint-disable no-var
|
|
4
|
+
if (global.loadStyleTransfer == null ||
|
|
5
|
+
global.loadImageSegmentation == null ||
|
|
6
|
+
global.loadExecutorchModule == null ||
|
|
7
|
+
global.loadClassification == null ||
|
|
8
|
+
global.loadObjectDetection == null ||
|
|
9
|
+
global.loadTokenizerModule == null ||
|
|
10
|
+
global.loadTextEmbeddings == null ||
|
|
11
|
+
global.loadImageEmbeddings == null ||
|
|
12
|
+
global.loadLLM == null ||
|
|
13
|
+
global.loadSpeechToText == null) {
|
|
14
|
+
if (!ETInstallerNativeModule) {
|
|
15
|
+
throw new Error(`Failed to install react-native-executorch: The native module could not be found.`);
|
|
16
|
+
}
|
|
17
|
+
ETInstallerNativeModule.install();
|
|
18
|
+
}
|
|
19
|
+
// hooks
|
|
20
|
+
export * from './hooks/computer_vision/useClassification';
|
|
21
|
+
export * from './hooks/computer_vision/useObjectDetection';
|
|
22
|
+
export * from './hooks/computer_vision/useStyleTransfer';
|
|
23
|
+
export * from './hooks/computer_vision/useImageSegmentation';
|
|
24
|
+
export * from './hooks/computer_vision/useOCR';
|
|
25
|
+
export * from './hooks/computer_vision/useVerticalOCR';
|
|
26
|
+
export * from './hooks/computer_vision/useImageEmbeddings';
|
|
27
|
+
export * from './hooks/natural_language_processing/useLLM';
|
|
28
|
+
export * from './hooks/natural_language_processing/useSpeechToText';
|
|
29
|
+
export * from './hooks/natural_language_processing/useTextEmbeddings';
|
|
30
|
+
export * from './hooks/natural_language_processing/useTokenizer';
|
|
31
|
+
export * from './hooks/general/useExecutorchModule';
|
|
32
|
+
// modules
|
|
33
|
+
export * from './modules/computer_vision/ClassificationModule';
|
|
34
|
+
export * from './modules/computer_vision/ObjectDetectionModule';
|
|
35
|
+
export * from './modules/computer_vision/StyleTransferModule';
|
|
36
|
+
export * from './modules/computer_vision/ImageSegmentationModule';
|
|
37
|
+
export * from './modules/computer_vision/OCRModule';
|
|
38
|
+
export * from './modules/computer_vision/VerticalOCRModule';
|
|
39
|
+
export * from './modules/general/ExecutorchModule';
|
|
40
|
+
export * from './modules/computer_vision/ImageEmbeddingsModule';
|
|
41
|
+
export * from './modules/natural_language_processing/LLMModule';
|
|
42
|
+
export * from './modules/natural_language_processing/SpeechToTextModule';
|
|
43
|
+
export * from './modules/natural_language_processing/TextEmbeddingsModule';
|
|
44
|
+
export * from './modules/natural_language_processing/TokenizerModule';
|
|
45
|
+
// utils
|
|
46
|
+
export * from './utils/ResourceFetcher';
|
|
47
|
+
export * from './utils/llm';
|
|
48
|
+
// types
|
|
49
|
+
export * from './types/objectDetection';
|
|
50
|
+
export * from './types/ocr';
|
|
51
|
+
export * from './types/imageSegmentation';
|
|
52
|
+
export * from './types/llm';
|
|
53
|
+
export { SpeechToTextLanguage };
|
|
54
|
+
// constants
|
|
55
|
+
export * from './constants/modelUrls';
|
|
56
|
+
export * from './constants/ocr/models';
|
|
57
|
+
export * from './constants/llmDefaults';
|
|
58
|
+
export { STREAMING_ACTION, MODES, AvailableModels, } from './constants/sttDefaults';
|
|
@@ -84,7 +84,16 @@ export class LLMController {
|
|
|
84
84
|
this.nativeModule = global.loadLLM(modelPath, tokenizerPath);
|
|
85
85
|
this.isReadyCallback(true);
|
|
86
86
|
this.onToken = data => {
|
|
87
|
-
if (!data
|
|
87
|
+
if (!data) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (SPECIAL_TOKENS.EOS_TOKEN in this.tokenizerConfig && data.indexOf(this.tokenizerConfig.eos_token) >= 0) {
|
|
91
|
+
data = data.replaceAll(this.tokenizerConfig.eos_token, '');
|
|
92
|
+
}
|
|
93
|
+
if (SPECIAL_TOKENS.PAD_TOKEN in this.tokenizerConfig && data.indexOf(this.tokenizerConfig.pad_token) >= 0) {
|
|
94
|
+
data = data.replaceAll(this.tokenizerConfig.pad_token, '');
|
|
95
|
+
}
|
|
96
|
+
if (data.length === 0) {
|
|
88
97
|
return;
|
|
89
98
|
}
|
|
90
99
|
this.tokenCallback(data);
|
|
@@ -100,13 +109,20 @@ export class LLMController {
|
|
|
100
109
|
}
|
|
101
110
|
configure({
|
|
102
111
|
chatConfig,
|
|
103
|
-
toolsConfig
|
|
112
|
+
toolsConfig,
|
|
113
|
+
generationConfig
|
|
104
114
|
}) {
|
|
105
115
|
this.chatConfig = {
|
|
106
116
|
...DEFAULT_CHAT_CONFIG,
|
|
107
117
|
...chatConfig
|
|
108
118
|
};
|
|
109
119
|
this.toolsConfig = toolsConfig;
|
|
120
|
+
if (generationConfig?.outputTokenBatchSize) {
|
|
121
|
+
this.nativeModule.setCountInterval(generationConfig.outputTokenBatchSize);
|
|
122
|
+
}
|
|
123
|
+
if (generationConfig?.batchTimeInterval) {
|
|
124
|
+
this.nativeModule.setTimeInterval(generationConfig.batchTimeInterval);
|
|
125
|
+
}
|
|
110
126
|
|
|
111
127
|
// reset inner state when loading new configuration
|
|
112
128
|
this.responseCallback('');
|
|
@@ -142,6 +158,9 @@ export class LLMController {
|
|
|
142
158
|
interrupt() {
|
|
143
159
|
this.nativeModule.interrupt();
|
|
144
160
|
}
|
|
161
|
+
getGeneratedTokenCount() {
|
|
162
|
+
return this.nativeModule.getGeneratedTokenCount();
|
|
163
|
+
}
|
|
145
164
|
async generate(messages, tools) {
|
|
146
165
|
if (!this._isReady) {
|
|
147
166
|
throw new Error(getError(ETError.ModuleNotLoaded));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ResourceFetcher","ETError","getError","Template","DEFAULT_CHAT_CONFIG","readAsStringAsync","SPECIAL_TOKENS","parseToolCall","Logger","LLMController","chatConfig","_response","_isReady","_isGenerating","_messageHistory","constructor","tokenCallback","responseCallback","messageHistoryCallback","isReadyCallback","isGeneratingCallback","undefined","warn","token","response","messageHistory","isReady","isGenerating","load","modelSource","tokenizerSource","tokenizerConfigSource","onDownloadProgressCallback","initialMessageHistory","tokenizersPromise","fetch","modelPromise","tokenizersResults","modelResult","Promise","all","tokenizerPath","tokenizerConfigPath","modelPath","Error","tokenizerConfig","JSON","parse","nativeModule","global","loadLLM","onToken","data","EOS_TOKEN","eos_token","PAD_TOKEN","pad_token","e","setTokenCallback","configure","toolsConfig","delete","ModelGenerating","unload","forward","input","ModuleNotLoaded","generate","interrupt","
|
|
1
|
+
{"version":3,"names":["ResourceFetcher","ETError","getError","Template","DEFAULT_CHAT_CONFIG","readAsStringAsync","SPECIAL_TOKENS","parseToolCall","Logger","LLMController","chatConfig","_response","_isReady","_isGenerating","_messageHistory","constructor","tokenCallback","responseCallback","messageHistoryCallback","isReadyCallback","isGeneratingCallback","undefined","warn","token","response","messageHistory","isReady","isGenerating","load","modelSource","tokenizerSource","tokenizerConfigSource","onDownloadProgressCallback","initialMessageHistory","tokenizersPromise","fetch","modelPromise","tokenizersResults","modelResult","Promise","all","tokenizerPath","tokenizerConfigPath","modelPath","Error","tokenizerConfig","JSON","parse","nativeModule","global","loadLLM","onToken","data","EOS_TOKEN","indexOf","eos_token","replaceAll","PAD_TOKEN","pad_token","length","e","setTokenCallback","configure","toolsConfig","generationConfig","outputTokenBatchSize","setCountInterval","batchTimeInterval","setTimeInterval","delete","ModelGenerating","unload","forward","input","ModuleNotLoaded","generate","interrupt","getGeneratedTokenCount","messages","tools","role","renderedChat","applyChatTemplate","tools_in_user_message","add_generation_prompt","sendMessage","message","content","messageHistoryWithPrompt","systemPrompt","slice","contextWindowLength","displayToolCalls","toolCalls","toolCall","executeToolCallback","then","toolResponse","deleteMessage","index","newMessageHistory","templateFlags","chat_template","template","specialTokens","Object","fromEntries","keys","filter","key","map","result","render"],"sourceRoot":"../../../src","sources":["controllers/LLMController.ts"],"mappings":";;AACA,SAASA,eAAe,QAAQ,0BAA0B;AAC1D,SAASC,OAAO,EAAEC,QAAQ,QAAQ,UAAU;AAC5C,SAASC,QAAQ,QAAQ,oBAAoB;AAC7C,SAASC,mBAAmB,QAAQ,0BAA0B;AAC9D,SAASC,iBAAiB,QAAQ,kBAAkB;AACpD,SAKEC,cAAc,QAET,cAAc;AACrB,SAASC,aAAa,QAAQ,cAAc;AAC5C,SAASC,MAAM,QAAQ,kBAAkB;AAEzC,OAAO,MAAMC,aAAa,CAAC;EAEjBC,UAAU,GAAeN,mBAAmB;EAI5CO,SAAS,GAAG,EAAE;EACdC,QAAQ,GAAG,KAAK;EAChBC,aAAa,GAAG,KAAK;EACrBC,eAAe,GAAc,EAAE;;EAEvC;;EAOAC,WAAWA,CAAC;IACVC,aAAa;IACbC,gBAAgB;IAChBC,sBAAsB;IACtBC,eAAe;IACfC;EAOF,CAAC,EAAE;IACD,IAAIH,gBAAgB,KAAKI,SAAS,EAAE;MAClCb,MAAM,CAACc,IAAI,CACT,sEACF,CAAC;IACH;IACA,IAAI,CAACN,aAAa,GAAIO,KAAK,IAAK;MAC9BP,aAAa,GAAGO,KAAK,CAAC;IACxB,CAAC;IACD,IAAI,CAACN,gBAAgB,GAAIO,QAAQ,IAAK;MACpC,IAAI,CAACb,SAAS,GAAGa,QAAQ;MACzBP,gBAAgB,GAAGO,QAAQ,CAAC;IAC9B,CAAC;IACD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
|
|
|
51
51
|
// memoization of returned functions
|
|
52
52
|
const configure = useCallback(({
|
|
53
53
|
chatConfig,
|
|
54
|
-
toolsConfig
|
|
54
|
+
toolsConfig,
|
|
55
|
+
generationConfig
|
|
55
56
|
}) => controllerInstance.configure({
|
|
56
57
|
chatConfig,
|
|
57
|
-
toolsConfig
|
|
58
|
+
toolsConfig,
|
|
59
|
+
generationConfig
|
|
58
60
|
}), [controllerInstance]);
|
|
59
61
|
const generate = useCallback((messages, tools) => {
|
|
60
62
|
setResponse('');
|
|
@@ -66,6 +68,7 @@ export const useLLM = ({
|
|
|
66
68
|
}, [controllerInstance]);
|
|
67
69
|
const deleteMessage = useCallback(index => controllerInstance.deleteMessage(index), [controllerInstance]);
|
|
68
70
|
const interrupt = useCallback(() => controllerInstance.interrupt(), [controllerInstance]);
|
|
71
|
+
const getGeneratedTokenCount = useCallback(() => controllerInstance.getGeneratedTokenCount(), [controllerInstance]);
|
|
69
72
|
return {
|
|
70
73
|
messageHistory,
|
|
71
74
|
response,
|
|
@@ -74,6 +77,7 @@ export const useLLM = ({
|
|
|
74
77
|
isGenerating,
|
|
75
78
|
downloadProgress,
|
|
76
79
|
error,
|
|
80
|
+
getGeneratedTokenCount: getGeneratedTokenCount,
|
|
77
81
|
configure: configure,
|
|
78
82
|
generate: generate,
|
|
79
83
|
sendMessage: sendMessage,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useCallback","useEffect","useMemo","useState","LLMController","useLLM","model","preventLoad","token","setToken","response","setResponse","messageHistory","setMessageHistory","isReady","setIsReady","isGenerating","setIsGenerating","downloadProgress","setDownloadProgress","error","setError","tokenCallback","newToken","prevResponse","controllerInstance","messageHistoryCallback","isReadyCallback","isGeneratingCallback","load","modelSource","tokenizerSource","tokenizerConfigSource","onDownloadProgressCallback","e","delete","configure","chatConfig","toolsConfig","generate","messages","tools","sendMessage","message","deleteMessage","index","interrupt"],"sourceRoot":"../../../../src","sources":["hooks/natural_language_processing/useLLM.ts"],"mappings":";;AAAA,SAASA,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;
|
|
1
|
+
{"version":3,"names":["useCallback","useEffect","useMemo","useState","LLMController","useLLM","model","preventLoad","token","setToken","response","setResponse","messageHistory","setMessageHistory","isReady","setIsReady","isGenerating","setIsGenerating","downloadProgress","setDownloadProgress","error","setError","tokenCallback","newToken","prevResponse","controllerInstance","messageHistoryCallback","isReadyCallback","isGeneratingCallback","load","modelSource","tokenizerSource","tokenizerConfigSource","onDownloadProgressCallback","e","delete","configure","chatConfig","toolsConfig","generationConfig","generate","messages","tools","sendMessage","message","deleteMessage","index","interrupt","getGeneratedTokenCount"],"sourceRoot":"../../../../src","sources":["hooks/natural_language_processing/useLLM.ts"],"mappings":";;AAAA,SAASA,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AAUjE,SAASC,aAAa,QAAQ,iCAAiC;;AAE/D;AACA;AACA;AACA,OAAO,MAAMC,MAAM,GAAGA,CAAC;EACrBC,KAAK;EACLC,WAAW,GAAG;AAQhB,CAAC,KAAc;EACb,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGN,QAAQ,CAAS,EAAE,CAAC;EAC9C,MAAM,CAACO,QAAQ,EAAEC,WAAW,CAAC,GAAGR,QAAQ,CAAS,EAAE,CAAC;EACpD,MAAM,CAACS,cAAc,EAAEC,iBAAiB,CAAC,GAAGV,QAAQ,CAAY,EAAE,CAAC;EACnE,MAAM,CAACW,OAAO,EAAEC,UAAU,CAAC,GAAGZ,QAAQ,CAAC,KAAK,CAAC;EAC7C,MAAM,CAACa,YAAY,EAAEC,eAAe,CAAC,GAAGd,QAAQ,CAAC,KAAK,CAAC;EACvD,MAAM,CAACe,gBAAgB,EAAEC,mBAAmB,CAAC,GAAGhB,QAAQ,CAAC,CAAC,CAAC;EAC3D,MAAM,CAACiB,KAAK,EAAEC,QAAQ,CAAC,GAAGlB,QAAQ,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Config,
|
|
29
|
-
toolsConfig
|
|
29
|
+
toolsConfig,
|
|
30
|
+
generationConfig
|
|
30
31
|
}) {
|
|
31
32
|
this.controller.configure({
|
|
32
33
|
chatConfig,
|
|
33
|
-
toolsConfig
|
|
34
|
+
toolsConfig,
|
|
35
|
+
generationConfig
|
|
34
36
|
});
|
|
35
37
|
}
|
|
36
38
|
async forward(input) {
|
|
@@ -52,6 +54,9 @@ export class LLMModule {
|
|
|
52
54
|
interrupt() {
|
|
53
55
|
this.controller.interrupt();
|
|
54
56
|
}
|
|
57
|
+
getGeneratedTokenCount() {
|
|
58
|
+
return this.controller.getGeneratedTokenCount();
|
|
59
|
+
}
|
|
55
60
|
delete() {
|
|
56
61
|
this.controller.delete();
|
|
57
62
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["LLMController","LLMModule","constructor","tokenCallback","responseCallback","messageHistoryCallback","controller","load","model","onDownloadProgressCallback","setTokenCallback","configure","chatConfig","toolsConfig","forward","input","response","generate","messages","tools","sendMessage","message","messageHistory","deleteMessage","index","interrupt","delete"],"sourceRoot":"../../../../src","sources":["modules/natural_language_processing/LLMModule.ts"],"mappings":";;AAAA,SAASA,aAAa,QAAQ,iCAAiC;
|
|
1
|
+
{"version":3,"names":["LLMController","LLMModule","constructor","tokenCallback","responseCallback","messageHistoryCallback","controller","load","model","onDownloadProgressCallback","setTokenCallback","configure","chatConfig","toolsConfig","generationConfig","forward","input","response","generate","messages","tools","sendMessage","message","messageHistory","deleteMessage","index","interrupt","getGeneratedTokenCount","delete"],"sourceRoot":"../../../../src","sources":["modules/natural_language_processing/LLMModule.ts"],"mappings":";;AAAA,SAASA,aAAa,QAAQ,iCAAiC;AAU/D,OAAO,MAAMC,SAAS,CAAC;EAGrBC,WAAWA,CAAC;IACVC,aAAa;IACbC,gBAAgB;IAChBC;EAKF,CAAC,GAAG,CAAC,CAAC,EAAE;IACN,IAAI,CAACC,UAAU,GAAG,IAAIN,aAAa,CAAC;MAClCG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AAA,EAAG;IACvB,OAAO,IAAI,CAACrB,UAAU,CAACqB,sBAAsB,CAAC,CAAC;EACjD;EAEAC,MAAMA,CAAA,EAAG;IACP,IAAI,CAACtB,UAAU,CAACsB,MAAM,CAAC,CAAC;EAC1B;AACF","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["SPECIAL_TOKENS","BOS_TOKEN","EOS_TOKEN","UNK_TOKEN","SEP_TOKEN","PAD_TOKEN","CLS_TOKEN","MASK_TOKEN"],"sourceRoot":"../../../src","sources":["types/llm.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"names":["SPECIAL_TOKENS","BOS_TOKEN","EOS_TOKEN","UNK_TOKEN","SEP_TOKEN","PAD_TOKEN","CLS_TOKEN","MASK_TOKEN"],"sourceRoot":"../../../src","sources":["types/llm.ts"],"mappings":";;AAoCA;AACA;;AAoBA,OAAO,MAAMA,cAAc,GAAG;EAC5BC,SAAS,EAAE,WAAW;EACtBC,SAAS,EAAE,WAAW;EACtBC,SAAS,EAAE,WAAW;EACtBC,SAAS,EAAE,WAAW;EACtBC,SAAS,EAAE,WAAW;EACtBC,SAAS,EAAE,WAAW;EACtBC,UAAU,EAAE;AACd,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ResourceFetcher } from '../utils/ResourceFetcher';
|
|
2
|
+
import { getError } from '../Error';
|
|
3
|
+
export class BaseModule {
|
|
4
|
+
static nativeModule;
|
|
5
|
+
static onDownloadProgressCallback = () => { };
|
|
6
|
+
static async load(sources, ...loadArgs // this can be used in derived classes to pass extra args to load method
|
|
7
|
+
) {
|
|
8
|
+
try {
|
|
9
|
+
const paths = await ResourceFetcher.fetch(this.onDownloadProgressCallback, ...sources);
|
|
10
|
+
if (paths === null || paths.length < sources.length) {
|
|
11
|
+
throw new Error('Download interrupted.');
|
|
12
|
+
}
|
|
13
|
+
await this.nativeModule.loadModule(...paths, ...loadArgs);
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
throw new Error(getError(error));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
static async forward(..._args) {
|
|
20
|
+
throw new Error('forward method is not implemented in the BaseModule class. Please implement it in the derived class.');
|
|
21
|
+
}
|
|
22
|
+
static onDownloadProgress(callback) {
|
|
23
|
+
this.onDownloadProgressCallback = callback;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export class BaseNonStaticModule {
|
|
2
|
+
nativeModule = null;
|
|
3
|
+
async forwardET(inputTensor) {
|
|
4
|
+
return await this.nativeModule.forward(inputTensor);
|
|
5
|
+
}
|
|
6
|
+
async getInputShape(methodName, index) {
|
|
7
|
+
return this.nativeModule.getInputShape(methodName, index);
|
|
8
|
+
}
|
|
9
|
+
delete() {
|
|
10
|
+
if (this.nativeModule !== null) {
|
|
11
|
+
this.nativeModule.unload();
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ResourceSource } from '../../types/common';
|
|
2
|
+
import { BaseNonStaticModule } from '../BaseNonStaticModule';
|
|
3
|
+
export declare class ClassificationModule extends BaseNonStaticModule {
|
|
4
|
+
load(model: {
|
|
5
|
+
modelSource: ResourceSource;
|
|
6
|
+
}, onDownloadProgressCallback?: (progress: number) => void): Promise<void>;
|
|
7
|
+
forward(imageSource: string): Promise<any>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ResourceFetcher } from '../../utils/ResourceFetcher';
|
|
2
|
+
import { ETError, getError } from '../../Error';
|
|
3
|
+
import { BaseNonStaticModule } from '../BaseNonStaticModule';
|
|
4
|
+
export class ClassificationModule extends BaseNonStaticModule {
|
|
5
|
+
async load(model, onDownloadProgressCallback = () => { }) {
|
|
6
|
+
const paths = await ResourceFetcher.fetch(onDownloadProgressCallback, model.modelSource);
|
|
7
|
+
if (paths === null || paths.length < 1) {
|
|
8
|
+
throw new Error('Download interrupted.');
|
|
9
|
+
}
|
|
10
|
+
this.nativeModule = global.loadClassification(paths[0] || '');
|
|
11
|
+
}
|
|
12
|
+
async forward(imageSource) {
|
|
13
|
+
if (this.nativeModule == null)
|
|
14
|
+
throw new Error(getError(ETError.ModuleNotLoaded));
|
|
15
|
+
return await this.nativeModule.generate(imageSource);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ResourceSource } from '../../types/common';
|
|
2
|
+
import { BaseNonStaticModule } from '../BaseNonStaticModule';
|
|
3
|
+
export declare class ImageEmbeddingsModule extends BaseNonStaticModule {
|
|
4
|
+
load(model: {
|
|
5
|
+
modelSource: ResourceSource;
|
|
6
|
+
}, onDownloadProgressCallback?: (progress: number) => void): Promise<void>;
|
|
7
|
+
forward(imageSource: string): Promise<Float32Array>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ResourceFetcher } from '../../utils/ResourceFetcher';
|
|
2
|
+
import { ETError, getError } from '../../Error';
|
|
3
|
+
import { BaseNonStaticModule } from '../BaseNonStaticModule';
|
|
4
|
+
export class ImageEmbeddingsModule extends BaseNonStaticModule {
|
|
5
|
+
async load(model, onDownloadProgressCallback = () => { }) {
|
|
6
|
+
const paths = await ResourceFetcher.fetch(onDownloadProgressCallback, model.modelSource);
|
|
7
|
+
if (paths === null || paths.length < 1) {
|
|
8
|
+
throw new Error('Download interrupted.');
|
|
9
|
+
}
|
|
10
|
+
this.nativeModule = global.loadImageEmbeddings(paths[0] || '');
|
|
11
|
+
}
|
|
12
|
+
async forward(imageSource) {
|
|
13
|
+
if (this.nativeModule == null)
|
|
14
|
+
throw new Error(getError(ETError.ModuleNotLoaded));
|
|
15
|
+
return new Float32Array(await this.nativeModule.generate(imageSource));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ResourceSource } from '../../types/common';
|
|
2
|
+
import { DeeplabLabel } from '../../types/imageSegmentation';
|
|
3
|
+
import { BaseNonStaticModule } from '../BaseNonStaticModule';
|
|
4
|
+
export declare class ImageSegmentationModule extends BaseNonStaticModule {
|
|
5
|
+
load(model: {
|
|
6
|
+
modelSource: ResourceSource;
|
|
7
|
+
}, onDownloadProgressCallback?: (progress: number) => void): Promise<void>;
|
|
8
|
+
forward(imageSource: string, classesOfInterest?: DeeplabLabel[], resize?: boolean): Promise<{
|
|
9
|
+
[key in DeeplabLabel]?: number[];
|
|
10
|
+
}>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ResourceFetcher } from '../../utils/ResourceFetcher';
|
|
2
|
+
import { DeeplabLabel } from '../../types/imageSegmentation';
|
|
3
|
+
import { ETError, getError } from '../../Error';
|
|
4
|
+
import { BaseNonStaticModule } from '../BaseNonStaticModule';
|
|
5
|
+
export class ImageSegmentationModule extends BaseNonStaticModule {
|
|
6
|
+
async load(model, onDownloadProgressCallback = () => { }) {
|
|
7
|
+
const paths = await ResourceFetcher.fetch(onDownloadProgressCallback, model.modelSource);
|
|
8
|
+
if (paths === null || paths.length < 1) {
|
|
9
|
+
throw new Error('Download interrupted.');
|
|
10
|
+
}
|
|
11
|
+
this.nativeModule = global.loadImageSegmentation(paths[0] || '');
|
|
12
|
+
}
|
|
13
|
+
async forward(imageSource, classesOfInterest, resize) {
|
|
14
|
+
if (this.nativeModule == null) {
|
|
15
|
+
throw new Error(getError(ETError.ModuleNotLoaded));
|
|
16
|
+
}
|
|
17
|
+
const stringDict = await this.nativeModule.generate(imageSource, (classesOfInterest || []).map((label) => DeeplabLabel[label]), resize || false);
|
|
18
|
+
let enumDict = {};
|
|
19
|
+
for (const key in stringDict) {
|
|
20
|
+
if (key in DeeplabLabel) {
|
|
21
|
+
const enumKey = DeeplabLabel[key];
|
|
22
|
+
enumDict[enumKey] = stringDict[key];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return enumDict;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { OCRController } from '../../controllers/OCRController';
|
|
2
|
+
import { ResourceSource } from '../../types/common';
|
|
3
|
+
import { OCRLanguage } from '../../types/ocr';
|
|
4
|
+
export declare class OCRModule {
|
|
5
|
+
static module: OCRController;
|
|
6
|
+
static load(model: {
|
|
7
|
+
detectorSource: ResourceSource;
|
|
8
|
+
recognizerLarge: ResourceSource;
|
|
9
|
+
recognizerMedium: ResourceSource;
|
|
10
|
+
recognizerSmall: ResourceSource;
|
|
11
|
+
language: OCRLanguage;
|
|
12
|
+
}, onDownloadProgressCallback?: (progress: number) => void): Promise<void>;
|
|
13
|
+
static forward(input: string): Promise<import("../../types/ocr").OCRDetection[]>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { OCRController } from '../../controllers/OCRController';
|
|
2
|
+
export class OCRModule {
|
|
3
|
+
static module;
|
|
4
|
+
static async load(model, onDownloadProgressCallback = () => { }) {
|
|
5
|
+
this.module = new OCRController({
|
|
6
|
+
modelDownloadProgressCallback: onDownloadProgressCallback,
|
|
7
|
+
});
|
|
8
|
+
await this.module.loadModel(model.detectorSource, {
|
|
9
|
+
recognizerLarge: model.recognizerLarge,
|
|
10
|
+
recognizerMedium: model.recognizerMedium,
|
|
11
|
+
recognizerSmall: model.recognizerSmall,
|
|
12
|
+
}, model.language);
|
|
13
|
+
}
|
|
14
|
+
static async forward(input) {
|
|
15
|
+
return await this.module.forward(input);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ResourceSource } from '../../types/common';
|
|
2
|
+
import { Detection } from '../../types/objectDetection';
|
|
3
|
+
import { BaseNonStaticModule } from '../BaseNonStaticModule';
|
|
4
|
+
export declare class ObjectDetectionModule extends BaseNonStaticModule {
|
|
5
|
+
load(model: {
|
|
6
|
+
modelSource: ResourceSource;
|
|
7
|
+
}, onDownloadProgressCallback?: (progress: number) => void): Promise<void>;
|
|
8
|
+
forward(imageSource: string, detectionThreshold?: number): Promise<Detection[]>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ResourceFetcher } from '../../utils/ResourceFetcher';
|
|
2
|
+
import { ETError, getError } from '../../Error';
|
|
3
|
+
import { BaseNonStaticModule } from '../BaseNonStaticModule';
|
|
4
|
+
export class ObjectDetectionModule extends BaseNonStaticModule {
|
|
5
|
+
async load(model, onDownloadProgressCallback = () => { }) {
|
|
6
|
+
const paths = await ResourceFetcher.fetch(onDownloadProgressCallback, model.modelSource);
|
|
7
|
+
if (paths === null || paths.length < 1) {
|
|
8
|
+
throw new Error('Download interrupted.');
|
|
9
|
+
}
|
|
10
|
+
this.nativeModule = global.loadObjectDetection(paths[0] || '');
|
|
11
|
+
}
|
|
12
|
+
async forward(imageSource, detectionThreshold = 0.7) {
|
|
13
|
+
if (this.nativeModule == null)
|
|
14
|
+
throw new Error(getError(ETError.ModuleNotLoaded));
|
|
15
|
+
return await this.nativeModule.generate(imageSource, detectionThreshold);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ResourceSource } from '../../types/common';
|
|
2
|
+
import { BaseNonStaticModule } from '../BaseNonStaticModule';
|
|
3
|
+
export declare class StyleTransferModule extends BaseNonStaticModule {
|
|
4
|
+
load(model: {
|
|
5
|
+
modelSource: ResourceSource;
|
|
6
|
+
}, onDownloadProgressCallback?: (progress: number) => void): Promise<void>;
|
|
7
|
+
forward(imageSource: string): Promise<string>;
|
|
8
|
+
}
|