code: def detect_encoding(texts, sample_size=32):
      if not CHARDET:
          raise ValueError(
              "charset-normalizer is missing - install with pip install charset-normalizer"
          )
      if isinstance(texts, str):
          texts = [texts]
      lst = [
          chardet.detect(doc)["encoding"] for doc in texts[:sample_size]
      ]
      encoding = max(set(lst), key=lst.count)
      encoding = (
          "utf-8"
          if encoding.lower() in ["ascii", "utf8", "utf-8"]
          else encoding
      )
      return encoding
  
file_path: ktrain/ktrain/text/shallownlp/utils.py
imports: from .imports import *
label_desc: Use image node_id 6 for calling a global function with example usage: detect_encoding(texts, sample_size) and returns: encoding