code: def to_sample(input: Any) -> Dict[str, Any]:
      """Cast a single input to a sample dictionary. Uses the following rules:
  
      * If the input is a dictionary with an "input" key, it will be returned
      * If the input is list-like and of length 2 then the first element will be treated as the input and the second
          element will be treated as the target
      * Else the whole input will be mapped by the input key in the returned sample
  
      Args:
          input: The input to cast to a sample.
  
      Returns:
          A sample dictionary.
  
      """
      if isinstance(input, dict) and DataKeys.INPUT in input:
          return input
      if _is_list_like(input) and len(input) == 2:
          if input[1] is not None:
              return {
                  DataKeys.INPUT: input[0],
                  DataKeys.TARGET: input[1],
              }
          input = input[0]
      return {DataKeys.INPUT: input}
  
imports: from typing import Any, Dict, List, Optional, TypeVar
  from flash.core.data.io.input import DataKeys
  from flash.core.data.utilities.classification import _is_list_like
label_desc: Use image node_id 1 for calling a global function with example usage: to_sample(input) and returns: dict, input, dict