code: def sample(
      model,
      prompt,
      n_runs=3,
      n_samples=2,
      H=512,
      W=512,
      C=4,
      f=8,
      scale=10.0,
      ddim_steps=50,
      ddim_eta=0.0,
      callback=None,
      skip_single_save=False,
      save_grid=True,
      ucg_schedule=None,
      negative_prompt="",
      adm_cond=None,
      adm_uc=None,
      use_full_precision=False,
      only_adm_cond=False,
  ):
      batch_size = n_samples
      precision_scope = (
          autocast if not use_full_precision else nullcontext
      )
      # decoderscope = autocast if not use_full_precision else nullcontext
      if use_full_precision:
          st.warning(
              f"Running {model.__class__.__name__} at full precision."
          )
      if isinstance(prompt, str):
          prompt = [prompt]
      prompts = batch_size * prompt
  
      outputs = st.empty()
  
      with precision_scope("cuda"):
          with model.ema_scope():
              all_samples = list()
              for n in trange(n_runs, desc="Sampling"):
                  shape = [C, H // f, W // f]
                  if not only_adm_cond:
                      uc = None
                      if scale != 1.0:
                          uc = model.get_learned_conditioning(
                              batch_size * [negative_prompt]
                          )
                      if isinstance(prompts, tuple):
                          prompts = list(prompts)
                      c = model.get_learned_conditioning(prompts)
  
                  if adm_cond is not None:
                      if adm_cond.shape[0] == 1:
                          adm_cond = repeat(
                              adm_cond, "1 ... -> b ...", b=batch_size
                          )
                      if adm_uc is None:
                          st.warning("Not guiding via c_adm")
                          adm_uc = adm_cond
                      else:
                          if adm_uc.shape[0] == 1:
                              adm_uc = repeat(
                                  adm_uc, "1 ... -> b ...", b=batch_size
                              )
                      if not only_adm_cond:
                          c = {"c_crossattn": [c], "c_adm": adm_cond}
                          uc = {"c_crossattn": [uc], "c_adm": adm_uc}
                      else:
                          c = adm_cond
                          uc = adm_uc
                  samples_ddim, _ = sampler.sample(
                      S=ddim_steps,
                      conditioning=c,
                      batch_size=batch_size,
                      shape=shape,
                      verbose=False,
                      unconditional_guidance_scale=scale,
                      unconditional_conditioning=uc,
                      eta=ddim_eta,
                      x_T=None,
                      callback=callback,
                      ucg_schedule=ucg_schedule,
                  )
                  x_samples = model.decode_first_stage(samples_ddim)
                  x_samples = torch.clamp(
                      (x_samples + 1.0) / 2.0, min=0.0, max=1.0
                  )
  
                  if not skip_single_save:
                      base_count = len(
                          os.listdir(os.path.join(SAVE_PATH, "samples"))
                      )
                      for x_sample in x_samples:
                          x_sample = 255.0 * rearrange(
                              x_sample.cpu().numpy(), "c h w -> h w c"
                          )
                          Image.fromarray(
                              x_sample.astype(np.uint8)
                          ).save(
                              os.path.join(
                                  SAVE_PATH,
                                  "samples",
                                  f"{base_count:09}.png",
                              )
                          )
                          base_count += 1
  
                  all_samples.append(x_samples)
  
                  # get grid of all samples
                  grid = torch.stack(all_samples, 0)
                  grid = rearrange(grid, "n b c h w -> (n h) (b w) c")
                  outputs.image(grid.cpu().numpy())
  
              # additionally, save grid
              grid = Image.fromarray(
                  (255.0 * grid.cpu().numpy()).astype(np.uint8)
              )
              if save_grid:
                  grid_count = len(os.listdir(SAVE_PATH)) - 1
                  grid.save(
                      os.path.join(
                          SAVE_PATH, f"grid-{grid_count:06}.png"
                      )
                  )
  
      return x_samples
  
imports: import importlib
  import streamlit
  import torch
  import cv2
  import numpy
  import PIL
  from omegaconf import OmegaConf
  from PIL import Image
  from tqdm import trange
  import io, os
  from torch import autocast
  from einops import rearrange, repeat
  from torchvision.utils import make_grid
  from pytorch_lightning import seed_everything
  from contextlib import nullcontext
  from ldm.models.diffusion.ddim import DDIMSampler
  from ldm.models.diffusion.plms import PLMSSampler
  from ldm.models.diffusion.dpm_solver import DPMSolverSampler
label_desc: Use image node_id 6 for calling a global function with example usage: sample(model, prompt, n_runs, n_samples, H, W, C, f, scale, ddim_steps, ddim_eta, callback, skip_single_save, save_grid, ucg_schedule, negative_prompt, adm_cond, adm_uc, use_full_precision, only_adm_cond) and returns: x_samples