44import subprocess
55import sys
66import time
7- from base64 import b64encode
87from typing import Any
98import gooey_gpu
109
3332)
3433from helpers .model_load import load_model , get_model_output_paths
3534from helpers .aesthetics import load_aesthetics_model
35+ from helpers .prompts import Prompts
3636
3737
3838# @markdown **Path Setup**
@@ -89,16 +89,20 @@ class DeforumAnimArgs(BaseModel):
8989 noise_schedule = "0: (0.02)" # @param {type:"string"}
9090 strength_schedule = "0: (0.65)" # @param {type:"string"}
9191 contrast_schedule = "0: (1.0)" # @param {type:"string"}
92- hybrid_video_comp_alpha_schedule = "0:(1)" # @param {type:"string"}
93- hybrid_video_comp_mask_blend_alpha_schedule = "0:(0.5)" # @param {type:"string"}
94- hybrid_video_comp_mask_contrast_schedule = "0:(1)" # @param {type:"string"}
95- hybrid_video_comp_mask_auto_contrast_cutoff_high_schedule = (
92+ hybrid_comp_alpha_schedule = "0:(1)" # @param {type:"string"}
93+ hybrid_comp_mask_blend_alpha_schedule = "0:(0.5)" # @param {type:"string"}
94+ hybrid_comp_mask_contrast_schedule = "0:(1)" # @param {type:"string"}
95+ hybrid_comp_mask_auto_contrast_cutoff_high_schedule = (
9696 "0:(100)" # @param {type:"string"}
9797 )
98- hybrid_video_comp_mask_auto_contrast_cutoff_low_schedule = (
98+ hybrid_comp_mask_auto_contrast_cutoff_low_schedule = (
9999 "0:(0)" # @param {type:"string"}
100100 )
101101
102+ # @markdown ####**Sampler Scheduling:**
103+ enable_schedule_samplers = False # @param {type:"boolean"}
104+ sampler_schedule = "0:('euler'),10:('dpm2'),20:('dpm2_ancestral'),30:('heun'),40:('euler'),50:('euler_ancestral'),60:('dpm_fast'),70:('dpm_adaptive'),80:('dpmpp_2s_a'),90:('dpmpp_2m')" # @param {type:"string"}
105+
102106 # @markdown ####**Unsharp mask (anti-blur) Parameters:**
103107 kernel_schedule = "0: (5)" # @param {type:"string"}
104108 sigma_schedule = "0: (1.0)" # @param {type:"string"}
@@ -108,6 +112,7 @@ class DeforumAnimArgs(BaseModel):
108112 # @markdown ####**Coherence:**
109113 color_coherence = "Match Frame 0 LAB" # @param ['None', 'Match Frame 0 HSV', 'Match Frame 0 LAB', 'Match Frame 0 RGB', 'Video Input'] {type:'string'}
110114 color_coherence_video_every_N_frames = 1 # @param {type:"integer"}
115+ color_force_grayscale = False # @param {type:"boolean"}
111116 diffusion_cadence = "1" # @param ['1','2','3','4','5','6','7','8'] {type:'string'}
112117
113118 # @markdown ####**3D Depth Warping:**
@@ -130,25 +135,26 @@ class DeforumAnimArgs(BaseModel):
130135 video_mask_path = "/content/video_in.mp4" # @param {type:"string"}
131136
132137 # @markdown ####**Hybrid Video for 2D/3D Animation Mode:**
133- hybrid_video_generate_inputframes = False # @param {type:"boolean"}
134- hybrid_video_use_first_frame_as_init_image = True # @param {type:"boolean"}
135- hybrid_video_motion = (
136- "None" # @param ['None','Optical Flow','Perspective','Affine']
138+ hybrid_generate_inputframes = False # @param {type:"boolean"}
139+ hybrid_use_first_frame_as_init_image = True # @param {type:"boolean"}
140+ hybrid_motion = "None" # @param ['None','Optical Flow','Perspective','Affine']
141+ hybrid_motion_use_prev_img = False # @param {type:"boolean"}
142+ hybrid_flow_method = (
143+ "DIS Medium" # @param ['DenseRLOF','DIS Medium','Farneback','SF']
137144 )
138- hybrid_video_flow_method = "Farneback" # @param ['Farneback','DenseRLOF','SF']
139- hybrid_video_composite = False # @param {type:"boolean"}
140- hybrid_video_comp_mask_type = (
145+ hybrid_composite = False # @param {type:"boolean"}
146+ hybrid_comp_mask_type = (
141147 "None" # @param ['None', 'Depth', 'Video Depth', 'Blend', 'Difference']
142148 )
143- hybrid_video_comp_mask_inverse = False # @param {type:"boolean"}
144- hybrid_video_comp_mask_equalize = "None" # @param ['None','Before','After','Both']
145- hybrid_video_comp_mask_auto_contrast = False # @param {type:"boolean"}
146- hybrid_video_comp_save_extra_frames = False # @param {type:"boolean"}
147- hybrid_video_use_video_as_mse_image = False # @param {type:"boolean"}
149+ hybrid_comp_mask_inverse = False # @param {type:"boolean"}
150+ hybrid_comp_mask_equalize = "None" # @param ['None','Before','After','Both']
151+ hybrid_comp_mask_auto_contrast = False # @param {type:"boolean"}
152+ hybrid_comp_save_extra_frames = False # @param {type:"boolean"}
153+ hybrid_use_video_as_mse_image = False # @param {type:"boolean"}
148154
149155 # @markdown ####**Interpolation:**
150156 interpolate_key_frames = False # @param {type:"boolean"}
151- interpolate_x_frames = 4 # @param {type:"number"}
157+ interpolate_x_frames = 20 # @param {type:"number"}
152158
153159 # @markdown ####**Resume Animation:**
154160 resume_from_timestring = False # @param {type:"boolean"}
@@ -157,6 +163,9 @@ class DeforumAnimArgs(BaseModel):
157163 prompts = []
158164
159165 animation_prompts = {}
166+ neg_animation_prompts = {}
167+
168+ args = {}
160169
161170
162171# @markdown **Load Settings**
@@ -195,7 +204,8 @@ class DeforumArgs:
195204
196205 # @markdown **Batch Settings**
197206 n_batch = 1 # @param
198- # batch_name = "StableFun" # @param {type:"string"}
207+ n_samples = 1 # @param
208+ batch_name = "StableFun" # @param {type:"string"}
199209 filename_format = "{timestring}_{index}_{prompt}.png" # @param ["{timestring}_{index}_{seed}.png","{timestring}_{index}_{prompt}.png"]
200210 seed_behavior = "iter" # @param ["iter","fixed","random","ladder","alternate"]
201211 seed_iter_N = 1 # @param {type:'integer'}
@@ -204,11 +214,13 @@ class DeforumArgs:
204214
205215 # @markdown **Init Settings**
206216 use_init = False # @param {type:"boolean"}
207- strength = 0.1 # @param {type:"number"}
217+ strength = 0.65 # @param {type:"number"}
208218 strength_0_no_init = (
209219 True # Set the strength to 0 automatically when no init image is used
210220 )
211221 init_image = "https://cdn.pixabay.com/photo/2022/07/30/13/10/green-longhorn-beetle-7353749_1280.jpg" # @param {type:"string"}
222+ add_init_noise = False # @param {type:"boolean"}
223+ init_noise = 0.01 # @param
212224 # Whiter areas of the mask are areas that change more
213225 use_mask = False # @param {type:"boolean"}
214226 use_alpha_as_mask = False # use the alpha channel of the init image as the mask
@@ -262,12 +274,15 @@ class DeforumArgs:
262274 # @markdown **Speed vs VRAM Settings**
263275 cond_uncond_sync = True # @param {type:"boolean"}
264276
265- n_samples = 1 # doesnt do anything
266277 precision = "autocast"
267278 C = 4
268279 f = 8
269280
270281 prompt = ""
282+ cond_prompt = ""
283+ cond_prompts = ""
284+ uncond_prompt = ""
285+ uncond_prompts = ""
271286 timestring = ""
272287 init_latent = None
273288 init_sample = None
@@ -310,7 +325,7 @@ def run(root: Root, args: DeforumArgs, anim_args: DeforumAnimArgs):
310325 if not args .use_init :
311326 args .init_image = None
312327 if args .sampler == "plms" and (args .use_init or anim_args .animation_mode != "None" ):
313- print (f "Init images aren't supported with PLMS yet, switching to KLMS" )
328+ print ("Init images aren't supported with PLMS yet, switching to KLMS" )
314329 args .sampler = "klms"
315330 if args .sampler != "ddim" :
316331 args .ddim_eta = 0
@@ -324,15 +339,20 @@ def run(root: Root, args: DeforumArgs, anim_args: DeforumAnimArgs):
324339 gc .collect ()
325340 torch .cuda .empty_cache ()
326341
342+ # get prompts
343+ cond , uncond = Prompts (
344+ prompt = anim_args .animation_prompts , neg_prompt = anim_args .neg_animation_prompts
345+ ).as_dict ()
346+
327347 # dispatch to appropriate renderer
328348 if anim_args .animation_mode == "2D" or anim_args .animation_mode == "3D" :
329- render_animation (args , anim_args , anim_args . animation_prompts , root )
349+ render_animation (root , anim_args , args , cond , uncond )
330350 elif anim_args .animation_mode == "Video Input" :
331- render_input_video (args , anim_args , anim_args . animation_prompts , root )
351+ render_input_video (root , anim_args , args , cond , uncond )
332352 elif anim_args .animation_mode == "Interpolation" :
333- render_interpolation (args , anim_args , anim_args . animation_prompts , root )
353+ render_interpolation (root , anim_args , args , cond , uncond )
334354 else :
335- render_image_batch (args , anim_args . prompts , root )
355+ render_image_batch (root , anim_args , args , cond , uncond )
336356
337357
338358def create_video (args : DeforumArgs , anim_args : DeforumAnimArgs ):
@@ -344,10 +364,10 @@ def create_video(args: DeforumArgs, anim_args: DeforumAnimArgs):
344364 # mp4_path = "/content/drive/MyDrive/AI/StableDiffusion/2023-01/StableFun/20230101212135.mp4" # @param {type:"string"}
345365 render_steps = False # @param {type: 'boolean'}
346366 path_name_modifier = "x0_pred" # @param ["x0_pred","x"]
347- make_gif = False
367+ # make_gif = False # Currently unused
348368 bitdepth_extension = "exr" if args .bit_depth_output == 32 else "png"
349369
350- if skip_video_for_run_all == True :
370+ if skip_video_for_run_all :
351371 print (
352372 "Skipping video creation, uncheck skip_video_for_run_all if you want to run it"
353373 )
0 commit comments