Spaces:
Sleeping
Sleeping
Download language_detection.py from hongyokps/Is-translator: direct link, hf CLI and curl.
- Browser
- Download file 377 Bytes
-
https://huggingface.co/spaces/hongyokps/Is-translator/resolve/main/language_detection.py
- Command line
-
hf download hf://spaces/hongyokps/Is-translator/language_detection.py
-
curl -L -o language_detection.py https://huggingface.co/spaces/hongyokps/Is-translator/resolve/main/language_detection.py
377 Bytes
| import pycld2 as cld2 | |
| from langdetect import detect | |
| def detect_language(input_text): | |
| if not input_text: | |
| return "unknown" | |
| _, _, details = cld2.detect(input_text) | |
| detected_langauge = details[0][0].lower() | |
| if detected_langauge == "unknown": | |
| language_code = detect(input_text) | |
| return language_code | |
| else: | |
| return detected_langauge |