code: def get_free_device():
      if gpus is None:
          return torch.device("cpu")
      if hasattr(torch.cuda, "mem_get_info"):
          free = [torch.cuda.mem_get_info(gpu)[0] for gpu in gpus]
          select = max(zip(free, range(len(free))))[1]
      else:
          import random
  
          select = random.randint(0, len(gpus) - 1)
      return gpus[select]
  
imports: import gradio
  import torch
  from mmengine.logging import MMLogger
  from mmdet.apis import DetInferencer
  from projects.XDecoder.xdecoder.inference import ImageCaptionInferencer, RefImageCaptionInferencer, TextToImageRegionRetrievalInferencer
label_desc: Use image node_id 1 for calling a global function with example usage: get_free_device() and returns: gpus, torch