code: def convert_nan_and_inf_to_str(tree):
      if tree == float("inf"):
          return "inf"
      if tree == float("-inf"):
          return "-inf"
      if (
          tree != tree
      ):  # x == x is False for NaN, strings break math.isnan
          return "NaN"
      if isinstance(tree, dict):
          return {
              key: convert_nan_and_inf_to_str(value)
              for key, value in tree.items()
          }
      if isinstance(tree, tuple):
          return tuple(
              convert_nan_and_inf_to_str(value) for value in tree
          )
      if isinstance(tree, list):
          return [convert_nan_and_inf_to_str(value) for value in tree]
      return tree
  
imports: import asyncio
  import numpy
  import random
  import struct
  import time
  from collections import namedtuple
  from itertools import chain
  from typing import Iterator, Tuple, Optional, List
  from typing import TYPE_CHECKING
  from fastapi import HTTPException
  from aim.storage.context import Context
  from aim.sdk import Run
  from aim.sdk.sequences.metric import Metric
  from aim.sdk.sequence_collection import SequenceCollection
  from aim.storage.query import syntax_error_check
  from aim.web.configs import AIM_PROGRESS_REPORT_INTERVAL
  from aim.web.api.projects.project import Project
  from aim.web.api.runs.pydantic_models import AlignedRunIn, TraceBase
  from aim.storage.treeutils import encode_tree
label_desc: Use image node_id 3 for calling a global function with example usage: convert_nan_and_inf_to_str(tree) and returns: tree, str, str, str, unknown, tuple, unknown