mirror of
https://github.com/Extraltodeus/test_my_prompt.git
synced 2026-03-02 20:09:54 +00:00
Merge pull request #15 from AnonymousCervine/main
Made grid save options more comprehensive.
This commit is contained in:
@@ -4,9 +4,19 @@ from PIL import Image, ImageFont, ImageDraw, ImageOps
|
||||
from fonts.ttf import Roboto
|
||||
import modules.scripts as scripts
|
||||
import gradio as gr
|
||||
from collections import namedtuple
|
||||
from random import randint
|
||||
|
||||
class Script(scripts.Script):
|
||||
GridSaveFlags = namedtuple('GridSaveFlags', ['never_grid', 'always_grid', 'always_save_grid'], defaults=(False, False, False))
|
||||
grid_options_mapping = {
|
||||
"Use user settings": GridSaveFlags(),
|
||||
"Don't generate": GridSaveFlags(never_grid=True),
|
||||
"Generate": GridSaveFlags(always_grid=True),
|
||||
"Generate and always save": GridSaveFlags(always_grid=True, always_save_grid=True),
|
||||
}
|
||||
default_grid_opt = list(grid_options_mapping.keys())[-1]
|
||||
|
||||
def title(self):
|
||||
return "Test my prompt!"
|
||||
|
||||
@@ -14,11 +24,11 @@ class Script(scripts.Script):
|
||||
neg_pos = gr.Dropdown(label="Test negative or positive", choices=["Positive","Negative"], value="Positive")
|
||||
skip_x_first = gr.Slider(minimum=0, maximum=32, step=1, label='Skip X first words', value=0)
|
||||
separator = gr.Textbox(label="Separator used", lines=1, value=", ")
|
||||
always_grid = gr.Checkbox(label='Always generate a grid', value=True)
|
||||
grid_option = gr.Radio(choices=list(self.grid_options_mapping.keys()), label='Grid generation', value=self.default_grid_opt)
|
||||
font_size = gr.Slider(minimum=12, maximum=64, step=1, label='Font size', value=32)
|
||||
return [neg_pos,skip_x_first,separator,always_grid,font_size]
|
||||
return [neg_pos,skip_x_first,separator,grid_option,font_size]
|
||||
|
||||
def run(self, p,neg_pos,skip_x_first,separator,always_grid,font_size):
|
||||
def run(self, p,neg_pos,skip_x_first,separator,grid_option,font_size):
|
||||
def write_on_image(img, msg):
|
||||
ix,iy = img.size
|
||||
draw = ImageDraw.Draw(img)
|
||||
@@ -74,13 +84,15 @@ class Script(scripts.Script):
|
||||
else:
|
||||
proc.images[0] = write_on_image(proc.images[0], "full prompt")
|
||||
|
||||
images.save_image(proc.images[0], p.outpath_samples, "", proc.seed, proc.prompt, opts.samples_format, info= proc.info, p=p)
|
||||
if opts.samples_save:
|
||||
images.save_image(proc.images[0], p.outpath_samples, "", proc.seed, proc.prompt, opts.samples_format, info= proc.info, p=p)
|
||||
|
||||
grid_flags = self.grid_options_mapping[grid_option]
|
||||
unwanted_grid_because_of_img_count = len(proc.images) < 2 and opts.grid_only_if_multiple
|
||||
if ((opts.return_grid or opts.grid_save) and not p.do_not_save_grid and not unwanted_grid_because_of_img_count) or always_grid:
|
||||
if ((opts.return_grid or opts.grid_save) and not p.do_not_save_grid and not grid_flags.never_grid and not unwanted_grid_because_of_img_count) or grid_flags.always_grid:
|
||||
grid = images.image_grid(proc.images)
|
||||
proc.images.insert(0,grid)
|
||||
proc.infotexts.insert(0, proc.infotexts[-1])
|
||||
if opts.grid_save or always_grid:
|
||||
if opts.grid_save or grid_flags.always_save_grid:
|
||||
images.save_image(grid, p.outpath_grids, "grid", initial_seed, initial_prompt, opts.grid_format, info=proc.info, short_filename=not opts.grid_extended_filename, p=p, grid=True)
|
||||
return proc
|
||||
|
||||
Reference in New Issue
Block a user