code: def data_to_df(
      data: Union[pd.DataFrame, Dict, List],
      required_columns: Optional[List] = None,
      all_columns: Optional[List] = None,
      header: Optional[str] = None,
  ):
      """
      Convert the input data to a dataframe.
  
      Parameters
      ----------
      data
          Input data provided by users during prediction/evaluation.
      required_columns
          Required columns.
      all_columns
          All the possible columns got from training data. The column order is preserved.
      header
          Provided header to create a dataframe.
  
      Returns
      -------
      A dataframe with required columns.
      """
      has_header = True
      if isinstance(data, pd.DataFrame):
          pass
      elif isinstance(data, dict):
          data = pd.DataFrame(data)
      elif isinstance(data, list):
          assert (
              len(data) > 0
          ), f"Expected data to have length > 0, but got {data} of len {len(data)}"
          if header is None:
              has_header = False
              data = pd.DataFrame(data)
          else:
              data = pd.DataFrame({header: data})
      elif isinstance(data, str):
          df = pd.DataFrame([data])
          col_name = list(df.columns)[0]
          if is_image_column(
              df[col_name], col_name=col_name, image_type=IMAGE_PATH
          ):
              has_header = False
              data = df
          else:
              data = load_pd.load(data)
      else:
          raise NotImplementedError(
              f"The format of data is not understood. "
              f'We have type(data)="{type(data)}", but a pd.DataFrame was required.'
          )
  
      if required_columns and all_columns:
          detected_columns = data.columns.values.tolist()
          missing_columns = []
          for per_col in required_columns:
              if per_col not in detected_columns:
                  missing_columns.append(per_col)
  
          if len(missing_columns) > 0:
              # assume no column names are provided and users organize data in the same column order of training data.
              if len(detected_columns) == len(all_columns):
                  if has_header:
                      warnings.warn(
                          f"Replacing detected dataframe columns `{detected_columns}` with columns "
                          f"`{all_columns}` from training data."
                          "Double check the correspondences between them to avoid unexpected behaviors.",
                          UserWarning,
                      )
                  data.rename(
                      dict(zip(detected_columns, required_columns)),
                      axis=1,
                      inplace=True,
                  )
              else:
                  raise ValueError(
                      f"Dataframe columns `{detected_columns}` are detected, but columns `{missing_columns}` are missing. "
                      f"Please double check your input data to provide all the "
                      f"required columns `{required_columns}`."
                  )
  
      return data
  
imports: import copy
  import logging
  import os
  import warnings
  from typing import Dict, List, Optional, Tuple, Union
  import pandas
  from omegaconf import DictConfig, OmegaConf
  from torch import nn
  from autogluon.core.utils import default_holdout_frac, generate_train_test_split_combined
  from autogluon.core.utils.loaders import load_pd
  from ..constants import BINARY, CATEGORICAL, DEFAULT_SHOT, DOCUMENT, FEW_SHOT, IMAGE, IMAGE_PATH, LABEL, MMLAB_MODELS, MULTICLASS, NER, NER_ANNOTATION, NER_TEXT, NUMERICAL, OVD, REGRESSION, ROIS, SAM, SEMANTIC_SEGMENTATION_IMG, TEXT, TEXT_NER
  from ..data import CategoricalProcessor, DocumentProcessor, ImageProcessor, LabelProcessor, MixupModule, MMDetProcessor, MMOcrProcessor, MultiModalFeaturePreprocessor, NerLabelEncoder, NerProcessor, NumericalProcessor, OVDProcessor, SemanticSegImageProcessor, TextProcessor
  from ..data.infer_types import is_image_column
label_desc: Use image node_id 7 for calling a global function with example usage: data_to_df(data, required_columns, all_columns, header) and returns: data