Path: blob/master/extensions-builtin/postprocessing-for-training/scripts/postprocessing_create_flipped_copies.py
2448 views
from PIL import ImageOps, Image12from modules import scripts_postprocessing, ui_components3import gradio as gr456class ScriptPostprocessingCreateFlippedCopies(scripts_postprocessing.ScriptPostprocessing):7name = "Create flipped copies"8order = 4030910def ui(self):11with ui_components.InputAccordion(False, label="Create flipped copies") as enable:12with gr.Row():13option = gr.CheckboxGroup(value=["Horizontal"], choices=["Horizontal", "Vertical", "Both"], show_label=False)1415return {16"enable": enable,17"option": option,18}1920def process(self, pp: scripts_postprocessing.PostprocessedImage, enable, option):21if not enable:22return2324if "Horizontal" in option:25pp.extra_images.append(ImageOps.mirror(pp.image))2627if "Vertical" in option:28pp.extra_images.append(pp.image.transpose(Image.Transpose.FLIP_TOP_BOTTOM))2930if "Both" in option:31pp.extra_images.append(pp.image.transpose(Image.Transpose.FLIP_TOP_BOTTOM).transpose(Image.Transpose.FLIP_LEFT_RIGHT))323334