code: def visualize_kie_page(
      page: Dict[str, Any],
      image: np.ndarray,
      words_only: bool = False,
      display_artefacts: bool = True,
      scale: float = 10,
      interactive: bool = True,
      add_labels: bool = True,
      **kwargs: Any,
  ) -> Figure:
      """Visualize a full page with predicted blocks, lines and words
  
      >>> import numpy as np
      >>> import matplotlib.pyplot as plt
      >>> from doctr.utils.visualization import visualize_page
      >>> from doctr.models import ocr_db_crnn
      >>> model = ocr_db_crnn(pretrained=True)
      >>> input_page = (255 * np.random.rand(600, 800, 3)).astype(np.uint8)
      >>> out = model([[input_page]])
      >>> visualize_kie_page(out[0].pages[0].export(), input_page)
      >>> plt.show()
  
      Args:
      ----
          page: the exported Page of a Document
          image: np array of the page, needs to have the same shape than page['dimensions']
          words_only: whether only words should be displayed
          display_artefacts: whether artefacts should be displayed
          scale: figsize of the largest windows side
          interactive: whether the plot should be interactive
          add_labels: for static plot, adds text labels on top of bounding box
          **kwargs: keyword arguments for the polygon patch
  
      Returns:
      -------
          the matplotlib figure
      """
      # Get proper scale and aspect ratio
      h, w = image.shape[:2]
      size = (scale * w / h, scale) if h > w else (scale, h / w * scale)
      fig, ax = plt.subplots(figsize=size)
      # Display the image
      ax.imshow(image)
      # hide both axis
      ax.axis("off")
  
      if interactive:
          artists: List[
              patches.Patch
          ] = (
              []
          )  # instantiate an empty list of patches (to be drawn on the page)
  
      colors = {
          k: color
          for color, k in zip(
              get_colors(len(page["predictions"])), page["predictions"]
          )
      }
      for key, value in page["predictions"].items():
          for prediction in value:
              if not words_only:
                  rect = create_obj_patch(
                      prediction["geometry"],
                      page["dimensions"],
                      label=f"{key} \n {prediction['value']} (confidence: {prediction['confidence']:.2%}",
                      color=colors[key],
                      linewidth=1,
                      **kwargs,
                  )
                  # add patch on figure
                  ax.add_patch(rect)
                  if interactive:
                      # add patch to cursor's artists
                      artists.append(rect)
  
      if interactive:
          # Create mlp Cursor to hover patches in artists
          mplcursors.Cursor(artists, hover=2).connect(
              "add",
              lambda sel: sel.annotation.set_text(
                  sel.artist.get_label()
              ),
          )
      fig.tight_layout(pad=0.0)
  
      return fig
  
imports: import colorsys
  from copy import deepcopy
  from typing import Any, Dict, List, Optional, Tuple, Union
  import cv2
  import matplotlib.patches
  import matplotlib.pyplot
  import mplcursors
  import numpy
  from matplotlib.figure import Figure
  from PIL import Image, ImageDraw
  from unidecode import unidecode
  from .common_types import BoundingBox, Polygon4P
  from .fonts import get_font
label_desc: Use image node_id 7 for calling a global function with example usage: visualize_kie_page(page, image, words_only, display_artefacts, scale, interactive, add_labels) and returns: fig