code: def nice_report(report) -> str:
      """
      Render an agent Report as a beautiful string.
  
      If pandas is installed,  we will use it to render as a table. Multitask
      metrics will be shown per row, e.g.
  
      .. code-block:
                   f1   ppl
         all     .410  27.0
         task1   .400  32.0
         task2   .420  22.0
  
      If pandas is not available, we will use a dict with like-metrics placed
      next to each other.
      """
      if not report:
          return ""
  
      from parlai.core.metrics import Metric
  
      try:
          import pandas as pd
  
          use_pandas = True
      except ImportError:
          use_pandas = False
  
      sorted_keys = sorted(report.keys(), key=_report_sort_key)
      output: OrderedDict[
          Union[str, Tuple[str, str]], float
      ] = OrderedDict()
      for k in sorted_keys:
          v = report[k]
          if isinstance(v, Metric):
              v = v.value()
          if use_pandas:
              output[_report_sort_key(k)] = v
          else:
              output[k] = v
  
      if use_pandas:
          line_width = _line_width()
  
          df = pd.DataFrame([output])
          df.columns = pd.MultiIndex.from_tuples(df.columns)
          df = df.stack().transpose().droplevel(0, axis=1)
          result = "   " + df.to_string(
              na_rep="",
              line_width=line_width
              - 3,  # -3 for the extra spaces we add
              float_format=float_formatter,
              index=df.shape[0] > 1,
          ).replace("\n\n", "\n").replace("\n", "\n   ")
          result = re.sub(r"\s+$", "", result)
          return result
      else:
          return json.dumps(
              {
                  k: round_sigfigs(v, 4) if isinstance(v, float) else v
                  for k, v in output.items()
              }
          )
  
imports: from collections import deque, OrderedDict
  from typing import Union, Optional, Set, Any, Dict, List, Tuple
  from datetime import timedelta
  import functools
  import math
  import time
  import re
  import shutil
  import json
  import os
  from parlai.core.message import Message
  from parlai.utils.strings import colorize
  from parlai.utils.io import PathManager
  import parlai.utils.logging
label_desc: Use image node_id 6 for calling a global function with example usage: nice_report(report) and returns: str, result, json