click integration

This commit is contained in:
incandenza 2024-06-04 19:29:18 +02:00
parent 57800a200d
commit 469252f5d3

View file

@ -37,7 +37,12 @@ os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
reload_presets(PRESETS)
@click.group(context_settings=cli.CLICK_CONTEXT_SETTINGS)
def main():
pass
def anlyzeSound():
# Assuming that into "generated" directoruy U've already create "project_name" subfolder
#audio_input_file = '/home/lalo/data/studio_grafica/deforum/stars_clip_r2.wav'
audio_input_file = '/home/lalo/data/studio_suono/ardourprojects/space/export/star_r1_sessione_20240310_msub07.wav'
@ -84,10 +89,30 @@ def main():
#generateSoundVariations("sands-of-time", 2226183906, rms,7500,10000)
#generateSoundVariations("sands-of-time", 2226183906, rms,10000,10333)
#generateSamples()
postprocessBrightness("/tmp/",cent, 8316,10000)
#postprocessBrightness("/tmp/",cent, 8316,10000)
return rms, cent
def width_option(default=1024, **attrs):
attrs.setdefault("help", "Output width, in pixels")
return int_option("--width", default=default, **attrs)
#gli estremi frame start e frame stop sono esclusi
def generateSoundVariations(preset_name, seed, rms, framestart = 1, framestop = -1):
@main.command()
@click.option('--width', required=True, type=int, default=1024)
@click.option('--height', required=True, type=int, default=1024)
@click.option('--seed', required=False, type=int, default=None)
@click.option('--framestart', required=False, type=int, default=1)
@click.option('--framestop', required=False, type=int, default=-1)
@click.option('--preset', type=click.Choice(["random"] + sorted(GENERATOR_PRESETS)))
@click.pass_context
def genframes(ctx,width, height,preset, seed, framestart, framestop):
rms, centroids = anlyzeSound()
if not seed:
seed = random.randint(1, MAX_SEED_VALUE)
print(f"(total frames: {len(rms[0])}) (framestart: {framestart}) (framestop: {framestop})")
time_dividend =10000
s = interp1d([min(rms[0]), max(rms[0])], [0, 0.9])
@ -99,13 +124,13 @@ def generateSoundVariations(preset_name, seed, rms, framestart = 1, framestop =
speed=float(format(trms[frame],'.3f'))
#print(f"(speed: {speed}) (trms: {trms[frame]}) )")
time = (float)((frame % time_dividend)/time_dividend)
filename = "/tmp/"+ preset_name + "_" + str(seed)+ "_" + str(frame).zfill(10) +".png"
filename = "/tmp/"+ preset + "_" + str(seed)+ "_" + str(frame).zfill(10) +".png"
print(f"(speed: {speed}) (time: {time}) (filename: {filename})")
generate(1080,1080,time,speed,seed,filename,False,False,False,False,False,False,"",False,False,preset_name)
generate(1080,1080,time,speed,seed,filename,False,False,False,False,False,False,"",False,False,preset)
#generate(1024,1024,ftime,1,seed,"/tmp/" + str(frame).zfill(10) +".png",False,False,False,False,False,False,"",False,False,preset_name)
#generate(1024,1024,0.0,ftime,seed,"/tmp/" + str(frame).zfill(10) +"_" + preset_name + ".png",False,False,False,False,False,False,"",False,False,preset_name)
except Exception as e:
print(f"Exception {e} on Preset: {preset_name}")
print(f"Exception {e} on Preset: {preset}")
continue
@ -174,7 +199,6 @@ def generateVariations(preset_name):
print(f"Exception on Preset: {preset_name}")
continue
def generate(width, height, time, speed, seed, filename, with_alpha, with_supersample, with_fxaa, with_ai, with_upscale,
with_alt_text, stability_model, debug_print, debug_out, preset_name):
if not seed:
@ -328,15 +352,6 @@ def _debug_print(seed, preset, with_alpha, with_supersample, with_fxaa, with_ai,
@cli.seed_option()
@cli.filename_option(default='mangled.png')
@cli.option('--no-resize', is_flag=True, help="Don't resize image. May break some presets.")
@click.option('--with-fxaa', help="Apply FXAA anti-aliasing", is_flag=True, default=False)
@cli.time_option()
@click.option('--speed', help="Animation speed", type=float, default=0.25)
@click.argument('preset_name', type=click.Choice(['random'] + sorted(EFFECT_PRESETS)))
@click.argument('input_filename')
@click.pass_context
def apply(ctx, seed, filename, no_resize, with_fxaa, time, speed, preset_name, input_filename):
if not seed:
seed = random.randint(1, MAX_SEED_VALUE)
@ -373,20 +388,6 @@ def apply(ctx, seed, filename, no_resize, with_fxaa, time, speed, preset_name, i
raise
@cli.width_option(default=512)
@cli.height_option(default=512)
@cli.seed_option()
@cli.option('--effect-preset', type=click.Choice(["random"] + sorted(EFFECT_PRESETS)))
@cli.filename_option(default='ani.gif')
@cli.option('--save-frames', default=None, type=click.Path(exists=True, dir_okay=True))
@cli.option('--frame-count', type=int, default=50, help="How many frames total")
@cli.option('--watermark', type=str)
@cli.option('--preview-filename', type=click.Path(exists=False))
@click.option('--with-alt-text', help="Generate alt text (requires OpenAI key)", is_flag=True, default=False)
@click.option('--with-supersample', help="Apply x2 supersample anti-aliasing", is_flag=True, default=False)
@click.option('--with-fxaa', help="Apply FXAA anti-aliasing", is_flag=True, default=False)
@click.argument('preset_name', type=click.Choice(['random'] + sorted(GENERATOR_PRESETS)))
@click.pass_context
def animate(ctx, width, height, seed, effect_preset, filename, save_frames, frame_count, watermark, preview_filename, with_alt_text, with_supersample, with_fxaa, preset_name):
if seed is None:
seed = random.randint(1, MAX_SEED_VALUE)
@ -476,13 +477,6 @@ def animate(ctx, width, height, seed, effect_preset, filename, save_frames, fra
util.magick(f'{tmp}/*png', filename)
@cli.input_dir_option(required=True)
@cli.filename_option(default="collage.png")
@click.option("--control-filename", help="Control image filename (optional)")
@cli.time_option()
@click.option('--speed', help="Animation speed", type=float, default=0.25)
@cli.seed_option()
@click.pass_context
def mashup(ctx, input_dir, filename, control_filename, time, speed, seed):
filenames = []
@ -544,9 +538,6 @@ def _use_reasonable_speed(preset, frame_count):
return preset.settings.get("speed", 0.25) * (frame_count / 50.0)
@cli.width_option()
@cli.height_option()
@cli.filename_option(default='dream.png')
def dream(width, height, filename):
name, prompt, description = dreamer.dream(width, height, filename=filename)
@ -554,6 +545,8 @@ def dream(width, height, filename):
print(prompt)
print(description)
main = click.CommandCollection(sources=[genframes])
if __name__ == "__main__":
main()
#testPillow()