diff --git a/.cspell-wordlist.txt b/.cspell-wordlist.txt index 283af1481..c0c708edf 100644 --- a/.cspell-wordlist.txt +++ b/.cspell-wordlist.txt @@ -95,6 +95,7 @@ Português codegen cstdint ocurred +RNFS libfbjni libc gradlew @@ -104,5 +105,8 @@ POTTEDPLANT TVMONITOR sublist TTFT +pogodin +kesha +antonov timestamping logprob diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7989ebb5d..dd9585bc2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: run: yarn lint - name: Typecheck files - run: yarn typecheck + run: yarn workspaces foreach --all --topological-dev run prepare && yarn typecheck build-library: runs-on: ubuntu-latest @@ -35,7 +35,5 @@ jobs: - name: Setup uses: ./.github/actions/setup - - name: Build package - run: | - cd packages/react-native-executorch - yarn prepare + - name: Build all packages + run: yarn workspaces foreach --all --topological-dev run prepare diff --git a/.nvmrc b/.nvmrc index 9a2a0e219..53d1c14db 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -v20 +v22 diff --git a/apps/computer-vision/app/_layout.tsx b/apps/computer-vision/app/_layout.tsx index 5914d2fe8..35fba7fb1 100644 --- a/apps/computer-vision/app/_layout.tsx +++ b/apps/computer-vision/app/_layout.tsx @@ -1,4 +1,7 @@ import { Drawer } from 'expo-router/drawer'; +import { initExecutorch } from 'react-native-executorch'; +import { ExpoResourceFetcher } from '@react-native-executorch/expo-resource-fetcher'; + import ColorPalette from '../colors'; import React, { useState } from 'react'; import { Text, StyleSheet, View } from 'react-native'; @@ -10,6 +13,10 @@ import { } from '@react-navigation/drawer'; import { GeneratingContext } from '../context'; +initExecutorch({ + resourceFetcher: ExpoResourceFetcher, +}); + interface CustomDrawerProps extends DrawerContentComponentProps { isGenerating: boolean; } diff --git a/apps/computer-vision/package.json b/apps/computer-vision/package.json index 63885109a..cce918197 100644 --- a/apps/computer-vision/package.json +++ b/apps/computer-vision/package.json @@ -11,7 +11,8 @@ "lint": "eslint . --ext .ts,.tsx --fix" }, "dependencies": { - "@react-native/metro-config": "^0.76.3", + "@react-native-executorch/expo-resource-fetcher": "workspace:*", + "@react-native/metro-config": "^0.81.5", "@react-navigation/drawer": "^7.3.9", "@react-navigation/native": "^7.1.6", "@shopify/react-native-skia": "2.2.12", @@ -21,7 +22,7 @@ "expo-linking": "~8.0.10", "expo-router": "~6.0.17", "expo-status-bar": "~3.0.9", - "metro-config": "^0.81.0", + "metro-config": "^0.81.5", "react": "19.1.0", "react-native": "0.81.5", "react-native-device-info": "^14.0.4", diff --git a/apps/computer-vision/tsconfig.json b/apps/computer-vision/tsconfig.json index 47026ce43..a08f2140a 100644 --- a/apps/computer-vision/tsconfig.json +++ b/apps/computer-vision/tsconfig.json @@ -9,7 +9,10 @@ "customConditions": ["react-native"], "noEmit": true, "paths": { - "react-native-executorch": ["../../packages/react-native-executorch/src"] + "react-native-executorch": ["../../packages/react-native-executorch/src"], + "@react-native-executorch/expo-resource-fetcher": [ + "../../packages/expo-resource-fetcher/src" + ] } } } diff --git a/apps/llm/app/_layout.tsx b/apps/llm/app/_layout.tsx index 68c715a80..5ece80f1f 100644 --- a/apps/llm/app/_layout.tsx +++ b/apps/llm/app/_layout.tsx @@ -1,8 +1,9 @@ import { Drawer } from 'expo-router/drawer'; +import { initExecutorch } from 'react-native-executorch'; +import { ExpoResourceFetcher } from '@react-native-executorch/expo-resource-fetcher'; import ColorPalette from '../colors'; import React, { useState } from 'react'; import { Text, StyleSheet, View } from 'react-native'; - import { DrawerContentComponentProps, DrawerContentScrollView, @@ -10,6 +11,10 @@ import { } from '@react-navigation/drawer'; import { GeneratingContext } from '../context'; +initExecutorch({ + resourceFetcher: ExpoResourceFetcher, +}); + interface CustomDrawerProps extends DrawerContentComponentProps { isGenerating: boolean; } diff --git a/apps/llm/package.json b/apps/llm/package.json index de046a299..04597d963 100644 --- a/apps/llm/package.json +++ b/apps/llm/package.json @@ -11,7 +11,8 @@ "lint": "eslint . --ext .ts,.tsx --fix" }, "dependencies": { - "@react-native/metro-config": "^0.76.3", + "@react-native-executorch/expo-resource-fetcher": "workspace:*", + "@react-native/metro-config": "^0.81.5", "@react-navigation/drawer": "^7.3.9", "@react-navigation/native": "^7.1.6", "expo": "^54.0.27", @@ -22,7 +23,7 @@ "expo-linking": "~8.0.10", "expo-router": "~6.0.17", "expo-status-bar": "~3.0.9", - "metro-config": "^0.81.0", + "metro-config": "^0.81.5", "react": "19.1.0", "react-native": "0.81.5", "react-native-audio-api": "^0.8.2", diff --git a/apps/llm/tsconfig.json b/apps/llm/tsconfig.json index 47026ce43..a08f2140a 100644 --- a/apps/llm/tsconfig.json +++ b/apps/llm/tsconfig.json @@ -9,7 +9,10 @@ "customConditions": ["react-native"], "noEmit": true, "paths": { - "react-native-executorch": ["../../packages/react-native-executorch/src"] + "react-native-executorch": ["../../packages/react-native-executorch/src"], + "@react-native-executorch/expo-resource-fetcher": [ + "../../packages/expo-resource-fetcher/src" + ] } } } diff --git a/apps/speech/App.tsx b/apps/speech/App.tsx index af0598b59..ab036678e 100644 --- a/apps/speech/App.tsx +++ b/apps/speech/App.tsx @@ -5,6 +5,12 @@ import { SpeechToTextScreen } from './screens/SpeechToTextScreen'; import ColorPalette from './colors'; import ExecutorchLogo from './assets/executorch.svg'; import { Quiz } from './screens/Quiz'; +import { initExecutorch } from 'react-native-executorch'; +import { ExpoResourceFetcher } from '@react-native-executorch/expo-resource-fetcher'; + +initExecutorch({ + resourceFetcher: ExpoResourceFetcher, +}); export default function App() { const [currentScreen, setCurrentScreen] = useState< diff --git a/apps/speech/package.json b/apps/speech/package.json index 1c0607be2..9c9fdbee1 100644 --- a/apps/speech/package.json +++ b/apps/speech/package.json @@ -11,12 +11,13 @@ "lint": "eslint . --ext .ts,.tsx --fix" }, "dependencies": { - "@react-native/metro-config": "^0.76.3", + "@react-native-executorch/expo-resource-fetcher": "workspace:*", + "@react-native/metro-config": "^0.81.5", "buffer": "^6.0.3", "expo": "^54.0.27", "expo-font": "~14.0.10", "expo-status-bar": "~3.0.9", - "metro-config": "^0.81.0", + "metro-config": "^0.81.5", "react": "19.1.0", "react-native": "0.81.5", "react-native-audio-api": "0.11.3", diff --git a/apps/speech/tsconfig.json b/apps/speech/tsconfig.json index 47026ce43..a08f2140a 100644 --- a/apps/speech/tsconfig.json +++ b/apps/speech/tsconfig.json @@ -9,7 +9,10 @@ "customConditions": ["react-native"], "noEmit": true, "paths": { - "react-native-executorch": ["../../packages/react-native-executorch/src"] + "react-native-executorch": ["../../packages/react-native-executorch/src"], + "@react-native-executorch/expo-resource-fetcher": [ + "../../packages/expo-resource-fetcher/src" + ] } } } diff --git a/apps/text-embeddings/app/_layout.tsx b/apps/text-embeddings/app/_layout.tsx index 16bf0e87a..c0633a993 100644 --- a/apps/text-embeddings/app/_layout.tsx +++ b/apps/text-embeddings/app/_layout.tsx @@ -1,4 +1,6 @@ import { Drawer } from 'expo-router/drawer'; +import { initExecutorch } from 'react-native-executorch'; +import { ExpoResourceFetcher } from '@react-native-executorch/expo-resource-fetcher'; import ColorPalette from '../colors'; import React, { useState } from 'react'; import { Text, StyleSheet, View } from 'react-native'; @@ -10,6 +12,10 @@ import { } from '@react-navigation/drawer'; import { GeneratingContext } from '../context'; +initExecutorch({ + resourceFetcher: ExpoResourceFetcher, +}); + interface CustomDrawerProps extends DrawerContentComponentProps { isGenerating: boolean; } diff --git a/apps/text-embeddings/package.json b/apps/text-embeddings/package.json index cbf0da96c..64093b919 100644 --- a/apps/text-embeddings/package.json +++ b/apps/text-embeddings/package.json @@ -14,6 +14,7 @@ "@react-navigation/native": "*" }, "dependencies": { + "@react-native-executorch/expo-resource-fetcher": "workspace:*", "@react-navigation/drawer": "^7.3.9", "expo": "^54.0.27", "expo-constants": "~18.0.11", diff --git a/apps/text-embeddings/tsconfig.json b/apps/text-embeddings/tsconfig.json index 47026ce43..a08f2140a 100644 --- a/apps/text-embeddings/tsconfig.json +++ b/apps/text-embeddings/tsconfig.json @@ -9,7 +9,10 @@ "customConditions": ["react-native"], "noEmit": true, "paths": { - "react-native-executorch": ["../../packages/react-native-executorch/src"] + "react-native-executorch": ["../../packages/react-native-executorch/src"], + "@react-native-executorch/expo-resource-fetcher": [ + "../../packages/expo-resource-fetcher/src" + ] } } } diff --git a/docs/docs/01-fundamentals/01-getting-started.md b/docs/docs/01-fundamentals/01-getting-started.md index 109f6e479..f1826c0b4 100644 --- a/docs/docs/01-fundamentals/01-getting-started.md +++ b/docs/docs/01-fundamentals/01-getting-started.md @@ -62,7 +62,7 @@ Installation is pretty straightforward, just use your favorite package manager. -If you're using bare React Native (instead of a managed Expo project), you also need to install Expo Modules because the underlying implementation relies on expo-file-system. Since expo-file-system is an Expo package, bare React Native projects need **Expo Modules** to properly integrate and use it. The link provided (https://docs.expo.dev/bare/installing-expo-modules/) offers guidance on setting up Expo Modules in a bare React Native environment. +Our library offers support for both bare React Native and Expo projects. We encourage you to use Expo project if possible. If you are planning to migrate from bare React Native to Expo project, the link (https://docs.expo.dev/bare/installing-expo-modules/) offers a guidance on setting up Expo Modules in a bare React Native environment. If you plan on using your models via require() instead of fetching them from a url, you also need to add following lines to your `metro.config.js`: diff --git a/docs/docs/01-fundamentals/02-loading-models.md b/docs/docs/01-fundamentals/02-loading-models.md index 96be9784f..ebc6e3079 100644 --- a/docs/docs/01-fundamentals/02-loading-models.md +++ b/docs/docs/01-fundamentals/02-loading-models.md @@ -4,6 +4,46 @@ title: Loading Models There are three different methods available for loading model files, depending on their size and location. +## Prerequisites + +In our library, you can use two different resource fetching mechanisms. One is implemented using Expo module, the other one uses external file-system library. We encourage you to use implementation utilizing Expo if possible. But sometimes you cannot add Expo module to your project, then you should use bare React Native implementation. + +To use initialize Expo adapter, please add these libraries: + +```bash +yarn add @rn-executorch/expo-adapter +yarn add expo-file-system expo-asset +``` + +and then add the following code in your React Native app: + +```typescript +import { initExecutorch } from 'react-native-executorch'; +import { ExpoResourceFetcher } from '@react-native-executorch/expo-resource-fetcher'; + +initExecutorch({ + resourceFetcher: ExpoResourceFetcher, +}); +``` + +If you cannot use Expo in your project, proceed with the following steps: + +```bash +yarn add @rn-executorch/bare-adapter +yarn add @dr.pogodin/react-native-fs @kesha-antonov/react-native-background-downloader +``` + +and + +```typescript +import { initExecutorch } from 'react-native-executorch'; +import { BareResourceFetcher } from '@rn-executorch/bare-adapter'; + +initExecutorch({ + resourceFetcher: BareResourceFetcher, +}); +``` + **1. Load from React Native assets folder (For Files < 512MB)** ```typescript diff --git a/docs/docs/01-fundamentals/03-frequently-asked-questions.md b/docs/docs/01-fundamentals/03-frequently-asked-questions.md index 9216c615f..69e3792d4 100644 --- a/docs/docs/01-fundamentals/03-frequently-asked-questions.md +++ b/docs/docs/01-fundamentals/03-frequently-asked-questions.md @@ -31,7 +31,7 @@ If your model doesn't support it, you can still work around it using context. Fo ### Can I use React Native ExecuTorch in bare React Native apps? -To use the library, you need to install Expo Modules first. For a setup guide, refer to [this tutorial](https://docs.expo.dev/bare/installing-expo-modules/). This is because we use Expo File System under the hood to download and manage the model binaries. +Yes, staring from version `0.8.x` you can use React Native ExecuTorch in bare React Native apps. You just need to use bare React Native resource fetcher instead of Expo one, see: [Loading models section](./02-loading-models.md) for more details. ### Do you support the old architecture? diff --git a/docs/docs/06-api-reference/index.md b/docs/docs/06-api-reference/index.md index 1415421de..debc55540 100644 --- a/docs/docs/06-api-reference/index.md +++ b/docs/docs/06-api-reference/index.md @@ -20,159 +20,159 @@ ## Models - Classification -- [EFFICIENTNET\_V2\_S](variables/EFFICIENTNET_V2_S.md) +- [EFFICIENTNET_V2_S](variables/EFFICIENTNET_V2_S.md) ## Models - Image Embeddings -- [CLIP\_VIT\_BASE\_PATCH32\_IMAGE](variables/CLIP_VIT_BASE_PATCH32_IMAGE.md) +- [CLIP_VIT_BASE_PATCH32_IMAGE](variables/CLIP_VIT_BASE_PATCH32_IMAGE.md) ## Models - Image Generation -- [BK\_SDM\_TINY\_VPRED\_256](variables/BK_SDM_TINY_VPRED_256.md) -- [BK\_SDM\_TINY\_VPRED\_512](variables/BK_SDM_TINY_VPRED_512.md) +- [BK_SDM_TINY_VPRED_256](variables/BK_SDM_TINY_VPRED_256.md) +- [BK_SDM_TINY_VPRED_512](variables/BK_SDM_TINY_VPRED_512.md) ## Models - Image Segmentation -- [DEEPLAB\_V3\_RESNET50](variables/DEEPLAB_V3_RESNET50.md) +- [DEEPLAB_V3_RESNET50](variables/DEEPLAB_V3_RESNET50.md) ## Models - LMM -- [HAMMER2\_1\_0\_5B](variables/HAMMER2_1_0_5B.md) -- [HAMMER2\_1\_0\_5B\_QUANTIZED](variables/HAMMER2_1_0_5B_QUANTIZED.md) -- [HAMMER2\_1\_1\_5B](variables/HAMMER2_1_1_5B.md) -- [HAMMER2\_1\_1\_5B\_QUANTIZED](variables/HAMMER2_1_1_5B_QUANTIZED.md) -- [HAMMER2\_1\_3B](variables/HAMMER2_1_3B.md) -- [HAMMER2\_1\_3B\_QUANTIZED](variables/HAMMER2_1_3B_QUANTIZED.md) -- [LLAMA3\_2\_1B](variables/LLAMA3_2_1B.md) -- [LLAMA3\_2\_1B\_QLORA](variables/LLAMA3_2_1B_QLORA.md) -- [LLAMA3\_2\_1B\_SPINQUANT](variables/LLAMA3_2_1B_SPINQUANT.md) -- [LLAMA3\_2\_3B](variables/LLAMA3_2_3B.md) -- [LLAMA3\_2\_3B\_QLORA](variables/LLAMA3_2_3B_QLORA.md) -- [LLAMA3\_2\_3B\_SPINQUANT](variables/LLAMA3_2_3B_SPINQUANT.md) -- [PHI\_4\_MINI\_4B](variables/PHI_4_MINI_4B.md) -- [PHI\_4\_MINI\_4B\_QUANTIZED](variables/PHI_4_MINI_4B_QUANTIZED.md) -- [QWEN2\_5\_0\_5B](variables/QWEN2_5_0_5B.md) -- [QWEN2\_5\_0\_5B\_QUANTIZED](variables/QWEN2_5_0_5B_QUANTIZED.md) -- [QWEN2\_5\_1\_5B](variables/QWEN2_5_1_5B.md) -- [QWEN2\_5\_1\_5B\_QUANTIZED](variables/QWEN2_5_1_5B_QUANTIZED.md) -- [QWEN2\_5\_3B](variables/QWEN2_5_3B.md) -- [QWEN2\_5\_3B\_QUANTIZED](variables/QWEN2_5_3B_QUANTIZED.md) -- [QWEN3\_0\_6B](variables/QWEN3_0_6B.md) -- [QWEN3\_0\_6B\_QUANTIZED](variables/QWEN3_0_6B_QUANTIZED.md) -- [QWEN3\_1\_7B](variables/QWEN3_1_7B.md) -- [QWEN3\_1\_7B\_QUANTIZED](variables/QWEN3_1_7B_QUANTIZED.md) -- [QWEN3\_4B](variables/QWEN3_4B.md) -- [QWEN3\_4B\_QUANTIZED](variables/QWEN3_4B_QUANTIZED.md) -- [SMOLLM2\_1\_1\_7B](variables/SMOLLM2_1_1_7B.md) -- [SMOLLM2\_1\_1\_7B\_QUANTIZED](variables/SMOLLM2_1_1_7B_QUANTIZED.md) -- [SMOLLM2\_1\_135M](variables/SMOLLM2_1_135M.md) -- [SMOLLM2\_1\_135M\_QUANTIZED](variables/SMOLLM2_1_135M_QUANTIZED.md) -- [SMOLLM2\_1\_360M](variables/SMOLLM2_1_360M.md) -- [SMOLLM2\_1\_360M\_QUANTIZED](variables/SMOLLM2_1_360M_QUANTIZED.md) +- [HAMMER2_1_0_5B](variables/HAMMER2_1_0_5B.md) +- [HAMMER2_1_0_5B_QUANTIZED](variables/HAMMER2_1_0_5B_QUANTIZED.md) +- [HAMMER2_1_1_5B](variables/HAMMER2_1_1_5B.md) +- [HAMMER2_1_1_5B_QUANTIZED](variables/HAMMER2_1_1_5B_QUANTIZED.md) +- [HAMMER2_1_3B](variables/HAMMER2_1_3B.md) +- [HAMMER2_1_3B_QUANTIZED](variables/HAMMER2_1_3B_QUANTIZED.md) +- [LLAMA3_2_1B](variables/LLAMA3_2_1B.md) +- [LLAMA3_2_1B_QLORA](variables/LLAMA3_2_1B_QLORA.md) +- [LLAMA3_2_1B_SPINQUANT](variables/LLAMA3_2_1B_SPINQUANT.md) +- [LLAMA3_2_3B](variables/LLAMA3_2_3B.md) +- [LLAMA3_2_3B_QLORA](variables/LLAMA3_2_3B_QLORA.md) +- [LLAMA3_2_3B_SPINQUANT](variables/LLAMA3_2_3B_SPINQUANT.md) +- [PHI_4_MINI_4B](variables/PHI_4_MINI_4B.md) +- [PHI_4_MINI_4B_QUANTIZED](variables/PHI_4_MINI_4B_QUANTIZED.md) +- [QWEN2_5_0_5B](variables/QWEN2_5_0_5B.md) +- [QWEN2_5_0_5B_QUANTIZED](variables/QWEN2_5_0_5B_QUANTIZED.md) +- [QWEN2_5_1_5B](variables/QWEN2_5_1_5B.md) +- [QWEN2_5_1_5B_QUANTIZED](variables/QWEN2_5_1_5B_QUANTIZED.md) +- [QWEN2_5_3B](variables/QWEN2_5_3B.md) +- [QWEN2_5_3B_QUANTIZED](variables/QWEN2_5_3B_QUANTIZED.md) +- [QWEN3_0_6B](variables/QWEN3_0_6B.md) +- [QWEN3_0_6B_QUANTIZED](variables/QWEN3_0_6B_QUANTIZED.md) +- [QWEN3_1_7B](variables/QWEN3_1_7B.md) +- [QWEN3_1_7B_QUANTIZED](variables/QWEN3_1_7B_QUANTIZED.md) +- [QWEN3_4B](variables/QWEN3_4B.md) +- [QWEN3_4B_QUANTIZED](variables/QWEN3_4B_QUANTIZED.md) +- [SMOLLM2_1_1_7B](variables/SMOLLM2_1_1_7B.md) +- [SMOLLM2_1_1_7B_QUANTIZED](variables/SMOLLM2_1_1_7B_QUANTIZED.md) +- [SMOLLM2_1_135M](variables/SMOLLM2_1_135M.md) +- [SMOLLM2_1_135M_QUANTIZED](variables/SMOLLM2_1_135M_QUANTIZED.md) +- [SMOLLM2_1_360M](variables/SMOLLM2_1_360M.md) +- [SMOLLM2_1_360M_QUANTIZED](variables/SMOLLM2_1_360M_QUANTIZED.md) ## Models - Object Detection -- [SSDLITE\_320\_MOBILENET\_V3\_LARGE](variables/SSDLITE_320_MOBILENET_V3_LARGE.md) +- [SSDLITE_320_MOBILENET_V3_LARGE](variables/SSDLITE_320_MOBILENET_V3_LARGE.md) ## Models - Speech To Text -- [WHISPER\_BASE](variables/WHISPER_BASE.md) -- [WHISPER\_BASE\_EN](variables/WHISPER_BASE_EN.md) -- [WHISPER\_SMALL](variables/WHISPER_SMALL.md) -- [WHISPER\_SMALL\_EN](variables/WHISPER_SMALL_EN.md) -- [WHISPER\_TINY](variables/WHISPER_TINY.md) -- [WHISPER\_TINY\_EN](variables/WHISPER_TINY_EN.md) -- [WHISPER\_TINY\_EN\_QUANTIZED](variables/WHISPER_TINY_EN_QUANTIZED.md) +- [WHISPER_BASE](variables/WHISPER_BASE.md) +- [WHISPER_BASE_EN](variables/WHISPER_BASE_EN.md) +- [WHISPER_SMALL](variables/WHISPER_SMALL.md) +- [WHISPER_SMALL_EN](variables/WHISPER_SMALL_EN.md) +- [WHISPER_TINY](variables/WHISPER_TINY.md) +- [WHISPER_TINY_EN](variables/WHISPER_TINY_EN.md) +- [WHISPER_TINY_EN_QUANTIZED](variables/WHISPER_TINY_EN_QUANTIZED.md) ## Models - Style Transfer -- [STYLE\_TRANSFER\_CANDY](variables/STYLE_TRANSFER_CANDY.md) -- [STYLE\_TRANSFER\_MOSAIC](variables/STYLE_TRANSFER_MOSAIC.md) -- [STYLE\_TRANSFER\_RAIN\_PRINCESS](variables/STYLE_TRANSFER_RAIN_PRINCESS.md) -- [STYLE\_TRANSFER\_UDNIE](variables/STYLE_TRANSFER_UDNIE.md) +- [STYLE_TRANSFER_CANDY](variables/STYLE_TRANSFER_CANDY.md) +- [STYLE_TRANSFER_MOSAIC](variables/STYLE_TRANSFER_MOSAIC.md) +- [STYLE_TRANSFER_RAIN_PRINCESS](variables/STYLE_TRANSFER_RAIN_PRINCESS.md) +- [STYLE_TRANSFER_UDNIE](variables/STYLE_TRANSFER_UDNIE.md) ## Models - Text Embeddings -- [ALL\_MINILM\_L6\_V2](variables/ALL_MINILM_L6_V2.md) -- [ALL\_MPNET\_BASE\_V2](variables/ALL_MPNET_BASE_V2.md) -- [CLIP\_VIT\_BASE\_PATCH32\_TEXT](variables/CLIP_VIT_BASE_PATCH32_TEXT.md) -- [MULTI\_QA\_MINILM\_L6\_COS\_V1](variables/MULTI_QA_MINILM_L6_COS_V1.md) -- [MULTI\_QA\_MPNET\_BASE\_DOT\_V1](variables/MULTI_QA_MPNET_BASE_DOT_V1.md) +- [ALL_MINILM_L6_V2](variables/ALL_MINILM_L6_V2.md) +- [ALL_MPNET_BASE_V2](variables/ALL_MPNET_BASE_V2.md) +- [CLIP_VIT_BASE_PATCH32_TEXT](variables/CLIP_VIT_BASE_PATCH32_TEXT.md) +- [MULTI_QA_MINILM_L6_COS_V1](variables/MULTI_QA_MINILM_L6_COS_V1.md) +- [MULTI_QA_MPNET_BASE_DOT_V1](variables/MULTI_QA_MPNET_BASE_DOT_V1.md) ## Models - Text to Speech -- [KOKORO\_MEDIUM](variables/KOKORO_MEDIUM.md) -- [KOKORO\_SMALL](variables/KOKORO_SMALL.md) +- [KOKORO_MEDIUM](variables/KOKORO_MEDIUM.md) +- [KOKORO_SMALL](variables/KOKORO_SMALL.md) ## Models - Voice Activity Detection -- [FSMN\_VAD](variables/FSMN_VAD.md) +- [FSMN_VAD](variables/FSMN_VAD.md) ## OCR Supported Alphabets -- [OCR\_ABAZA](variables/OCR_ABAZA.md) -- [OCR\_ADYGHE](variables/OCR_ADYGHE.md) -- [OCR\_AFRIKAANS](variables/OCR_AFRIKAANS.md) -- [OCR\_ALBANIAN](variables/OCR_ALBANIAN.md) -- [OCR\_AVAR](variables/OCR_AVAR.md) -- [OCR\_AZERBAIJANI](variables/OCR_AZERBAIJANI.md) -- [OCR\_BELARUSIAN](variables/OCR_BELARUSIAN.md) -- [OCR\_BOSNIAN](variables/OCR_BOSNIAN.md) -- [OCR\_BULGARIAN](variables/OCR_BULGARIAN.md) -- [OCR\_CHECHEN](variables/OCR_CHECHEN.md) -- [OCR\_CROATIAN](variables/OCR_CROATIAN.md) -- [OCR\_CZECH](variables/OCR_CZECH.md) -- [OCR\_DANISH](variables/OCR_DANISH.md) -- [OCR\_DARGWA](variables/OCR_DARGWA.md) -- [OCR\_DUTCH](variables/OCR_DUTCH.md) -- [OCR\_ENGLISH](variables/OCR_ENGLISH.md) -- [OCR\_ESTONIAN](variables/OCR_ESTONIAN.md) -- [OCR\_FRENCH](variables/OCR_FRENCH.md) -- [OCR\_GERMAN](variables/OCR_GERMAN.md) -- [OCR\_HUNGARIAN](variables/OCR_HUNGARIAN.md) -- [OCR\_ICELANDIC](variables/OCR_ICELANDIC.md) -- [OCR\_INDONESIAN](variables/OCR_INDONESIAN.md) -- [OCR\_INGUSH](variables/OCR_INGUSH.md) -- [OCR\_IRISH](variables/OCR_IRISH.md) -- [OCR\_ITALIAN](variables/OCR_ITALIAN.md) -- [OCR\_JAPANESE](variables/OCR_JAPANESE.md) -- [OCR\_KANNADA](variables/OCR_KANNADA.md) -- [OCR\_KARBADIAN](variables/OCR_KARBADIAN.md) -- [OCR\_KOREAN](variables/OCR_KOREAN.md) -- [OCR\_KURDISH](variables/OCR_KURDISH.md) -- [OCR\_LAK](variables/OCR_LAK.md) -- [OCR\_LATIN](variables/OCR_LATIN.md) -- [OCR\_LATVIAN](variables/OCR_LATVIAN.md) -- [OCR\_LEZGHIAN](variables/OCR_LEZGHIAN.md) -- [OCR\_LITHUANIAN](variables/OCR_LITHUANIAN.md) -- [OCR\_MALAY](variables/OCR_MALAY.md) -- [OCR\_MALTESE](variables/OCR_MALTESE.md) -- [OCR\_MAORI](variables/OCR_MAORI.md) -- [OCR\_MONGOLIAN](variables/OCR_MONGOLIAN.md) -- [OCR\_NORWEGIAN](variables/OCR_NORWEGIAN.md) -- [OCR\_OCCITAN](variables/OCR_OCCITAN.md) -- [OCR\_PALI](variables/OCR_PALI.md) -- [OCR\_POLISH](variables/OCR_POLISH.md) -- [OCR\_PORTUGUESE](variables/OCR_PORTUGUESE.md) -- [OCR\_ROMANIAN](variables/OCR_ROMANIAN.md) -- [OCR\_RUSSIAN](variables/OCR_RUSSIAN.md) -- [OCR\_SERBIAN\_CYRILLIC](variables/OCR_SERBIAN_CYRILLIC.md) -- [OCR\_SERBIAN\_LATIN](variables/OCR_SERBIAN_LATIN.md) -- [OCR\_SIMPLIFIED\_CHINESE](variables/OCR_SIMPLIFIED_CHINESE.md) -- [OCR\_SLOVAK](variables/OCR_SLOVAK.md) -- [OCR\_SLOVENIAN](variables/OCR_SLOVENIAN.md) -- [OCR\_SPANISH](variables/OCR_SPANISH.md) -- [OCR\_SWAHILI](variables/OCR_SWAHILI.md) -- [OCR\_SWEDISH](variables/OCR_SWEDISH.md) -- [OCR\_TABASSARAN](variables/OCR_TABASSARAN.md) -- [OCR\_TAGALOG](variables/OCR_TAGALOG.md) -- [OCR\_TAJIK](variables/OCR_TAJIK.md) -- [OCR\_TELUGU](variables/OCR_TELUGU.md) -- [OCR\_TURKISH](variables/OCR_TURKISH.md) -- [OCR\_UKRAINIAN](variables/OCR_UKRAINIAN.md) -- [OCR\_UZBEK](variables/OCR_UZBEK.md) -- [OCR\_VIETNAMESE](variables/OCR_VIETNAMESE.md) -- [OCR\_WELSH](variables/OCR_WELSH.md) +- [OCR_ABAZA](variables/OCR_ABAZA.md) +- [OCR_ADYGHE](variables/OCR_ADYGHE.md) +- [OCR_AFRIKAANS](variables/OCR_AFRIKAANS.md) +- [OCR_ALBANIAN](variables/OCR_ALBANIAN.md) +- [OCR_AVAR](variables/OCR_AVAR.md) +- [OCR_AZERBAIJANI](variables/OCR_AZERBAIJANI.md) +- [OCR_BELARUSIAN](variables/OCR_BELARUSIAN.md) +- [OCR_BOSNIAN](variables/OCR_BOSNIAN.md) +- [OCR_BULGARIAN](variables/OCR_BULGARIAN.md) +- [OCR_CHECHEN](variables/OCR_CHECHEN.md) +- [OCR_CROATIAN](variables/OCR_CROATIAN.md) +- [OCR_CZECH](variables/OCR_CZECH.md) +- [OCR_DANISH](variables/OCR_DANISH.md) +- [OCR_DARGWA](variables/OCR_DARGWA.md) +- [OCR_DUTCH](variables/OCR_DUTCH.md) +- [OCR_ENGLISH](variables/OCR_ENGLISH.md) +- [OCR_ESTONIAN](variables/OCR_ESTONIAN.md) +- [OCR_FRENCH](variables/OCR_FRENCH.md) +- [OCR_GERMAN](variables/OCR_GERMAN.md) +- [OCR_HUNGARIAN](variables/OCR_HUNGARIAN.md) +- [OCR_ICELANDIC](variables/OCR_ICELANDIC.md) +- [OCR_INDONESIAN](variables/OCR_INDONESIAN.md) +- [OCR_INGUSH](variables/OCR_INGUSH.md) +- [OCR_IRISH](variables/OCR_IRISH.md) +- [OCR_ITALIAN](variables/OCR_ITALIAN.md) +- [OCR_JAPANESE](variables/OCR_JAPANESE.md) +- [OCR_KANNADA](variables/OCR_KANNADA.md) +- [OCR_KARBADIAN](variables/OCR_KARBADIAN.md) +- [OCR_KOREAN](variables/OCR_KOREAN.md) +- [OCR_KURDISH](variables/OCR_KURDISH.md) +- [OCR_LAK](variables/OCR_LAK.md) +- [OCR_LATIN](variables/OCR_LATIN.md) +- [OCR_LATVIAN](variables/OCR_LATVIAN.md) +- [OCR_LEZGHIAN](variables/OCR_LEZGHIAN.md) +- [OCR_LITHUANIAN](variables/OCR_LITHUANIAN.md) +- [OCR_MALAY](variables/OCR_MALAY.md) +- [OCR_MALTESE](variables/OCR_MALTESE.md) +- [OCR_MAORI](variables/OCR_MAORI.md) +- [OCR_MONGOLIAN](variables/OCR_MONGOLIAN.md) +- [OCR_NORWEGIAN](variables/OCR_NORWEGIAN.md) +- [OCR_OCCITAN](variables/OCR_OCCITAN.md) +- [OCR_PALI](variables/OCR_PALI.md) +- [OCR_POLISH](variables/OCR_POLISH.md) +- [OCR_PORTUGUESE](variables/OCR_PORTUGUESE.md) +- [OCR_ROMANIAN](variables/OCR_ROMANIAN.md) +- [OCR_RUSSIAN](variables/OCR_RUSSIAN.md) +- [OCR_SERBIAN_CYRILLIC](variables/OCR_SERBIAN_CYRILLIC.md) +- [OCR_SERBIAN_LATIN](variables/OCR_SERBIAN_LATIN.md) +- [OCR_SIMPLIFIED_CHINESE](variables/OCR_SIMPLIFIED_CHINESE.md) +- [OCR_SLOVAK](variables/OCR_SLOVAK.md) +- [OCR_SLOVENIAN](variables/OCR_SLOVENIAN.md) +- [OCR_SPANISH](variables/OCR_SPANISH.md) +- [OCR_SWAHILI](variables/OCR_SWAHILI.md) +- [OCR_SWEDISH](variables/OCR_SWEDISH.md) +- [OCR_TABASSARAN](variables/OCR_TABASSARAN.md) +- [OCR_TAGALOG](variables/OCR_TAGALOG.md) +- [OCR_TAJIK](variables/OCR_TAJIK.md) +- [OCR_TELUGU](variables/OCR_TELUGU.md) +- [OCR_TURKISH](variables/OCR_TURKISH.md) +- [OCR_UKRAINIAN](variables/OCR_UKRAINIAN.md) +- [OCR_UZBEK](variables/OCR_UZBEK.md) +- [OCR_VIETNAMESE](variables/OCR_VIETNAMESE.md) +- [OCR_WELSH](variables/OCR_WELSH.md) ## Other @@ -181,14 +181,14 @@ ## TTS Supported Voices -- [KOKORO\_VOICE\_AF\_HEART](variables/KOKORO_VOICE_AF_HEART.md) -- [KOKORO\_VOICE\_AF\_RIVER](variables/KOKORO_VOICE_AF_RIVER.md) -- [KOKORO\_VOICE\_AF\_SARAH](variables/KOKORO_VOICE_AF_SARAH.md) -- [KOKORO\_VOICE\_AM\_ADAM](variables/KOKORO_VOICE_AM_ADAM.md) -- [KOKORO\_VOICE\_AM\_MICHAEL](variables/KOKORO_VOICE_AM_MICHAEL.md) -- [KOKORO\_VOICE\_AM\_SANTA](variables/KOKORO_VOICE_AM_SANTA.md) -- [KOKORO\_VOICE\_BF\_EMMA](variables/KOKORO_VOICE_BF_EMMA.md) -- [KOKORO\_VOICE\_BM\_DANIEL](variables/KOKORO_VOICE_BM_DANIEL.md) +- [KOKORO_VOICE_AF_HEART](variables/KOKORO_VOICE_AF_HEART.md) +- [KOKORO_VOICE_AF_RIVER](variables/KOKORO_VOICE_AF_RIVER.md) +- [KOKORO_VOICE_AF_SARAH](variables/KOKORO_VOICE_AF_SARAH.md) +- [KOKORO_VOICE_AM_ADAM](variables/KOKORO_VOICE_AM_ADAM.md) +- [KOKORO_VOICE_AM_MICHAEL](variables/KOKORO_VOICE_AM_MICHAEL.md) +- [KOKORO_VOICE_AM_SANTA](variables/KOKORO_VOICE_AM_SANTA.md) +- [KOKORO_VOICE_BF_EMMA](variables/KOKORO_VOICE_BF_EMMA.md) +- [KOKORO_VOICE_BM_DANIEL](variables/KOKORO_VOICE_BM_DANIEL.md) ## Types @@ -251,7 +251,7 @@ - [SpeechToTextLanguage](type-aliases/SpeechToTextLanguage.md) - [TensorBuffer](type-aliases/TensorBuffer.md) - [TextToSpeechLanguage](type-aliases/TextToSpeechLanguage.md) -- [SPECIAL\_TOKENS](variables/SPECIAL_TOKENS.md) +- [SPECIAL_TOKENS](variables/SPECIAL_TOKENS.md) ## Typescript API @@ -277,11 +277,11 @@ ## Utilities - LLM -- [DEFAULT\_CHAT\_CONFIG](variables/DEFAULT_CHAT_CONFIG.md) -- [DEFAULT\_CONTEXT\_WINDOW\_LENGTH](variables/DEFAULT_CONTEXT_WINDOW_LENGTH.md) -- [DEFAULT\_MESSAGE\_HISTORY](variables/DEFAULT_MESSAGE_HISTORY.md) -- [DEFAULT\_SYSTEM\_PROMPT](variables/DEFAULT_SYSTEM_PROMPT.md) +- [DEFAULT_CHAT_CONFIG](variables/DEFAULT_CHAT_CONFIG.md) +- [DEFAULT_CONTEXT_WINDOW_LENGTH](variables/DEFAULT_CONTEXT_WINDOW_LENGTH.md) +- [DEFAULT_MESSAGE_HISTORY](variables/DEFAULT_MESSAGE_HISTORY.md) +- [DEFAULT_SYSTEM_PROMPT](variables/DEFAULT_SYSTEM_PROMPT.md) - [parseToolCall](variables/parseToolCall.md) -- [DEFAULT\_STRUCTURED\_OUTPUT\_PROMPT](functions/DEFAULT_STRUCTURED_OUTPUT_PROMPT.md) +- [DEFAULT_STRUCTURED_OUTPUT_PROMPT](functions/DEFAULT_STRUCTURED_OUTPUT_PROMPT.md) - [fixAndValidateStructuredOutput](functions/fixAndValidateStructuredOutput.md) - [getStructuredOutputPrompt](functions/getStructuredOutputPrompt.md) diff --git a/docs/src/theme/SearchBar.tsx b/docs/src/theme/SearchBar.tsx index 7536c3716..8dd05bdab 100644 --- a/docs/src/theme/SearchBar.tsx +++ b/docs/src/theme/SearchBar.tsx @@ -2,4 +2,4 @@ import React from 'react'; export default function SearchBar() { return
; -} \ No newline at end of file +} diff --git a/docs/versioned_docs/version-0.6.x/02-hooks/02-computer-vision/useOCR.md b/docs/versioned_docs/version-0.6.x/02-hooks/02-computer-vision/useOCR.md index 0c804e1a0..d491ed65b 100644 --- a/docs/versioned_docs/version-0.6.x/02-hooks/02-computer-vision/useOCR.md +++ b/docs/versioned_docs/version-0.6.x/02-hooks/02-computer-vision/useOCR.md @@ -309,7 +309,7 @@ You need to make sure the recognizer models you pass in `recognizerSources` matc |  |  | | ----------------------------------------------- | ----------------------------------------------------- | -| Original Image | Image with detected Text Boxes | +| Original Image | Image with detected Text Boxes | :::warning Times presented in the tables are measured as consecutive runs of the model. Initial run times may be up to 2x longer due to model loading and initialization. diff --git a/docs/versioned_docs/version-0.6.x/02-hooks/02-computer-vision/useTextToImage.md b/docs/versioned_docs/version-0.6.x/02-hooks/02-computer-vision/useTextToImage.md index 1d35d7a3a..476f8d95d 100644 --- a/docs/versioned_docs/version-0.6.x/02-hooks/02-computer-vision/useTextToImage.md +++ b/docs/versioned_docs/version-0.6.x/02-hooks/02-computer-vision/useTextToImage.md @@ -94,7 +94,7 @@ function App() { |  |  | | ------------------------------------------------------- | ------------------------------------------------------- | -| Image of size 256×256 | Image of size 512×512 | +| Image of size 256×256 | Image of size 512×512 | ## Supported models diff --git a/docs/versioned_docs/version-0.6.x/02-hooks/02-computer-vision/useVerticalOCR.md b/docs/versioned_docs/version-0.6.x/02-hooks/02-computer-vision/useVerticalOCR.md index 33f4d935f..88934fd2e 100644 --- a/docs/versioned_docs/version-0.6.x/02-hooks/02-computer-vision/useVerticalOCR.md +++ b/docs/versioned_docs/version-0.6.x/02-hooks/02-computer-vision/useVerticalOCR.md @@ -324,7 +324,7 @@ You need to make sure the recognizer models you pass in `recognizerSources` matc |  |  | | ------------------------------------------------------- | ------------------------------------------------------------ | -| Original Image | Image with detected Text Boxes | +| Original Image | Image with detected Text Boxes | :::warning Times presented in the tables are measured as consecutive runs of the model. Initial run times may be up to 2x longer due to model loading and initialization. diff --git a/package.json b/package.json index e4ee020b2..33cbcc2d9 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "packageManager": "yarn@4.1.1", "workspaces": { "packages": [ - "packages/react-native-executorch", + "packages/*", "apps/*" ] }, diff --git a/packages/bare-resource-fetcher/README.md b/packages/bare-resource-fetcher/README.md new file mode 100644 index 000000000..9b1493f1d --- /dev/null +++ b/packages/bare-resource-fetcher/README.md @@ -0,0 +1,37 @@ +# @react-native-executorch/bare-resource-fetcher + +Bare React Native adapter for `react-native-executorch` that provides resource fetching capabilities using native filesystem libraries. + +## Installation + +```bash +yarn add @react-native-executorch/bare-resource-fetcher +yarn add @dr.pogodin/react-native-fs @kesha-antonov/react-native-background-downloader +``` + +### Native Dependencies Setup + +After installing, follow the setup guides for the native dependencies: + +- **[@dr.pogodin/react-native-fs](https://github.com/birdofpreyru/react-native-fs#getting-started)** - Filesystem operations +- **[@kesha-antonov/react-native-background-downloader](https://github.com/kesha-antonov/react-native-background-downloader#bare-react-native-projects)** - Background download support + +> **Note**: Make sure to complete the native setup (iOS/Android configuration) for both dependencies before using this adapter. + +## Usage + +```typescript +import { initExecutorch } from 'react-native-executorch'; +import { BareResourceFetcher } from '@react-native-executorch/bare-resource-fetcher'; + +initExecutorch({ + resourceFetcher: BareResourceFetcher, +}); +``` + +## When to Use + +Use this adapter if you're working with: +- Bare React Native projects (created with `npx @react-native-community/cli@latest init`) +- Projects that need true background downloads +- Projects requiring direct native filesystem access diff --git a/packages/bare-resource-fetcher/package.json b/packages/bare-resource-fetcher/package.json new file mode 100644 index 000000000..b5533ac48 --- /dev/null +++ b/packages/bare-resource-fetcher/package.json @@ -0,0 +1,43 @@ +{ + "name": "@react-native-executorch/bare-resource-fetcher", + "version": "0.1.0", + "description": "Bare React Native resource fetcher for react-native-executorch", + "main": "lib/index.js", + "types": "lib/index.d.ts", + "exports": { + ".": { + "import": "./lib/index.js", + "types": "./lib/index.d.ts" + } + }, + "files": [ + "lib" + ], + "license": "MIT", + "repository": { + "type": "git", + "url": "git+https://github.com/software-mansion/react-native-executorch.git", + "directory": "packages/bare-resource-fetcher" + }, + "scripts": { + "prepare": "tsc", + "typecheck": "tsc --noEmit", + "lint": "eslint \"**/*.{js,ts,tsx}\"", + "clean": "del-cli lib" + }, + "peerDependencies": { + "@dr.pogodin/react-native-fs": "^2.0.0", + "@kesha-antonov/react-native-background-downloader": "^4.0.0", + "react-native": "*", + "react-native-executorch": "*" + }, + "devDependencies": { + "@dr.pogodin/react-native-fs": "^2.36.2", + "@kesha-antonov/react-native-background-downloader": "^4.4.5", + "@types/react": "~19.1.10", + "react": "19.1.0", + "react-native": "0.81.5", + "react-native-executorch": "workspace:*", + "typescript": "~5.9.2" + } +} diff --git a/packages/bare-resource-fetcher/src/ResourceFetcher.ts b/packages/bare-resource-fetcher/src/ResourceFetcher.ts new file mode 100644 index 000000000..c5cee0fd7 --- /dev/null +++ b/packages/bare-resource-fetcher/src/ResourceFetcher.ts @@ -0,0 +1,572 @@ +/** + * Resource Fetcher for React Native applications. + * + * This module provides functions to download and manage files stored in the application's document directory + * inside the `react-native-executorch/` directory. These utilities help manage storage and clean up downloaded + * files when they are no longer needed. + * + * @category Utilities - General + * + * @remarks + * **Key Functionality:** + * - **Download Control**: Pause, resume, and cancel operations through: + * - {@link pauseFetching} - Pause ongoing downloads + * - {@link resumeFetching} - Resume paused downloads + * - {@link cancelFetching} - Cancel ongoing or paused downloads + * - **File Management**: + * - {@link getFilesTotalSize} - Get total size of resources + * - {@link listDownloadedFiles} - List all downloaded files + * - {@link listDownloadedModels} - List downloaded model files (.pte) + * - {@link deleteResources} - Delete downloaded resources + * + * **Important Notes:** + * - Pause/resume/cancel operations work only for remote resources + * - Most functions accept multiple `ResourceSource` arguments (string, number, or object) + * - The {@link fetch} method accepts a progress callback (0-1) and returns file paths or null if interrupted + * + * **Technical Implementation:** + * - Maintains a `downloads` Map to track active and paused downloads + * - Successful downloads are automatically removed from the Map + * - Uses `ResourceSourceExtended` interface for pause/resume functionality with linked-list behavior + */ + +import { + createDownloadTask, + completeHandler, + DownloadTask, + BeginHandlerParams, + ProgressHandlerParams, +} from '@kesha-antonov/react-native-background-downloader'; +import * as RNFS from '@dr.pogodin/react-native-fs'; +import { Image } from 'react-native'; +import { RNEDirectory } from './constants/directories'; +import { + ResourceSource, + ResourceFetcherAdapter, + RnExecutorchErrorCode, + RnExecutorchError, +} from 'react-native-executorch'; +import { + ResourceFetcherUtils, + DownloadStatus, + SourceType, + ResourceSourceExtended, +} from './ResourceFetcherUtils'; + +interface DownloadResource { + task: DownloadTask; + status: DownloadStatus; + extendedInfo: ResourceSourceExtended; +} + +interface BareResourceFetcherInterface extends ResourceFetcherAdapter { + downloads: Map