code: def build_model(model_name: str) -> Union[Model, Any]:
      """
      This function builds a deepface model
      Parameters:
              model_name (string): face recognition or facial attribute model
                      VGG-Face, Facenet, OpenFace, DeepFace, DeepID for face recognition
                      Age, Gender, Emotion, Race for facial attributes
  
      Returns:
              built deepface model ( (tf.)keras.models.Model )
      """
  
      # singleton design pattern
      global model_obj
  
      models = {
          "VGG-Face": VGGFace.loadModel,
          "OpenFace": OpenFace.loadModel,
          "Facenet": Facenet.loadModel,
          "Facenet512": Facenet512.loadModel,
          "DeepFace": FbDeepFace.loadModel,
          "DeepID": DeepID.loadModel,
          "Dlib": DlibWrapper.loadModel,
          "ArcFace": ArcFace.loadModel,
          "SFace": SFace.load_model,
          "Emotion": Emotion.loadModel,
          "Age": Age.loadModel,
          "Gender": Gender.loadModel,
          "Race": Race.loadModel,
      }
  
      if not "model_obj" in globals():
          model_obj = {}
  
      if not model_name in model_obj:
          model = models.get(model_name)
          if model:
              model = model()
              model_obj[model_name] = model
          else:
              raise ValueError(
                  f"Invalid model_name passed - {model_name}"
              )
  
      return model_obj[model_name]
  
imports: from typing import Any, Union
  import tensorflow
  from deepface.basemodels import VGGFace, OpenFace, Facenet, Facenet512, FbDeepFace, DeepID, DlibWrapper, ArcFace, SFace
  from deepface.extendedmodels import Age, Gender, Race, Emotion
label_desc: Use image node_id 1 for calling a global function with example usage: build_model(model_name) and returns: model_obj