code: def condition(
      result: Dict,
      include_classes=None,
      average=False,
      max_gain=None,
      min_allowed_gain=None,
  ) -> ConditionResult:
      scores = result["scores"]
      task_type = result["type"]
      scorers_perfect = result["scorers_perfect"]
  
      # If the depth of the nested scores dict is 2, average is not relevant and is set to True
      inner_dict = scores[list(scores.keys())[0]]
      inner_inner_dict = inner_dict[list(inner_dict.keys())[0]]
      force_average = isinstance(inner_inner_dict, Number)
  
      passed_condition = True
      if (
          task_type in [TaskType.MULTICLASS, TaskType.BINARY]
          and not average
          and not force_average
      ):
          passed_metrics = {}
          failed_classes = defaultdict(dict)
          perfect_metrics = []
          for metric, classes_scores in scores.items():
              gains = {}
              metric_passed = True
              for clas, models_scores in classes_scores.items():
                  # Skip if class is not in class list
                  if (
                      include_classes is not None
                      and clas not in include_classes
                  ):
                      continue
  
                  # If origin model is perfect, skip the gain calculation
                  if models_scores["Origin"] == scorers_perfect[metric]:
                      continue
  
                  gains[clas] = get_gain(
                      models_scores["Simple"],
                      models_scores["Origin"],
                      scorers_perfect[metric],
                      max_gain,
                  )
                  # Save dict of failed classes and metrics gain
                  if gains[clas] <= min_allowed_gain:
                      failed_classes[clas][metric] = format_percent(
                          gains[clas]
                      )
                      metric_passed = False
  
              if metric_passed and gains:
                  avg_gain = sum(gains.values()) / len(gains)
                  passed_metrics[metric] = format_percent(avg_gain)
              elif metric_passed and not gains:
                  perfect_metrics.append(metric)
  
          if failed_classes:
              msg = f"Found classes with failed metric's gain: {dict(failed_classes)}"
              passed_condition = False
          elif passed_metrics:
              msg = f"All classes passed, average gain for metrics: {passed_metrics}"
          else:
              msg = f"Found metrics with perfect score, no gain is calculated: {perfect_metrics}"
      else:
          passed_metrics = {}
          failed_metrics = {}
          perfect_metrics = []
          if (
              task_type in [TaskType.MULTICLASS, TaskType.BINARY]
              and not force_average
          ):
              scores = average_scores(scores, include_classes)
          for metric, models_scores in scores.items():
              # If origin model is perfect, skip the gain calculation
              if models_scores["Origin"] == scorers_perfect[metric]:
                  perfect_metrics.append(metric)
                  continue
              gain = get_gain(
                  models_scores["Simple"],
                  models_scores["Origin"],
                  scorers_perfect[metric],
                  max_gain,
              )
              if gain <= min_allowed_gain:
                  failed_metrics[metric] = format_percent(gain)
              else:
                  passed_metrics[metric] = format_percent(gain)
          if failed_metrics:
              msg = f"Found failed metrics: {failed_metrics}"
              passed_condition = False
          elif passed_metrics:
              msg = (
                  f"All metrics passed, metric's gain: {passed_metrics}"
              )
          else:
              msg = f"Found metrics with perfect score, no gain is calculated: {perfect_metrics}"
  
      category = (
          ConditionCategory.PASS
          if passed_condition
          else ConditionCategory.FAIL
      )
      return ConditionResult(category, msg)
  
imports: import warnings
  from collections import defaultdict
  from numbers import Number
  from typing import TYPE_CHECKING, Callable, Dict, Hashable, List, Mapping, Union
  import numpy
  import pandas
  import plotly.express
  from sklearn.dummy import DummyClassifier, DummyRegressor
  from sklearn.pipeline import Pipeline
  from sklearn.tree import DecisionTreeClassifier, DecisionTreeRegressor
  from deepchecks.core import CheckResult, ConditionResult
  from deepchecks.core.condition import ConditionCategory
  from deepchecks.core.errors import DeepchecksValueError
  from deepchecks.tabular import Context, Dataset, TrainTestCheck
  from deepchecks.tabular.utils.task_type import TaskType
  from deepchecks.utils.distribution.preprocessing import ScaledNumerics
  from deepchecks.utils.docref import doclink
  from deepchecks.utils.metrics import get_gain
  from deepchecks.utils.simple_models import ClassificationUniformModel, RandomModel, RegressionUniformModel
  from deepchecks.utils.strings import format_percent
label_desc: Use image node_id 1 for calling a global function with example usage: condition(result, include_classes, average, max_gain, min_allowed_gain) and returns: ConditionResult