From f783821d8a2366514eeed366010d2e2bbc489cb0 Mon Sep 17 00:00:00 2001 From: hithereai <121192995+hithereai@users.noreply.github.com> Date: Wed, 17 May 2023 14:39:16 +0300 Subject: [PATCH] C1 --- requirements.txt | 3 +- scripts/deforum.py | 385 +------ scripts/deforum_helpers/animation.py | 3 +- scripts/deforum_helpers/args.py | 1021 ++---------------- scripts/deforum_helpers/defaults.py | 180 +++ scripts/deforum_helpers/depth_adabins.py | 2 +- scripts/deforum_helpers/gradio_funcs.py | 48 +- scripts/deforum_helpers/render.py | 1 - scripts/deforum_helpers/render_modes.py | 1 - scripts/deforum_helpers/run_deforum.py | 196 ++++ scripts/deforum_helpers/settings.py | 8 +- scripts/deforum_helpers/ui_left.py | 614 +++++++++++ scripts/deforum_helpers/ui_right.py | 141 +++ scripts/deforum_helpers/ui_settings.py | 19 + scripts/deforum_helpers/vid2depth.py | 4 +- scripts/deforum_helpers/webui_sd_pipeline.py | 9 +- scripts/deforum_helpers/word_masking.py | 9 +- 17 files changed, 1297 insertions(+), 1347 deletions(-) create mode 100644 scripts/deforum_helpers/defaults.py create mode 100644 scripts/deforum_helpers/run_deforum.py create mode 100644 scripts/deforum_helpers/ui_left.py create mode 100644 scripts/deforum_helpers/ui_right.py create mode 100644 scripts/deforum_helpers/ui_settings.py diff --git a/requirements.txt b/requirements.txt index ed9a1dc9..62796188 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,5 +5,4 @@ av pims imageio_ffmpeg rich -gdown -py3d \ No newline at end of file +gdown \ No newline at end of file diff --git a/scripts/deforum.py b/scripts/deforum.py index 393fdf2a..d14de840 100644 --- a/scripts/deforum.py +++ b/scripts/deforum.py @@ -1,368 +1,27 @@ -# Detach 'deforum_helpers' from 'scripts' to prevent "No module named 'scripts.deforum_helpers'" error -# causing Deforum's tab not show up in some cases when you've might've broken the environment with webui packages updates -import sys, os, shutil +import sys, os +from modules import script_callbacks -deforum_folder_name = os.path.sep.join(os.path.abspath(__file__).split(os.path.sep)[:-2]) +def deforum_sys_extend(): + deforum_folder_name = os.path.sep.join(os.path.abspath(__file__).split(os.path.sep)[:-2]) -basedirs = [os.getcwd()] -if 'google.colab' in sys.modules: - basedirs.append('/content/gdrive/MyDrive/sd/stable-diffusion-webui') #hardcode as TheLastBen's colab seems to be the primal source + basedirs = [os.getcwd()] + if 'google.colab' in sys.modules: + basedirs.append('/content/gdrive/MyDrive/sd/stable-diffusion-webui') # for TheLastBen's colab + for basedir in basedirs: + deforum_paths_to_ensure = [ + os.path.join(deforum_folder_name, 'scripts'), + os.path.join(deforum_folder_name, 'scripts', 'deforum_helpers', 'src') + ] + for deforum_scripts_path_fix in deforum_paths_to_ensure: + if not deforum_scripts_path_fix in sys.path: + sys.path.extend([deforum_scripts_path_fix]) -for basedir in basedirs: - deforum_paths_to_ensure = [ - os.path.join(deforum_folder_name, 'scripts'), - os.path.join(deforum_folder_name, 'scripts', 'deforum_helpers', 'src') - ] +def init_deforum(): + deforum_sys_extend() - for deforum_scripts_path_fix in deforum_paths_to_ensure: - if not deforum_scripts_path_fix in sys.path: - sys.path.extend([deforum_scripts_path_fix]) + from deforum_helpers.ui_right import on_ui_tabs + script_callbacks.on_ui_tabs(on_ui_tabs) + from deforum_helpers.ui_settings import on_ui_settings + script_callbacks.on_ui_settings(on_ui_settings) -# Main deforum stuff -import deforum_helpers.args as deforum_args -import deforum_helpers.settings as deforum_settings -from deforum_helpers.save_images import dump_frames_cache, reset_frames_cache -from deforum_helpers.frame_interpolation import process_video_interpolation - -import modules.scripts as wscripts -from modules import script_callbacks, ui_components -import gradio as gr -import json -import traceback - -from modules.processing import Processed, StableDiffusionProcessingImg2Img, process_images -from PIL import Image -from deforum_helpers.video_audio_utilities import ffmpeg_stitch_video, make_gifski_gif, handle_imgs_deletion, find_ffmpeg_binary, get_ffmpeg_params -from deforum_helpers.general_utils import get_deforum_version -from deforum_helpers.upscaling import make_upscale_v2 -import gc -import numpy as np -import torch -from webui import wrap_gradio_gpu_call -import modules.shared as shared -from modules.shared import opts, cmd_opts, state -from modules.ui import create_output_panel, plaintext_to_html, wrap_gradio_call -from types import SimpleNamespace -from deforum_helpers.subtitle_handler import get_user_values - -DEBUG_MODE = opts.data.get("deforum_debug_mode_enabled", False) - -def run_deforum(*args, **kwargs): - f_location, f_crf, f_preset = get_ffmpeg_params() # get params for ffmpeg exec - component_names = deforum_args.get_component_names() - args_dict = {component_names[i]: args[i+2] for i in range(0, len(component_names))} - p = StableDiffusionProcessingImg2Img( - sd_model=shared.sd_model, - outpath_samples = opts.outdir_samples or opts.outdir_img2img_samples, - outpath_grids = opts.outdir_grids or opts.outdir_img2img_grids - ) #we'll setup the rest later - - times_to_run = 1 - if args_dict['custom_settings_file'] is not None and len(args_dict['custom_settings_file']) > 1: - times_to_run = len(args_dict['custom_settings_file']) - - for i in range(times_to_run): - print(f"\033[4;33mDeforum extension for auto1111 webui, v2.4b\033[0m") - print(f"Git commit: {get_deforum_version()}") - args_dict['self'] = None - args_dict['p'] = p - try: - args_loaded_ok, root, args, anim_args, video_args, parseq_args, loop_args, controlnet_args = deforum_args.process_args(args_dict, i) - except Exception as e: - print("\n*START OF TRACEBACK*") - traceback.print_exc() - print("*END OF TRACEBACK*\n") - print("User friendly error message:") - print(f"Error: {e}. Check your prompts with a JSON validator please.") - return None, None, None, None, f"Error: '{e}'. Check your prompts with a JSON validator please. Full error message is in your terminal/ cli.", plaintext_to_html('') - if args_loaded_ok is False: - if times_to_run > 1: - print(f"\033[31mWARNING:\033[0m skipped running from the following setting file, as it contains an invalid JSON: {os.path.basename(args_dict['custom_settings_file'][i].name)}") - continue - else: - print(f"\033[31mERROR!\033[0m Couldn't load data from '{os.path.basename(args_dict['custom_settings_file'][i].name)}'. Make sure it's a valid JSON using a JSON validator") - return None, None, None, None, f"Couldn't load data from '{os.path.basename(args_dict['custom_settings_file'][i].name)}'. Make sure it's a valid JSON using a JSON validator", plaintext_to_html('') - - root.clipseg_model = None - - root.initial_clipskip = opts.data.get("CLIP_stop_at_last_layers", 1) - root.initial_img2img_fix_steps = opts.data.get("img2img_fix_steps", False) - root.initial_noise_multiplier = opts.data.get("initial_noise_multiplier", 1.0) - root.initial_ddim_eta = opts.data.get("eta_ddim", 0.0) - root.initial_ancestral_eta = opts.data.get("eta_ancestral", 1.0) - - root.basedirs = basedirs - for basedir in basedirs: - sys.path.extend([os.path.join(deforum_folder_name, 'scripts', 'deforum_helpers', 'src')]) - - # clean up unused memory - reset_frames_cache(root) - gc.collect() - torch.cuda.empty_cache() - - from deforum_helpers.render import render_animation - from deforum_helpers.render_modes import render_input_video, render_animation_with_video_mask, render_interpolation - - tqdm_backup = shared.total_tqdm - shared.total_tqdm = deforum_settings.DeforumTQDM(args, anim_args, parseq_args, video_args) - try: # dispatch to appropriate renderer - if anim_args.animation_mode == '2D' or anim_args.animation_mode == '3D': - if anim_args.use_mask_video: - render_animation_with_video_mask(args, anim_args, video_args, parseq_args, loop_args, controlnet_args, root.animation_prompts, root) # allow mask video without an input video - else: - render_animation(args, anim_args, video_args, parseq_args, loop_args, controlnet_args, root.animation_prompts, root) - elif anim_args.animation_mode == 'Video Input': - render_input_video(args, anim_args, video_args, parseq_args, loop_args, controlnet_args, root.animation_prompts, root)#TODO: prettify code - elif anim_args.animation_mode == 'Interpolation': - render_interpolation(args, anim_args, video_args, parseq_args, loop_args, controlnet_args, root.animation_prompts, root) - else: - print('Other modes are not available yet!') - except Exception as e: - print("\n*START OF TRACEBACK*") - traceback.print_exc() - print("*END OF TRACEBACK*\n") - print("User friendly error message:") - print(f"Error: {e}. Check your schedules/ init values please. Also make sure you don't have a backwards slash in any of your PATHs - use / instead of \\.") - return None, None, None, None, f"Error: '{e}'. Check your schedules/ init values please. Also make sure you don't have a backwards slash in any of your PATHs - use / instead of \\. Full error message is in your terminal/ cli.", plaintext_to_html('') - finally: - shared.total_tqdm = tqdm_backup - # reset opts.data vals to what they were before we started the animation. Else they will stick to the last value - it actually updates webui settings (config.json) - opts.data["CLIP_stop_at_last_layers"] = root.initial_clipskip - opts.data["img2img_fix_steps"] = root.initial_img2img_fix_steps - opts.data["initial_noise_multiplier"] = root.initial_noise_multiplier - opts.data["eta_ddim"] = root.initial_ddim_eta - opts.data["eta_ancestral"] = root.initial_ancestral_eta - - - - if video_args.store_frames_in_ram: - dump_frames_cache(root) - - from base64 import b64encode - - real_audio_track = None - if video_args.add_soundtrack != 'None': - real_audio_track = anim_args.video_init_path if video_args.add_soundtrack == 'Init Video' else video_args.soundtrack_path - - # Establish path of subtitles file - if opts.data.get("deforum_save_gen_info_as_srt", False) and opts.data.get("deforum_embed_srt", False): - srt_path = os.path.join(args.outdir, f"{args.timestring}.srt") - else: - srt_path = None - - # Delete folder with duplicated imgs from OS temp folder - shutil.rmtree(root.tmp_deforum_run_duplicated_folder, ignore_errors=True) - - # Decide whether or not we need to try and frame interpolate laters - need_to_frame_interpolate = False - if video_args.frame_interpolation_engine != "None" and not video_args.skip_video_creation and not video_args.store_frames_in_ram: - need_to_frame_interpolate = True - - if video_args.skip_video_creation: - print("\nSkipping video creation, uncheck 'Skip video creation' in 'Output' tab if you want to get a video too :)") - else: - import subprocess # DO WE USE IT? - - image_path = os.path.join(args.outdir, f"{args.timestring}_%09d.png") - mp4_path = os.path.join(args.outdir, f"{args.timestring}.mp4") - max_video_frames = anim_args.max_frames - - # Stitch video using ffmpeg! - try: - f_location, f_crf, f_preset = get_ffmpeg_params() # get params for ffmpeg exec - ffmpeg_stitch_video(ffmpeg_location=f_location, fps=video_args.fps, outmp4_path=mp4_path, stitch_from_frame=0, stitch_to_frame=max_video_frames, imgs_path=image_path, add_soundtrack=video_args.add_soundtrack, audio_path=real_audio_track, crf=f_crf, preset=f_preset, srt_path=srt_path) - mp4 = open(mp4_path,'rb').read() - data_url = "data:video/mp4;base64," + b64encode(mp4).decode() - deforum_args.i1_store = f'
Deforum extension for auto1111 — version 2.2b
' - except Exception as e: - if need_to_frame_interpolate: - print(f"FFMPEG DID NOT STITCH ANY VIDEO. However, you requested to frame interpolate - so we will continue to frame interpolation, but you'll be left only with the interpolated frames and not a video, since ffmpeg couldn't run. Original ffmpeg error: {e}") - else: - print(f"** FFMPEG DID NOT STITCH ANY VIDEO ** Error: {e}") - pass - - if root.initial_info is None: - root.initial_info = "An error has occured and nothing has been generated!" - root.initial_info += "\nPlease, report the bug to https://github.com/deforum-art/deforum-for-automatic1111-webui/issues" - a = np.random.rand(args.W, args.H, 3)*255 - root.first_frame = Image.fromarray(a.astype('uint8')).convert('RGB') - root.initial_seed = 6934 - # FRAME INTERPOLATION TIME - if need_to_frame_interpolate: - print(f"Got a request to *frame interpolate* using {video_args.frame_interpolation_engine}") - process_video_interpolation(frame_interpolation_engine=video_args.frame_interpolation_engine, frame_interpolation_x_amount=video_args.frame_interpolation_x_amount,frame_interpolation_slow_mo_enabled=video_args.frame_interpolation_slow_mo_enabled, frame_interpolation_slow_mo_amount=video_args.frame_interpolation_slow_mo_amount, orig_vid_fps=video_args.fps, deforum_models_path=root.models_path, real_audio_track=real_audio_track, raw_output_imgs_path=args.outdir, img_batch_id=args.timestring, ffmpeg_location=f_location, ffmpeg_crf=f_crf, ffmpeg_preset=f_preset, keep_interp_imgs=video_args.frame_interpolation_keep_imgs, orig_vid_name=None, resolution=None, srt_path=srt_path) - - if video_args.make_gif and not video_args.skip_video_creation and not video_args.store_frames_in_ram: - make_gifski_gif(imgs_raw_path = args.outdir, imgs_batch_id = args.timestring, fps = video_args.fps, models_folder = root.models_path, current_user_os = root.current_user_os) - - # Upscale video once generation is done: - if video_args.r_upscale_video and not video_args.skip_video_creation and not video_args.store_frames_in_ram: - # out mp4 path is defined in make_upscale func - make_upscale_v2(upscale_factor = video_args.r_upscale_factor, upscale_model = video_args.r_upscale_model, keep_imgs = video_args.r_upscale_keep_imgs, imgs_raw_path = args.outdir, imgs_batch_id = args.timestring, fps = video_args.fps, deforum_models_path = root.models_path, current_user_os = root.current_user_os, ffmpeg_location=f_location, stitch_from_frame=0, stitch_to_frame=max_video_frames, ffmpeg_crf=f_crf, ffmpeg_preset=f_preset, add_soundtrack = video_args.add_soundtrack ,audio_path=real_audio_track, srt_path=srt_path) - - if video_args.delete_imgs and not video_args.skip_video_creation: - handle_imgs_deletion(vid_path=mp4_path, imgs_folder_path=args.outdir, batch_id=args.timestring) - - root.initial_info += "\n The animation is stored in " + args.outdir - reset_frames_cache(root) # cleanup the RAM in any case - processed = Processed(p, [root.first_frame], root.initial_seed, root.initial_info) - - if processed is None: - processed = process_images(p) - - shared.total_tqdm.clear() - - generation_info_js = processed.js() - if getattr(opts, 'samples_log_stdout', False): - print(generation_info_js) - - if opts.do_not_show_images: - processed.images = [] - - if opts.data.get("deforum_enable_persistent_settings"): - persistent_sett_path = opts.data.get("deforum_persistent_settings_path") - deforum_settings.save_settings_from_animation_run(args, anim_args, parseq_args, loop_args, controlnet_args, video_args, root, persistent_sett_path) - - return processed.images, args.timestring, generation_info_js, plaintext_to_html(processed.info), plaintext_to_html('') - -def on_ui_tabs(): - with gr.Blocks(analytics_enabled=False) as deforum_interface: - components = {} - dummy_component = gr.Label(visible=False) - with gr.Row(elem_id='deforum_progress_row').style(equal_height=False, variant='compact'): - with gr.Column(scale=1, variant='panel'): - components = deforum_args.setup_deforum_setting_dictionary(None, True, True) - - with gr.Column(scale=1, variant='compact'): - with gr.Row(variant='compact'): - btn = gr.Button("Click here after the generation to show the video") - components['btn'] = btn - close_btn = gr.Button("Close the video", visible=False) - with gr.Row(variant='compact'): - i1 = gr.HTML(deforum_args.i1_store, elem_id='deforum_header') - components['i1'] = i1 - # Show video - def show_vid(): - return { - i1: gr.update(value=deforum_args.i1_store, visible=True), - close_btn: gr.update(visible=True), - btn: gr.update(value="Update the video", visible=True), - } - - btn.click( - show_vid, - [], - [i1, close_btn, btn], - ) - # Close video - def close_vid(): - return { - i1: gr.update(value=deforum_args.i1_store_backup, visible=True), - close_btn: gr.update(visible=False), - btn: gr.update(value="Click here after the generation to show the video", visible=True), - } - - close_btn.click( - close_vid, - [], - [i1, close_btn, btn], - ) - id_part = 'deforum' - with gr.Row(elem_id=f"{id_part}_generate_box", variant='compact'): - skip = gr.Button('Pause/Resume', elem_id=f"{id_part}_skip", visible=False) - interrupt = gr.Button('Interrupt', elem_id=f"{id_part}_interrupt", visible=True) - submit = gr.Button('Generate', elem_id=f"{id_part}_generate", variant='primary') - - skip.click( - fn=lambda: state.skip(), - inputs=[], - outputs=[], - ) - - interrupt.click( - fn=lambda: state.interrupt(), - inputs=[], - outputs=[], - ) - - deforum_gallery, generation_info, html_info, html_log = create_output_panel("deforum", opts.outdir_img2img_samples) - - with gr.Row(variant='compact'): - settings_path = gr.Textbox("deforum_settings.txt", elem_id='deforum_settings_path', label="Settings File", info="settings file path can be relative to webui folder OR full - absolute") - #reuse_latest_settings_btn = gr.Button('Reuse Latest', elem_id='deforum_reuse_latest_settings_btn')#TODO - with gr.Row(variant='compact'): - save_settings_btn = gr.Button('Save Settings', elem_id='deforum_save_settings_btn') - load_settings_btn = gr.Button('Load All Settings', elem_id='deforum_load_settings_btn') - load_video_settings_btn = gr.Button('Load Video Settings', elem_id='deforum_load_video_settings_btn') - - component_list = [components[name] for name in deforum_args.get_component_names()] - - submit.click( - fn=wrap_gradio_gpu_call(run_deforum, extra_outputs=[None, '', '']), - _js="submit_deforum", - inputs=[dummy_component, dummy_component] + component_list, - outputs=[ - deforum_gallery, - components["resume_timestring"], - generation_info, - html_info, - html_log, - ], - ) - - settings_component_list = [components[name] for name in deforum_args.get_settings_component_names()] - video_settings_component_list = [components[name] for name in deforum_args.video_args_names] - stuff = gr.HTML("") # wrap gradio call garbage - stuff.visible = False - - save_settings_btn.click( - fn=wrap_gradio_call(deforum_settings.save_settings), - inputs=[settings_path] + settings_component_list + video_settings_component_list, - outputs=[stuff], - ) - - load_settings_btn.click( - fn=wrap_gradio_call(lambda *args, **kwargs: deforum_settings.load_all_settings(*args, ui_launch=False, **kwargs)), - inputs=[settings_path] + settings_component_list, - outputs=settings_component_list + [stuff], - ) - - load_video_settings_btn.click( - fn=wrap_gradio_call(deforum_settings.load_video_settings), - inputs=[settings_path] + video_settings_component_list, - outputs=video_settings_component_list + [stuff], - ) - - def trigger_load_general_settings(): - print("Loading general settings...") - wrapped_fn = wrap_gradio_call(lambda *args, **kwargs: deforum_settings.load_all_settings(*args, ui_launch=True, **kwargs)) - inputs = [settings_path.value] + [component.value for component in settings_component_list] - outputs = settings_component_list + [stuff] - updated_values = wrapped_fn(*inputs, *outputs)[0] - - settings_component_name_to_obj = {name: component for name, component in zip(deforum_args.get_settings_component_names(), settings_component_list)} - for key, value in updated_values.items(): - settings_component_name_to_obj[key].value = value['value'] - - - if opts.data.get("deforum_enable_persistent_settings"): - trigger_load_general_settings() - - return [(deforum_interface, "Deforum", "deforum_interface")] - -def on_ui_settings(): - srt_ui_params = get_user_values() - section = ('deforum', "Deforum") - shared.opts.add_option("deforum_keep_3d_models_in_vram", shared.OptionInfo(False, "Keep 3D models in VRAM between runs", gr.Checkbox, {"interactive": True, "visible": True if not (cmd_opts.lowvram or cmd_opts.medvram) else False}, section=section)) - shared.opts.add_option("deforum_enable_persistent_settings", shared.OptionInfo(False, "Keep settings persistent upon relaunch of webui", gr.Checkbox, {"interactive": True}, section=section)) - shared.opts.add_option("deforum_persistent_settings_path", shared.OptionInfo("models/Deforum/deforum_persistent_settings.txt", "Path for saving your persistent settings file:", section=section)) - shared.opts.add_option("deforum_ffmpeg_location", shared.OptionInfo(find_ffmpeg_binary(), "FFmpeg path/ location", section=section)) - shared.opts.add_option("deforum_ffmpeg_crf", shared.OptionInfo(17, "FFmpeg CRF value", gr.Slider, {"interactive": True, "minimum": 0, "maximum": 51}, section=section)) - shared.opts.add_option("deforum_ffmpeg_preset", shared.OptionInfo('slow', "FFmpeg Preset", gr.Dropdown, {"interactive": True, "choices": ['veryslow', 'slower', 'slow', 'medium', 'fast', 'faster', 'veryfast', 'superfast', 'ultrafast']}, section=section)) - shared.opts.add_option("deforum_debug_mode_enabled", shared.OptionInfo(False, "Enable Dev mode - adds extra reporting in console", gr.Checkbox, {"interactive": True}, section=section)) - shared.opts.add_option("deforum_save_gen_info_as_srt", shared.OptionInfo(False, "Save an .srt (subtitles) file with the generation info along with each animation", gr.Checkbox, {"interactive": True}, section=section)) - shared.opts.add_option("deforum_embed_srt", shared.OptionInfo(False, "If .srt file is saved, soft-embed the subtitles into the rendered video file", gr.Checkbox, {"interactive": True}, section=section)) - shared.opts.add_option("deforum_save_gen_info_as_srt_params", shared.OptionInfo(['Noise Schedule'], "Choose which animation params are to be saved to the .srt file (Frame # and Seed will always be saved):", ui_components.DropdownMulti, lambda: {"interactive": True, "choices": srt_ui_params}, section=section)) - -script_callbacks.on_ui_tabs(on_ui_tabs) -script_callbacks.on_ui_settings(on_ui_settings) +init_deforum() \ No newline at end of file diff --git a/scripts/deforum_helpers/animation.py b/scripts/deforum_helpers/animation.py index 7e8c2c01..fe20276c 100644 --- a/scripts/deforum_helpers/animation.py +++ b/scripts/deforum_helpers/animation.py @@ -2,11 +2,12 @@ import numpy as np import cv2 from functools import reduce import math -import py3d_tools as p3d +# import py3d_tools as p3d import torch from einops import rearrange from .prompt import check_is_number from .general_utils import debug_print +import py3d_tools as p3d # Webui from modules.shared import state, opts diff --git a/scripts/deforum_helpers/args.py b/scripts/deforum_helpers/args.py index b83375a2..42ac41a9 100644 --- a/scripts/deforum_helpers/args.py +++ b/scripts/deforum_helpers/args.py @@ -1,19 +1,19 @@ -from modules.shared import cmd_opts, opts +import os +import time +import json +import tempfile +from types import SimpleNamespace + +from modules.shared import cmd_opts from modules.processing import get_fixed_seed -from modules.ui_components import FormRow import modules.shared as sh import modules.paths as ph -import os -from .frame_interpolation import set_interp_out_fps, gradio_f_interp_get_fps_and_fcount, process_interp_vid_upload_logic, process_interp_pics_upload_logic -from .upscaling import process_ncnn_upscale_vid_upload_logic -from .vid2depth import process_depth_vid_upload_logic -from .video_audio_utilities import find_ffmpeg_binary, ffmpeg_stitch_video, direct_stitch_vid_from_frames, get_quick_vid_info, extract_number, get_ffmpeg_params -from .gradio_funcs import * -from .general_utils import get_os, get_deforum_version, custom_placeholder_format, test_long_path_support, get_max_path_length, substitute_placeholders -from .deforum_controlnet import setup_controlnet_ui, controlnet_component_names, controlnet_infotext -import tempfile + +from .general_utils import get_os, get_deforum_version, substitute_placeholders +from .deforum_controlnet import controlnet_component_names +from .defaults import get_guided_imgs_default_json -def Root(): +def RootArgs(): device = sh.device models_path = ph.models_path + '/Deforum' half_precision = not cmd_opts.no_half @@ -64,40 +64,35 @@ def DeforumAnimArgs(): near_schedule = "0: (200)" far_schedule = "0: (10000)" seed_schedule = '0:(s), 1:(-1), "max_f-2":(-1), "max_f-1":(s)' - pix2pix_img_cfg_scale = "1.5" pix2pix_img_cfg_scale_schedule = "0:(1.5)" enable_subseed_scheduling = False subseed_schedule = "0:(1)" subseed_strength_schedule = "0:(0)" - # Sampler Scheduling - enable_sampler_scheduling = False + enable_sampler_scheduling = False # Sampler Scheduling sampler_schedule = '0: ("Euler a")' - # Composable mask scheduling - use_noise_mask = False + use_noise_mask = False # Composable mask scheduling mask_schedule = '0: ("{video_mask}")' noise_mask_schedule = '0: ("{video_mask}")' - # Checkpoint Scheduling - enable_checkpoint_scheduling = False + enable_checkpoint_scheduling = False # Checkpoint Scheduling checkpoint_schedule = '0: ("model1.ckpt"), 100: ("model2.safetensors")' - # CLIP skip Scheduling - enable_clipskip_scheduling = False + enable_clipskip_scheduling = False # CLIP skip Scheduling clipskip_schedule = '0: (2)' - # Noise Multiplier Scheduling - enable_noise_multiplier_scheduling = True + enable_noise_multiplier_scheduling = True # Noise Multiplier Scheduling noise_multiplier_schedule = '0: (1.05)' + # resume params + resume_from_timestring = False + resume_timestring = "20230129210106" + # DDIM AND Ancestral ETA scheds + enable_ddim_eta_scheduling = False + ddim_eta_schedule = "0:(0)" + enable_ancestral_eta_scheduling = False + ancestral_eta_schedule = "0:(1)" # Anti-blur amount_schedule = "0: (0.1)" kernel_schedule = "0: (5)" sigma_schedule = "0: (1.0)" threshold_schedule = "0: (0.0)" - # Hybrid video - hybrid_comp_alpha_schedule = "0:(0.5)" - hybrid_comp_mask_blend_alpha_schedule = "0:(0.5)" - hybrid_comp_mask_contrast_schedule = "0:(1)" - hybrid_comp_mask_auto_contrast_cutoff_high_schedule = "0:(100)" - hybrid_comp_mask_auto_contrast_cutoff_low_schedule = "0:(0)" - hybrid_flow_factor_schedule = "0:(1)" - #Coherence + # Coherence color_coherence = 'LAB' # ['None', 'HSV', 'LAB', 'RGB', 'Video Input', 'Image'] color_coherence_image_path = "" color_coherence_video_every_N_frames = 1 @@ -109,14 +104,14 @@ def DeforumAnimArgs(): optical_flow_redo_generation = 'None' #['None', 'RAFT', 'DIS Medium', 'DIS Fine', 'Farneback'] redo_flow_factor_schedule = "0: (1)" diffusion_redo = '0' - #**Noise settings:** + # **Noise settings:** noise_type = 'perlin' # ['uniform', 'perlin'] # Perlin params perlin_w = 8 perlin_h = 8 perlin_octaves = 4 perlin_persistence = 0.5 - #**3D Depth Warping:** + # **3D Depth Warping:** use_depth_warping = True depth_algorithm = 'Midas-3-Hybrid' # ['Midas+AdaBins (old)','Zoe+AdaBins (old)', 'Midas-3-Hybrid','Midas-3.1-BeitLarge', 'AdaBins', 'Zoe', 'Leres'] Midas-3.1-BeitLarge is temporarily removed 04-05-23 until fixed midas_weight = 0.2 # midas/ zoe weight - only relevant in old/ legacy depth_algorithm modes. see above ^ @@ -132,6 +127,12 @@ def DeforumAnimArgs(): use_mask_video = False video_mask_path ='https://deforum.github.io/a1/VM1.mp4' #**Hybrid Video for 2D/3D Animation Mode:** + hybrid_comp_alpha_schedule = "0:(0.5)" + hybrid_comp_mask_blend_alpha_schedule = "0:(0.5)" + hybrid_comp_mask_contrast_schedule = "0:(1)" + hybrid_comp_mask_auto_contrast_cutoff_high_schedule = "0:(100)" + hybrid_comp_mask_auto_contrast_cutoff_low_schedule = "0:(0)" + hybrid_flow_factor_schedule = "0:(1)" hybrid_generate_inputframes = False hybrid_generate_human_masks = "None" #['None','PNGs','Video', 'Both'] hybrid_use_first_frame_as_init_image = True @@ -147,67 +148,32 @@ def DeforumAnimArgs(): hybrid_comp_mask_equalize = "None" # ['None','Before','After','Both'] hybrid_comp_mask_auto_contrast = False hybrid_comp_save_extra_frames = False - #**Resume Animation:** - resume_from_timestring = False - resume_timestring = "20230129210106" - enable_ddim_eta_scheduling = False - ddim_eta_schedule = "0:(0)" - enable_ancestral_eta_scheduling = False - ancestral_eta_schedule = "0:(1)" return locals() -def DeforumAnimPrompts(): - return r"""{ - "0": "tiny cute swamp bunny, highly detailed, intricate, ultra hd, sharp photo, crepuscular rays, in focus, by tomasz alen kopera", - "30": "anthropomorphic clean cat, surrounded by fractals, epic angle and pose, symmetrical, 3d, depth of field, ruan jia and fenghua zhong", - "60": "a beautiful coconut --neg photo, realistic", - "90": "a beautiful durian, trending on Artstation" -} - """ - def DeforumArgs(): - #**Image Settings** - W = 512 # - H = 512 # - W, H = map(lambda x: x - x % 64, (W, H)) # resize to integer multiple of 64 - + # set default image size and make sure to resize to multiples of 64 if needed + W, H = map(lambda x: x - x % 64, (512, 512)) + # wether or not to show gradio's info section for all params in the ui. it's a realtime toggle show_info_on_ui = True - #**Webui stuff** tiling = False restore_faces = False seed_enable_extras = False - subseed = -1 - subseed_strength = 0 seed_resize_from_w = 0 seed_resize_from_h = 0 - #**Sampling Settings** seed = -1 # sampler = 'euler_ancestral' # ["klms","dpm2","dpm2_ancestral","heun","euler","euler_ancestral","plms", "ddim"] steps = 25 # - scale = 7 # - - dynamic_threshold = None - static_threshold = None - #**Save & Display Settings** save_settings = True save_sample_per_step = False - - #**Prompt Settings** - prompt_weighting = False - normalize_prompt_weights = True - log_weighted_subprompts = False - #**Batch Settings** n_batch = 1 # batch_name = "Deforum_{timestring}" seed_behavior = "iter" # ["iter","fixed","random","ladder","alternate","schedule"] seed_iter_N = 1 - outdir = "" - #**Init Settings** use_init = False strength = 0.8 @@ -225,37 +191,17 @@ def DeforumArgs(): overlay_mask = True # Blur edges of final overlay mask, if used. Minimum = 0 (no blur) mask_overlay_blur = 4 - fill = 1 #MASKARGSEXPANSION Todo : Rename and convert to same formatting as used in img2img masked content full_res_mask = True full_res_mask_padding = 4 reroll_blank_frames = 'reroll' # reroll, interrupt, or ignore reroll_patience = 10 - n_samples = 1 # doesnt do anything - precision = 'autocast' - - prompt = "" - timestring = "" - init_sample = None - mask_image = None - noise_mask = None - seed_internal = 0 - return locals() -def keyframeExamples(): - return '''{ - "0": "https://deforum.github.io/a1/Gi1.png", - "max_f/4-5": "https://deforum.github.io/a1/Gi2.png", - "max_f/2-10": "https://deforum.github.io/a1/Gi3.png", - "3*max_f/4-15": "https://deforum.github.io/a1/Gi4.jpg", - "max_f-20": "https://deforum.github.io/a1/Gi1.png" -}''' - def LoopArgs(): use_looper = False - init_images = keyframeExamples() + init_images = get_guided_imgs_default_json() image_strength_schedule = "0:(0.75)" blendFactorMax = "0:(0.35)" blendFactorSlope = "0:(0.25)" @@ -274,7 +220,7 @@ def DeforumOutputArgs(): make_gif = False delete_imgs = False # True will delete all imgs after a successful mp4 creation image_path = "C:/SD/20230124234916_%09d.png" - mp4_path = "testvidmanualsettings.mp4" + # mp4_path = "testvidmanualsettings.mp4" add_soundtrack = 'None' # ["File","Init Video"] soundtrack_path = "https://deforum.github.io/a1/A1.mp3" # End-Run upscaling @@ -291,834 +237,47 @@ def DeforumOutputArgs(): frame_interpolation_slow_mo_amount = 2 #[2 to 10] frame_interpolation_keep_imgs = False return locals() - -import gradio as gr -import time -from types import SimpleNamespace i1_store_backup = f"Deforum extension for auto1111 — version 2.4b | Git commit: {get_deforum_version()}
" i1_store = i1_store_backup -mask_fill_choices=['fill', 'original', 'latent noise', 'latent nothing'] +d = SimpleNamespace(**DeforumArgs()) #default args +da = SimpleNamespace(**DeforumAnimArgs()) #default anim args +dp = SimpleNamespace(**ParseqArgs()) #default parseq ars +dv = SimpleNamespace(**DeforumOutputArgs()) #default video args +dr = SimpleNamespace(**RootArgs()) # ROOT args +dloopArgs = SimpleNamespace(**LoopArgs()) -def setup_deforum_setting_dictionary(self, is_img2img, is_extension = True): - d = SimpleNamespace(**DeforumArgs()) #default args - da = SimpleNamespace(**DeforumAnimArgs()) #default anim args - dp = SimpleNamespace(**ParseqArgs()) #default parseq ars - dv = SimpleNamespace(**DeforumOutputArgs()) #default video args - dr = SimpleNamespace(**Root()) # ROOT args - dloopArgs = SimpleNamespace(**LoopArgs()) - if not is_extension: - with gr.Row(variant='compact'): - btn = gr.Button("Click here after the generation to show the video") - with gr.Row(variant='compact'): - i1 = gr.HTML(i1_store, elem_id='deforum_header') - else: - btn = i1 = gr.HTML("") - # MAIN (TOP) EXTENSION INFO ACCORD - with gr.Accordion("Info, Links and Help", open=False, elem_id='main_top_info_accord'): - gr.HTML("""Made by deforum.github.io, port for AUTOMATIC1111's webui maintained by kabachuha & hithereai """) - gr.HTML("""FOR HELP CLICK HERE -Use a Parseq manifest for your animation (leave blank to ignore).
-- Fields managed in your Parseq manifest override the values and schedules set in other parts of this UI. You can select which values to override by using the "Managed Fields" section in Parseq. -
- """) - with gr.Row(variant='compact'): - parseq_manifest = gr.Textbox(label="Parseq Manifest (JSON or URL)", lines=4, value = dp.parseq_manifest, interactive=True) - with gr.Row(variant='compact'): - parseq_use_deltas = gr.Checkbox(label="Use delta values for movement parameters", value=dp.parseq_use_deltas, interactive=True) - # CONTROLNET TAB - with gr.TabItem('ControlNet'): - gr.HTML(controlnet_infotext()) - try: - controlnet_dict = setup_controlnet_ui() - except Exception as e: - raise Exception(e) - # HYBRID VIDEO TAB - with gr.TabItem('Hybrid Video'): - # this html only shows when not in 2d/3d mode - hybrid_msg_html = gr.HTML(value='Please, change animation mode to 2D or 3D to enable Hybrid Mode',visible=False, elem_id='hybrid_msg_html') - # HYBRID INFO ACCORD - with gr.Accordion("Info & Help", open=False): - hybrid_html = "Hybrid Video Compositing in 2D/3D Modeby reallybigname
" - hybrid_html += "- Supported engines: -
- Important notes: -
- Important Notes: -
+ Hybrid Video Compositing in 2D/3D Mode + + by reallybigname + +
+Use a Parseq manifest for your animation (leave blank to ignore).
++ Fields managed in your Parseq manifest override the values and schedules set in other parts of this UI. You can select which values to override by using the "Managed Fields" section in Parseq. +
+ """ + +def get_prompts_info_html(): + return """ +You can use this as a guided image tool or as a looper depending on your settings in the keyframe images field. + Set the keyframes and the images that you want to show up. + Note: the number of frames between each keyframe should be greater than the tweening frames.
+ +Prerequisites and Important Info:
+Looping recommendations:
+The Guided images mode exposes the following variables for the prompts and the schedules:
+Made by deforum.github.io, port for AUTOMATIC1111's webui maintained by kabachuha & hithereai
+ ++ Supported engines: +
+ Important notes: +
+ Important Notes: +
Deforum extension for auto1111 — version 2.2b
' + except Exception as e: + if need_to_frame_interpolate: + print(f"FFMPEG DID NOT STITCH ANY VIDEO. However, you requested to frame interpolate - so we will continue to frame interpolation, but you'll be left only with the interpolated frames and not a video, since ffmpeg couldn't run. Original ffmpeg error: {e}") + else: + print(f"** FFMPEG DID NOT STITCH ANY VIDEO ** Error: {e}") + pass + + if root.initial_info is None: + root.initial_info = "An error has occured and nothing has been generated!" + root.initial_info += "\nPlease, report the bug to https://github.com/deforum-art/deforum-for-automatic1111-webui/issues" + a = np.random.rand(args.W, args.H, 3)*255 + root.first_frame = Image.fromarray(a.astype('uint8')).convert('RGB') + root.initial_seed = 6934 + # FRAME INTERPOLATION TIME + if need_to_frame_interpolate: + print(f"Got a request to *frame interpolate* using {video_args.frame_interpolation_engine}") + process_video_interpolation(frame_interpolation_engine=video_args.frame_interpolation_engine, frame_interpolation_x_amount=video_args.frame_interpolation_x_amount,frame_interpolation_slow_mo_enabled=video_args.frame_interpolation_slow_mo_enabled, frame_interpolation_slow_mo_amount=video_args.frame_interpolation_slow_mo_amount, orig_vid_fps=video_args.fps, deforum_models_path=root.models_path, real_audio_track=real_audio_track, raw_output_imgs_path=args.outdir, img_batch_id=args.timestring, ffmpeg_location=f_location, ffmpeg_crf=f_crf, ffmpeg_preset=f_preset, keep_interp_imgs=video_args.frame_interpolation_keep_imgs, orig_vid_name=None, resolution=None, srt_path=srt_path) + + if video_args.make_gif and not video_args.skip_video_creation and not video_args.store_frames_in_ram: + make_gifski_gif(imgs_raw_path = args.outdir, imgs_batch_id = args.timestring, fps = video_args.fps, models_folder = root.models_path, current_user_os = root.current_user_os) + + # Upscale video once generation is done: + if video_args.r_upscale_video and not video_args.skip_video_creation and not video_args.store_frames_in_ram: + # out mp4 path is defined in make_upscale func + make_upscale_v2(upscale_factor = video_args.r_upscale_factor, upscale_model = video_args.r_upscale_model, keep_imgs = video_args.r_upscale_keep_imgs, imgs_raw_path = args.outdir, imgs_batch_id = args.timestring, fps = video_args.fps, deforum_models_path = root.models_path, current_user_os = root.current_user_os, ffmpeg_location=f_location, stitch_from_frame=0, stitch_to_frame=max_video_frames, ffmpeg_crf=f_crf, ffmpeg_preset=f_preset, add_soundtrack = video_args.add_soundtrack ,audio_path=real_audio_track, srt_path=srt_path) + + if video_args.delete_imgs and not video_args.skip_video_creation: + handle_imgs_deletion(vid_path=mp4_path, imgs_folder_path=args.outdir, batch_id=args.timestring) + + root.initial_info += "\n The animation is stored in " + args.outdir + reset_frames_cache(root) # cleanup the RAM in any case + processed = Processed(p, [root.first_frame], root.initial_seed, root.initial_info) + + if processed is None: + processed = process_images(p) + + shared.total_tqdm.clear() + + generation_info_js = processed.js() + if getattr(shared.opts, 'samples_log_stdout', False): + print(generation_info_js) + + if shared.opts.do_not_show_images: + processed.images = [] + + if shared.opts.data.get("deforum_enable_persistent_settings"): + persistent_sett_path = shared.opts.data.get("deforum_persistent_settings_path") + deforum_settings.save_settings_from_animation_run(args, anim_args, parseq_args, loop_args, controlnet_args, video_args, root, persistent_sett_path) + + return processed.images, args.timestring, generation_info_js, plaintext_to_html(processed.info), plaintext_to_html('') \ No newline at end of file diff --git a/scripts/deforum_helpers/settings.py b/scripts/deforum_helpers/settings.py index d78e7619..aa8b9eaa 100644 --- a/scripts/deforum_helpers/settings.py +++ b/scripts/deforum_helpers/settings.py @@ -2,14 +2,12 @@ from math import ceil import os import json import deforum_helpers.args as deforum_args -from .args import mask_fill_choices, DeforumArgs, DeforumAnimArgs +from .args import DeforumArgs, DeforumAnimArgs +from .defaults import mask_fill_choices from .deprecation_utils import handle_deprecated_settings from .general_utils import get_deforum_version, clean_gradio_path_strings from modules.shared import opts import modules.shared as sh -import logging - -DEBUG_MODE = opts.data.get("deforum_debug_mode_enabled", False) def get_keys_to_exclude(): return ["n_batch", "seed_enable_extras", "scale", "subseed", "subseed_strength", "init_sample", @@ -128,7 +126,7 @@ def load_all_settings(*args, ui_launch=False, **kwargs): val = mask_fill_choices[val] elif key in {'reroll_blank_frames', 'noise_type'} and key not in jdata: default_key_val = (DeforumArgs if key != 'noise_type' else DeforumAnimArgs)[key] - logging.debug(f"{key} not found in load file, using default value: {default_key_val}") + print(f"{key} not found in load file, using default value: {default_key_val}") val = default_key_val elif key in {'animation_prompts_positive', 'animation_prompts_negative'}: val = jdata.get(key, default_val) diff --git a/scripts/deforum_helpers/ui_left.py b/scripts/deforum_helpers/ui_left.py new file mode 100644 index 00000000..06b6343f --- /dev/null +++ b/scripts/deforum_helpers/ui_left.py @@ -0,0 +1,614 @@ +from types import SimpleNamespace +import gradio as gr +from modules.ui_components import FormRow +import modules.shared as sh +from .defaults import * ## TODO: change this to not * +from .deforum_controlnet import setup_controlnet_ui, controlnet_component_names, controlnet_infotext +from .gradio_funcs import * +from .video_audio_utilities import direct_stitch_vid_from_frames +from .frame_interpolation import set_interp_out_fps, gradio_f_interp_get_fps_and_fcount + +def setup_deforum_setting_dictionary(is_img2img, d, da, dp, dv, dr, dloopArgs): + btn = i1 = gr.HTML("") + # MAIN (TOP) EXTENSION INFO ACCORD + with gr.Accordion("Info, Links and Help", open=False, elem_id='main_top_info_accord'): + gr.HTML(value=get_gradio_html('main')) + with gr.Row(variant='compact'): + show_info_on_ui = gr.Checkbox(label="Show more info", value=d.show_info_on_ui, interactive=True) + with gr.Blocks(): + with gr.Tabs(): + # RUN TAB + with gr.TabItem('Run'): + from modules.sd_samplers import samplers_for_img2img + with gr.Row(variant='compact'): + sampler = gr.Dropdown(label="Sampler", choices=[x.name for x in samplers_for_img2img], value=samplers_for_img2img[0].name, type="value", elem_id="sampler", interactive=True) + steps = gr.Slider(label="Steps", minimum=0, maximum=200, step=1, value=d.steps, interactive=True) + with gr.Row(variant='compact'): + W = gr.Slider(label="Width", minimum=64, maximum=2048, step=64, value=d.W, interactive=True) + H = gr.Slider(label="Height", minimum=64, maximum=2048, step=64, value=d.H, interactive=True) + with gr.Row(variant='compact'): + seed = gr.Number(label="Seed", value=d.seed, interactive=True, precision=0, info="Starting seed for the animation. -1 for random") + n_batch = gr.Slider(label="# of vids", minimum=1, maximum=100, step=1, value=d.n_batch, interactive=True, info="if seed is set to random (-1), generate a few vids in one run", visible=False) + batch_name = gr.Textbox(label="Batch name", lines=1, interactive=True, value = d.batch_name, info="output images will be placed in a folder with this name ({timestring} token will be replaced) inside the img2img output folder. Supports params placeholders. e.g {seed}, {w}, {h}, {prompts}") + with gr.Row(variant='compact'): + restore_faces = gr.Checkbox(label='Restore Faces', value=d.restore_faces) + tiling = gr.Checkbox(label='Tiling', value=d.tiling) + enable_ddim_eta_scheduling = gr.Checkbox(label='Enable DDIM ETA scheduling', value=da.enable_ddim_eta_scheduling, visible=False) + enable_ancestral_eta_scheduling = gr.Checkbox(label='Enable Ancestral ETA scheduling', value=da.enable_ancestral_eta_scheduling) + with gr.Row(variant='compact') as eta_sch_row: + ddim_eta_schedule = gr.Textbox(label="DDIM ETA Schedule", lines=1, value=da.ddim_eta_schedule, interactive=True, visible=False) + ancestral_eta_schedule = gr.Textbox(label="Ancestral ETA Schedule", lines=1, value=da.ancestral_eta_schedule, interactive=True, visible=False) + # RUN FROM SETTING FILE ACCORD + with gr.Accordion('Batch Mode, Resume and more', open=False): + with gr.Tab('Batch Mode/ run from setting files'): + with gr.Row(variant='compact'): + override_settings_with_file = gr.Checkbox(label="Enable batch mode", value=False, interactive=True, elem_id='override_settings', info="run from a list of setting .txt files. Upload them to the box on the right (visible when enabled)") + custom_settings_file = gr.File(label="Setting files", interactive=True, file_count="multiple", file_types=[".txt"], elem_id="custom_setting_file", visible=False) + # RESUME ANIMATION ACCORD + with gr.Tab('Resume Animation'): + with gr.Row(variant='compact'): + resume_from_timestring = gr.Checkbox(label="Resume from timestring", value=da.resume_from_timestring, interactive=True) + resume_timestring = gr.Textbox(label="Resume timestring", lines=1, value = da.resume_timestring, interactive=True) + with gr.Row(variant='compact') as pix2pix_img_cfg_scale_row: + pix2pix_img_cfg_scale_schedule = gr.Textbox(label="Pix2Pix img CFG schedule", value=da.pix2pix_img_cfg_scale_schedule, interactive=True, info="ONLY in use when working with a P2P ckpt!") + # KEYFRAMES TAB + with gr.TabItem('Keyframes'): #TODO make a some sort of the original dictionary parsing + with gr.Row(variant='compact'): + with gr.Column(scale=2): + animation_mode = gr.Radio(['2D', '3D', 'Interpolation', 'Video Input'], label="Animation mode", value=da.animation_mode, elem_id="animation_mode", info="control animation mode, will hide non relevant params upon change") + with gr.Column(scale=1, min_width=180): + border = gr.Radio(['replicate', 'wrap'], label="Border", value=da.border, elem_id="border", info="controls pixel generation method for images smaller than the frame. hover on the options to see more info") + with gr.Row(variant='compact'): + diffusion_cadence = gr.Slider(label="Cadence", minimum=1, maximum=50, step=1, value=da.diffusion_cadence, interactive=True, info="# of in-between frames that will not be directly diffused") + max_frames = gr.Number(label="Max frames", lines=1, value = da.max_frames, interactive=True, precision=0, info="end the animation at this frame number") + # GUIDED IMAGES ACCORD + with gr.Accordion('Guided Images', open=False, elem_id='guided_images_accord') as guided_images_accord: + # GUIDED IMAGES INFO ACCORD + with gr.Accordion('*READ ME before you use this mode!*', open=False): + gr.HTML(value=get_gradio_html('guided_imgs')) + with gr.Row(variant='compact'): + use_looper = gr.Checkbox(label="Enable guided images mode", value=dloopArgs.use_looper, interactive=True) + with gr.Row(variant='compact'): + init_images = gr.Textbox(label="Images to use for keyframe guidance", lines=9, value = get_guided_imgs_default_json(), interactive=True) + # GUIDED IMAGES SCHEDULES ACCORD + with gr.Accordion('Guided images schedules', open=False): + with gr.Row(variant='compact'): + image_strength_schedule = gr.Textbox(label="Image strength schedule", lines=1, value = dloopArgs.image_strength_schedule, interactive=True) + with gr.Row(variant='compact'): + blendFactorMax = gr.Textbox(label="Blend factor max", lines=1, value = dloopArgs.blendFactorMax, interactive=True) + with gr.Row(variant='compact'): + blendFactorSlope = gr.Textbox(label="Blend factor slope", lines=1, value = dloopArgs.blendFactorSlope, interactive=True) + with gr.Row(variant='compact'): + tweening_frames_schedule = gr.Textbox(label="Tweening frames schedule", lines=1, value = dloopArgs.tweening_frames_schedule, interactive=True) + with gr.Row(variant='compact'): + color_correction_factor = gr.Textbox(label="Color correction factor", lines=1, value = dloopArgs.color_correction_factor, interactive=True) + # EXTA SCHEDULES TABS + with gr.Tabs(elem_id='extra_schedules'): + with gr.TabItem('Strength'): + with gr.Row(variant='compact'): + strength_schedule = gr.Textbox(label="Strength schedule", lines=1, value = da.strength_schedule, interactive=True, info="amount of presence of previous frame to influence next frame, also controls steps in the following formula [steps - (strength_schedule * steps)]") + with gr.TabItem('CFG'): + with gr.Row(variant='compact'): + cfg_scale_schedule = gr.Textbox(label="CFG scale schedule", lines=1, value = da.cfg_scale_schedule, interactive=True, info="how closely the image should conform to the prompt. Lower values produce more creative results. (recommended range 5-15)") + with gr.Row(variant='compact'): + enable_clipskip_scheduling = gr.Checkbox(label="Enable CLIP skip scheduling", value=da.enable_clipskip_scheduling, interactive=True) + with gr.Row(variant='compact'): + clipskip_schedule = gr.Textbox(label="CLIP skip schedule", lines=1, value = da.clipskip_schedule, interactive=True) + with gr.TabItem('Seed') as a3: + with gr.Row(variant='compact'): + seed_behavior = gr.Radio(['iter', 'fixed', 'random', 'ladder', 'alternate', 'schedule'], label="Seed behavior", value=d.seed_behavior, elem_id="seed_behavior", info="controls the seed behavior that is used for animation. hover on the options to see more info") + with gr.Row(variant='compact') as seed_iter_N_row: + seed_iter_N = gr.Number(label="Seed iter N", value=d.seed_iter_N, interactive=True, precision=0, info="for how many frames the same seed should stick before iterating to the next one") + with gr.Row(visible=False) as seed_schedule_row: + seed_schedule = gr.Textbox(label="Seed schedule", lines=1, value = da.seed_schedule, interactive=True) + with gr.TabItem('SubSeed', open=False) as subseed_sch_tab: + with gr.Row(variant='compact'): + enable_subseed_scheduling = gr.Checkbox(label="Enable Subseed scheduling", value=da.enable_subseed_scheduling, interactive=True) + subseed_schedule = gr.Textbox(label="Subseed schedule", lines=1, value = da.subseed_schedule, interactive=True) + subseed_strength_schedule = gr.Textbox(label="Subseed strength schedule", lines=1, value = da.subseed_strength_schedule, interactive=True) + with gr.Row(variant='compact'): + seed_resize_from_w = gr.Slider(minimum=0, maximum=2048, step=64, label="Resize seed from width", value=0) + seed_resize_from_h = gr.Slider(minimum=0, maximum=2048, step=64, label="Resize seed from height", value=0) + # Steps Scheduling + with gr.TabItem('Step') as a13: + with gr.Row(variant='compact'): + enable_steps_scheduling = gr.Checkbox(label="Enable steps scheduling", value=da.enable_steps_scheduling, interactive=True) + with gr.Row(variant='compact'): + steps_schedule = gr.Textbox(label="Steps schedule", lines=1, value = da.steps_schedule, interactive=True, info="mainly allows using more than 200 steps. otherwise, it's a mirror-like param of 'strength schedule'") + # Sampler Scheduling + with gr.TabItem('Sampler') as a14: + with gr.Row(variant='compact'): + enable_sampler_scheduling = gr.Checkbox(label="Enable sampler scheduling", value=da.enable_sampler_scheduling, interactive=True) + with gr.Row(variant='compact'): + sampler_schedule = gr.Textbox(label="Sampler schedule", lines=1, value = da.sampler_schedule, interactive=True, info="allows keyframing different samplers. Use names as they appear in ui dropdown in 'run' tab") + # Checkpoint Scheduling + with gr.TabItem('Checkpoint') as a15: + with gr.Row(variant='compact'): + enable_checkpoint_scheduling = gr.Checkbox(label="Enable checkpoint scheduling", value=da.enable_checkpoint_scheduling, interactive=True) + with gr.Row(variant='compact'): + checkpoint_schedule = gr.Textbox(label="Checkpoint schedule", lines=1, value = da.checkpoint_schedule, interactive=True, info="allows keyframing different sd models. use *full* name as appears in ui dropdown") + # MOTION INNER TAB + with gr.Tabs(elem_id='motion_noise_etc'): + with gr.TabItem('Motion') as motion_tab: + with gr.Column(visible=True) as only_2d_motion_column: + with gr.Row(variant='compact'): + zoom = gr.Textbox(label="Zoom", lines=1, value = da.zoom, interactive=True, info="scale the canvas size, multiplicatively. [static = 1.0]") + with gr.Row(variant='compact'): + angle = gr.Textbox(label="Angle", lines=1, value = da.angle, interactive=True, info="rotate canvas clockwise/anticlockwise in degrees per frame") + with gr.Row(variant='compact'): + transform_center_x = gr.Textbox(label="Transform Center X", lines=1, value = da.transform_center_x, interactive=True, info="x center axis for 2D angle/zoom") + with gr.Row(variant='compact'): + transform_center_y = gr.Textbox(label="Transform Center Y", lines=1, value = da.transform_center_y, interactive=True, info="y center axis for 2D angle/zoom") + with gr.Column(visible=True) as both_anim_mode_motion_params_column: + with gr.Row(variant='compact'): + translation_x = gr.Textbox(label="Translation X", lines=1, value = da.translation_x, interactive=True, info="move canvas left/right in pixels per frame") + with gr.Row(variant='compact'): + translation_y = gr.Textbox(label="Translation Y", lines=1, value = da.translation_y, interactive=True, info="move canvas up/down in pixels per frame") + with gr.Column(visible=False) as only_3d_motion_column: + with gr.Row(variant='compact'): + translation_z = gr.Textbox(label="Translation Z", lines=1, value = da.translation_z, interactive=True, info="move canvas towards/away from view [speed set by FOV]") + with gr.Row(variant='compact'): + rotation_3d_x = gr.Textbox(label="Rotation 3D X", lines=1, value = da.rotation_3d_x, interactive=True, info="tilt canvas up/down in degrees per frame") + with gr.Row(variant='compact'): + rotation_3d_y = gr.Textbox(label="Rotation 3D Y", lines=1, value = da.rotation_3d_y, interactive=True, info="pan canvas left/right in degrees per frame") + with gr.Row(variant='compact'): + rotation_3d_z = gr.Textbox(label="Rotation 3D Z", lines=1, value = da.rotation_3d_z, interactive=True, info="roll canvas clockwise/anticlockwise") + # PERSPECTIVE FLIP - params are hidden if not enabled + with gr.Row(variant='compact') as enable_per_f_row: + enable_perspective_flip = gr.Checkbox(label="Enable perspective flip", value=da.enable_perspective_flip, interactive=True) + with gr.Row(variant='compact', visible=False) as per_f_th_row: + perspective_flip_theta = gr.Textbox(label="Perspective flip theta", lines=1, value = da.perspective_flip_theta, interactive=True) + with gr.Row(variant='compact', visible=False) as per_f_ph_row: + perspective_flip_phi = gr.Textbox(label="Perspective flip phi", lines=1, value = da.perspective_flip_phi, interactive=True) + with gr.Row(variant='compact', visible=False) as per_f_ga_row: + perspective_flip_gamma = gr.Textbox(label="Perspective flip gamma", lines=1, value = da.perspective_flip_gamma, interactive=True) + with gr.Row(variant='compact', visible=False) as per_f_f_row: + perspective_flip_fv = gr.Textbox(label="Perspective flip fv", lines=1, value = da.perspective_flip_fv, interactive=True, info="the 2D vanishing point of perspective (rec. range 30-160)") + # NOISE INNER TAB + with gr.TabItem('Noise'): + with gr.Column() as noise_tab_column: + with gr.Row(variant='compact'): + noise_type = gr.Radio(['uniform', 'perlin'], label="Noise type", value=da.noise_type, elem_id="noise_type") + with gr.Row(variant='compact'): + noise_schedule = gr.Textbox(label="Noise schedule", lines=1, value = da.noise_schedule, interactive=True) + with gr.Row(variant='compact') as perlin_row: + with gr.Column(min_width=220): + perlin_octaves = gr.Slider(label="Perlin octaves", minimum=1, maximum=7, value=da.perlin_octaves, step=1, interactive=True) + with gr.Column(min_width=220): + perlin_persistence = gr.Slider(label="Perlin persistence", minimum=0, maximum=1, value=da.perlin_persistence, step=0.02, interactive=True) + with gr.Row(variant='compact'): + enable_noise_multiplier_scheduling = gr.Checkbox(label="Enable noise multiplier scheduling", value=da.enable_noise_multiplier_scheduling, interactive=True) + with gr.Row(variant='compact'): + noise_multiplier_schedule = gr.Textbox(label="Noise multiplier schedule", lines=1, value = da.noise_multiplier_schedule, interactive=True) + # COHERENCE INNER TAB + with gr.TabItem('Coherence', open=False) as coherence_accord: + with gr.Row(variant='compact'): + color_coherence = gr.Dropdown(label="Color coherence", choices=['None', 'HSV', 'LAB', 'RGB', 'Video Input', 'Image'], value=da.color_coherence, type="value", elem_id="color_coherence", interactive=True, info="choose an algorithm/ method for keeping color coherence across the animation") + color_force_grayscale = gr.Checkbox(label="Color force Grayscale", value=da.color_force_grayscale, interactive=True, info="force all frames to be in grayscale") + with gr.Row(variant='compact'): + legacy_colormatch = gr.Checkbox(label="Legacy colormatch", value=da.legacy_colormatch, interactive=True) + with gr.Row(visible=False) as color_coherence_image_path_row: + color_coherence_image_path = gr.Textbox(label="Color coherence image path", lines=1, value=da.color_coherence_image_path, interactive=True) + with gr.Row(visible=False) as color_coherence_video_every_N_frames_row: + color_coherence_video_every_N_frames = gr.Number(label="Color coherence video every N frames", value=1, interactive=True) + with gr.Row(variant='compact') as optical_flow_cadence_row: + with gr.Column(min_width=220) as optical_flow_cadence_column: + optical_flow_cadence = gr.Dropdown(choices=['None', 'RAFT', 'DIS Medium', 'DIS Fine', 'Farneback'], label="Optical flow cadence", value=da.optical_flow_cadence, elem_id="optical_flow_cadence", interactive=True, info="use optical flow estimation for your in-between (cadence) frames") + with gr.Column(min_width=220, visible=False) as cadence_flow_factor_schedule_column: + cadence_flow_factor_schedule = gr.Textbox(label="Cadence flow factor schedule", lines=1, value = da.cadence_flow_factor_schedule, interactive=True) + with gr.Row(variant='compact'): + with gr.Column(min_width=220): + optical_flow_redo_generation = gr.Dropdown(choices=['None', 'RAFT', 'DIS Medium', 'DIS Fine', 'Farneback'], label="Optical flow generation", value=da.optical_flow_redo_generation, elem_id="optical_flow_redo_generation", visible=True, interactive=True, info="this option takes twice as long because it generates twice in order to capture the optical flow from the previous image to the first generation, then warps the previous image and redoes the generation") + with gr.Column(min_width=220, visible=False) as redo_flow_factor_schedule_column: + redo_flow_factor_schedule = gr.Textbox(label="Generation flow factor schedule", lines=1, value = da.redo_flow_factor_schedule, interactive=True) + with gr.Row(variant='compact'): + contrast_schedule = gr.Textbox(label="Contrast schedule", lines=1, value = da.contrast_schedule, interactive=True, info="adjusts the overall contrast per frame [neutral at 1.0, recommended to *not* play with this param]") + diffusion_redo = gr.Slider(label="Redo generation", minimum=0, maximum=50, step=1, value=da.diffusion_redo, interactive=True, info="this option renders N times before the final render. it is suggested to lower your steps if you up your redo. seed is randomized during redo generations and restored afterwards") + with gr.Row(variant='compact'): + # what to do with blank frames (they may result from glitches or the NSFW filter being turned on): reroll with +1 seed, interrupt the animation generation, or do nothing + reroll_blank_frames = gr.Radio(['reroll', 'interrupt', 'ignore'], label="Reroll blank frames", value=d.reroll_blank_frames, elem_id="reroll_blank_frames") + reroll_patience = gr.Number(value=d.reroll_patience, label="Reroll patience", interactive=True) + # ANTI BLUR INNER TAB + with gr.TabItem('Anti Blur', elem_id='anti_blur_accord') as anti_blur_tab: + with gr.Row(variant='compact'): + amount_schedule = gr.Textbox(label="Amount schedule", lines=1, value = da.amount_schedule, interactive=True) + with gr.Row(variant='compact'): + kernel_schedule = gr.Textbox(label="Kernel schedule", lines=1, value = da.kernel_schedule, interactive=True) + with gr.Row(variant='compact'): + sigma_schedule = gr.Textbox(label="Sigma schedule", lines=1, value = da.sigma_schedule, interactive=True) + with gr.Row(variant='compact'): + threshold_schedule = gr.Textbox(label="Threshold schedule", lines=1, value = da.threshold_schedule, interactive=True) + with gr.TabItem('Depth Warping & FOV', elem_id='depth_warp_fov_tab') as depth_warp_fov_tab: + # this html only shows when not in 2d/3d mode + depth_warp_msg_html = gr.HTML(value='Please switch to 3D animation mode to view this section.', elem_id='depth_warp_msg_html') + with gr.Row(variant='compact', visible=False) as depth_warp_row_1: + use_depth_warping = gr.Checkbox(label="Use depth warping", value=da.use_depth_warping, interactive=True) + # this following html only shows when using LeReS depth + leres_license_msg = gr.HTML(value='Note that LeReS has a Non-Commercial license. Use it only for fun/personal use.', visible=False, elem_id='leres_license_msg') + depth_algorithm = gr.Dropdown(label="Depth Algorithm", choices=['Midas+AdaBins (old)','Zoe+AdaBins (old)','Midas-3-Hybrid','AdaBins','Zoe', 'Leres'], value=da.depth_algorithm, type="value", elem_id="df_depth_algorithm", interactive=True) # 'Midas-3.1-BeitLarge' is temporarily removed until fixed 04-05-23 + midas_weight = gr.Number(label="MiDaS/Zoe weight", value=da.midas_weight, interactive=True, visible=False, info="sets a midpoint at which a depthmap is to be drawn: range [-1 to +1]") + with gr.Row(variant='compact', visible=False) as depth_warp_row_2: + padding_mode = gr.Radio(['border', 'reflection', 'zeros'], label="Padding mode", value=da.padding_mode, elem_id="padding_mode", info="controls the handling of pixels outside the field of view as they come into the scene. hover on the options for more info") + sampling_mode = gr.Radio(['bicubic', 'bilinear', 'nearest'], label="Sampling mode", value=da.sampling_mode, elem_id="sampling_mode") + with gr.Row(variant='compact', visible=False) as depth_warp_row_3: + aspect_ratio_use_old_formula = gr.Checkbox(label="Use old aspect ratio formula", value=da.aspect_ratio_use_old_formula, interactive=True, info="for backward compatibility. uses the formula width/height") + with gr.Row(variant='compact', visible=False) as depth_warp_row_4: + aspect_ratio_schedule = gr.Textbox(label="Aspect Ratio schedule", lines=1, value = da.aspect_ratio_schedule, interactive=True, info="adjusts the aspect ratio for the depth calculation") + with gr.Row(variant='compact', visible=False) as depth_warp_row_5: + fov_schedule = gr.Textbox(label="FOV schedule", lines=1, value = da.fov_schedule, interactive=True, info="adjusts the scale at which the canvas is moved in 3D by the translation_z value. [maximum range -180 to +180, with 0 being undefined. Values closer to 180 will make the image have less depth, while values closer to 0 will allow more depth]") + with gr.Row(variant='compact', visible=False) as depth_warp_row_6: + near_schedule = gr.Textbox(label="Near schedule", lines=1, value = da.near_schedule, interactive=True) + with gr.Row(variant='compact', visible=False) as depth_warp_row_7: + far_schedule = gr.Textbox(label="Far schedule", lines=1, value = da.far_schedule, interactive=True) + # PROMPTS TAB + with gr.TabItem('Prompts'): + # PROMPTS INFO ACCORD + with gr.Accordion(label='*Important* notes on Prompts', elem_id='prompts_info_accord', open=False, visible=True) as prompts_info_accord: + gr.HTML(value=get_gradio_html('prompts')) + with gr.Row(variant='compact'): + animation_prompts = gr.Textbox(label="Prompts", lines=8, interactive=True, value = DeforumAnimPrompts(), info="full prompts list in a JSON format. value on left side is the frame number") + with gr.Row(variant='compact'): + animation_prompts_positive = gr.Textbox(label="Prompts positive", lines=1, interactive=True, placeholder="words in here will be added to the start of all positive prompts") + with gr.Row(variant='compact'): + animation_prompts_negative = gr.Textbox(label="Prompts negative", value="nsfw, nude", lines=1, interactive=True, placeholder="words in here will be added to the end of all negative prompts") + # COMPOSABLE MASK SCHEDULING ACCORD + with gr.Accordion('Composable Mask scheduling', open=False): + gr.HTML(value=get_gradio_html('composable_masks')) + with gr.Row(variant='compact'): + mask_schedule = gr.Textbox(label="Mask schedule", lines=1, value = da.mask_schedule, interactive=True) + with gr.Row(variant='compact'): + use_noise_mask = gr.Checkbox(label="Use noise mask", value=da.use_noise_mask, interactive=True) + with gr.Row(variant='compact'): + noise_mask_schedule = gr.Textbox(label="Noise mask schedule", lines=1, value = da.noise_mask_schedule, interactive=True) + # INIT MAIN TAB + with gr.TabItem('Init'): + # IMAGE INIT INNER-TAB + with gr.Tab('Image Init'): + with gr.Row(variant='compact'): + with gr.Column(min_width=150): + use_init = gr.Checkbox(label="Use init", value=d.use_init, interactive=True, visible=True) + with gr.Column(min_width=150): + strength_0_no_init = gr.Checkbox(label="Strength 0 no init", value=d.strength_0_no_init, interactive=True) + with gr.Column(min_width=170): + strength = gr.Slider(label="Strength", minimum=0, maximum=1, step=0.01, value=d.strength, interactive=True) + with gr.Row(variant='compact'): + init_image = gr.Textbox(label="Init image", lines=1, interactive=True, value = d.init_image) + # VIDEO INIT INNER-TAB + with gr.Tab('Video Init'): + with gr.Row(variant='compact'): + video_init_path = gr.Textbox(label="Video init path", lines=1, value = da.video_init_path, interactive=True) + with gr.Row(variant='compact'): + extract_from_frame = gr.Number(label="Extract from frame", value=da.extract_from_frame, interactive=True, precision=0) + extract_to_frame = gr.Number(label="Extract to frame", value=da.extract_to_frame, interactive=True, precision=0) + extract_nth_frame = gr.Number(label="Extract nth frame", value=da.extract_nth_frame, interactive=True, precision=0) + overwrite_extracted_frames = gr.Checkbox(label="Overwrite extracted frames", value=False, interactive=True) + use_mask_video = gr.Checkbox(label="Use mask video", value=False, interactive=True) + with gr.Row(variant='compact'): + video_mask_path = gr.Textbox(label="Video mask path", lines=1, value = da.video_mask_path, interactive=True) + # MASK INIT INNER-TAB + with gr.Tab('Mask Init'): + with gr.Row(variant='compact'): + use_mask = gr.Checkbox(label="Use mask", value=d.use_mask, interactive=True) + use_alpha_as_mask = gr.Checkbox(label="Use alpha as mask", value=d.use_alpha_as_mask, interactive=True) + invert_mask = gr.Checkbox(label="Invert mask", value=d.invert_mask, interactive=True) + overlay_mask = gr.Checkbox(label="Overlay mask", value=d.overlay_mask, interactive=True) + with gr.Row(variant='compact'): + mask_file = gr.Textbox(label="Mask file", lines=1, interactive=True, value = d.mask_file) + with gr.Row(variant='compact'): + mask_overlay_blur = gr.Slider(label="Mask overlay blur", minimum=0, maximum=64, step=1, value=d.mask_overlay_blur, interactive=True) + with gr.Row(variant='compact'): + choice = mask_fill_choices[d.fill] + fill = gr.Radio(label='Mask fill', choices=mask_fill_choices, value=choice, type="index") + with gr.Row(variant='compact'): + full_res_mask = gr.Checkbox(label="Full res mask", value=d.full_res_mask, interactive=True) + full_res_mask_padding = gr.Slider(minimum=0, maximum=512, step=1, label="Full res mask padding", value=d.full_res_mask_padding, interactive=True) + with gr.Row(variant='compact'): + with gr.Column(min_width=240): + mask_contrast_adjust = gr.Number(label="Mask contrast adjust", value=d.mask_contrast_adjust, interactive=True) + with gr.Column(min_width=250): + mask_brightness_adjust = gr.Number(label="Mask brightness adjust", value=d.mask_brightness_adjust, interactive=True) + # PARSEQ ACCORD + with gr.Accordion('Parseq', open=False): + gr.HTML(value=get_gradio_html('parseq')) + with gr.Row(variant='compact'): + parseq_manifest = gr.Textbox(label="Parseq Manifest (JSON or URL)", lines=4, value = dp.parseq_manifest, interactive=True) + with gr.Row(variant='compact'): + parseq_use_deltas = gr.Checkbox(label="Use delta values for movement parameters", value=dp.parseq_use_deltas, interactive=True) + # CONTROLNET TAB + with gr.TabItem('ControlNet'): + gr.HTML(controlnet_infotext()) + try: + controlnet_dict = setup_controlnet_ui() + except Exception as e: + raise Exception(e) + # HYBRID VIDEO TAB + with gr.TabItem('Hybrid Video'): + # this html only shows when not in 2d/3d mode + hybrid_msg_html = gr.HTML(value='Please, change animation mode to 2D or 3D to enable Hybrid Mode',visible=False, elem_id='hybrid_msg_html') + # HYBRID INFO ACCORD + with gr.Accordion("Info & Help", open=False): + gr.HTML(value=get_gradio_html('hybrid_video')) + # HYBRID SETTINGS ACCORD + with gr.Accordion("Hybrid Settings", open=True) as hybrid_settings_accord: + with gr.Row(variant='compact'): + hybrid_composite = gr.Radio(['None', 'Normal', 'Before Motion', 'After Generation'], label="Hybrid composite", value=da.hybrid_composite, elem_id="hybrid_composite") + with gr.Row(variant='compact'): + with gr.Column(min_width=340): + with gr.Row(variant='compact'): + hybrid_generate_inputframes = gr.Checkbox(label="Generate inputframes", value=da.hybrid_generate_inputframes, interactive=True) + hybrid_use_first_frame_as_init_image = gr.Checkbox(label="First frame as init image", value=da.hybrid_use_first_frame_as_init_image, interactive=True, visible=False) + hybrid_use_init_image = gr.Checkbox(label="Use init image as video", value=da.hybrid_use_init_image, interactive=True, visible=True) + with gr.Row(variant='compact'): + with gr.Column(variant='compact'): + with gr.Row(variant='compact'): + hybrid_motion = gr.Radio(['None', 'Optical Flow', 'Perspective', 'Affine'], label="Hybrid motion", value=da.hybrid_motion, elem_id="hybrid_motion") + with gr.Column(variant='compact'): + with gr.Row(variant='compact'): + with gr.Column(scale=1): + hybrid_flow_method = gr.Radio(['RAFT', 'DIS Medium', 'DIS Fine', 'Farneback'], label="Flow method", value=da.hybrid_flow_method, elem_id="hybrid_flow_method", visible=False) + with gr.Row(variant='compact'): + with gr.Column(variant='compact'): + hybrid_flow_consistency = gr.Checkbox(label="Flow consistency mask", value=da.hybrid_flow_consistency, interactive=True, visible=False) + hybrid_consistency_blur = gr.Slider(label="Consistency mask blur", minimum=0, maximum=16, step=1, value=da.hybrid_consistency_blur, interactive=True, visible=False) + with gr.Column(variant='compact'): + hybrid_motion_use_prev_img = gr.Checkbox(label="Motion use prev img", value=da.hybrid_motion_use_prev_img, interactive=True, visible=False) + with gr.Row(variant='compact'): + hybrid_comp_mask_type = gr.Radio(['None', 'Depth', 'Video Depth', 'Blend', 'Difference'], label="Comp mask type", value=da.hybrid_comp_mask_type, elem_id="hybrid_comp_mask_type", visible=False) + with gr.Row(visible=False, variant='compact') as hybrid_comp_mask_row: + hybrid_comp_mask_equalize = gr.Radio(['None', 'Before', 'After', 'Both'], label="Comp mask equalize", value=da.hybrid_comp_mask_equalize, elem_id="hybrid_comp_mask_equalize") + with gr.Column(variant='compact'): + hybrid_comp_mask_auto_contrast = gr.Checkbox(label="Comp mask auto contrast", value=False, interactive=True) + hybrid_comp_mask_inverse = gr.Checkbox(label="Comp mask inverse", value=da.hybrid_comp_mask_inverse, interactive=True) + with gr.Row(variant='compact'): + hybrid_comp_save_extra_frames = gr.Checkbox(label="Comp save extra frames", value=False, interactive=True) + # HYBRID SCHEDULES ACCORD + with gr.Accordion("Hybrid Schedules", open=False, visible=False) as hybrid_sch_accord: + with gr.Row(variant='compact') as hybrid_comp_alpha_schedule_row: + hybrid_comp_alpha_schedule = gr.Textbox(label="Comp alpha schedule", lines=1, value = da.hybrid_comp_alpha_schedule, interactive=True) + with gr.Row(variant='compact') as hybrid_flow_factor_schedule_row: + hybrid_flow_factor_schedule = gr.Textbox(label="Flow factor schedule", visible=False, lines=1, value = da.hybrid_flow_factor_schedule, interactive=True) + with gr.Row(variant='compact', visible=False) as hybrid_comp_mask_blend_alpha_schedule_row: + hybrid_comp_mask_blend_alpha_schedule = gr.Textbox(label="Comp mask blend alpha schedule", lines=1, value = da.hybrid_comp_mask_blend_alpha_schedule, interactive=True, elem_id="hybridelemtest") + with gr.Row(variant='compact', visible=False) as hybrid_comp_mask_contrast_schedule_row: + hybrid_comp_mask_contrast_schedule = gr.Textbox(label="Comp mask contrast schedule", lines=1, value = da.hybrid_comp_mask_contrast_schedule, interactive=True) + with gr.Row(variant='compact', visible=False) as hybrid_comp_mask_auto_contrast_cutoff_high_schedule_row : + hybrid_comp_mask_auto_contrast_cutoff_high_schedule = gr.Textbox(label="Comp mask auto contrast cutoff high schedule", lines=1, value = da.hybrid_comp_mask_auto_contrast_cutoff_high_schedule, interactive=True) + with gr.Row(variant='compact', visible=False) as hybrid_comp_mask_auto_contrast_cutoff_low_schedule_row: + hybrid_comp_mask_auto_contrast_cutoff_low_schedule = gr.Textbox(label="Comp mask auto contrast cutoff low schedule", lines=1, value = da.hybrid_comp_mask_auto_contrast_cutoff_low_schedule, interactive=True) + # HUMANS MASKING ACCORD + with gr.Accordion("Humans Masking", open=False, visible=False) as humans_masking_accord: + with gr.Row(variant='compact'): + hybrid_generate_human_masks = gr.Radio(['None', 'PNGs', 'Video', 'Both'], label="Generate human masks", value=da.hybrid_generate_human_masks, elem_id="hybrid_generate_human_masks") + # OUTPUT TAB + with gr.TabItem('Output', elem_id='output_tab'): + # VID OUTPUT ACCORD + with gr.Accordion('Video Output Settings', open=True): + with gr.Row(variant='compact') as fps_out_format_row: + fps = gr.Slider(label="FPS", value=dv.fps, minimum=1, maximum=240, step=1) + with gr.Column(variant='compact'): + with gr.Row(variant='compact') as soundtrack_row: + add_soundtrack = gr.Radio(['None', 'File', 'Init Video'], label="Add soundtrack", value=dv.add_soundtrack, info="add audio to video from file/url or init video", elem_id="add_soundtrack") + soundtrack_path = gr.Textbox(label="Soundtrack path", lines=1, interactive=True, value = dv.soundtrack_path, info="abs. path or url to audio file") + # TODO: auto-hide if video input is selected?! + with gr.Row(variant='compact'): + skip_video_creation = gr.Checkbox(label="Skip video creation", value=dv.skip_video_creation, interactive=True, info="If enabled, only images will be saved") + delete_imgs = gr.Checkbox(label="Delete Imgs", value=dv.delete_imgs, interactive=True, info="auto-delete imgs when video is ready") + store_frames_in_ram = gr.Checkbox(label="Store frames in ram", value=dv.store_frames_in_ram, interactive=True, visible=False) + save_depth_maps = gr.Checkbox(label="Save depth maps", value=da.save_depth_maps, interactive=True, info="save animation's depth maps as extra files") + # the following param only shows for windows and linux users! + make_gif = gr.Checkbox(label="Make GIF", value=dv.make_gif, interactive=True, info="make gif in addition to the video/s") + with gr.Row(equal_height=True, variant='compact', visible=True) as r_upscale_row: + r_upscale_video = gr.Checkbox(label="Upscale", value=dv.r_upscale_video, interactive=True, info="upscale output imgs when run is finished") + r_upscale_model = gr.Dropdown(label="Upscale model", choices=['realesr-animevideov3', 'realesrgan-x4plus', 'realesrgan-x4plus-anime'], interactive=True, value = dv.r_upscale_model, type="value") + r_upscale_factor = gr.Dropdown(choices=['x2', 'x3', 'x4'], label="Upscale factor", interactive=True, value=dv.r_upscale_factor, type="value") + r_upscale_keep_imgs = gr.Checkbox(label="Keep Imgs", value=dv.r_upscale_keep_imgs, interactive=True, info="don't delete upscaled imgs") + # FRAME INTERPOLATION TAB + with gr.Tab('Frame Interpolation') as frame_interp_tab: + with gr.Accordion('Important notes and Help', open=False, elem_id="f_interp_accord"): + gr.HTML(value=get_gradio_html('frame_interpolation')) + with gr.Column(variant='compact'): + with gr.Row(variant='compact'): + # Interpolation Engine + with gr.Column(min_width=110, scale = 3): + frame_interpolation_engine = gr.Radio(['None','RIFE v4.6','FILM'], label="Engine", value=dv.frame_interpolation_engine, info="select the frame interpolation engine. hover on the options for more info") + with gr.Column(min_width=30, scale = 1): + frame_interpolation_slow_mo_enabled = gr.Checkbox(label="Slow Mo", elem_id="frame_interpolation_slow_mo_enabled", value=dv.frame_interpolation_slow_mo_enabled, interactive=True, visible=False) + with gr.Column(min_width=30, scale = 1): + # If this is set to True, we keep all of the interpolated frames in a folder. Default is False - means we delete them at the end of the run + frame_interpolation_keep_imgs = gr.Checkbox(label="Keep Imgs", elem_id="frame_interpolation_keep_imgs", value=dv.frame_interpolation_keep_imgs, interactive=True, visible=False) + with gr.Row(variant='compact', visible=False) as frame_interp_amounts_row: + with gr.Column(min_width=180) as frame_interp_x_amount_column: + # How many times to interpolate (interp X) + frame_interpolation_x_amount = gr.Slider(minimum=2, maximum=10, step=1, label="Interp X", value=dv.frame_interpolation_x_amount, interactive=True) + with gr.Column(min_width=180, visible=False) as frame_interp_slow_mo_amount_column: + # Interp Slow-Mo (setting final output fps, not really doing anything direclty with RIFE/FILM) + frame_interpolation_slow_mo_amount = gr.Slider(minimum=2, maximum=10, step=1, label="Slow-Mo X", value=dv.frame_interpolation_x_amount, interactive=True) + with gr.Row(visible=False) as interp_existing_video_row: + # Intrpolate any existing video from the connected PC + with gr.Accordion('Interpolate existing Video/ Images', open=False) as interp_existing_video_accord: + with gr.Row(variant='compact') as interpolate_upload_files_row: + # A drag-n-drop UI box to which the user uploads a *single* (at this stage) video + vid_to_interpolate_chosen_file = gr.File(label="Video to Interpolate", interactive=True, file_count="single", file_types=["video"], elem_id="vid_to_interpolate_chosen_file") + # A drag-n-drop UI box to which the user uploads a pictures to interpolate + pics_to_interpolate_chosen_file = gr.File(label="Pics to Interpolate", interactive=True, file_count="multiple", file_types=["image"], elem_id="pics_to_interpolate_chosen_file") + with gr.Row(variant='compact', visible=False) as interp_live_stats_row: + # Non interactive textbox showing uploaded input vid total Frame Count + in_vid_frame_count_window = gr.Textbox(label="In Frame Count", lines=1, interactive=False, value='---') + # Non interactive textbox showing uploaded input vid FPS + in_vid_fps_ui_window = gr.Textbox(label="In FPS", lines=1, interactive=False, value='---') + # Non interactive textbox showing expected output interpolated video FPS + out_interp_vid_estimated_fps = gr.Textbox(label="Interpolated Vid FPS", value='---') + with gr.Row(variant='compact') as interp_buttons_row: + # This is the actual button that's pressed to initiate the interpolation: + interpolate_button = gr.Button(value="*Interpolate Video*") + interpolate_pics_button = gr.Button(value="*Interpolate Pics*") + # Show a text about CLI outputs: + gr.HTML("* check your CLI for outputs *", elem_id="below_interpolate_butts_msg") # TODO: CSS THIS TO CENTER OF ROW! + # make the functin call when the interpolation button is clicked + interpolate_button.click(upload_vid_to_interpolate,inputs=[vid_to_interpolate_chosen_file, frame_interpolation_engine, frame_interpolation_x_amount, frame_interpolation_slow_mo_enabled, frame_interpolation_slow_mo_amount, frame_interpolation_keep_imgs, in_vid_fps_ui_window]) + interpolate_pics_button.click(upload_pics_to_interpolate,inputs=[pics_to_interpolate_chosen_file, frame_interpolation_engine, frame_interpolation_x_amount, frame_interpolation_slow_mo_enabled, frame_interpolation_slow_mo_amount, frame_interpolation_keep_imgs, fps, add_soundtrack, soundtrack_path]) + # VIDEO UPSCALE TAB + with gr.TabItem('Video Upscaling'): + vid_to_upscale_chosen_file = gr.File(label="Video to Upscale", interactive=True, file_count="single", file_types=["video"], elem_id="vid_to_upscale_chosen_file") + with gr.Column(): + # NCNN UPSCALE TAB + with gr.Row(variant='compact') as ncnn_upload_vid_stats_row: + ncnn_upscale_in_vid_frame_count_window = gr.Textbox(label="In Frame Count", lines=1, interactive=False, value='---') # Non interactive textbox showing uploaded input vid Frame Count + ncnn_upscale_in_vid_fps_ui_window = gr.Textbox(label="In FPS", lines=1, interactive=False, value='---') # Non interactive textbox showing uploaded input vid FPS + ncnn_upscale_in_vid_res = gr.Textbox(label="In Res", lines=1, interactive=False, value='---') # Non interactive textbox showing uploaded input resolution + ncnn_upscale_out_vid_res = gr.Textbox(label="Out Res", value='---') # Non interactive textbox showing expected output resolution + with gr.Column(): + with gr.Row(variant='compact', visible=True) as ncnn_actual_upscale_row: + ncnn_upscale_model = gr.Dropdown(label="Upscale model", choices=['realesr-animevideov3', 'realesrgan-x4plus', 'realesrgan-x4plus-anime'], interactive=True, value = "realesr-animevideov3", type="value") + ncnn_upscale_factor = gr.Dropdown(choices=['x2', 'x3', 'x4'], label="Upscale factor", interactive=True, value="x2", type="value") + ncnn_upscale_keep_imgs = gr.Checkbox(label="Keep Imgs", value=True, interactive=True) # fix value + ncnn_upscale_btn = gr.Button(value="*Upscale uploaded video*") + ncnn_upscale_btn.click(ncnn_upload_vid_to_upscale,inputs=[vid_to_upscale_chosen_file, ncnn_upscale_in_vid_fps_ui_window, ncnn_upscale_in_vid_res, ncnn_upscale_out_vid_res, ncnn_upscale_model, ncnn_upscale_factor, ncnn_upscale_keep_imgs]) + with gr.Column(visible=False): # Upscale V1. Disabled 06-03-23 + selected_tab = gr.State(value=0) + with gr.Tabs(elem_id="extras_resize_mode"): + with gr.TabItem('Scale by', elem_id="extras_scale_by_tab") as tab_scale_by: + upscaling_resize = gr.Slider(minimum=1.0, maximum=8.0, step=0.05, label="Resize", value=2, elem_id="extras_upscaling_resize") + with gr.TabItem('Scale to', elem_id="extras_scale_to_tab") as tab_scale_to: + with FormRow(): + upscaling_resize_w = gr.Slider(label="Width", minimum=1, maximum=7680, step=1, value=512, elem_id="extras_upscaling_resize_w") + upscaling_resize_h = gr.Slider(label="Height", minimum=1, maximum=7680, step=1, value=512, elem_id="extras_upscaling_resize_h") + upscaling_crop = gr.Checkbox(label='Crop to fit', value=True, elem_id="extras_upscaling_crop") + with FormRow(): + extras_upscaler_1 = gr.Dropdown(label='Upscaler 1', elem_id="extras_upscaler_1", choices=[x.name for x in sh.sd_upscalers], value=sh.sd_upscalers[3].name) + extras_upscaler_2 = gr.Dropdown(label='Upscaler 2', elem_id="extras_upscaler_2", choices=[x.name for x in sh.sd_upscalers], value=sh.sd_upscalers[0].name) + with FormRow(): + with gr.Column(scale=3): + extras_upscaler_2_visibility = gr.Slider(minimum=0.0, maximum=1.0, step=0.001, label="Upscaler 2 visibility", value=0.0, elem_id="extras_upscaler_2_visibility") + with gr.Column(scale=1, min_width=80): + upscale_keep_imgs = gr.Checkbox(label="Keep Imgs", elem_id="upscale_keep_imgs", value=True, interactive=True) + tab_scale_by.select(fn=lambda: 0, inputs=[], outputs=[selected_tab]) + tab_scale_to.select(fn=lambda: 1, inputs=[], outputs=[selected_tab]) + # This is the actual button that's pressed to initiate the Upscaling: + upscale_btn = gr.Button(value="*Upscale uploaded video*") + # Show a text about CLI outputs: + gr.HTML("* check your CLI for outputs") + # Vid2Depth TAB + with gr.TabItem('Vid2depth'): + vid_to_depth_chosen_file = gr.File(label="Video to get Depth from", interactive=True, file_count="single", file_types=["video"], elem_id="vid_to_depth_chosen_file") + with gr.Row(variant='compact'): + mode = gr.Dropdown(label='Mode', elem_id="mode", choices=['Depth (Midas/Adabins)', 'Anime Remove Background', 'Mixed', 'None (just grayscale)'], value='Depth (Midas/Adabins)') + threshold_value = gr.Slider(label="Threshold Value Lower", value=127, minimum=0, maximum=255, step=1) + threshold_value_max = gr.Slider(label="Threshold Value Upper", value=255, minimum=0, maximum=255, step=1) + with gr.Row(variant='compact'): + thresholding = gr.Radio(['None', 'Simple', 'Simple (Auto-value)', 'Adaptive (Mean)', 'Adaptive (Gaussian)'], label="Thresholding Mode", value='None') + with gr.Row(variant='compact'): + adapt_block_size = gr.Number(label="Block size", value=11) + adapt_c = gr.Number(label="C", value=2) + invert = gr.Checkbox(label='Closer is brighter', value=True, elem_id="invert") + with gr.Row(variant='compact'): + end_blur = gr.Slider(label="End blur width", value=0, minimum=0, maximum=255, step=1) + midas_weight_vid2depth = gr.Slider(label="MiDaS weight (vid2depth)", value=da.midas_weight, minimum=0, maximum=1, step=0.05, interactive=True, info="sets a midpoint at which a depthmap is to be drawn: range [-1 to +1]") + depth_keep_imgs = gr.Checkbox(label='Keep Imgs', value=True, elem_id="depth_keep_imgs") + with gr.Row(variant='compact'): + # This is the actual button that's pressed to initiate the Upscaling: + depth_btn = gr.Button(value="*Get depth from uploaded video*") + with gr.Row(variant='compact'): + # Show a text about CLI outputs: + gr.HTML("* check your CLI for outputs") + # make the function call when the UPSCALE button is clicked + depth_btn.click(upload_vid_to_depth,inputs=[vid_to_depth_chosen_file, mode, thresholding, threshold_value, threshold_value_max, adapt_block_size, adapt_c, invert, end_blur, midas_weight_vid2depth, depth_keep_imgs]) + # STITCH FRAMES TO VID TAB + with gr.TabItem('Frames to Video') as stitch_imgs_to_vid_row: + gr.HTML(value=get_gradio_html('frames_to_video')) + with gr.Row(variant='compact'): + image_path = gr.Textbox(label="Image path", lines=1, interactive=True, value = dv.image_path) + ffmpeg_stitch_imgs_but = gr.Button(value="*Stitch frames to video*") + ffmpeg_stitch_imgs_but.click(direct_stitch_vid_from_frames,inputs=[image_path, fps, add_soundtrack, soundtrack_path]) + # **OLD + NON ACTIVES AREA** + with gr.Accordion(visible=False, label='INVISIBLE') as not_in_use_accordion: + perlin_w = gr.Slider(label="Perlin W", minimum=0.1, maximum=16, step=0.1, value=da.perlin_w, interactive=True) + perlin_h = gr.Slider(label="Perlin H", minimum=0.1, maximum=16, step=0.1, value=da.perlin_h, interactive=True) + save_settings = gr.Checkbox(label="save_settings", value=d.save_settings, interactive=True) + seed_enable_extras = gr.Checkbox(label="Enable subseed controls", value=False) + save_sample_per_step = gr.Checkbox(label="Save sample per step", value=d.save_sample_per_step, interactive=True) + # Gradio's Change functions - hiding and renaming elements based on other elements + show_info_on_ui.change(fn=change_css, inputs=show_info_on_ui, outputs = gr.outputs.HTML()) + # seed.change(fn=auto_hide_n_batch, inputs=seed, outputs=n_batch) + fps.change(fn=change_gif_button_visibility, inputs=fps, outputs=make_gif) + r_upscale_model.change(fn=update_r_upscale_factor, inputs=r_upscale_model, outputs=r_upscale_factor) + ncnn_upscale_model.change(fn=update_r_upscale_factor, inputs=ncnn_upscale_model, outputs=ncnn_upscale_factor) + ncnn_upscale_model.change(update_upscale_out_res_by_model_name, inputs=[ncnn_upscale_in_vid_res, ncnn_upscale_model], outputs=ncnn_upscale_out_vid_res) + ncnn_upscale_factor.change(update_upscale_out_res, inputs=[ncnn_upscale_in_vid_res, ncnn_upscale_factor], outputs=ncnn_upscale_out_vid_res) + vid_to_upscale_chosen_file.change(vid_upscale_gradio_update_stats,inputs=[vid_to_upscale_chosen_file, ncnn_upscale_factor],outputs=[ncnn_upscale_in_vid_fps_ui_window, ncnn_upscale_in_vid_frame_count_window, ncnn_upscale_in_vid_res, ncnn_upscale_out_vid_res]) + animation_mode.change(fn=change_max_frames_visibility, inputs=animation_mode, outputs=max_frames) + diffusion_cadence_outputs = [diffusion_cadence,guided_images_accord,optical_flow_cadence_row,cadence_flow_factor_schedule, + optical_flow_redo_generation,redo_flow_factor_schedule,diffusion_redo] + for output in diffusion_cadence_outputs: + animation_mode.change(fn=change_diffusion_cadence_visibility, inputs=animation_mode, outputs=output) + three_d_related_outputs = [only_3d_motion_column, depth_warp_row_1, depth_warp_row_2, depth_warp_row_3, depth_warp_row_4, depth_warp_row_5, depth_warp_row_6, depth_warp_row_7] # depth_3d_warping_accord, fov_accord + for output in three_d_related_outputs: + animation_mode.change(fn=disble_3d_related_stuff, inputs=animation_mode, outputs=output) + pers_flip_outputs = [per_f_th_row, per_f_ph_row, per_f_ga_row, per_f_f_row] + for output in pers_flip_outputs: + enable_perspective_flip.change(fn=hide_if_false,inputs=enable_perspective_flip,outputs=output) + animation_mode.change(fn=only_show_in_non_3d_mode, inputs=animation_mode, outputs=depth_warp_msg_html) + animation_mode.change(fn=enable_2d_related_stuff, inputs=animation_mode, outputs=only_2d_motion_column) + animation_mode.change(fn=disable_by_interpolation, inputs=animation_mode, outputs=color_force_grayscale) + animation_mode.change(fn=disable_by_interpolation, inputs=animation_mode, outputs=noise_tab_column) + pers_flip_hide_all_param_names = [per_f_th_row, per_f_ph_row, per_f_ga_row, per_f_f_row] + for output in pers_flip_hide_all_param_names: + animation_mode.change(fn=per_flip_handle, inputs=[animation_mode, enable_perspective_flip], outputs=output) + # show/hide enable persp flip mode button. Shown only in 2d/3d anim modes + animation_mode.change(fn=disable_pers_flip_accord, inputs=animation_mode, outputs=enable_per_f_row) + animation_mode.change(fn=disable_pers_flip_accord, inputs=animation_mode, outputs=both_anim_mode_motion_params_column) + aspect_ratio_use_old_formula.change(fn=hide_if_true, inputs=aspect_ratio_use_old_formula, outputs=aspect_ratio_schedule) + #Hybrid related: + animation_mode.change(fn=show_hybrid_html_msg, inputs=animation_mode, outputs=hybrid_msg_html) + animation_mode.change(fn=change_hybrid_tab_status, inputs=animation_mode, outputs=hybrid_sch_accord) + animation_mode.change(fn=change_hybrid_tab_status, inputs=animation_mode, outputs=hybrid_settings_accord) + animation_mode.change(fn=change_hybrid_tab_status, inputs=animation_mode, outputs=humans_masking_accord) + optical_flow_redo_generation.change(fn=hide_if_none, inputs=optical_flow_redo_generation, outputs=redo_flow_factor_schedule_column) + override_settings_with_file.change(fn=hide_if_false, inputs=override_settings_with_file,outputs=custom_settings_file) + hybrid_comp_mask_type.change(fn=hide_if_none, inputs=hybrid_comp_mask_type, outputs=hybrid_comp_mask_row) + hybrid_motion_outputs = [hybrid_flow_method, hybrid_flow_factor_schedule, hybrid_flow_consistency, hybrid_consistency_blur, hybrid_motion_use_prev_img] + for output in hybrid_motion_outputs: + hybrid_motion.change(fn=disable_by_non_optical_flow, inputs=hybrid_motion, outputs=output) + hybrid_flow_consistency.change(fn=hide_if_false, inputs=hybrid_flow_consistency, outputs=hybrid_consistency_blur) + optical_flow_cadence.change(fn=hide_if_none, inputs=optical_flow_cadence, outputs=cadence_flow_factor_schedule_column) + hybrid_composite.change(fn=disable_by_hybrid_composite_dynamic, inputs=[hybrid_composite, hybrid_comp_mask_type], outputs=hybrid_comp_mask_row) + hybrid_composite_outputs = [humans_masking_accord, hybrid_sch_accord, hybrid_comp_mask_type, hybrid_use_first_frame_as_init_image, hybrid_use_init_image] + for output in hybrid_composite_outputs: + hybrid_composite.change(fn=hide_if_false, inputs=hybrid_composite, outputs=output) + hybrid_comp_mask_type_outputs = [hybrid_comp_mask_blend_alpha_schedule_row, hybrid_comp_mask_contrast_schedule_row, hybrid_comp_mask_auto_contrast_cutoff_high_schedule_row, hybrid_comp_mask_auto_contrast_cutoff_low_schedule_row] + for output in hybrid_comp_mask_type_outputs: + hybrid_comp_mask_type.change(fn=hide_if_none, inputs=hybrid_comp_mask_type, outputs=output) + # End of hybrid related + seed_behavior.change(fn=change_seed_iter_visibility, inputs=seed_behavior, outputs=seed_iter_N_row) + seed_behavior.change(fn=change_seed_schedule_visibility, inputs=seed_behavior, outputs=seed_schedule_row) + color_coherence.change(fn=change_color_coherence_video_every_N_frames_visibility, inputs=color_coherence, outputs=color_coherence_video_every_N_frames_row) + color_coherence.change(fn=change_color_coherence_image_path_visibility, inputs=color_coherence, outputs=color_coherence_image_path_row) + noise_type.change(fn=change_perlin_visibility, inputs=noise_type, outputs=perlin_row) + skip_video_creation_outputs = [fps_out_format_row, soundtrack_row, store_frames_in_ram, make_gif, r_upscale_row, delete_imgs] + for output in skip_video_creation_outputs: + skip_video_creation.change(fn=change_visibility_from_skip_video, inputs=skip_video_creation, outputs=output) + frame_interpolation_slow_mo_enabled.change(fn=hide_if_false,inputs=frame_interpolation_slow_mo_enabled,outputs=frame_interp_slow_mo_amount_column) + frame_interpolation_engine.change(fn=change_interp_x_max_limit,inputs=[frame_interpolation_engine,frame_interpolation_x_amount],outputs=frame_interpolation_x_amount) + [change_fn.change(set_interp_out_fps, inputs=[frame_interpolation_x_amount, frame_interpolation_slow_mo_enabled, frame_interpolation_slow_mo_amount, in_vid_fps_ui_window], outputs=out_interp_vid_estimated_fps) for change_fn in [frame_interpolation_x_amount, frame_interpolation_slow_mo_amount, frame_interpolation_slow_mo_enabled]] + # Populate the FPS and FCount values as soon as a video is uploaded to the FileUploadBox (vid_to_interpolate_chosen_file) + vid_to_interpolate_chosen_file.change(gradio_f_interp_get_fps_and_fcount,inputs=[vid_to_interpolate_chosen_file, frame_interpolation_x_amount, frame_interpolation_slow_mo_enabled, frame_interpolation_slow_mo_amount],outputs=[in_vid_fps_ui_window,in_vid_frame_count_window, out_interp_vid_estimated_fps]) + vid_to_interpolate_chosen_file.change(fn=hide_interp_stats,inputs=[vid_to_interpolate_chosen_file],outputs=[interp_live_stats_row]) + interp_hide_list = [frame_interpolation_slow_mo_enabled,frame_interpolation_keep_imgs,frame_interp_amounts_row,interp_existing_video_row] + for output in interp_hide_list: + frame_interpolation_engine.change(fn=hide_interp_by_interp_status,inputs=frame_interpolation_engine,outputs=output) + diffusion_cadence.change(fn=hide_optical_flow_cadence, inputs=diffusion_cadence,outputs=optical_flow_cadence_row) + depth_algorithm.change(fn=legacy_3d_mode, inputs=depth_algorithm, outputs=midas_weight) + depth_algorithm.change(fn=show_leres_html_msg, inputs=depth_algorithm, outputs=leres_license_msg) + ddim_outputs = [enable_ddim_eta_scheduling] + for output in ddim_outputs: + sampler.change(fn=show_when_ddim,inputs=sampler,outputs=output) + ancestral_outputs = [enable_ancestral_eta_scheduling] + for output in ancestral_outputs: + sampler.change(fn=show_when_ancestral_samplers,inputs=sampler,outputs=output) + enable_ancestral_eta_scheduling.change(fn=hide_if_false,inputs=enable_ancestral_eta_scheduling,outputs=ancestral_eta_schedule) + enable_ddim_eta_scheduling.change(fn=hide_if_false,inputs=enable_ddim_eta_scheduling,outputs=ddim_eta_schedule) + # END OF UI TABS + stuff = locals() + stuff = {**stuff, **controlnet_dict} + stuff.pop('controlnet_dict') + return stuff \ No newline at end of file diff --git a/scripts/deforum_helpers/ui_right.py b/scripts/deforum_helpers/ui_right.py new file mode 100644 index 00000000..a3b18ff3 --- /dev/null +++ b/scripts/deforum_helpers/ui_right.py @@ -0,0 +1,141 @@ +import os, sys +from .args import d, da, dp, dv, dr, dloopArgs, i1_store, i1_store_backup, get_component_names, get_settings_component_names, video_args_names +from modules.shared import opts, state +from modules.ui import create_output_panel, wrap_gradio_call +from webui import wrap_gradio_gpu_call +from .run_deforum import run_deforum +from .settings import save_settings, load_all_settings, load_video_settings +from .ui_left import setup_deforum_setting_dictionary +import gradio as gr + +def on_ui_tabs(): + deforum_folder_name = os.path.sep.join(os.path.abspath(__file__).split(os.path.sep)[:-3]) + basedirs = [os.getcwd()] + if 'google.colab' in sys.modules: + basedirs.append('/content/gdrive/MyDrive/sd/stable-diffusion-webui') #for TheLastBen's colab + for basedir in basedirs: + sys.path.extend([os.path.join(deforum_folder_name, 'scripts', 'deforum_helpers', 'src')]) + + with gr.Blocks(analytics_enabled=False) as deforum_interface: + components = {} + dummy_component = gr.Label(visible=False) + with gr.Row(elem_id='deforum_progress_row').style(equal_height=False, variant='compact'): + with gr.Column(scale=1, variant='panel'): + components = setup_deforum_setting_dictionary(True, d, da,dp,dv,dr,dloopArgs) + + with gr.Column(scale=1, variant='compact'): + with gr.Row(variant='compact'): + btn = gr.Button("Click here after the generation to show the video") + components['btn'] = btn + close_btn = gr.Button("Close the video", visible=False) + with gr.Row(variant='compact'): + i1 = gr.HTML(i1_store, elem_id='deforum_header') + components['i1'] = i1 + # Show video + def show_vid(): + return { + i1: gr.update(value=i1_store, visible=True), + close_btn: gr.update(visible=True), + btn: gr.update(value="Update the video", visible=True), + } + + btn.click( + show_vid, + [], + [i1, close_btn, btn], + ) + # Close video + def close_vid(): + return { + i1: gr.update(value=i1_store_backup, visible=True), + close_btn: gr.update(visible=False), + btn: gr.update(value="Click here after the generation to show the video", visible=True), + } + + close_btn.click( + close_vid, + [], + [i1, close_btn, btn], + ) + id_part = 'deforum' + with gr.Row(elem_id=f"{id_part}_generate_box", variant='compact'): + skip = gr.Button('Pause/Resume', elem_id=f"{id_part}_skip", visible=False) + interrupt = gr.Button('Interrupt', elem_id=f"{id_part}_interrupt", visible=True) + submit = gr.Button('Generate', elem_id=f"{id_part}_generate", variant='primary') + + skip.click( + fn=lambda: state.skip(), + inputs=[], + outputs=[], + ) + + interrupt.click( + fn=lambda: state.interrupt(), + inputs=[], + outputs=[], + ) + + deforum_gallery, generation_info, html_info, html_log = create_output_panel("deforum", opts.outdir_img2img_samples) + + with gr.Row(variant='compact'): + settings_path = gr.Textbox("deforum_settings.txt", elem_id='deforum_settings_path', label="Settings File", info="settings file path can be relative to webui folder OR full - absolute") + #reuse_latest_settings_btn = gr.Button('Reuse Latest', elem_id='deforum_reuse_latest_settings_btn')#TODO + with gr.Row(variant='compact'): + save_settings_btn = gr.Button('Save Settings', elem_id='deforum_save_settings_btn') + load_settings_btn = gr.Button('Load All Settings', elem_id='deforum_load_settings_btn') + load_video_settings_btn = gr.Button('Load Video Settings', elem_id='deforum_load_video_settings_btn') + + component_list = [components[name] for name in get_component_names()] + + submit.click( + fn=wrap_gradio_gpu_call(run_deforum, extra_outputs=[None, '', '']), + _js="submit_deforum", + inputs=[dummy_component, dummy_component] + component_list, + outputs=[ + deforum_gallery, + components["resume_timestring"], + generation_info, + html_info, + html_log, + ], + ) + + settings_component_list = [components[name] for name in get_settings_component_names()] + video_settings_component_list = [components[name] for name in video_args_names] + stuff = gr.HTML("") # wrap gradio call garbage + stuff.visible = False + + save_settings_btn.click( + fn=wrap_gradio_call(save_settings), + inputs=[settings_path] + settings_component_list + video_settings_component_list, + outputs=[stuff], + ) + + load_settings_btn.click( + fn=wrap_gradio_call(lambda *args, **kwargs: load_all_settings(*args, ui_launch=False, **kwargs)), + inputs=[settings_path] + settings_component_list, + outputs=settings_component_list + [stuff], + ) + + load_video_settings_btn.click( + fn=wrap_gradio_call(load_video_settings), + inputs=[settings_path] + video_settings_component_list, + outputs=video_settings_component_list + [stuff], + ) + + def trigger_load_general_settings(): + print("Loading general settings...") + wrapped_fn = wrap_gradio_call(lambda *args, **kwargs: load_all_settings(*args, ui_launch=True, **kwargs)) + inputs = [settings_path.value] + [component.value for component in settings_component_list] + outputs = settings_component_list + [stuff] + updated_values = wrapped_fn(*inputs, *outputs)[0] + + settings_component_name_to_obj = {name: component for name, component in zip(get_settings_component_names(), settings_component_list)} + for key, value in updated_values.items(): + settings_component_name_to_obj[key].value = value['value'] + + + if opts.data.get("deforum_enable_persistent_settings", False): + trigger_load_general_settings() + + return [(deforum_interface, "Deforum", "deforum_interface")] \ No newline at end of file diff --git a/scripts/deforum_helpers/ui_settings.py b/scripts/deforum_helpers/ui_settings.py new file mode 100644 index 00000000..74c24aae --- /dev/null +++ b/scripts/deforum_helpers/ui_settings.py @@ -0,0 +1,19 @@ +import gradio as gr +from modules import ui_components +from modules.shared import opts, cmd_opts, state, OptionInfo +from deforum_helpers.video_audio_utilities import find_ffmpeg_binary +from deforum_helpers.subtitle_handler import get_user_values + +def on_ui_settings(): + srt_ui_params = get_user_values() + section = ('deforum', "Deforum") + opts.add_option("deforum_keep_3d_models_in_vram", OptionInfo(False, "Keep 3D models in VRAM between runs", gr.Checkbox, {"interactive": True, "visible": True if not (cmd_opts.lowvram or cmd_opts.medvram) else False}, section=section)) + opts.add_option("deforum_enable_persistent_settings", OptionInfo(False, "Keep settings persistent upon relaunch of webui", gr.Checkbox, {"interactive": True}, section=section)) + opts.add_option("deforum_persistent_settings_path", OptionInfo("models/Deforum/deforum_persistent_settings.txt", "Path for saving your persistent settings file:", section=section)) + opts.add_option("deforum_ffmpeg_location", OptionInfo(find_ffmpeg_binary(), "FFmpeg path/ location", section=section)) + opts.add_option("deforum_ffmpeg_crf", OptionInfo(17, "FFmpeg CRF value", gr.Slider, {"interactive": True, "minimum": 0, "maximum": 51}, section=section)) + opts.add_option("deforum_ffmpeg_preset", OptionInfo('slow', "FFmpeg Preset", gr.Dropdown, {"interactive": True, "choices": ['veryslow', 'slower', 'slow', 'medium', 'fast', 'faster', 'veryfast', 'superfast', 'ultrafast']}, section=section)) + opts.add_option("deforum_debug_mode_enabled", OptionInfo(False, "Enable Dev mode - adds extra reporting in console", gr.Checkbox, {"interactive": True}, section=section)) + opts.add_option("deforum_save_gen_info_as_srt", OptionInfo(False, "Save an .srt (subtitles) file with the generation info along with each animation", gr.Checkbox, {"interactive": True}, section=section)) + opts.add_option("deforum_embed_srt", OptionInfo(False, "If .srt file is saved, soft-embed the subtitles into the rendered video file", gr.Checkbox, {"interactive": True}, section=section)) + opts.add_option("deforum_save_gen_info_as_srt_params", OptionInfo(['Noise Schedule'], "Choose which animation params are to be saved to the .srt file (Frame # and Seed will always be saved):", ui_components.DropdownMulti, lambda: {"interactive": True, "choices": srt_ui_params}, section=section)) \ No newline at end of file diff --git a/scripts/deforum_helpers/vid2depth.py b/scripts/deforum_helpers/vid2depth.py index e27ccae8..5569938a 100644 --- a/scripts/deforum_helpers/vid2depth.py +++ b/scripts/deforum_helpers/vid2depth.py @@ -12,14 +12,11 @@ from modules import devices import shutil from queue import Queue, Empty import modules.scripts as scr -from .depth import DepthModel from .frame_interpolation import clean_folder_name from rife.inference_video import duplicate_pngs_from_folder from .video_audio_utilities import get_quick_vid_info, vid2frames, ffmpeg_stitch_video from modules.shared import opts -DEBUG_MODE = opts.data.get("deforum_debug_mode_enabled", False) - def process_depth_vid_upload_logic(file, mode, thresholding, threshold_value, threshold_value_max, adapt_block_size, adapt_c, invert, end_blur, midas_weight_vid2depth, vid_file_name, keep_imgs, f_location, f_crf, f_preset, f_models_path): print("got a request to *vid2depth* an existing video.") @@ -179,6 +176,7 @@ def stitch_video(img_batch_id, fps, img_folder_path, audio_path, ffmpeg_location # Midas/Adabins Depth mode with the usual workflow def load_depth_model(models_path, midas_weight_vid2depth): + from .depth import DepthModel device = ('cpu' if cmd_opts.lowvram or cmd_opts.medvram else sh_device) keep_in_vram = False # TODO: Future - handle this too? print('Loading Depth Model') diff --git a/scripts/deforum_helpers/webui_sd_pipeline.py b/scripts/deforum_helpers/webui_sd_pipeline.py index 14974d21..2c2eb256 100644 --- a/scripts/deforum_helpers/webui_sd_pipeline.py +++ b/scripts/deforum_helpers/webui_sd_pipeline.py @@ -2,8 +2,6 @@ from modules.processing import StableDiffusionProcessingImg2Img from modules.shared import opts, sd_model import os -DEBUG_MODE = opts.data.get("deforum_debug_mode_enabled", False) - def get_webui_sd_pipeline(args, root, frame): import re assert args.prompt is not None @@ -28,7 +26,7 @@ def get_webui_sd_pipeline(args, root, frame): p.seed_resize_from_w = args.seed_resize_from_w p.seed_resize_from_h = args.seed_resize_from_h p.fill = args.fill - p.batch_size = args.n_samples + p.batch_size = 1 # b.size 1 as this is DEFORUM :) p.seed = args.seed p.do_not_save_samples = True # Setting this to False will trigger webui's saving mechanism - and we will end up with duplicated files, and another folder within our destination folder - big no no. p.sampler_name = args.sampler @@ -36,10 +34,7 @@ def get_webui_sd_pipeline(args, root, frame): p.extra_generation_params["Mask blur"] = args.mask_overlay_blur p.n_iter = 1 p.steps = args.steps - if opts.img2img_fix_steps: - p.denoising_strength = 1 / (1 - args.strength + 1.0/args.steps) #see https://github.com/deforum-art/deforum-for-automatic1111-webui/issues/3 - else: - p.denoising_strength = 1 - args.strength + p.denoising_strength = 1 - args.strength p.cfg_scale = args.scale p.image_cfg_scale = args.pix2pix_img_cfg_scale p.outpath_samples = root.outpath_samples diff --git a/scripts/deforum_helpers/word_masking.py b/scripts/deforum_helpers/word_masking.py index 2e2246ed..2396928c 100644 --- a/scripts/deforum_helpers/word_masking.py +++ b/scripts/deforum_helpers/word_masking.py @@ -2,7 +2,6 @@ import os import torch from PIL import Image from torchvision import transforms -from clipseg.models.clipseg import CLIPDensePredT from modules.shared import opts from torch.nn.functional import interpolate import cv2 @@ -13,9 +12,10 @@ preclipseg_transform = transforms.Compose([ transforms.Resize((512, 512)), #TODO: check if the size is hardcoded ]) -def find_clipseg(root): +def find_clipseg(): + basedirs = [os.getcwd()] src_basedirs = [] - for basedir in root.basedirs: + for basedir in basedirs: src_basedirs.append(os.path.join(os.path.sep.join(os.path.abspath(__file__).split(os.path.sep)[:-2]), 'deforum_helpers', 'src')) for basedir in src_basedirs: @@ -25,9 +25,10 @@ def find_clipseg(root): raise Exception('CLIPseg weights not found!') def setup_clipseg(root): + from clipseg.models.clipseg import CLIPDensePredT model = CLIPDensePredT(version='ViT-B/16', reduce_dim=64) model.eval() - model.load_state_dict(torch.load(find_clipseg(root), map_location=root.device), strict=False) + model.load_state_dict(torch.load(find_clipseg(), map_location=root.device), strict=False) model.to(root.device) root.clipseg_model = model