UNPKG

react-native-executorch

Version:

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

35 lines (34 loc) 1.08 kB
"use strict"; import { useEffect, useState } from 'react'; import { OCRController } from '../../controllers/OCRController'; export const useOCR = ({ detectorSource, recognizerSources, language = 'en' }) => { const [error, setError] = useState(null); const [isReady, setIsReady] = useState(false); const [isGenerating, setIsGenerating] = useState(false); const [downloadProgress, setDownloadProgress] = useState(0); const [model, _] = useState(() => new OCRController({ modelDownloadProgressCallback: setDownloadProgress, isReadyCallback: setIsReady, isGeneratingCallback: setIsGenerating, errorCallback: setError })); useEffect(() => { const loadModel = async () => { await model.loadModel(detectorSource, recognizerSources, language); }; loadModel(); // eslint-disable-next-line react-hooks/exhaustive-deps }, [detectorSource, language, JSON.stringify(recognizerSources)]); return { error, isReady, isGenerating, forward: model.forward, downloadProgress }; }; //# sourceMappingURL=useOCR.js.map