MCPcopy Create free account
hub / github.com/EmbodiedGPT/EmbodiedGPT_Pytorch / detect_language

Function detect_language

robohusky/utils.py:225–238  ·  view source on GitHub ↗

Detect the langauge of a string.

(text: str)

Source from the content-addressed store, hash-verified

223
224
225def detect_language(text: str) -> str:
226 """Detect the langauge of a string."""
227 import polyglot # pip3 install polyglot pyicu pycld2
228 from polyglot.detect import Detector
229 from polyglot.detect.base import logger as polyglot_logger
230 import pycld2
231
232 polyglot_logger.setLevel("ERROR")
233
234 try:
235 lang_code = Detector(text).language.name
236 except (pycld2.error, polyglot.detect.base.UnknownLanguage):
237 lang_code = "unknown"
238 return lang_code

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected