code: def embed_image_html(image):
      
      if image is None:
          return None
      elif isinstance(image, PIL.Image.Image):
          pass
      elif isinstance(image, np.ndarray):
          image = PIL.Image.fromarray(image)
      else:
          raise ValueError('image must be a PIL.Image or a np.ndarray')
  
      # Read format from the image
      fmt = image.format
      if not fmt:
          # default to JPEG
          fmt = 'jpeg'
      else:
          fmt = fmt.lower()
  
      string_buf = StringIO()
      image.save(string_buf, format=fmt)
      data = string_buf.getvalue().encode('base64').replace('\n', '')
      return 'data:image/%s;base64,%s' % (fmt, data)
docs: Returns an image embedded in HTML base64 format
      (Based on Caffe's web_demo)
      Arguments:
      image -- a PIL.Image or np.ndarray