code: def detect_lang(texts, sample_size=32):
      """
      detect language
      """
      if not LANGDETECT:
          raise ValueError(
              "langdetect is missing - install with pip install langdetect"
          )
  
      if isinstance(texts, str):
          texts = [texts]
      if not isinstance(texts, (list, np.ndarray)):
          raise ValueError(
              "texts must be a list or NumPy array of strings"
          )
      lst = []
      for doc in texts[:sample_size]:
          try:
              lst.append(langdetect.detect(doc))
          except:
              continue
      if len(lst) == 0:
          raise Exception(
              "could not detect language in random sample of %s docs."
              % (sample_size)
          )
      return max(set(lst), key=lst.count)
  
file_path: ktrain/ktrain/text/shallownlp/utils.py
imports: from .imports import *
label_desc: Use image node_id 2 for calling a global function with example usage: detect_lang(texts, sample_size) and returns: max