@@ -80,22 +80,30 @@ def _resolve_rapidocr(lang: list[str], backend: str) -> "tuple[OCRVersion, str]"
8080 aliased = COMMON_LANG_ALIASES .get (code , code )
8181
8282 if aliased in PP_OCRV6_LANGS :
83- return OCRVersion .PPOCRV6 , aliased
84-
85- if backend == "torch" :
86- if aliased in _PPOCRV4_LANGS :
87- return OCRVersion .PPOCRV4 , aliased
83+ version = OCRVersion .PPOCRV6
84+ elif backend == "torch" :
85+ if aliased not in _PPOCRV4_LANGS :
86+ raise ValueError (
87+ f"RapidOCR torch backend does not support language { langs [0 ]!r} . "
88+ f"Supported: { sorted (PP_OCRV6_LANGS | _PPOCRV4_LANGS )} ."
89+ )
90+ version = OCRVersion .PPOCRV4
91+ elif aliased in _PPOCRV5_LANGS :
92+ version = OCRVersion .PPOCRV5
93+ else :
8894 raise ValueError (
89- f"RapidOCR torch backend does not support language { langs [0 ]!r} . "
90- f"Supported: { sorted (PP_OCRV6_LANGS | _PPOCRV4_LANGS )} ."
95+ f"RapidOCR { backend } backend does not support language { langs [0 ]!r} . "
96+ f"Supported: { sorted (PP_OCRV6_LANGS | _PPOCRV5_LANGS )} ."
9197 )
9298
93- if aliased in _PPOCRV5_LANGS :
94- return OCRVersion .PPOCRV5 , aliased
95- raise ValueError (
96- f"RapidOCR { backend } backend does not support language { langs [0 ]!r} . "
97- f"Supported: { sorted (PP_OCRV6_LANGS | _PPOCRV5_LANGS )} ."
99+ _log .debug (
100+ "RapidOCR resolved lang=%r backend=%r -> version=%s rec_lang=%r" ,
101+ lang ,
102+ backend ,
103+ version .value ,
104+ aliased ,
98105 )
106+ return version , aliased
99107
100108
101109def _download_if_missing (url : str , dest : Path , * , force : bool , progress : bool ) -> Path :
0 commit comments