code: def ui(self, is_img2img):
      self.current_axis_options = [
          x
          for x in axis_options
          if type(x) == AxisOption or x.is_img2img == is_img2img
      ]
  
      with gr.Row():
          with gr.Column(scale=19):
              with gr.Row():
                  x_type = gr.Dropdown(
                      label="X type",
                      choices=[
                          x.label for x in self.current_axis_options
                      ],
                      value=self.current_axis_options[1].label,
                      type="index",
                      elem_id=self.elem_id("x_type"),
                  )
                  x_values = gr.Textbox(
                      label="X values",
                      lines=1,
                      elem_id=self.elem_id("x_values"),
                  )
                  x_values_dropdown = gr.Dropdown(
                      label="X values",
                      visible=False,
                      multiselect=True,
                      interactive=True,
                  )
                  fill_x_button = ToolButton(
                      value=fill_values_symbol,
                      elem_id="xyz_grid_fill_x_tool_button",
                      visible=False,
                  )
  
              with gr.Row():
                  y_type = gr.Dropdown(
                      label="Y type",
                      choices=[
                          x.label for x in self.current_axis_options
                      ],
                      value=self.current_axis_options[0].label,
                      type="index",
                      elem_id=self.elem_id("y_type"),
                  )
                  y_values = gr.Textbox(
                      label="Y values",
                      lines=1,
                      elem_id=self.elem_id("y_values"),
                  )
                  y_values_dropdown = gr.Dropdown(
                      label="Y values",
                      visible=False,
                      multiselect=True,
                      interactive=True,
                  )
                  fill_y_button = ToolButton(
                      value=fill_values_symbol,
                      elem_id="xyz_grid_fill_y_tool_button",
                      visible=False,
                  )
  
              with gr.Row():
                  z_type = gr.Dropdown(
                      label="Z type",
                      choices=[
                          x.label for x in self.current_axis_options
                      ],
                      value=self.current_axis_options[0].label,
                      type="index",
                      elem_id=self.elem_id("z_type"),
                  )
                  z_values = gr.Textbox(
                      label="Z values",
                      lines=1,
                      elem_id=self.elem_id("z_values"),
                  )
                  z_values_dropdown = gr.Dropdown(
                      label="Z values",
                      visible=False,
                      multiselect=True,
                      interactive=True,
                  )
                  fill_z_button = ToolButton(
                      value=fill_values_symbol,
                      elem_id="xyz_grid_fill_z_tool_button",
                      visible=False,
                  )
  
      with gr.Row(variant="compact", elem_id="axis_options"):
          with gr.Column():
              draw_legend = gr.Checkbox(
                  label="Draw legend",
                  value=True,
                  elem_id=self.elem_id("draw_legend"),
              )
              no_fixed_seeds = gr.Checkbox(
                  label="Keep -1 for seeds",
                  value=False,
                  elem_id=self.elem_id("no_fixed_seeds"),
              )
          with gr.Column():
              include_lone_images = gr.Checkbox(
                  label="Include Sub Images",
                  value=False,
                  elem_id=self.elem_id("include_lone_images"),
              )
              include_sub_grids = gr.Checkbox(
                  label="Include Sub Grids",
                  value=False,
                  elem_id=self.elem_id("include_sub_grids"),
              )
          with gr.Column():
              margin_size = gr.Slider(
                  label="Grid margins (px)",
                  minimum=0,
                  maximum=500,
                  value=0,
                  step=2,
                  elem_id=self.elem_id("margin_size"),
              )
          with gr.Column():
              csv_mode = gr.Checkbox(
                  label="Use text inputs instead of dropdowns",
                  value=False,
                  elem_id=self.elem_id("csv_mode"),
              )
  
      with gr.Row(variant="compact", elem_id="swap_axes"):
          swap_xy_axes_button = gr.Button(
              value="Swap X/Y axes", elem_id="xy_grid_swap_axes_button"
          )
          swap_yz_axes_button = gr.Button(
              value="Swap Y/Z axes", elem_id="yz_grid_swap_axes_button"
          )
          swap_xz_axes_button = gr.Button(
              value="Swap X/Z axes", elem_id="xz_grid_swap_axes_button"
          )
  
      def swap_axes(
          axis1_type,
          axis1_values,
          axis1_values_dropdown,
          axis2_type,
          axis2_values,
          axis2_values_dropdown,
      ):
          return (
              self.current_axis_options[axis2_type].label,
              axis2_values,
              axis2_values_dropdown,
              self.current_axis_options[axis1_type].label,
              axis1_values,
              axis1_values_dropdown,
          )
  
      xy_swap_args = [
          x_type,
          x_values,
          x_values_dropdown,
          y_type,
          y_values,
          y_values_dropdown,
      ]
      swap_xy_axes_button.click(
          swap_axes, inputs=xy_swap_args, outputs=xy_swap_args
      )
      yz_swap_args = [
          y_type,
          y_values,
          y_values_dropdown,
          z_type,
          z_values,
          z_values_dropdown,
      ]
      swap_yz_axes_button.click(
          swap_axes, inputs=yz_swap_args, outputs=yz_swap_args
      )
      xz_swap_args = [
          x_type,
          x_values,
          x_values_dropdown,
          z_type,
          z_values,
          z_values_dropdown,
      ]
      swap_xz_axes_button.click(
          swap_axes, inputs=xz_swap_args, outputs=xz_swap_args
      )
  
      def fill(axis_type, csv_mode):
          axis = self.current_axis_options[axis_type]
          if axis.choices:
              if csv_mode:
                  return list_to_csv_string(axis.choices()), gr.update()
              else:
                  return gr.update(), axis.choices()
          else:
              return gr.update(), gr.update()
  
      fill_x_button.click(
          fn=fill,
          inputs=[x_type, csv_mode],
          outputs=[x_values, x_values_dropdown],
      )
      fill_y_button.click(
          fn=fill,
          inputs=[y_type, csv_mode],
          outputs=[y_values, y_values_dropdown],
      )
      fill_z_button.click(
          fn=fill,
          inputs=[z_type, csv_mode],
          outputs=[z_values, z_values_dropdown],
      )
  
      def select_axis(
          axis_type, axis_values, axis_values_dropdown, csv_mode
      ):
          choices = self.current_axis_options[axis_type].choices
          has_choices = choices is not None
  
          if has_choices:
              choices = choices()
              if csv_mode:
                  if axis_values_dropdown:
                      axis_values = list_to_csv_string(
                          list(
                              filter(
                                  lambda x: x in choices,
                                  axis_values_dropdown,
                              )
                          )
                      )
                      axis_values_dropdown = []
              else:
                  if axis_values:
                      axis_values_dropdown = list(
                          filter(
                              lambda x: x in choices,
                              csv_string_to_list_strip(axis_values),
                          )
                      )
                      axis_values = ""
  
          return (
              gr.Button.update(visible=has_choices),
              gr.Textbox.update(
                  visible=not has_choices or csv_mode, value=axis_values
              ),
              gr.update(
                  choices=choices if has_choices else None,
                  visible=has_choices and not csv_mode,
                  value=axis_values_dropdown,
              ),
          )
  
      x_type.change(
          fn=select_axis,
          inputs=[x_type, x_values, x_values_dropdown, csv_mode],
          outputs=[fill_x_button, x_values, x_values_dropdown],
      )
      y_type.change(
          fn=select_axis,
          inputs=[y_type, y_values, y_values_dropdown, csv_mode],
          outputs=[fill_y_button, y_values, y_values_dropdown],
      )
      z_type.change(
          fn=select_axis,
          inputs=[z_type, z_values, z_values_dropdown, csv_mode],
          outputs=[fill_z_button, z_values, z_values_dropdown],
      )
  
      def change_choice_mode(
          csv_mode,
          x_type,
          x_values,
          x_values_dropdown,
          y_type,
          y_values,
          y_values_dropdown,
          z_type,
          z_values,
          z_values_dropdown,
      ):
          _fill_x_button, _x_values, _x_values_dropdown = select_axis(
              x_type, x_values, x_values_dropdown, csv_mode
          )
          _fill_y_button, _y_values, _y_values_dropdown = select_axis(
              y_type, y_values, y_values_dropdown, csv_mode
          )
          _fill_z_button, _z_values, _z_values_dropdown = select_axis(
              z_type, z_values, z_values_dropdown, csv_mode
          )
          return (
              _fill_x_button,
              _x_values,
              _x_values_dropdown,
              _fill_y_button,
              _y_values,
              _y_values_dropdown,
              _fill_z_button,
              _z_values,
              _z_values_dropdown,
          )
  
      csv_mode.change(
          fn=change_choice_mode,
          inputs=[
              csv_mode,
              x_type,
              x_values,
              x_values_dropdown,
              y_type,
              y_values,
              y_values_dropdown,
              z_type,
              z_values,
              z_values_dropdown,
          ],
          outputs=[
              fill_x_button,
              x_values,
              x_values_dropdown,
              fill_y_button,
              y_values,
              y_values_dropdown,
              fill_z_button,
              z_values,
              z_values_dropdown,
          ],
      )
  
      def get_dropdown_update_from_params(axis, params):
          val_key = f"{axis} Values"
          vals = params.get(val_key, "")
          valslist = csv_string_to_list_strip(vals)
          return gr.update(value=valslist)
  
      self.infotext_fields = (
          (x_type, "X Type"),
          (x_values, "X Values"),
          (
              x_values_dropdown,
              lambda params: get_dropdown_update_from_params(
                  "X", params
              ),
          ),
          (y_type, "Y Type"),
          (y_values, "Y Values"),
          (
              y_values_dropdown,
              lambda params: get_dropdown_update_from_params(
                  "Y", params
              ),
          ),
          (z_type, "Z Type"),
          (z_values, "Z Values"),
          (
              z_values_dropdown,
              lambda params: get_dropdown_update_from_params(
                  "Z", params
              ),
          ),
      )
  
      return [
          x_type,
          x_values,
          x_values_dropdown,
          y_type,
          y_values,
          y_values_dropdown,
          z_type,
          z_values,
          z_values_dropdown,
          draw_legend,
          include_lone_images,
          include_sub_grids,
          no_fixed_seeds,
          margin_size,
          csv_mode,
      ]
  
imports: from collections import namedtuple
  from copy import copy
  from itertools import permutations, chain
  import random
  import csv
  import os.path
  from io import StringIO
  from PIL import Image
  import numpy
  import modules.scripts
  import gradio
  from modules import images, sd_samplers, processing, sd_models, sd_vae, sd_samplers_kdiffusion, errors
  from modules.processing import process_images, Processed, StableDiffusionProcessingTxt2Img
  from modules.shared import opts, state
  import modules.shared
  import modules.sd_samplers
  import modules.sd_models
  import modules.sd_vae
  import re
  from modules.ui_components import ToolButton
label_desc: Use image node_id 2 for calling the Script obj's underlying member method code with example usage: obj.ui(is_img2img) and returns: list, self,  axis2_values,  axis2_values_dropdown,  self,  axis1_values,  axis1_values_dropdown, gr,  gr,  gr, _fill_x_button,  _x_values,  _x_values_dropdown,  _fill_y_button,  _y_values,  _y_values_dropdown,  _fill_z_button,  _z_values,  _z_values_dropdown, gr, gr,  gr, list_to_csv_string,  gr, gr,  axis