react-native-executorch
Version:
An easy way to run AI models in react native with ExecuTorch
40 lines (39 loc) • 1.34 kB
JavaScript
import { useEffect, useState } from 'react';
import { VerticalOCRController } from '../../controllers/VerticalOCRController';
export const useVerticalOCR = ({
detectorSources,
recognizerSources,
language = 'en',
independentCharacters = false
}) => {
const [error, setError] = useState(null);
const [isReady, setIsReady] = useState(false);
const [isGenerating, setIsGenerating] = useState(false);
const [downloadProgress, setDownloadProgress] = useState(0);
const [model, _] = useState(() => new VerticalOCRController({
modelDownloadProgressCallback: setDownloadProgress,
isReadyCallback: setIsReady,
isGeneratingCallback: setIsGenerating,
errorCallback: setError
}));
useEffect(() => {
const loadModel = async () => {
await model.loadModel(detectorSources, recognizerSources, language, independentCharacters);
};
loadModel();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
// eslint-disable-next-line react-hooks/exhaustive-deps
JSON.stringify(detectorSources), language, independentCharacters,
// eslint-disable-next-line react-hooks/exhaustive-deps
JSON.stringify(recognizerSources)]);
return {
error,
isReady,
isGenerating,
forward: model.forward,
downloadProgress
};
};
//# sourceMappingURL=useVerticalOCR.js.map
;