Spaces:
Running
Running
Create language_detection.py
Browse files- language_detection.py +13 -0
language_detection.py
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pycld2 as cld2
|
2 |
+
from langdetect import detect
|
3 |
+
|
4 |
+
def detect_language(input_text):
|
5 |
+
if not input_text:
|
6 |
+
return "unknown"
|
7 |
+
_, _, details = cld2.detect(input_text)
|
8 |
+
detected_langauge = details[0][0].lower()
|
9 |
+
if detected_langauge == "unknown":
|
10 |
+
language_code = detect(input_text)
|
11 |
+
return language_code
|
12 |
+
else:
|
13 |
+
return detected_langauge
|