  
                  # Preview Monitor
                  if self._preview.should_quit():
                      break
  
                  # Console Monitor
                  if self._check_keypress(keypress):
                      break  # Exit requested
  
                  # GUI Preview trigger update monitor
 
</s> remove                 if not self._preview_monitor(cv_key):
 </s> add                 if self._preview.should_quit(): </s> remove                     print("\n")
                    logger.info("Refresh preview requested")

                setattr(self, parent_flags[trigger], True)
 </s> add                     print("\n")  # Let log print on different line from loss output
                    logger.info("Refresh preview requested...")
                getattr(self._preview, parent_flags[trigger])() </s> remove                     self._do_preview(window_created)
                    cv_key = cv2.waitKey(1000)  # pylint: disable=no-member
                else:
                    cv_key = None
 </s> add                     self._preview.display_preview() </s> remove             if self._refresh_preview and viewer is not None:
                if self._args.redirect_gui:  # Remove any gui trigger files following an update
                    print("\n")
                    logger.info("[Preview Updated]")
                self._refresh_preview = False

            if save_iteration:
                logger.debug("Save Iteration: (iteration: %s", iteration)
                model.save(is_exit=False)
            elif self._save_now:
                logger.debug("Save Requested: (iteration: %s", iteration)
 </s> add             if save_iteration or self._save_now:
                logger.debug("Saving (save_iterations: %s, save_now: %s) Iteration: "
                             "(iteration: %s)", save_iteration, self._save_now, iteration) </s> remove     def _preview_monitor(self, key_press: str) -> bool:
        """ Monitors keyboard presses on the pop-up OpenCV Preview Window.

        Parameters
        ----------
        key_press: str
            The key press received from OpenCV or ``None`` if no press received

        Returns
        -------
        bool
            ``True`` if the process should continue training. ``False`` if an exit has been
            requested and process should terminate
        """
        if not self._args.preview:
            return True

        if key_press == ord("\n") or key_press == ord("\r"):
            logger.debug("Exit requested")
            return False

        if key_press == ord("s"):
            print("\n")
            logger.info("Save requested")
            self._save_now = True
        if key_press == ord("r"):
            print("\n")
            logger.info("Refresh preview requested")
            self._refresh_preview = True
        if key_press == ord("m"):
            print("\n")
            logger.verbose("Toggle mask display requested")  # type:ignore
            self._toggle_preview_mask = True

        return True

 </s> add 
                if self._preview.should_save():
                    self._save_now = True
  
                  # Preview Monitor
                  if self._preview.should_quit():
                      break
                if self._preview.should_save():
                    self._save_now = True
  
                  # Console Monitor
                  if self._check_keypress(keypress):
                      break  # Exit requested
  
                  # GUI Preview trigger update monitor
keep keep keep add keep keep keep keep keep keep
 Live Preview - Replace cv2 with matplotlib viewer 
scripts/train.py