code: def build_recipe(results, sizes, psnr_threshold, default_nbits):
      stats = {"nbits": 0}
      recipe = {}
  
      for key in results[str(NBITS[0])]:
          if key == "metadata":
              continue
  
          achieved_nbits = default_nbits
          for nbits in NBITS:
              avg_psnr = sum(results[str(nbits)][key]) / len(
                  RANDOM_TEST_DATA
              )
              if avg_psnr > psnr_threshold:
                  achieved_nbits = nbits
                  break
          recipe[key] = achieved_nbits
          stats["nbits"] += achieved_nbits * sizes[key]
  
      stats["size_mb"] = stats["nbits"] / (8 * 1e6)
      tot_size = sum(list(sizes.values()))
      stats["nbits"] /= tot_size
  
      return recipe, stats
  
imports: from collections import OrderedDict
  from copy import deepcopy
  from functools import partial
  import argparse
  import gc
  import json
  import logging
  import numpy
  import os
  from PIL import Image
  from python_coreml_stable_diffusion.torch2coreml import compute_psnr, get_pipeline
  import time
  import torch
  import torch.nn
  import requests
  from tqdm import tqdm, trange
  from coremltools.converters.mil.mil import types
label_desc: Use image node_id 12 for calling a global function with example usage: build_recipe(results, sizes, psnr_threshold, default_nbits) and returns: recipe,  stats