Krishna086 commited on
Commit
e2b9d0c
·
verified ·
1 Parent(s): a14b507

Update lang_detect.py

Browse files
Files changed (1) hide show
  1. lang_detect.py +5 -5
lang_detect.py CHANGED
@@ -2,15 +2,15 @@ from langdetect import detect_langs
2
 
3
  def detect_language(text):
4
  try:
5
- if not text.strip() or len(text) < 5:
6
- return [("Hindi", 1.0, "हिन्दी")]
7
  lang_detections = detect_langs(text)
8
  native_lang_map = {
9
  "en": ("English", "English"), "fr": ("Français", "French"), "es": ("Español", "Spanish"),
10
  "de": ("Deutsch", "German"), "hi": ("हिन्दी", "Hindi"), "zh": ("中文", "Chinese"),
11
  "ar": ("العربية", "Arabic"), "ru": ("Русский", "Russian"), "ja": ("日本語", "Japanese")
12
  }
13
- detected_options = [(native_lang_map.get(lang.lang, ("Hindi", "हिन्दी"))[1], lang.prob, native_lang_map.get(lang.lang, ("Hindi", "हिन्दी"))[0]) for lang in lang_detections if lang.prob >= 0.3]
14
- return detected_options[:1] if detected_options else [("Hindi", 0.5, "हिन्दी")]
15
  except Exception:
16
- return [("Hindi", 0.5, "हिन्दी")]
 
2
 
3
  def detect_language(text):
4
  try:
5
+ if not text.strip() or len(text) < 3:
6
+ return [("Auto-detect", 1.0, "Auto-detect")]
7
  lang_detections = detect_langs(text)
8
  native_lang_map = {
9
  "en": ("English", "English"), "fr": ("Français", "French"), "es": ("Español", "Spanish"),
10
  "de": ("Deutsch", "German"), "hi": ("हिन्दी", "Hindi"), "zh": ("中文", "Chinese"),
11
  "ar": ("العربية", "Arabic"), "ru": ("Русский", "Russian"), "ja": ("日本語", "Japanese")
12
  }
13
+ detected_options = [(native_lang_map.get(lang.lang, ("Auto-detect", "Auto-detect"))[1], lang.prob, native_lang_map.get(lang.lang, ("Auto-detect", "Auto-detect"))[0]) for lang in lang_detections if lang.prob >= 0.2]
14
+ return detected_options[:1] if detected_options else [("Auto-detect", 0.5, "Auto-detect")]
15
  except Exception:
16
+ return [("Auto-detect", 0.5, "Auto-detect")]