code: def _collect_layout(
      app: "lightning.app.LightningApp",
      flow: "lightning.app.LightningFlow",
  ) -> Union[Dict, List[Dict]]:
      """Process the layout returned by the ``configure_layout()`` method in each flow."""
      layout = flow.configure_layout()
  
      if isinstance(layout, Frontend):
          frontend = layout
          frontend.flow = flow
          app.frontends.setdefault(flow.name, frontend)
  
          # When running locally, the target will get overwritten by the dispatcher when launching the frontend servers
          # When running in the cloud, the frontend code will construct the URL based on the flow name
          return flow._layout
      if isinstance(layout, _MagicMockJsonSerializable):
          # The import was mocked, we set a dummy `Frontend` so that `is_headless` knows there is a UI
          app.frontends.setdefault(flow.name, "mock")
          return flow._layout
      if isinstance(layout, dict):
          layout = _collect_content_layout([layout], app, flow)
      elif isinstance(layout, (list, tuple)) and all(
          isinstance(item, dict) for item in layout
      ):
          layout = _collect_content_layout(layout, app, flow)
      else:
          lines = _add_comment_to_literal_code(
              flow.configure_layout,
              contains="return",
              comment="  <------- this guy",
          )
          raise TypeError(
              f"""
          The return value of configure_layout() in `{flow.__class__.__name__}`  is an unsupported layout format:
          \n{lines}
  
          Return either an object of type {Frontend} (e.g., StreamlitFrontend, StaticWebFrontend):
              def configure_layout(self):
                  return la.frontend.Frontend(...)
  
          OR a single dict:
              def configure_layout(self):
                  tab1 = {{'name': 'tab name', 'content': self.a_component}}
                  return tab1
  
          OR a list of dicts:
              def configure_layout(self):
                  tab1 = {{'name': 'tab name 1', 'content': self.component_a}}
                  tab2 = {{'name': 'tab name 2', 'content': self.component_b}}
                  return [tab1, tab2]
  
          (see the docs for `LightningFlow.configure_layout`).
          """
          )
  
      return layout
  
file_path: pytorch-lightning/src/lightning/app/utilities/layout.py
imports: import inspect
  import warnings
  from typing import Dict, List, Union
  import lightning.app
  from lightning.app.frontend.frontend import Frontend
  from lightning.app.utilities.app_helpers import _MagicMockJsonSerializable, is_overridden
  from lightning.app.utilities.cloud import is_running_in_cloud
label_desc: Use image node_id 2 for calling a global function with example usage: _collect_layout(app, flow) and returns: layout, flow, flow