code: def instantiate_from_dir(
      project_dir: typing.Union[pathlib.Path, str], debug: bool = False
  ):
      """Launch server located in project_dir, and instantiate a Project API Client
      connected to it."""
      proc_args = None
      project_dir = pathlib.Path(project_dir)
  
      python_script = project_dir / SERVER_PYTHON_FILENAME
      if python_script.is_file():
          proc_args = [sys.executable, str(python_script)]
  
      launch_script = project_dir / SERVER_LAUNCH_SCRIPT_FILENAME
      if launch_script.is_file():
          proc_args = [str(launch_script), str(python_script)]
  
      if proc_args is None:
          raise ProjectAPIServerNotFoundError(
              f"No Project API server found in project directory: {project_dir}"
              "\n"
              f"Tried: {SERVER_LAUNCH_SCRIPT_FILENAME}, {SERVER_PYTHON_FILENAME}"
          )
  
      api_server_read_fd, tvm_write_fd = os.pipe()
      tvm_read_fd, api_server_write_fd = os.pipe()
  
      proc_args.extend(
          [
              "--read-fd",
              str(api_server_read_fd),
              "--write-fd",
              str(api_server_write_fd),
          ]
      )
      if debug:
          proc_args.append("--debug")
  
      api_server_proc = (
          subprocess.Popen(  # pylint: disable=unused-variable
              proc_args,
              bufsize=0,
              pass_fds=(api_server_read_fd, api_server_write_fd),
              cwd=project_dir,
          )
      )
      os.close(api_server_read_fd)
      os.close(api_server_write_fd)
  
      return ProjectAPIClient(
          os.fdopen(tvm_read_fd, "rb", buffering=0),
          os.fdopen(tvm_write_fd, "wb", buffering=0),
      )
  
imports: import base64
  import io
  import json
  import logging
  import platform
  import os
  import pathlib
  import subprocess
  import sys
  import typing
  from .None import server
label_desc: Use image node_id 1 for calling a global function with example usage: instantiate_from_dir(project_dir, debug) and returns: ProjectAPIClient