removed "magic numbers"
- Set up constants for Sliders - No more changing a dozen values across the scriptspull/19/head
parent
4b536edb18
commit
a9c76cb4c2
|
|
@ -1,3 +1,6 @@
|
||||||
|
### v1.4.8 - 2023 Nov.01
|
||||||
|
- Removed "**magic numbers**"
|
||||||
|
|
||||||
### v1.4.7 - 2023 Nov.01
|
### v1.4.7 - 2023 Nov.01
|
||||||
- Removed **Skip** parameter
|
- Removed **Skip** parameter
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
from modules.sd_samplers_kdiffusion import KDiffusionSampler
|
from modules.sd_samplers_kdiffusion import KDiffusionSampler
|
||||||
import modules.scripts as scripts
|
import modules.scripts as scripts
|
||||||
|
import scripts.cc_const as const
|
||||||
from modules import shared
|
from modules import shared
|
||||||
import gradio as gr
|
import gradio as gr
|
||||||
import random
|
import random
|
||||||
|
|
@ -46,15 +47,15 @@ class VectorscopeCC(scripts.Script):
|
||||||
latent = gr.Checkbox(label="Alt. (Stronger Effects)")
|
latent = gr.Checkbox(label="Alt. (Stronger Effects)")
|
||||||
|
|
||||||
with gr.Row():
|
with gr.Row():
|
||||||
bri = gr.Slider(label="Brightness", minimum=-6.0, maximum=6.0, step=0.1, value=0.0)
|
bri = gr.Slider(label="Brightness", minimum=const.Brightness.minimum, maximum=const.Brightness.maximum, step=0.1, value=const.Brightness.default)
|
||||||
con = gr.Slider(label="Contrast", minimum=-2.5, maximum=2.5, step=0.05, value=0.0)
|
con = gr.Slider(label="Contrast", minimum=const.Contrast.minimum, maximum=const.Contrast.maximum, step=0.05, value=const.Contrast.default)
|
||||||
sat = gr.Slider(label="Saturation", minimum=0.25, maximum=1.75, step=0.05, value=1.0)
|
sat = gr.Slider(label="Saturation", minimum=const.Saturation.minimum, maximum=const.Saturation.maximum, step=0.05, value=const.Saturation.default)
|
||||||
|
|
||||||
with gr.Row():
|
with gr.Row():
|
||||||
with gr.Column():
|
with gr.Column():
|
||||||
r = gr.Slider(label="R", info='Cyan | Red', minimum=-3.0, maximum=3.0, step=0.05, value=0.0, elem_id='cc-r-' + ('img' if is_img2img else 'txt'))
|
r = gr.Slider(label="R", info='Cyan | Red', minimum=const.R.minimum, maximum=const.R.maximum, step=0.05, value=const.R.default, elem_id='cc-r-' + ('img' if is_img2img else 'txt'))
|
||||||
g = gr.Slider(label="G", info='Magenta | Green',minimum=-3.0, maximum=3.0, step=0.05, value=0.0, elem_id='cc-g-' + ('img' if is_img2img else 'txt'))
|
g = gr.Slider(label="G", info='Magenta | Green',minimum=const.G.minimum, maximum=const.G.maximum, step=0.05, value=const.G.default, elem_id='cc-g-' + ('img' if is_img2img else 'txt'))
|
||||||
b = gr.Slider(label="B", info='Yellow | Blue',minimum=-3.0, maximum=3.0, step=0.05, value=0.0, elem_id='cc-b-' + ('img' if is_img2img else 'txt'))
|
b = gr.Slider(label="B", info='Yellow | Blue',minimum=const.B.minimum, maximum=const.B.maximum, step=0.05, value=const.B.default, elem_id='cc-b-' + ('img' if is_img2img else 'txt'))
|
||||||
|
|
||||||
create_colorpicker(is_img2img)
|
create_colorpicker(is_img2img)
|
||||||
|
|
||||||
|
|
@ -117,16 +118,16 @@ class VectorscopeCC(scripts.Script):
|
||||||
for component in [bri, con, r, g, b]:
|
for component in [bri, con, r, g, b]:
|
||||||
reset_btn.click(fn=lambda _: gr.update(value=0.0), outputs=component)
|
reset_btn.click(fn=lambda _: gr.update(value=0.0), outputs=component)
|
||||||
for component in [sat]:
|
for component in [sat]:
|
||||||
reset_btn.click(fn=lambda _: gr.update(value=1.0), outputs=component)
|
reset_btn.click(fn=lambda _: gr.update(value=const.Saturation.default), outputs=component)
|
||||||
|
|
||||||
reset_btn.click(fn=lambda _: gr.update(value='Straight Abs.'), outputs=method)
|
reset_btn.click(fn=lambda _: gr.update(value='Straight Abs.'), outputs=method)
|
||||||
reset_btn.click(fn=lambda _: gr.update(value='Flat'), outputs=scaling)
|
reset_btn.click(fn=lambda _: gr.update(value='Flat'), outputs=scaling)
|
||||||
|
|
||||||
def register_random(self, random_btn, bri, con, sat, r, g, b):
|
def register_random(self, random_btn, bri, con, sat, r, g, b):
|
||||||
for component in [bri, con, r, g, b]:
|
for component in [bri, con, r, g, b]:
|
||||||
random_btn.click(fn=lambda _: gr.update(value=round(random.uniform(-2.5, 2.5), 2)), outputs=component)
|
random_btn.click(fn=lambda _: gr.update(value=round(random.uniform(const.R.minimum, const.R.maximum), 2)), outputs=component)
|
||||||
for component in [sat]:
|
for component in [sat]:
|
||||||
random_btn.click(fn=lambda _: gr.update(value=round(random.uniform(0.5, 1.5), 2)), outputs=component)
|
random_btn.click(fn=lambda _: gr.update(value=round(random.uniform(const.Saturation.minimum, const.Saturation.maximum), 2)), outputs=component)
|
||||||
|
|
||||||
def parse_bool(self, string:str):
|
def parse_bool(self, string:str):
|
||||||
if string.lower() == "true":
|
if string.lower() == "true":
|
||||||
|
|
@ -195,13 +196,13 @@ class VectorscopeCC(scripts.Script):
|
||||||
if cc_seed is not None:
|
if cc_seed is not None:
|
||||||
random.seed(cc_seed)
|
random.seed(cc_seed)
|
||||||
|
|
||||||
bri = round(random.uniform(-3.0, 3.0), 2)
|
bri = round(random.uniform(const.Contrast.minimum, const.Contrast.maximum), 2)
|
||||||
r = round(random.uniform(-3.0, 3.0), 2)
|
con = round(random.uniform(const.Contrast.minimum, const.Contrast.maximum), 2)
|
||||||
g = round(random.uniform(-3.0, 3.0), 2)
|
r = round(random.uniform(const.R.minimum, const.R.maximum), 2)
|
||||||
b = round(random.uniform(-3.0, 3.0), 2)
|
g = round(random.uniform(const.G.minimum, const.G.maximum), 2)
|
||||||
|
b = round(random.uniform(const.B.minimum, const.B.maximum), 2)
|
||||||
|
|
||||||
con = round(random.uniform(0.25, 1.75), 2)
|
sat = round(random.uniform(const.Saturation.minimum, const.Saturation.maximum), 2)
|
||||||
sat = round(random.uniform(0.25, 1.75), 2)
|
|
||||||
|
|
||||||
print(f'-> Seed: {cc_seed}')
|
print(f'-> Seed: {cc_seed}')
|
||||||
print(f'Brightness:\t{bri}')
|
print(f'Brightness:\t{bri}')
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
class Param():
|
||||||
|
def __init__(self, minimum, maximum, default):
|
||||||
|
self.minimum = minimum
|
||||||
|
self.maximum = maximum
|
||||||
|
self.default = default
|
||||||
|
|
||||||
|
Brightness = Param(-7.5, 7.5, 0.0)
|
||||||
|
Contrast = Param(-5.0, 5.0, 0.0)
|
||||||
|
Saturation = Param(0.15, 1.85, 1.0)
|
||||||
|
R = Param(-4.0, 4.0, 0.0)
|
||||||
|
G = Param(-4.0, 4.0, 0.0)
|
||||||
|
B = Param(-4.0, 4.0, 0.0)
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import modules.scripts as scripts
|
import modules.scripts as scripts
|
||||||
|
import scripts.cc_const as const
|
||||||
import json
|
import json
|
||||||
|
|
||||||
STYLE_FILE = scripts.basedir() + '/' + 'styles.json'
|
STYLE_FILE = scripts.basedir() + '/' + 'styles.json'
|
||||||
|
|
@ -35,7 +36,7 @@ class StyleManager():
|
||||||
return style['alt'], style['brightness'], style['contrast'], style['saturation'], style['rgb'][0], style['rgb'][1], style['rgb'][2]
|
return style['alt'], style['brightness'], style['contrast'], style['saturation'], style['rgb'][0], style['rgb'][1], style['rgb'][2]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
print(f'\n[Warning] No Style of Name "{style_name}" Found!\n')
|
print(f'\n[Warning] No Style of Name "{style_name}" Found!\n')
|
||||||
return False, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0
|
return False, const.Brightness.default, const.Contrast.default, const.Saturation.default, const.R.default, const.G.default, const.B.default
|
||||||
|
|
||||||
def save_style(self, style_name, latent, bri, con, sat, r, g, b):
|
def save_style(self, style_name, latent, bri, con, sat, r, g, b):
|
||||||
if style_name in self.STYLE_SHEET['styles'].keys():
|
if style_name in self.STYLE_SHEET['styles'].keys():
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import modules.scripts as scripts
|
import modules.scripts as scripts
|
||||||
import json
|
import json
|
||||||
|
|
||||||
VERSION = 'v1.4.7'
|
VERSION = 'v1.4.8'
|
||||||
|
|
||||||
def clean_outdated(EXT_NAME:str):
|
def clean_outdated(EXT_NAME:str):
|
||||||
with open(scripts.basedir() + '/' + 'ui-config.json', 'r') as json_file:
|
with open(scripts.basedir() + '/' + 'ui-config.json', 'r') as json_file:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue