code: def get_trial_dir(model_dir, tuner_id):
      """Helper function to get trial directory."""
      tuner_dir = os.path.join(model_dir, tuner_id)
      if not tf.io.gfile.exists(tuner_dir):
          tf.io.gfile.makedirs(tuner_dir)
      existing_trials = tf.io.gfile.listdir(tuner_dir)
      if not existing_trials:
          trial_dir = os.path.join(tuner_dir, "1")
      else:
          last_id = sorted(
              [
                  int(os.path.basename(t_dir))
                  for t_dir in existing_trials
                  if os.path.basename(t_dir).isdigit()
              ]
          )[-1]
          trial_dir = os.path.join(tuner_dir, str(int(last_id) + 1))
  
      if tf.io.gfile.exists(trial_dir):
          tf.io.gfile.rmtree(trial_dir)
  
      logging.info("creating directory: %s", trial_dir)
      tf.io.gfile.makedirs(trial_dir)
      return trial_dir
  
imports: import contextlib
  import copy
  import json
  import os
  import random
  from absl import flags
  from absl import logging
  import keras_tuner
  from model_search import hparam
  from model_search import phoenix
  from model_search import registry
  from model_search.data import data
  from model_search.metadata import ml_metadata_db
  from model_search.proto import phoenix_spec_pb2
  import tensorflow.compat.v2
  from google.protobuf import text_format
label_desc: Use image node_id 6 for calling a global function with example usage: get_trial_dir(model_dir, tuner_id) and returns: trial_dir