Basque_EU_Euskera_Translator / language_detection.py
AItool's picture
Upload 9 files
7aa9e56 verified
raw
history blame contribute delete
389 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_language = details[0][0].lower()
if detected_language == "unknown":
language_code = detect(input_text)
return language_code
else:
return detected_language