Download LanguageTool.py from CalebKoster/Translation_Note_Alignment: direct link, hf CLI and curl.
- Browser
- Download file 410 Bytes
-
https://huggingface.co/spaces/CalebKoster/Translation_Note_Alignment/resolve/main/LanguageTool.py
- Command line
-
hf download hf://spaces/CalebKoster/Translation_Note_Alignment/LanguageTool.py
-
curl -L -o LanguageTool.py https://huggingface.co/spaces/CalebKoster/Translation_Note_Alignment/resolve/main/LanguageTool.py
410 Bytes
| from langdetect import detect | |
| import pycountry | |
| import langid | |
| class Lang: | |
| def __init__(self, text, options=None): | |
| if options: | |
| langid.set_languages(options) # ISO 639-1 codes | |
| self.lang_code, _ = langid.classify(text) | |
| else: | |
| self.lang_code = detect(text[:1000]) | |
| self.lang_name = pycountry.languages.get(alpha_2=self.lang_code).name |