code: def save_files(js_data, images, do_make_zip, index):
      import csv
  
      filenames = []
      fullfns = []
  
      # quick dictionary to class object conversion. Its necessary due apply_filename_pattern requiring it
      class MyObject:
          def __init__(self, d=None):
              if d is not None:
                  for key, value in d.items():
                      setattr(self, key, value)
  
      data = json.loads(js_data)
  
      p = MyObject(data)
      path = shared.opts.outdir_save
      save_to_dirs = shared.opts.use_save_to_dirs_for_ui
      extension: str = shared.opts.samples_format
      start_index = 0
      only_one = False
  
      if (
          index > -1
          and shared.opts.save_selected_only
          and (index >= data["index_of_first_image"])
      ):  # ensures we are looking at a specific non-grid picture, and we have save_selected_only
          only_one = True
          images = [images[index]]
          start_index = index
  
      os.makedirs(shared.opts.outdir_save, exist_ok=True)
  
      with open(
          os.path.join(shared.opts.outdir_save, "log.csv"),
          "a",
          encoding="utf8",
          newline="",
      ) as file:
          at_start = file.tell() == 0
          writer = csv.writer(file)
          if at_start:
              writer.writerow(
                  [
                      "prompt",
                      "seed",
                      "width",
                      "height",
                      "sampler",
                      "cfgs",
                      "steps",
                      "filename",
                      "negative_prompt",
                  ]
              )
  
          for image_index, filedata in enumerate(images, start_index):
              image = image_from_url_text(filedata)
  
              is_grid = image_index < p.index_of_first_image
              i = (
                  0
                  if is_grid
                  else (image_index - p.index_of_first_image)
              )
  
              p.batch_index = image_index - 1
              fullfn, txt_fullfn = modules.images.save_image(
                  image,
                  path,
                  "",
                  seed=p.all_seeds[i],
                  prompt=p.all_prompts[i],
                  extension=extension,
                  info=p.infotexts[image_index],
                  grid=is_grid,
                  p=p,
                  save_to_dirs=save_to_dirs,
              )
  
              filename = os.path.relpath(fullfn, path)
              filenames.append(filename)
              fullfns.append(fullfn)
              if txt_fullfn:
                  filenames.append(os.path.basename(txt_fullfn))
                  fullfns.append(txt_fullfn)
  
          writer.writerow(
              [
                  data["prompt"],
                  data["seed"],
                  data["width"],
                  data["height"],
                  data["sampler_name"],
                  data["cfg_scale"],
                  data["steps"],
                  filenames[0],
                  data["negative_prompt"],
              ]
          )
  
      # Make Zip
      if do_make_zip:
          zip_fileseed = (
              p.all_seeds[index - 1] if only_one else p.all_seeds[0]
          )
          namegen = modules.images.FilenameGenerator(
              p, zip_fileseed, p.all_prompts[0], image, True
          )
          zip_filename = namegen.apply(
              shared.opts.grid_zip_filename_pattern
              or "[datetime]_[[model_name]]_[seed]-[seed_last]"
          )
          zip_filepath = os.path.join(path, f"{zip_filename}.zip")
  
          from zipfile import ZipFile
  
          with ZipFile(zip_filepath, "w") as zip_file:
              for i in range(len(fullfns)):
                  with open(fullfns[i], mode="rb") as f:
                      zip_file.writestr(filenames[i], f.read())
          fullfns.insert(0, zip_filepath)
  
      return gr.File.update(
          value=fullfns, visible=True
      ), plaintext_to_html(f"Saved: {filenames[0]}")
  
file_path: stable-diffusion-webui/modules/ui_common.py
imports: import json
  import html
  import os
  import platform
  import sys
  import gradio
  import subprocess
  from modules import call_queue, shared
  from modules.generation_parameters_copypaste import image_from_url_text
  import modules.images
  from modules.ui_components import ToolButton
  import modules.generation_parameters_copypaste
label_desc: Use image node_id 3 for calling a global function with example usage: save_files(js_data, images, do_make_zip, index) and returns: gr,  plaintext_to_html