react-native-executorch 0.3.2 → 0.4.1
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/README.md +30 -13
- package/android/build.gradle +1 -1
- package/android/libs/executorch.aar +0 -0
- package/android/src/main/java/com/swmansion/rnexecutorch/ETModule.kt +1 -2
- package/android/src/main/java/com/swmansion/rnexecutorch/ImageSegmentation.kt +58 -0
- package/android/src/main/java/com/swmansion/rnexecutorch/LLM.kt +13 -49
- package/android/src/main/java/com/swmansion/rnexecutorch/RnExecutorchPackage.kt +37 -0
- package/android/src/main/java/com/swmansion/rnexecutorch/StyleTransfer.kt +1 -1
- package/android/src/main/java/com/swmansion/rnexecutorch/TextEmbeddings.kt +51 -0
- package/android/src/main/java/com/swmansion/rnexecutorch/Tokenizer.kt +86 -0
- package/android/src/main/java/com/swmansion/rnexecutorch/models/BaseModel.kt +3 -4
- package/android/src/main/java/com/swmansion/rnexecutorch/models/TextEmbeddings/TextEmbeddingsModel.kt +48 -0
- package/android/src/main/java/com/swmansion/rnexecutorch/models/TextEmbeddings/TextEmbeddingsUtils.kt +37 -0
- package/android/src/main/java/com/swmansion/rnexecutorch/models/classification/ClassificationModel.kt +1 -0
- package/android/src/main/java/com/swmansion/rnexecutorch/models/imageSegmentation/Constants.kt +26 -0
- package/android/src/main/java/com/swmansion/rnexecutorch/models/imageSegmentation/ImageSegmentationModel.kt +142 -0
- package/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/utils/RecognizerUtils.kt +3 -0
- package/android/src/main/java/com/swmansion/rnexecutorch/models/{StyleTransferModel.kt → styleTransfer/StyleTransferModel.kt} +2 -1
- package/android/src/main/java/com/swmansion/rnexecutorch/utils/ArrayUtils.kt +0 -8
- package/android/src/main/java/com/swmansion/rnexecutorch/{models/classification/Utils.kt → utils/Numerical.kt} +1 -1
- package/ios/ExecutorchLib.xcframework/Info.plist +4 -4
- package/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/ExecutorchLib +0 -0
- package/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/Headers/HuggingFaceTokenizer.h +14 -0
- package/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/Headers/LLaMARunner.h +1 -23
- package/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/Info.plist +0 -0
- package/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/ExecutorchLib +0 -0
- package/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/Headers/HuggingFaceTokenizer.h +14 -0
- package/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/Headers/LLaMARunner.h +1 -23
- package/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/Info.plist +0 -0
- package/ios/RnExecutorch/Classification.mm +15 -18
- package/ios/RnExecutorch/ETModule.mm +6 -5
- package/ios/RnExecutorch/ImageSegmentation.h +5 -0
- package/ios/RnExecutorch/ImageSegmentation.mm +60 -0
- package/ios/RnExecutorch/LLM.mm +12 -53
- package/ios/RnExecutorch/OCR.mm +39 -43
- package/ios/RnExecutorch/ObjectDetection.mm +20 -20
- package/ios/RnExecutorch/SpeechToText.mm +6 -7
- package/ios/RnExecutorch/StyleTransfer.mm +16 -19
- package/ios/RnExecutorch/TextEmbeddings.h +5 -0
- package/ios/RnExecutorch/TextEmbeddings.mm +62 -0
- package/ios/RnExecutorch/Tokenizer.h +5 -0
- package/ios/RnExecutorch/Tokenizer.mm +83 -0
- package/ios/RnExecutorch/VerticalOCR.mm +36 -36
- package/ios/RnExecutorch/models/BaseModel.h +2 -5
- package/ios/RnExecutorch/models/BaseModel.mm +5 -15
- package/ios/RnExecutorch/models/classification/ClassificationModel.mm +2 -3
- package/ios/RnExecutorch/models/classification/Constants.mm +0 -1
- package/ios/RnExecutorch/models/image_segmentation/Constants.h +4 -0
- package/ios/RnExecutorch/models/image_segmentation/Constants.mm +8 -0
- package/ios/RnExecutorch/models/image_segmentation/ImageSegmentationModel.h +10 -0
- package/ios/RnExecutorch/models/image_segmentation/ImageSegmentationModel.mm +146 -0
- package/ios/RnExecutorch/models/object_detection/SSDLiteLargeModel.mm +1 -2
- package/ios/RnExecutorch/models/ocr/Detector.h +0 -2
- package/ios/RnExecutorch/models/ocr/Detector.mm +2 -1
- package/ios/RnExecutorch/models/ocr/RecognitionHandler.h +5 -4
- package/ios/RnExecutorch/models/ocr/RecognitionHandler.mm +9 -26
- package/ios/RnExecutorch/models/ocr/Recognizer.mm +1 -2
- package/ios/RnExecutorch/models/ocr/VerticalDetector.h +0 -2
- package/ios/RnExecutorch/models/ocr/VerticalDetector.mm +2 -1
- package/ios/RnExecutorch/models/ocr/utils/OCRUtils.mm +0 -1
- package/ios/RnExecutorch/models/stt/Moonshine.mm +1 -6
- package/ios/RnExecutorch/models/stt/SpeechToTextBaseModel.mm +7 -11
- package/ios/RnExecutorch/models/stt/Whisper.mm +0 -5
- package/ios/RnExecutorch/models/{StyleTransferModel.h → style_transfer/StyleTransferModel.h} +1 -1
- package/ios/RnExecutorch/models/{StyleTransferModel.mm → style_transfer/StyleTransferModel.mm} +2 -3
- package/ios/RnExecutorch/models/text_embeddings/TextEmbeddingsModel.h +15 -0
- package/ios/RnExecutorch/models/text_embeddings/TextEmbeddingsModel.mm +45 -0
- package/ios/RnExecutorch/models/text_embeddings/TextEmbeddingsUtils.h +8 -0
- package/ios/RnExecutorch/models/text_embeddings/TextEmbeddingsUtils.mm +49 -0
- package/ios/RnExecutorch/utils/Conversions.h +15 -0
- package/ios/RnExecutorch/utils/ImageProcessor.h +0 -1
- package/ios/RnExecutorch/{models/classification/Utils.h → utils/Numerical.h} +0 -2
- package/ios/RnExecutorch/{models/classification/Utils.mm → utils/Numerical.mm} +0 -2
- package/ios/RnExecutorch/utils/ObjectDetectionUtils.mm +0 -2
- package/ios/RnExecutorch/utils/SFFT.mm +1 -1
- package/ios/RnExecutorch/utils/ScalarType.h +0 -2
- package/lib/module/Error.js +16 -2
- package/lib/module/Error.js.map +1 -1
- package/lib/module/constants/{llamaDefaults.js → llmDefaults.js} +7 -3
- package/lib/module/constants/llmDefaults.js.map +1 -0
- package/lib/module/constants/modelUrls.js +88 -27
- package/lib/module/constants/modelUrls.js.map +1 -1
- package/lib/module/constants/ocr/models.js +290 -0
- package/lib/module/constants/ocr/models.js.map +1 -0
- package/lib/module/constants/ocr/symbols.js +137 -2
- package/lib/module/constants/ocr/symbols.js.map +1 -1
- package/lib/module/constants/sttDefaults.js +50 -25
- package/lib/module/constants/sttDefaults.js.map +1 -1
- package/lib/module/controllers/LLMController.js +205 -0
- package/lib/module/controllers/LLMController.js.map +1 -0
- package/lib/module/controllers/OCRController.js +5 -10
- package/lib/module/controllers/OCRController.js.map +1 -1
- package/lib/module/controllers/SpeechToTextController.js +225 -122
- package/lib/module/controllers/SpeechToTextController.js.map +1 -1
- package/lib/module/controllers/VerticalOCRController.js +6 -10
- package/lib/module/controllers/VerticalOCRController.js.map +1 -1
- package/lib/module/hooks/computer_vision/useClassification.js +8 -23
- package/lib/module/hooks/computer_vision/useClassification.js.map +1 -1
- package/lib/module/hooks/computer_vision/useImageSegmentation.js +13 -0
- package/lib/module/hooks/computer_vision/useImageSegmentation.js.map +1 -0
- package/lib/module/hooks/computer_vision/useOCR.js +11 -6
- package/lib/module/hooks/computer_vision/useOCR.js.map +1 -1
- package/lib/module/hooks/computer_vision/useObjectDetection.js +8 -23
- package/lib/module/hooks/computer_vision/useObjectDetection.js.map +1 -1
- package/lib/module/hooks/computer_vision/useStyleTransfer.js +8 -23
- package/lib/module/hooks/computer_vision/useStyleTransfer.js.map +1 -1
- package/lib/module/hooks/computer_vision/useVerticalOCR.js +10 -7
- package/lib/module/hooks/computer_vision/useVerticalOCR.js.map +1 -1
- package/lib/module/hooks/general/useExecutorchModule.js +8 -36
- package/lib/module/hooks/general/useExecutorchModule.js.map +1 -1
- package/lib/module/hooks/natural_language_processing/useLLM.js +54 -63
- package/lib/module/hooks/natural_language_processing/useLLM.js.map +1 -1
- package/lib/module/hooks/natural_language_processing/useSpeechToText.js +15 -11
- package/lib/module/hooks/natural_language_processing/useSpeechToText.js.map +1 -1
- package/lib/module/hooks/natural_language_processing/useTextEmbeddings.js +14 -0
- package/lib/module/hooks/natural_language_processing/useTextEmbeddings.js.map +1 -0
- package/lib/module/hooks/natural_language_processing/useTokenizer.js +54 -0
- package/lib/module/hooks/natural_language_processing/useTokenizer.js.map +1 -0
- package/lib/module/hooks/useModule.js +18 -62
- package/lib/module/hooks/useModule.js.map +1 -1
- package/lib/module/index.js +16 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/modules/BaseModule.js +9 -10
- package/lib/module/modules/BaseModule.js.map +1 -1
- package/lib/module/modules/computer_vision/ClassificationModule.js +8 -5
- package/lib/module/modules/computer_vision/ClassificationModule.js.map +1 -1
- package/lib/module/modules/computer_vision/ImageSegmentationModule.js +28 -0
- package/lib/module/modules/computer_vision/ImageSegmentationModule.js.map +1 -0
- package/lib/module/modules/computer_vision/ObjectDetectionModule.js +8 -5
- package/lib/module/modules/computer_vision/ObjectDetectionModule.js.map +1 -1
- package/lib/module/modules/computer_vision/StyleTransferModule.js +8 -5
- package/lib/module/modules/computer_vision/StyleTransferModule.js.map +1 -1
- package/lib/module/modules/general/ExecutorchModule.js +8 -5
- package/lib/module/modules/general/ExecutorchModule.js.map +1 -1
- package/lib/module/modules/natural_language_processing/LLMModule.js +46 -27
- package/lib/module/modules/natural_language_processing/LLMModule.js.map +1 -1
- package/lib/module/modules/natural_language_processing/SpeechToTextModule.js +8 -5
- package/lib/module/modules/natural_language_processing/SpeechToTextModule.js.map +1 -1
- package/lib/module/modules/natural_language_processing/TextEmbeddingsModule.js +14 -0
- package/lib/module/modules/natural_language_processing/TextEmbeddingsModule.js.map +1 -0
- package/lib/module/modules/natural_language_processing/TokenizerModule.js +26 -0
- package/lib/module/modules/natural_language_processing/TokenizerModule.js.map +1 -0
- package/lib/module/native/NativeClassification.js.map +1 -1
- package/lib/module/native/NativeImageSegmentation.js +5 -0
- package/lib/module/native/NativeImageSegmentation.js.map +1 -0
- package/lib/module/native/NativeLLM.js.map +1 -1
- package/lib/module/native/NativeTextEmbeddings.js +5 -0
- package/lib/module/native/NativeTextEmbeddings.js.map +1 -0
- package/lib/module/native/NativeTokenizer.js +5 -0
- package/lib/module/native/NativeTokenizer.js.map +1 -0
- package/lib/module/native/RnExecutorchModules.js +18 -113
- package/lib/module/native/RnExecutorchModules.js.map +1 -1
- package/lib/module/types/common.js.map +1 -1
- package/lib/module/types/imageSegmentation.js +29 -0
- package/lib/module/types/imageSegmentation.js.map +1 -0
- package/lib/module/types/llm.js +7 -0
- package/lib/module/types/llm.js.map +1 -0
- package/lib/module/types/{object_detection.js → objectDetection.js} +1 -1
- package/lib/module/types/objectDetection.js.map +1 -0
- package/lib/module/types/ocr.js +2 -0
- package/lib/module/types/stt.js +82 -0
- package/lib/module/types/stt.js.map +1 -0
- package/lib/module/utils/ResourceFetcher.js +156 -0
- package/lib/module/utils/ResourceFetcher.js.map +1 -0
- package/lib/module/utils/llm.js +25 -0
- package/lib/module/utils/llm.js.map +1 -0
- package/lib/module/utils/stt.js +22 -0
- package/lib/module/utils/stt.js.map +1 -0
- package/lib/typescript/Error.d.ts +4 -1
- package/lib/typescript/Error.d.ts.map +1 -1
- package/lib/typescript/constants/{llamaDefaults.d.ts → llmDefaults.d.ts} +5 -5
- package/lib/typescript/constants/llmDefaults.d.ts.map +1 -0
- package/lib/typescript/constants/modelUrls.d.ts +74 -28
- package/lib/typescript/constants/modelUrls.d.ts.map +1 -1
- package/lib/typescript/constants/ocr/models.d.ts +285 -0
- package/lib/typescript/constants/ocr/models.d.ts.map +1 -0
- package/lib/typescript/constants/ocr/symbols.d.ts +73 -1
- package/lib/typescript/constants/ocr/symbols.d.ts.map +1 -1
- package/lib/typescript/constants/sttDefaults.d.ts +8 -13
- package/lib/typescript/constants/sttDefaults.d.ts.map +1 -1
- package/lib/typescript/controllers/LLMController.d.ts +46 -0
- package/lib/typescript/controllers/LLMController.d.ts.map +1 -0
- package/lib/typescript/controllers/OCRController.d.ts.map +1 -1
- package/lib/typescript/controllers/SpeechToTextController.d.ts +30 -16
- package/lib/typescript/controllers/SpeechToTextController.d.ts.map +1 -1
- package/lib/typescript/controllers/VerticalOCRController.d.ts +1 -1
- package/lib/typescript/controllers/VerticalOCRController.d.ts.map +1 -1
- package/lib/typescript/hooks/computer_vision/useClassification.d.ts +5 -5
- package/lib/typescript/hooks/computer_vision/useClassification.d.ts.map +1 -1
- package/lib/typescript/hooks/computer_vision/useImageSegmentation.d.ts +37 -0
- package/lib/typescript/hooks/computer_vision/useImageSegmentation.d.ts.map +1 -0
- package/lib/typescript/hooks/computer_vision/useOCR.d.ts +2 -1
- package/lib/typescript/hooks/computer_vision/useOCR.d.ts.map +1 -1
- package/lib/typescript/hooks/computer_vision/useObjectDetection.d.ts +5 -4
- package/lib/typescript/hooks/computer_vision/useObjectDetection.d.ts.map +1 -1
- package/lib/typescript/hooks/computer_vision/useStyleTransfer.d.ts +4 -2
- package/lib/typescript/hooks/computer_vision/useStyleTransfer.d.ts.map +1 -1
- package/lib/typescript/hooks/computer_vision/useVerticalOCR.d.ts +2 -1
- package/lib/typescript/hooks/computer_vision/useVerticalOCR.d.ts.map +1 -1
- package/lib/typescript/hooks/general/useExecutorchModule.d.ts +5 -6
- package/lib/typescript/hooks/general/useExecutorchModule.d.ts.map +1 -1
- package/lib/typescript/hooks/natural_language_processing/useLLM.d.ts +6 -6
- package/lib/typescript/hooks/natural_language_processing/useLLM.d.ts.map +1 -1
- package/lib/typescript/hooks/natural_language_processing/useSpeechToText.d.ts +7 -3
- package/lib/typescript/hooks/natural_language_processing/useSpeechToText.d.ts.map +1 -1
- package/lib/typescript/hooks/natural_language_processing/useTextEmbeddings.d.ts +13 -0
- package/lib/typescript/hooks/natural_language_processing/useTextEmbeddings.d.ts.map +1 -0
- package/lib/typescript/hooks/natural_language_processing/useTokenizer.d.ts +16 -0
- package/lib/typescript/hooks/natural_language_processing/useTokenizer.d.ts.map +1 -0
- package/lib/typescript/hooks/useModule.d.ts +11 -10
- package/lib/typescript/hooks/useModule.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +15 -2
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/modules/BaseModule.d.ts +4 -5
- package/lib/typescript/modules/BaseModule.d.ts.map +1 -1
- package/lib/typescript/modules/computer_vision/ClassificationModule.d.ts +7 -7
- package/lib/typescript/modules/computer_vision/ClassificationModule.d.ts.map +1 -1
- package/lib/typescript/modules/computer_vision/ImageSegmentationModule.d.ts +32 -0
- package/lib/typescript/modules/computer_vision/ImageSegmentationModule.d.ts.map +1 -0
- package/lib/typescript/modules/computer_vision/OCRModule.d.ts.map +1 -1
- package/lib/typescript/modules/computer_vision/ObjectDetectionModule.d.ts +6 -5
- package/lib/typescript/modules/computer_vision/ObjectDetectionModule.d.ts.map +1 -1
- package/lib/typescript/modules/computer_vision/StyleTransferModule.d.ts +6 -5
- package/lib/typescript/modules/computer_vision/StyleTransferModule.d.ts.map +1 -1
- package/lib/typescript/modules/computer_vision/VerticalOCRModule.d.ts.map +1 -1
- package/lib/typescript/modules/general/ExecutorchModule.d.ts +4 -3
- package/lib/typescript/modules/general/ExecutorchModule.d.ts.map +1 -1
- package/lib/typescript/modules/natural_language_processing/LLMModule.d.ts +19 -5
- package/lib/typescript/modules/natural_language_processing/LLMModule.d.ts.map +1 -1
- package/lib/typescript/modules/natural_language_processing/SpeechToTextModule.d.ts +7 -4
- package/lib/typescript/modules/natural_language_processing/SpeechToTextModule.d.ts.map +1 -1
- package/lib/typescript/modules/natural_language_processing/TextEmbeddingsModule.d.ts +8 -0
- package/lib/typescript/modules/natural_language_processing/TextEmbeddingsModule.d.ts.map +1 -0
- package/lib/typescript/modules/natural_language_processing/TokenizerModule.d.ts +12 -0
- package/lib/typescript/modules/natural_language_processing/TokenizerModule.d.ts.map +1 -0
- package/lib/typescript/native/NativeClassification.d.ts.map +1 -1
- package/lib/typescript/native/NativeImageSegmentation.d.ts +10 -0
- package/lib/typescript/native/NativeImageSegmentation.d.ts.map +1 -0
- package/lib/typescript/native/NativeLLM.d.ts +3 -4
- package/lib/typescript/native/NativeLLM.d.ts.map +1 -1
- package/lib/typescript/native/NativeObjectDetection.d.ts +1 -1
- package/lib/typescript/native/NativeObjectDetection.d.ts.map +1 -1
- package/lib/typescript/native/NativeSpeechToText.d.ts +2 -2
- package/lib/typescript/native/NativeSpeechToText.d.ts.map +1 -1
- package/lib/typescript/native/NativeTextEmbeddings.d.ts +8 -0
- package/lib/typescript/native/NativeTextEmbeddings.d.ts.map +1 -0
- package/lib/typescript/native/NativeTokenizer.d.ts +12 -0
- package/lib/typescript/native/NativeTokenizer.d.ts.map +1 -0
- package/lib/typescript/native/RnExecutorchModules.d.ts +18 -41
- package/lib/typescript/native/RnExecutorchModules.d.ts.map +1 -1
- package/lib/typescript/types/common.d.ts +1 -26
- package/lib/typescript/types/common.d.ts.map +1 -1
- package/lib/typescript/types/imageSegmentation.d.ts +25 -0
- package/lib/typescript/types/imageSegmentation.d.ts.map +1 -0
- package/lib/typescript/types/llm.d.ts +38 -0
- package/lib/typescript/types/llm.d.ts.map +1 -0
- package/lib/typescript/types/{object_detection.d.ts → objectDetection.d.ts} +1 -1
- package/lib/typescript/types/objectDetection.d.ts.map +1 -0
- package/lib/typescript/types/ocr.d.ts +2 -1
- package/lib/typescript/types/ocr.d.ts.map +1 -1
- package/lib/typescript/types/stt.d.ts +91 -0
- package/lib/typescript/types/stt.d.ts.map +1 -0
- package/lib/typescript/utils/ResourceFetcher.d.ts +17 -0
- package/lib/typescript/utils/ResourceFetcher.d.ts.map +1 -0
- package/lib/typescript/utils/llm.d.ts +3 -0
- package/lib/typescript/utils/llm.d.ts.map +1 -0
- package/lib/typescript/utils/stt.d.ts +2 -0
- package/lib/typescript/utils/stt.d.ts.map +1 -0
- package/package.json +12 -48
- package/react-native-executorch.podspec +1 -1
- package/src/Error.ts +16 -3
- package/src/constants/llmDefaults.ts +14 -0
- package/src/constants/modelUrls.ts +146 -39
- package/src/constants/ocr/models.ts +453 -0
- package/src/constants/ocr/symbols.ts +147 -3
- package/src/constants/sttDefaults.ts +55 -37
- package/src/controllers/LLMController.ts +286 -0
- package/src/controllers/OCRController.ts +14 -28
- package/src/controllers/SpeechToTextController.ts +318 -180
- package/src/controllers/VerticalOCRController.ts +17 -32
- package/src/hooks/computer_vision/useClassification.ts +11 -26
- package/src/hooks/computer_vision/useImageSegmentation.ts +18 -0
- package/src/hooks/computer_vision/useOCR.ts +17 -5
- package/src/hooks/computer_vision/useObjectDetection.ts +10 -24
- package/src/hooks/computer_vision/useStyleTransfer.ts +9 -25
- package/src/hooks/computer_vision/useVerticalOCR.ts +11 -4
- package/src/hooks/general/useExecutorchModule.ts +10 -50
- package/src/hooks/natural_language_processing/useLLM.ts +80 -97
- package/src/hooks/natural_language_processing/useSpeechToText.ts +39 -12
- package/src/hooks/natural_language_processing/useTextEmbeddings.ts +18 -0
- package/src/hooks/natural_language_processing/useTokenizer.ts +61 -0
- package/src/hooks/useModule.ts +32 -92
- package/src/index.tsx +16 -2
- package/src/modules/BaseModule.ts +16 -26
- package/src/modules/computer_vision/ClassificationModule.ts +13 -8
- package/src/modules/computer_vision/ImageSegmentationModule.ts +39 -0
- package/src/modules/computer_vision/ObjectDetectionModule.ts +13 -8
- package/src/modules/computer_vision/StyleTransferModule.ts +13 -8
- package/src/modules/general/ExecutorchModule.ts +11 -6
- package/src/modules/natural_language_processing/LLMModule.ts +64 -51
- package/src/modules/natural_language_processing/SpeechToTextModule.ts +25 -10
- package/src/modules/natural_language_processing/TextEmbeddingsModule.ts +18 -0
- package/src/modules/natural_language_processing/TokenizerModule.ts +34 -0
- package/src/native/NativeClassification.ts +0 -1
- package/src/native/NativeImageSegmentation.ts +14 -0
- package/src/native/NativeLLM.ts +3 -10
- package/src/native/NativeObjectDetection.ts +1 -1
- package/src/native/NativeSpeechToText.ts +2 -2
- package/src/native/NativeTextEmbeddings.ts +9 -0
- package/src/native/NativeTokenizer.ts +13 -0
- package/src/native/RnExecutorchModules.ts +54 -234
- package/src/types/common.ts +1 -44
- package/src/types/imageSegmentation.ts +25 -0
- package/src/types/llm.ts +57 -0
- package/src/types/ocr.ts +3 -1
- package/src/types/stt.ts +93 -0
- package/src/utils/ResourceFetcher.ts +196 -0
- package/src/utils/llm.ts +34 -0
- package/src/utils/stt.ts +28 -0
- package/android/src/main/java/com/swmansion/rnexecutorch/utils/llms/ConversationManager.kt +0 -68
- package/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/_CodeSignature/CodeResources +0 -124
- package/ios/RnExecutorch/utils/llms/Constants.h +0 -6
- package/ios/RnExecutorch/utils/llms/Constants.mm +0 -23
- package/ios/RnExecutorch/utils/llms/ConversationManager.h +0 -26
- package/ios/RnExecutorch/utils/llms/ConversationManager.mm +0 -71
- package/lib/module/constants/llamaDefaults.js.map +0 -1
- package/lib/module/modules/computer_vision/BaseCVModule.js +0 -14
- package/lib/module/modules/computer_vision/BaseCVModule.js.map +0 -1
- package/lib/module/types/object_detection.js.map +0 -1
- package/lib/module/utils/fetchResource.js +0 -93
- package/lib/module/utils/fetchResource.js.map +0 -1
- package/lib/module/utils/listDownloadedResources.js +0 -13
- package/lib/module/utils/listDownloadedResources.js.map +0 -1
- package/lib/typescript/constants/llamaDefaults.d.ts.map +0 -1
- package/lib/typescript/modules/computer_vision/BaseCVModule.d.ts +0 -9
- package/lib/typescript/modules/computer_vision/BaseCVModule.d.ts.map +0 -1
- package/lib/typescript/types/object_detection.d.ts.map +0 -1
- package/lib/typescript/utils/fetchResource.d.ts +0 -3
- package/lib/typescript/utils/fetchResource.d.ts.map +0 -1
- package/lib/typescript/utils/listDownloadedResources.d.ts +0 -3
- package/lib/typescript/utils/listDownloadedResources.d.ts.map +0 -1
- package/src/constants/llamaDefaults.ts +0 -9
- package/src/modules/computer_vision/BaseCVModule.ts +0 -22
- package/src/utils/fetchResource.ts +0 -106
- package/src/utils/listDownloadedResources.ts +0 -12
- /package/src/types/{object_detection.ts → objectDetection.ts} +0 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
package com.swmansion.rnexecutorch.models.imagesegmentation
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.Arguments
|
|
4
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
5
|
+
import com.facebook.react.bridge.ReadableArray
|
|
6
|
+
import com.facebook.react.bridge.WritableMap
|
|
7
|
+
import com.swmansion.rnexecutorch.models.BaseModel
|
|
8
|
+
import com.swmansion.rnexecutorch.utils.ArrayUtils
|
|
9
|
+
import com.swmansion.rnexecutorch.utils.ImageProcessor
|
|
10
|
+
import com.swmansion.rnexecutorch.utils.softmax
|
|
11
|
+
import org.opencv.core.CvType
|
|
12
|
+
import org.opencv.core.Mat
|
|
13
|
+
import org.opencv.core.Size
|
|
14
|
+
import org.opencv.imgproc.Imgproc
|
|
15
|
+
import org.pytorch.executorch.EValue
|
|
16
|
+
|
|
17
|
+
class ImageSegmentationModel(
|
|
18
|
+
reactApplicationContext: ReactApplicationContext,
|
|
19
|
+
) : BaseModel<Triple<Mat, ReadableArray, Boolean>, WritableMap>(reactApplicationContext) {
|
|
20
|
+
private lateinit var originalSize: Size
|
|
21
|
+
|
|
22
|
+
private fun getModelImageSize(): Size {
|
|
23
|
+
val inputShape = module.getInputShape(0)
|
|
24
|
+
val width = inputShape[inputShape.lastIndex]
|
|
25
|
+
val height = inputShape[inputShape.lastIndex - 1]
|
|
26
|
+
|
|
27
|
+
return Size(height.toDouble(), width.toDouble())
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
fun preprocess(input: Mat): EValue {
|
|
31
|
+
originalSize = input.size()
|
|
32
|
+
Imgproc.resize(input, input, getModelImageSize())
|
|
33
|
+
return ImageProcessor.matToEValue(input, module.getInputShape(0))
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
private fun extractResults(
|
|
37
|
+
result: FloatArray,
|
|
38
|
+
numLabels: Int,
|
|
39
|
+
resize: Boolean,
|
|
40
|
+
): List<FloatArray> {
|
|
41
|
+
val modelSize = getModelImageSize()
|
|
42
|
+
val numModelPixels = (modelSize.height * modelSize.width).toInt()
|
|
43
|
+
|
|
44
|
+
val extractedLabelScores = mutableListOf<FloatArray>()
|
|
45
|
+
|
|
46
|
+
for (label in 0..<numLabels) {
|
|
47
|
+
// Calls to OpenCV via JNI are very slow so we do as much as we can
|
|
48
|
+
// with pure Kotlin
|
|
49
|
+
val range = IntRange(label * numModelPixels, (label + 1) * numModelPixels - 1)
|
|
50
|
+
val pixelBuffer = result.slice(range).toFloatArray()
|
|
51
|
+
|
|
52
|
+
if (resize) {
|
|
53
|
+
// Rescale the image with OpenCV
|
|
54
|
+
val mat = Mat(modelSize, CvType.CV_32F)
|
|
55
|
+
mat.put(0, 0, pixelBuffer)
|
|
56
|
+
val resizedMat = Mat()
|
|
57
|
+
Imgproc.resize(mat, resizedMat, originalSize)
|
|
58
|
+
val resizedBuffer = FloatArray((originalSize.height * originalSize.width).toInt())
|
|
59
|
+
resizedMat.get(0, 0, resizedBuffer)
|
|
60
|
+
extractedLabelScores.add(resizedBuffer)
|
|
61
|
+
} else {
|
|
62
|
+
extractedLabelScores.add(pixelBuffer)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return extractedLabelScores
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private fun adjustScoresPerPixel(
|
|
69
|
+
labelScores: List<FloatArray>,
|
|
70
|
+
numLabels: Int,
|
|
71
|
+
outputSize: Size,
|
|
72
|
+
): IntArray {
|
|
73
|
+
val numPixels = (outputSize.height * outputSize.width).toInt()
|
|
74
|
+
val argMax = IntArray(numPixels)
|
|
75
|
+
for (pixel in 0..<numPixels) {
|
|
76
|
+
val scores = mutableListOf<Float>()
|
|
77
|
+
for (buffer in labelScores) {
|
|
78
|
+
scores.add(buffer[pixel])
|
|
79
|
+
}
|
|
80
|
+
val adjustedScores = softmax(scores.toTypedArray())
|
|
81
|
+
for (label in 0..<numLabels) {
|
|
82
|
+
labelScores[label][pixel] = adjustedScores[label]
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
val maxIndex = scores.withIndex().maxBy { it.value }.index
|
|
86
|
+
argMax[pixel] = maxIndex
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return argMax
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
fun postprocess(
|
|
93
|
+
output: Array<EValue>,
|
|
94
|
+
classesOfInterest: ReadableArray,
|
|
95
|
+
resize: Boolean,
|
|
96
|
+
): WritableMap {
|
|
97
|
+
val outputData = output[0].toTensor().dataAsFloatArray
|
|
98
|
+
val modelSize = getModelImageSize()
|
|
99
|
+
val numLabels = deeplabv3_resnet50_labels.size
|
|
100
|
+
|
|
101
|
+
require(outputData.count() == (numLabels * modelSize.height * modelSize.width).toInt()) { "Model generated unexpected output size." }
|
|
102
|
+
|
|
103
|
+
val outputSize = if (resize) originalSize else modelSize
|
|
104
|
+
|
|
105
|
+
val extractedResults = extractResults(outputData, numLabels, resize)
|
|
106
|
+
|
|
107
|
+
val argMax = adjustScoresPerPixel(extractedResults, numLabels, outputSize)
|
|
108
|
+
|
|
109
|
+
val labelSet = mutableSetOf<String>()
|
|
110
|
+
// Filter by the label set when base class changed
|
|
111
|
+
for (i in 0..<classesOfInterest.size()) {
|
|
112
|
+
val label = classesOfInterest.getString(i)
|
|
113
|
+
if (label != null) {
|
|
114
|
+
labelSet.add(label)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
val res = Arguments.createMap()
|
|
119
|
+
|
|
120
|
+
for (label in 0..<numLabels) {
|
|
121
|
+
if (labelSet.contains(deeplabv3_resnet50_labels[label])) {
|
|
122
|
+
res.putArray(
|
|
123
|
+
deeplabv3_resnet50_labels[label],
|
|
124
|
+
ArrayUtils.createReadableArrayFromFloatArray(extractedResults[label]),
|
|
125
|
+
)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
res.putArray(
|
|
130
|
+
"ARGMAX",
|
|
131
|
+
ArrayUtils.createReadableArrayFromIntArray(argMax),
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
return res
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
override fun runModel(input: Triple<Mat, ReadableArray, Boolean>): WritableMap {
|
|
138
|
+
val modelInput = preprocess(input.first)
|
|
139
|
+
val modelOutput = forward(modelInput)
|
|
140
|
+
return postprocess(modelOutput, input.second, input.third)
|
|
141
|
+
}
|
|
142
|
+
}
|
package/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/utils/RecognizerUtils.kt
CHANGED
|
@@ -335,6 +335,9 @@ class RecognizerUtils {
|
|
|
335
335
|
cords.x *= originalPaddings["resizeRatio"]!! as Float
|
|
336
336
|
cords.y *= originalPaddings["resizeRatio"]!! as Float
|
|
337
337
|
|
|
338
|
+
cords.x = cords.x.coerceIn(0.0, (image.cols() - 1).toDouble())
|
|
339
|
+
cords.y = cords.y.coerceIn(0.0, (image.rows() - 1).toDouble())
|
|
340
|
+
|
|
338
341
|
points[i] = Point(cords.x, cords.y)
|
|
339
342
|
}
|
|
340
343
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
package com.swmansion.rnexecutorch.models
|
|
1
|
+
package com.swmansion.rnexecutorch.models.styletransfer
|
|
2
2
|
|
|
3
3
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
4
4
|
import com.swmansion.rnexecutorch.utils.ImageProcessor
|
|
@@ -6,6 +6,7 @@ import org.opencv.core.Mat
|
|
|
6
6
|
import org.opencv.core.Size
|
|
7
7
|
import org.opencv.imgproc.Imgproc
|
|
8
8
|
import org.pytorch.executorch.EValue
|
|
9
|
+
import com.swmansion.rnexecutorch.models.BaseModel
|
|
9
10
|
|
|
10
11
|
class StyleTransferModel(
|
|
11
12
|
reactApplicationContext: ReactApplicationContext,
|
|
@@ -32,14 +32,6 @@ class ArrayUtils {
|
|
|
32
32
|
fun createDoubleArray(input: ReadableArray): DoubleArray =
|
|
33
33
|
createTypedArrayFromReadableArray(input) { array, index -> array.getDouble(index) }.toDoubleArray()
|
|
34
34
|
|
|
35
|
-
fun <V> createMapArray(input: ReadableArray): Array<Map<String, V>> {
|
|
36
|
-
val mapArray = Array<Map<String, V>>(input.size()) { mapOf() }
|
|
37
|
-
for (i in 0 until input.size()) {
|
|
38
|
-
mapArray[i] = input.getMap(i).toHashMap() as Map<String, V>
|
|
39
|
-
}
|
|
40
|
-
return mapArray
|
|
41
|
-
}
|
|
42
|
-
|
|
43
35
|
fun createReadableArrayFromTensor(result: Tensor): ReadableArray {
|
|
44
36
|
val resultArray = Arguments.createArray()
|
|
45
37
|
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
<key>BinaryPath</key>
|
|
9
9
|
<string>ExecutorchLib.framework/ExecutorchLib</string>
|
|
10
10
|
<key>LibraryIdentifier</key>
|
|
11
|
-
<string>ios-arm64</string>
|
|
11
|
+
<string>ios-arm64-simulator</string>
|
|
12
12
|
<key>LibraryPath</key>
|
|
13
13
|
<string>ExecutorchLib.framework</string>
|
|
14
14
|
<key>SupportedArchitectures</key>
|
|
@@ -17,12 +17,14 @@
|
|
|
17
17
|
</array>
|
|
18
18
|
<key>SupportedPlatform</key>
|
|
19
19
|
<string>ios</string>
|
|
20
|
+
<key>SupportedPlatformVariant</key>
|
|
21
|
+
<string>simulator</string>
|
|
20
22
|
</dict>
|
|
21
23
|
<dict>
|
|
22
24
|
<key>BinaryPath</key>
|
|
23
25
|
<string>ExecutorchLib.framework/ExecutorchLib</string>
|
|
24
26
|
<key>LibraryIdentifier</key>
|
|
25
|
-
<string>ios-arm64
|
|
27
|
+
<string>ios-arm64</string>
|
|
26
28
|
<key>LibraryPath</key>
|
|
27
29
|
<string>ExecutorchLib.framework</string>
|
|
28
30
|
<key>SupportedArchitectures</key>
|
|
@@ -31,8 +33,6 @@
|
|
|
31
33
|
</array>
|
|
32
34
|
<key>SupportedPlatform</key>
|
|
33
35
|
<string>ios</string>
|
|
34
|
-
<key>SupportedPlatformVariant</key>
|
|
35
|
-
<string>simulator</string>
|
|
36
36
|
</dict>
|
|
37
37
|
</array>
|
|
38
38
|
<key>CFBundlePackageType</key>
|
|
Binary file
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
|
|
3
|
+
@interface HuggingFaceTokenizer : NSObject
|
|
4
|
+
|
|
5
|
+
- (instancetype)initWithTokenizerPath:(NSString *)tokenizerPath;
|
|
6
|
+
- (NSArray<NSNumber *> *)encode:(NSString *)text;
|
|
7
|
+
- (NSString *)decode:(NSArray<NSNumber *> *)tokenIds;
|
|
8
|
+
- (NSString *)decode:(NSArray<NSNumber *> *)tokenIds
|
|
9
|
+
skipSpecialTokens:(BOOL)skipSpecialTokens;
|
|
10
|
+
- (NSUInteger)getVocabSize;
|
|
11
|
+
- (NSString *)idToToken:(NSInteger)tokenId;
|
|
12
|
+
- (NSInteger)tokenToId:(NSString *)token;
|
|
13
|
+
|
|
14
|
+
@end
|
package/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/Headers/LLaMARunner.h
CHANGED
|
@@ -11,14 +11,13 @@
|
|
|
11
11
|
NS_ASSUME_NONNULL_BEGIN
|
|
12
12
|
|
|
13
13
|
FOUNDATION_EXPORT NSErrorDomain const LLaMARunnerErrorDomain;
|
|
14
|
-
FOUNDATION_EXPORT NSErrorDomain const LLaVARunnerErrorDomain;
|
|
15
14
|
|
|
16
15
|
NS_SWIFT_NAME(Runner)
|
|
17
16
|
@interface LLaMARunner : NSObject
|
|
18
17
|
|
|
19
18
|
- (instancetype)initWithModelPath:(NSString *)filePath
|
|
20
19
|
tokenizerPath:(NSString *)tokenizerPath;
|
|
21
|
-
- (BOOL)
|
|
20
|
+
- (BOOL)isLoaded;
|
|
22
21
|
- (BOOL)loadWithError:(NSError **)error;
|
|
23
22
|
- (BOOL)generate:(NSString *)prompt
|
|
24
23
|
withTokenCallback:(nullable void (^)(NSString *))callback
|
|
@@ -30,25 +29,4 @@ NS_SWIFT_NAME(Runner)
|
|
|
30
29
|
|
|
31
30
|
@end
|
|
32
31
|
|
|
33
|
-
NS_SWIFT_NAME(LLaVARunner)
|
|
34
|
-
@interface LLaVARunner : NSObject
|
|
35
|
-
|
|
36
|
-
- (instancetype)initWithModelPath:(NSString *)filePath
|
|
37
|
-
tokenizerPath:(NSString *)tokenizerPath;
|
|
38
|
-
- (BOOL)isloaded;
|
|
39
|
-
- (BOOL)loadWithError:(NSError **)error;
|
|
40
|
-
- (BOOL)generate:(void *)imageBuffer
|
|
41
|
-
width:(CGFloat)width
|
|
42
|
-
height:(CGFloat)height
|
|
43
|
-
prompt:(NSString *)prompt
|
|
44
|
-
sequenceLength:(NSInteger)seq_len
|
|
45
|
-
withTokenCallback:(nullable void (^)(NSString *))callback
|
|
46
|
-
error:(NSError **)error;
|
|
47
|
-
- (void)stop;
|
|
48
|
-
|
|
49
|
-
+ (instancetype)new NS_UNAVAILABLE;
|
|
50
|
-
- (instancetype)init NS_UNAVAILABLE;
|
|
51
|
-
|
|
52
|
-
@end
|
|
53
|
-
|
|
54
32
|
NS_ASSUME_NONNULL_END
|
|
Binary file
|
package/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/ExecutorchLib
CHANGED
|
Binary file
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
|
|
3
|
+
@interface HuggingFaceTokenizer : NSObject
|
|
4
|
+
|
|
5
|
+
- (instancetype)initWithTokenizerPath:(NSString *)tokenizerPath;
|
|
6
|
+
- (NSArray<NSNumber *> *)encode:(NSString *)text;
|
|
7
|
+
- (NSString *)decode:(NSArray<NSNumber *> *)tokenIds;
|
|
8
|
+
- (NSString *)decode:(NSArray<NSNumber *> *)tokenIds
|
|
9
|
+
skipSpecialTokens:(BOOL)skipSpecialTokens;
|
|
10
|
+
- (NSUInteger)getVocabSize;
|
|
11
|
+
- (NSString *)idToToken:(NSInteger)tokenId;
|
|
12
|
+
- (NSInteger)tokenToId:(NSString *)token;
|
|
13
|
+
|
|
14
|
+
@end
|
|
@@ -11,14 +11,13 @@
|
|
|
11
11
|
NS_ASSUME_NONNULL_BEGIN
|
|
12
12
|
|
|
13
13
|
FOUNDATION_EXPORT NSErrorDomain const LLaMARunnerErrorDomain;
|
|
14
|
-
FOUNDATION_EXPORT NSErrorDomain const LLaVARunnerErrorDomain;
|
|
15
14
|
|
|
16
15
|
NS_SWIFT_NAME(Runner)
|
|
17
16
|
@interface LLaMARunner : NSObject
|
|
18
17
|
|
|
19
18
|
- (instancetype)initWithModelPath:(NSString *)filePath
|
|
20
19
|
tokenizerPath:(NSString *)tokenizerPath;
|
|
21
|
-
- (BOOL)
|
|
20
|
+
- (BOOL)isLoaded;
|
|
22
21
|
- (BOOL)loadWithError:(NSError **)error;
|
|
23
22
|
- (BOOL)generate:(NSString *)prompt
|
|
24
23
|
withTokenCallback:(nullable void (^)(NSString *))callback
|
|
@@ -30,25 +29,4 @@ NS_SWIFT_NAME(Runner)
|
|
|
30
29
|
|
|
31
30
|
@end
|
|
32
31
|
|
|
33
|
-
NS_SWIFT_NAME(LLaVARunner)
|
|
34
|
-
@interface LLaVARunner : NSObject
|
|
35
|
-
|
|
36
|
-
- (instancetype)initWithModelPath:(NSString *)filePath
|
|
37
|
-
tokenizerPath:(NSString *)tokenizerPath;
|
|
38
|
-
- (BOOL)isloaded;
|
|
39
|
-
- (BOOL)loadWithError:(NSError **)error;
|
|
40
|
-
- (BOOL)generate:(void *)imageBuffer
|
|
41
|
-
width:(CGFloat)width
|
|
42
|
-
height:(CGFloat)height
|
|
43
|
-
prompt:(NSString *)prompt
|
|
44
|
-
sequenceLength:(NSInteger)seq_len
|
|
45
|
-
withTokenCallback:(nullable void (^)(NSString *))callback
|
|
46
|
-
error:(NSError **)error;
|
|
47
|
-
- (void)stop;
|
|
48
|
-
|
|
49
|
-
+ (instancetype)new NS_UNAVAILABLE;
|
|
50
|
-
- (instancetype)init NS_UNAVAILABLE;
|
|
51
|
-
|
|
52
|
-
@end
|
|
53
|
-
|
|
54
32
|
NS_ASSUME_NONNULL_END
|
package/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/Info.plist
CHANGED
|
Binary file
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
#import "Classification.h"
|
|
2
2
|
#import "ImageProcessor.h"
|
|
3
|
-
#import "models/BaseModel.h"
|
|
4
3
|
#import "models/classification/ClassificationModel.h"
|
|
5
|
-
#import "opencv2/opencv.hpp"
|
|
6
|
-
#import "utils/ETError.h"
|
|
7
|
-
#import <ExecutorchLib/ETModel.h>
|
|
8
|
-
#import <React/RCTBridgeModule.h>
|
|
9
4
|
|
|
10
5
|
@implementation Classification {
|
|
11
6
|
ClassificationModel *model;
|
|
@@ -13,23 +8,25 @@
|
|
|
13
8
|
|
|
14
9
|
RCT_EXPORT_MODULE()
|
|
15
10
|
|
|
11
|
+
- (void)releaseResources {
|
|
12
|
+
model = nil;
|
|
13
|
+
}
|
|
14
|
+
|
|
16
15
|
- (void)loadModule:(NSString *)modelSource
|
|
17
16
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
18
17
|
reject:(RCTPromiseRejectBlock)reject {
|
|
19
18
|
model = [[ClassificationModel alloc] init];
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return;
|
|
32
|
-
}];
|
|
19
|
+
|
|
20
|
+
NSNumber *errorCode = [model loadModel:modelSource];
|
|
21
|
+
if ([errorCode intValue] != 0) {
|
|
22
|
+
[self releaseResources];
|
|
23
|
+
reject(@"init_module_error",
|
|
24
|
+
[NSString stringWithFormat:@"%ld", (long)[errorCode longValue]],
|
|
25
|
+
nil);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
resolve(@0);
|
|
33
30
|
}
|
|
34
31
|
|
|
35
32
|
- (void)forward:(NSString *)input
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
#import "ETModule.h"
|
|
2
2
|
#import <ExecutorchLib/ETModel.h>
|
|
3
|
-
#include <Foundation/Foundation.h>
|
|
4
|
-
#import <React/RCTBridgeModule.h>
|
|
5
|
-
#include <string>
|
|
6
3
|
|
|
7
4
|
@implementation ETModule {
|
|
8
5
|
ETModel *module;
|
|
@@ -10,16 +7,20 @@
|
|
|
10
7
|
|
|
11
8
|
RCT_EXPORT_MODULE()
|
|
12
9
|
|
|
10
|
+
- (void)releaseResources {
|
|
11
|
+
module = nil;
|
|
12
|
+
}
|
|
13
|
+
|
|
13
14
|
- (void)loadModule:(NSString *)modelSource
|
|
14
15
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
15
16
|
reject:(RCTPromiseRejectBlock)reject {
|
|
16
17
|
if (!module) {
|
|
17
18
|
module = [[ETModel alloc] init];
|
|
18
19
|
}
|
|
19
|
-
NSURL *modelURL = [NSURL URLWithString:modelSource];
|
|
20
|
-
NSNumber *result = [self->module loadModel:modelURL.path];
|
|
21
20
|
|
|
21
|
+
NSNumber *result = [self->module loadModel:modelSource];
|
|
22
22
|
if ([result intValue] != 0) {
|
|
23
|
+
[self releaseResources];
|
|
23
24
|
NSError *error =
|
|
24
25
|
[NSError errorWithDomain:@"ETModuleErrorDomain"
|
|
25
26
|
code:[result intValue]
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#import "ImageSegmentation.h"
|
|
2
|
+
#import "ImageProcessor.h"
|
|
3
|
+
#import "models/image_segmentation/ImageSegmentationModel.h"
|
|
4
|
+
|
|
5
|
+
@implementation ImageSegmentation {
|
|
6
|
+
ImageSegmentationModel *model;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
RCT_EXPORT_MODULE()
|
|
10
|
+
|
|
11
|
+
- (void)releaseResources {
|
|
12
|
+
model = nil;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
- (void)loadModule:(NSString *)modelSource
|
|
16
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
17
|
+
reject:(RCTPromiseRejectBlock)reject {
|
|
18
|
+
model = [[ImageSegmentationModel alloc] init];
|
|
19
|
+
|
|
20
|
+
NSNumber *errorCode = [model loadModel:modelSource];
|
|
21
|
+
if ([errorCode intValue] != 0) {
|
|
22
|
+
[self releaseResources];
|
|
23
|
+
reject(@"init_module_error",
|
|
24
|
+
[NSString stringWithFormat:@"%ld", (long)[errorCode longValue]],
|
|
25
|
+
nil);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
resolve(@0);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
- (void)forward:(NSString *)input
|
|
33
|
+
classesOfInterest:(NSArray *)classesOfInterest
|
|
34
|
+
resize:(BOOL)resize
|
|
35
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
36
|
+
reject:(RCTPromiseRejectBlock)reject {
|
|
37
|
+
|
|
38
|
+
@try {
|
|
39
|
+
cv::Mat image = [ImageProcessor readImage:input];
|
|
40
|
+
NSDictionary *result = [model runModel:image
|
|
41
|
+
returnClasses:classesOfInterest
|
|
42
|
+
resize:resize];
|
|
43
|
+
|
|
44
|
+
resolve(result);
|
|
45
|
+
return;
|
|
46
|
+
} @catch (NSException *exception) {
|
|
47
|
+
NSLog(@"An exception occurred: %@, %@", exception.name, exception.reason);
|
|
48
|
+
reject(@"forward_error",
|
|
49
|
+
[NSString stringWithFormat:@"%@", exception.reason], nil);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
55
|
+
(const facebook::react::ObjCTurboModule::InitParams &)params {
|
|
56
|
+
return std::make_shared<facebook::react::NativeImageSegmentationSpecJSI>(
|
|
57
|
+
params);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
@end
|
package/ios/RnExecutorch/LLM.mm
CHANGED
|
@@ -1,28 +1,12 @@
|
|
|
1
1
|
#import "LLM.h"
|
|
2
|
-
#import "utils/llms/Constants.h"
|
|
3
|
-
#import "utils/llms/ConversationManager.h"
|
|
4
2
|
#import <ExecutorchLib/LLaMARunner.h>
|
|
5
|
-
#import <React/RCTBridge+Private.h>
|
|
6
|
-
#import <React/RCTBridge.h>
|
|
7
|
-
#import <React/RCTBridgeModule.h>
|
|
8
|
-
#import <React/RCTUtils.h>
|
|
9
|
-
#import <ReactCommon/CallInvoker.h>
|
|
10
|
-
#import <ReactCommon/RCTTurboModule.h>
|
|
11
|
-
#import <UIKit/UIKit.h>
|
|
12
|
-
#import <react/renderer/uimanager/primitives.h>
|
|
13
|
-
#import <string>
|
|
14
3
|
|
|
15
4
|
@implementation LLM {
|
|
16
5
|
LLaMARunner *runner;
|
|
17
|
-
ConversationManager *conversationManager;
|
|
18
|
-
NSMutableString *tempLlamaResponse;
|
|
19
6
|
}
|
|
20
7
|
|
|
21
8
|
- (instancetype)init {
|
|
22
9
|
self = [super init];
|
|
23
|
-
if (self) {
|
|
24
|
-
tempLlamaResponse = [[NSMutableString alloc] init];
|
|
25
|
-
}
|
|
26
10
|
|
|
27
11
|
return self;
|
|
28
12
|
}
|
|
@@ -36,64 +20,39 @@ RCT_EXPORT_MODULE()
|
|
|
36
20
|
|
|
37
21
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
38
22
|
[self emitOnToken:token];
|
|
39
|
-
[self->tempLlamaResponse appendString:token];
|
|
40
23
|
});
|
|
41
24
|
}
|
|
42
25
|
|
|
43
26
|
- (void)loadLLM:(NSString *)modelSource
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
contextWindowLength:(double)contextWindowLength
|
|
48
|
-
resolve:(RCTPromiseResolveBlock)resolve
|
|
49
|
-
reject:(RCTPromiseRejectBlock)reject {
|
|
50
|
-
NSURL *modelURL = [NSURL URLWithString:modelSource];
|
|
51
|
-
NSURL *tokenizerURL = [NSURL URLWithString:tokenizerSource];
|
|
27
|
+
tokenizerSource:(NSString *)tokenizerSource
|
|
28
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
29
|
+
reject:(RCTPromiseRejectBlock)reject {
|
|
52
30
|
@try {
|
|
53
|
-
self->runner = [[LLaMARunner alloc] initWithModelPath:
|
|
54
|
-
tokenizerPath:
|
|
55
|
-
NSUInteger contextWindowLengthUInt = (NSUInteger)round(contextWindowLength);
|
|
56
|
-
|
|
57
|
-
self->conversationManager = [[ConversationManager alloc]
|
|
58
|
-
initWithNumMessagesContextWindow:contextWindowLengthUInt
|
|
59
|
-
systemPrompt:systemPrompt
|
|
60
|
-
messageHistory:messageHistory];
|
|
31
|
+
self->runner = [[LLaMARunner alloc] initWithModelPath:modelSource
|
|
32
|
+
tokenizerPath:tokenizerSource];
|
|
61
33
|
|
|
62
|
-
self->tempLlamaResponse = [NSMutableString string];
|
|
63
34
|
resolve(@"Model and tokenizer loaded successfully");
|
|
64
35
|
return;
|
|
65
36
|
} @catch (NSException *exception) {
|
|
37
|
+
[self releaseResources];
|
|
66
38
|
reject(@"Model or tokenizer loading failed", exception.reason, nil);
|
|
67
39
|
return;
|
|
68
40
|
}
|
|
69
41
|
}
|
|
70
42
|
|
|
71
|
-
- (void)
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
[conversationManager addResponse:input senderRole:ChatRole::USER];
|
|
75
|
-
NSString *prompt = [conversationManager getConversation];
|
|
43
|
+
- (void)forward:(NSString *)input
|
|
44
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
45
|
+
reject:(RCTPromiseRejectBlock)reject {
|
|
76
46
|
|
|
77
47
|
dispatch_async(
|
|
78
48
|
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
|
79
49
|
NSError *error = nil;
|
|
80
|
-
[self->runner generate:
|
|
50
|
+
[self->runner generate:input
|
|
81
51
|
withTokenCallback:^(NSString *token) {
|
|
82
|
-
[self onResult:token prompt:
|
|
52
|
+
[self onResult:token prompt:input];
|
|
83
53
|
}
|
|
84
54
|
error:&error];
|
|
85
55
|
|
|
86
|
-
// make sure to add eot token once generation is done
|
|
87
|
-
if (![self->tempLlamaResponse hasSuffix:END_OF_TEXT_TOKEN_NS]) {
|
|
88
|
-
[self onResult:END_OF_TEXT_TOKEN_NS prompt:prompt];
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (self->tempLlamaResponse) {
|
|
92
|
-
[self->conversationManager addResponse:self->tempLlamaResponse
|
|
93
|
-
senderRole:ChatRole::ASSISTANT];
|
|
94
|
-
self->tempLlamaResponse = [NSMutableString string];
|
|
95
|
-
}
|
|
96
|
-
|
|
97
56
|
if (error) {
|
|
98
57
|
reject(@"error_in_generation", error.localizedDescription, nil);
|
|
99
58
|
return;
|
|
@@ -107,7 +66,7 @@ RCT_EXPORT_MODULE()
|
|
|
107
66
|
[self->runner stop];
|
|
108
67
|
}
|
|
109
68
|
|
|
110
|
-
- (void)
|
|
69
|
+
- (void)releaseResources {
|
|
111
70
|
self->runner = nil;
|
|
112
71
|
}
|
|
113
72
|
|