code: def decode_to_unicode(text, default_encoding='utf-8'):
      
      if not text:
          return ""
      try:
          return text.decode(default_encoding)
      except (UnicodeError, LookupError):
          pass
      detected_encoding = None
      if CHARDET_AVAILABLE:
          # We can use chardet to perform detection
          res = chardet.detect(text)
          if res['confidence'] >= 0.8:
              detected_encoding = res['encoding']
      if detected_encoding is None:
          # No chardet detection, try to make a basic guess
          dummy, detected_encoding = guess_minimum_encoding(text)
      return text.decode(detected_encoding)
docs: Decode input text into Unicode representation.
  
      Decode input text into Unicode representation by first using the default
      encoding utf-8.
      If the operation fails, it detects the type of encoding used in the
      given text.
      For optimal result, it is recommended that the 'chardet' module is
      installed.
      NOTE: Beware that this might be slow for *very* large strings.
  
      If chardet detection fails, it will try to decode the string using the basic
      detection function guess_minimum_encoding().
  
      Also, bear in mind that it is impossible to detect the correct encoding at
      all times, other then taking educated guesses. With that said, this function
      will always return some decoded Unicode string, however the data returned
      may not be the same as original data in some cases.
  
      :param text: the text to decode
      :type text: string
  
      :param default_encoding: the character encoding to use. Optional.
      :type default_encoding: string
  
      :return: input text as Unicode
      :rtype: string