UNPKG

react-native-executorch

Version:

An easy way to run AI models in react native with ExecuTorch

43 lines (42 loc) 1.42 kB
"use strict"; import { useEffect, useMemo, useState } from 'react'; import { VerticalOCRController } from '../../controllers/VerticalOCRController'; export const useVerticalOCR = ({ detectorSources, recognizerSources, language = 'en', independentCharacters = false, preventLoad = false }) => { const [error, setError] = useState(null); const [isReady, setIsReady] = useState(false); const [isGenerating, setIsGenerating] = useState(false); const [downloadProgress, setDownloadProgress] = useState(0); const model = useMemo(() => new VerticalOCRController({ modelDownloadProgressCallback: setDownloadProgress, isReadyCallback: setIsReady, isGeneratingCallback: setIsGenerating, errorCallback: setError }), []); useEffect(() => { const loadModel = async () => { await model.loadModel(detectorSources, recognizerSources, language, independentCharacters); }; if (!preventLoad) { loadModel(); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [model, // eslint-disable-next-line react-hooks/exhaustive-deps JSON.stringify(detectorSources), language, independentCharacters, // eslint-disable-next-line react-hooks/exhaustive-deps JSON.stringify(recognizerSources), preventLoad]); return { error, isReady, isGenerating, forward: model.forward, downloadProgress }; }; //# sourceMappingURL=useVerticalOCR.js.map