Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
AUTOMATIC1111
GitHub Repository: AUTOMATIC1111/stable-diffusion-webui
Path: blob/master/extensions-builtin/postprocessing-for-training/scripts/postprocessing_create_flipped_copies.py
2448 views
1
from PIL import ImageOps, Image
2
3
from modules import scripts_postprocessing, ui_components
4
import gradio as gr
5
6
7
class ScriptPostprocessingCreateFlippedCopies(scripts_postprocessing.ScriptPostprocessing):
8
name = "Create flipped copies"
9
order = 4030
10
11
def ui(self):
12
with ui_components.InputAccordion(False, label="Create flipped copies") as enable:
13
with gr.Row():
14
option = gr.CheckboxGroup(value=["Horizontal"], choices=["Horizontal", "Vertical", "Both"], show_label=False)
15
16
return {
17
"enable": enable,
18
"option": option,
19
}
20
21
def process(self, pp: scripts_postprocessing.PostprocessedImage, enable, option):
22
if not enable:
23
return
24
25
if "Horizontal" in option:
26
pp.extra_images.append(ImageOps.mirror(pp.image))
27
28
if "Vertical" in option:
29
pp.extra_images.append(pp.image.transpose(Image.Transpose.FLIP_TOP_BOTTOM))
30
31
if "Both" in option:
32
pp.extra_images.append(pp.image.transpose(Image.Transpose.FLIP_TOP_BOTTOM).transpose(Image.Transpose.FLIP_LEFT_RIGHT))
33
34