code: def setup_http_app(
      composition: "Composition", debug: bool
  ) -> "FastAPI":
      from flash import __version__
  
      app = FastAPI(
          debug=debug,
          version=__version__,
          title="FlashServe",
      )
      # Endpoint Route
      #   `/flashserve/alive`
      app.get(
          "/flashserve/alive",
          name="alive",
          description="If you can reach this endpoint, the server is runnning.",
          response_model=Alive,
      )(_build_alive_check())
  
      _no_optimization_dsk = build_composition(
          endpoint_protocol=first(
              composition.endpoint_protocols.values()
          ),
          components=composition.components,
          connections=composition.connections,
      )
      pth = Path(__file__).parent.joinpath("templates")
      templates = Jinja2Templates(directory=str(pth.absolute()))
  
      # Endpoint Route
      #   `/flashserve/component_dags`
      app.get(
          "/flashserve/component_dags",
          name="component_dags",
          summary="HTML Rendering of Component DAGs",
          response_class=HTMLResponse,
      )(
          _build_visualization(
              dsk_composition=_no_optimization_dsk,
              templates=templates,
              no_optimization=True,
          )
      )
  
      # Endpoint Route
      #   `/flashserve/dag_json`
      app.get(
          "/flashserve/dag_json",
          name="components JSON DAG",
          summary="JSON representation of component DAG",
          response_model=ComponentJSON,
      )(
          _build_dag_json(
              components=composition.components,
              ep_proto=None,
              show_connected_components=False,
          )
      )
  
      for ep_name, ep_proto in composition.endpoint_protocols.items():
          dsk = build_composition(
              endpoint_protocol=ep_proto,
              components=composition.components,
              connections=composition.connections,
          )
          RequestModel = ep_proto.request_model  # skipcq: PYL-W0621
          ResponseModel = ep_proto.response_model  # skipcq: PYL-W0621
  
          # Endpoint Route
          #   `/{proto}
          app.post(
              f"{ep_proto.route}",
              name=ep_name,
              tags=[ep_name],
              summary="Perform a Compution.",
              description="Computes results of DAG defined by these components & endpoint.",
              response_model=ResponseModel,
          )(_build_endpoint(RequestModel, dsk, ResponseModel))
  
          # Endpoint Route:
          #   `/{proto}/meta`
          app.get(
              f"{ep_proto.route}/meta",
              name=f"{ep_name} meta schema",
              tags=[ep_name],
              summary="OpenAPI schema",
              description="OpenAPI schema for this endpoints's compute route.",
          )(_build_meta(RequestModel))
  
          # Endpoint Route
          #   `/{proto}/dag`
          app.get(
              f"{ep_proto.route}/dag",
              name=f"{ep_name} DAG Visualization",
              tags=[ep_name],
              summary="HTML Rendering of DAG",
              description=(
                  "Displays an html image rendering the DAG of functions "
                  "& components executed to reach the endpoint outputs."
              ),
              response_class=HTMLResponse,
          )(_build_visualization(dsk, templates))
  
          # Endpoint Route
          #   `/{proto}/dag_json`
          app.get(
              f"{ep_proto.route}/dag_json",
              name=f"{ep_name} JSON DAG",
              tags=[ep_name],
              summary="JSON representatino of DAG",
              response_model=MergedJSON,
          )(
              _build_dag_json(
                  components=composition.components,
                  ep_proto=ep_proto,
                  show_connected_components=True,
              )
          )
      return app
  
file_path: lightning-flash/src/flash/core/serve/interfaces/http.py
imports: import base64
  import uuid
  from io import BytesIO
  from pathlib import Path
  from typing import TYPE_CHECKING, Any, Callable, Dict, Optional
  from flash.core.serve.dag.task import get
  from flash.core.serve.dag.visualize import visualize
  from flash.core.serve.execution import ComponentJSON, MergedJSON, TaskComposition, build_composition, component_dag_content, merged_dag_content
  from flash.core.serve.interfaces.models import Alive, EndpointProtocol
  from flash.core.utilities.imports import _CYTOOLZ_AVAILABLE, _FASTAPI_AVAILABLE
label_desc: Use image node_id 6 for calling a global function with example usage: setup_http_app(composition, debug) and returns: app