code: def component_to_metadata(
      obj: Union["LightningWork", "LightningFlow"]
  ) -> Dict:
      from lightning.app.core import LightningWork
  
      extras = {}
  
      if isinstance(obj, LightningWork):
          extras = {
              "local_build_config": obj.local_build_config.to_dict(),
              "cloud_build_config": obj.cloud_build_config.to_dict(),
              "cloud_compute": obj.cloud_compute.to_dict(),
          }
  
      return dict(
          affiliation=obj.name.split("."),
          cls_name=obj.__class__.__name__,
          module=obj.__module__,
          docstring=inspect.getdoc(obj.__init__),
          **extras,
      )
  
imports: import inspect
  import os
  import sys
  import traceback
  import types
  from contextlib import contextmanager
  from copy import copy
  from typing import TYPE_CHECKING, Any, Dict, List, Tuple, Type, Union
  from lightning.app.utilities.exceptions import MisconfigurationException
  from lightning.app.utilities.app_helpers import Logger, _mock_missing_imports
label_desc: Use image node_id 12 for calling a global function with example usage: component_to_metadata(obj) and returns: dict