code: def score(
      hyp_json,
      reference_jsons,
      scenario_tag,
      output_folder,
      uem_file=None,
      collar=0.5,
      use_diarization=True,
  ):
      scenario_dir = os.path.join(output_folder, scenario_tag)
      Path(scenario_dir).mkdir(parents=True, exist_ok=True)
  
      if uem_file is not None:
          with open(uem_file, "r") as f:
              lines = f.readlines()
          lines = [x.rstrip("\n") for x in lines]
          uem2sess = {}
          for x in lines:
              sess_id, _, start, stop = x.split(" ")
              uem2sess[sess_id] = (float(start), float(stop))
  
      # load all reference jsons
      refs = []
      for j in reference_jsons:
          with open(j, "r") as f:
              refs.extend(json.load(f))
  
      with open(hyp_json, "r") as f:
          hyps = json.load(f)
  
      def get_sess2segs(segments):
          out = {}
          for x in segments:
              c_sess = x["session_id"]
              if c_sess not in out.keys():
                  out[c_sess] = []
              out[c_sess].append(x)
          return out
  
      h_sess2segs = get_sess2segs(hyps)
      r_sess2segs = get_sess2segs(refs)
  
      if not (h_sess2segs.keys() == r_sess2segs.keys()):
          print(
              "Hypothesis JSON does not have all sessions as in the reference JSONs."
              "The sessions that are missing: {}".format(
                  set(h_sess2segs.keys()).difference(
                      set(r_sess2segs.keys())
                  )
              )
          )
          raise RuntimeError
  
      all_sess_stats = []
      all_spk_stats = []
      sessions = list(r_sess2segs.keys())
      for indx in tqdm(range(len(sessions))):
          session = sessions[indx]
          hyp_segs = sorted(
              h_sess2segs[session], key=lambda x: float(x["start_time"])
          )
          ref_segs = sorted(
              r_sess2segs[session], key=lambda x: float(x["start_time"])
          )
          # compute diarization error and best permutation here
          if uem_file is not None:
              c_uem = uem2sess[session]
          else:
              c_uem = None
  
          sess_dir = os.path.join(scenario_dir, session)
          Path(sess_dir).mkdir(exist_ok=True)
  
          if use_diarization:
              (
                  mapping,
                  der_score,
                  jer_score,
                  reference,
                  hypothesis,
                  errors,
              ) = compute_diar_errors(
                  session, hyp_segs, ref_segs, c_uem, collar=collar
              )
  
              log_diarization(sess_dir, reference, hypothesis, errors)
              # save ref hyps and errors in a folder
              # save also compatible format for audacity
              c_sess_stats = {
                  "session id": session,
                  "scenario": scenario_tag,
                  "num spk hyp": len(hypothesis.labels()),
                  "num spk ref": len(reference.labels()),
                  "tot utterances hyp": len(hypothesis),
                  "tot utterances ref": len(reference),
              }
  
              c_sess_stats.update({k: v for k, v in der_score.items()})
              c_sess_stats.update({k: v for k, v in jer_score.items()})
              asr_err_sess, asr_err_spk = compute_asr_errors(
                  sess_dir, hyp_segs, ref_segs, mapping, uem=c_uem
              )
  
          else:
              if not len(hyp_segs) == len(ref_segs):
                  warnings.warn(
                      "If oracle diarization was used, "
                      "I expect the hypothesis to have the same number "
                      "of utterances as the "
                      "reference. Have you discarded some utterances "
                      "(e.g. too long) ? "
                      "These will be counted as deletions so be careful !"
                  )
              asr_err_sess, asr_err_spk = compute_asr_errors(
                  sess_dir, hyp_segs, ref_segs, mapping=None, uem=c_uem
              )
              c_sess_stats = {
                  "session id": session,
                  "scenario": scenario_tag,
                  "num spk hyp": len(
                      set([x["speaker"] for x in hyp_segs])
                  ),
                  "num spk ref": len(
                      set([x["speaker"] for x in ref_segs])
                  ),
                  "tot utterances hyp": len(hyp_segs),
                  "tot utterances ref": len(ref_segs),
              }
              # add to each speaker, session id and scenario
          [
              x.update(
                  {"session_id": session, "scenario": scenario_tag}
              )
              for x in asr_err_spk
          ]
          c_sess_stats.update(asr_err_sess)
          all_sess_stats.append(c_sess_stats)
          all_spk_stats.extend(asr_err_spk)
  
      sess_df = pd.DataFrame(all_sess_stats)
      # pretty print because it may be useful
      print(tabulate(sess_df, headers="keys", tablefmt="psql"))
      # accumulate for all scenario
      scenario_wise_df = sess_df.sum(0).to_frame().transpose()
      scenario_wise_df["scenario"] = scenario_tag
      # need to recompute these
      scenario_wer = compute_wer(sess_df)
      scenario_wise_df["wer"] = scenario_wer
      if use_diarization:
          scenario_der = compute_der(sess_df)
          scenario_wise_df["diarization error rate"] = scenario_der
          scenario_jer = compute_jer(sess_df)
          scenario_wise_df["Jaccard error rate"] = scenario_jer
      del scenario_wise_df["session id"]  # delete session
  
      return scenario_wise_df, all_sess_stats, all_spk_stats
  
imports: import argparse
  import glob
  import json
  import os
  import pickle
  import warnings
  from collections import OrderedDict
  from copy import deepcopy
  from pathlib import Path
  from typing import Dict, Optional
  import jiwer
  import pandas
  from pyannote.core.utils.types import Label
  from pyannote.metrics.diarization import DiarizationErrorRate
  from pyannote.metrics.errors.identification import IdentificationErrorAnalysis
  from pyannote.metrics.identification import IdentificationErrorRate
  from pyannote.metrics.matcher import HungarianMapper
  from pyannote.metrics.segmentation import Annotation, Segment, Timeline
  from pyannote.metrics.types import MetricComponents
  from tabulate import tabulate
  from tqdm import tqdm
label_desc: Use image node_id 8 for calling a global function with example usage: score(hyp_json, reference_jsons, scenario_tag, output_folder, uem_file, collar, use_diarization) and returns: scenario_wise_df,  all_sess_stats,  all_spk_stats, out