diff --git a/BatchFuncs.py b/BatchFuncs.py index e9b14af..647ba10 100644 --- a/BatchFuncs.py +++ b/BatchFuncs.py @@ -121,14 +121,15 @@ def interpolate_prompt_seriesA(animation_prompts, settings:ScheduleSettings): sorted_prompts.append((str(settings.max_frames), sorted_prompts[-1][1])) # Setup containers for interpolated prompts - cur_prompt_series = pd.Series([np.nan for a in range(settings.max_frames)]) - nxt_prompt_series = pd.Series([np.nan for a in range(settings.max_frames)]) + nan_list = [np.nan for a in range(settings.max_frames)] + cur_prompt_series = pd.Series(nan_list,dtype=object) + nxt_prompt_series = pd.Series(nan_list,dtype=object) # simple array for strength values weight_series = [np.nan] * settings.max_frames # in case there is only one keyed prompt, set all prompts to that prompt - if len(sorted_prompts) == 1: + if settings.max_frames == 1: for i in range(0, len(cur_prompt_series) - 1): current_prompt = sorted_prompts[0][1] cur_prompt_series[i] = str(current_prompt) @@ -140,6 +141,7 @@ def interpolate_prompt_seriesA(animation_prompts, settings:ScheduleSettings): # Initialized outside of loop for nan check current_key = 0 next_key = 0 + # For every keyframe prompt except the last for i in range(0, len(sorted_prompts) - 1): # Get current and next keyframe @@ -178,7 +180,7 @@ def interpolate_prompt_seriesA(animation_prompts, settings:ScheduleSettings): index_offset = 0 # Evaluate the current and next prompt's expressions - for i in range(0, len(cur_prompt_series)): + for i in range(settings.start_frame, min(settings.end_frame,len(cur_prompt_series))): cur_prompt_series[i] = prepare_batch_promptA(cur_prompt_series[i], settings, i) nxt_prompt_series[i] = prepare_batch_promptA(nxt_prompt_series[i], settings, i) if settings.print_output == True: diff --git a/ValueFuncs.py b/ValueFuncs.py index 026cdab..57e3fb5 100644 --- a/ValueFuncs.py +++ b/ValueFuncs.py @@ -55,12 +55,22 @@ def parse_key_frames(string, max_frames): for match_object in string.split(","): frameParam = match_object.split(":") max_f = max_frames - 1 # needed for numexpr even though it doesn't look like it's in use. - frame = int(sanitize_value(frameParam[0])) if check_is_number( - sanitize_value(frameParam[0].strip())) else int(numexpr.evaluate( - frameParam[0].strip().replace("'", "", 1).replace('"', "", 1)[::-1].replace("'", "", 1).replace('"', "", 1)[::-1])) + frame_str = sanitize_value(frameParam[0].strip()) + + try: + if check_is_number(frame_str): + frame = int(frame_str) + else: + # Simplified expression evaluation + frame = int(numexpr.evaluate(frame_str)) + except Exception as e: + raise RuntimeError(f"Error evaluating frame expression '{frame_str}': {e}") + frames[frame] = frameParam[1].strip() + if frames == {} and len(string) != 0: raise RuntimeError('Key Frame string not correctly formatted') + return frames def batch_get_inbetweens(key_frames, max_frames, integer=False, interp_method='Linear', is_single_string=False):