code: def file_exists(file_path: str, is_dir: bool = False) -> bool:
      """Try to expand `~/` and check if a file or dir exists.
      Optionally check if it's a dir.
  
      >>> file_exists('~/fake_file')
      False
  
      >>> file_exists('~/', is_dir=True)
      True
      """
      file_path_expanded = os.path.expanduser(file_path)  # type: str
      if is_dir:
          return os.path.isdir(file_path_expanded)
      return os.path.isfile(file_path_expanded)
  
imports: import os
  import sys
  from contextlib import contextmanager
  from enum import EnumMeta, IntEnum
  from typing import Any, Dict, List, Optional, Union
  import requests
  from tqdm import tqdm
label_desc: Use image node_id 1 for calling a global function with example usage: file_exists(file_path, is_dir) and returns: os, os