From f47c9c6a82fbe313ba88360ed9f01c518ddd977e Mon Sep 17 00:00:00 2001 From: Craulback <92492424+Craulback@users.noreply.github.com> Date: Mon, 21 Nov 2022 17:47:35 -0700 Subject: [PATCH 1/4] stop at total_frames, up default fps when saving --- scripts/txt2vid.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/scripts/txt2vid.py b/scripts/txt2vid.py index 1edcfe4..51749d7 100644 --- a/scripts/txt2vid.py +++ b/scripts/txt2vid.py @@ -1195,13 +1195,13 @@ def load_diffusers_model(weights_path,torch_device): st.session_state["progress_bar_text"].error(e) # -def save_video_to_disk(frames, seeds, sanitized_prompt, fps=6,save_video=True, outdir='outputs'): +def save_video_to_disk(frames, seeds, sanitized_prompt, fps=30,save_video=True, outdir='outputs'): if save_video: # write video to memory #output = io.BytesIO() #writer = imageio.get_writer(os.path.join(os.getcwd(), st.session_state['defaults'].general.outdir, "txt2vid"), im, extension=".mp4", fps=30) #try: - video_path = os.path.join(os.getcwd(), outdir, "txt2vid",f"{seeds}_{sanitized_prompt}{datetime.now().strftime('%Y%m-%d%H-%M%S-') + str(uuid4())[:8]}.mp4") + video_path = os.path.join(os.getcwd(), outdir, "txt2vid",f"{seeds}_{sanitized_prompt}{datetime.datetime.now().strftime('%Y%m-%d%H-%M%S-') + str(uuid4())[:8]}.mp4") writer = imageio.get_writer(video_path, fps=fps) for frame in frames: writer.append_data(frame) @@ -1484,7 +1484,7 @@ def txt2vid( # old code total_frames = (st.session_state.sampling_steps + st.session_state.num_inference_steps) * st.session_state.max_duration_in_seconds - while second_count < max_duration_in_seconds: + while frame_index+1 < total_frames: st.session_state["frame_duration"] = 0 st.session_state["frame_speed"] = 0 st.session_state["current_frame"] = frame_index @@ -1601,10 +1601,6 @@ def layout(): placeholder = "A corgi wearing a top hat as an oil painting." prompt = st.text_area("Input Text","", placeholder=placeholder, height=54) sygil_suggestions.suggestion_area(placeholder) - - if "defaults" in st.session_state: - if st.session_state['defaults'].admin.global_negative_prompt: - prompt += f"### {st.session_state['defaults'].admin.global_negative_prompt}" # Every form must have a submit button, the extra blank spaces is a temp way to align it with the input field. Needs to be done in CSS or some other way. generate_col1.write("") @@ -1914,9 +1910,10 @@ def layout(): beta_schedule=beta_scheduler_type, starting_image=None) if video and save_video_on_stop: + if os.path.exists(video): # temporary solution to bypass exception # show video preview on the UI after we hit the stop button # currently not working as session_state is cleared on StopException - preview_video.video(open(video, 'rb').read()) + preview_video.video(open(video, 'rb').read()) #message.success('Done!', icon="✅") message.success('Render Complete: ' + info + '; Stats: ' + stats, icon="✅") From a5fd15e412e95202b9e0ac62bf152448965f932e Mon Sep 17 00:00:00 2001 From: Craulback <92492424+Craulback@users.noreply.github.com> Date: Mon, 21 Nov 2022 18:06:54 -0700 Subject: [PATCH 2/4] change max duration & frames math --- scripts/txt2vid.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/txt2vid.py b/scripts/txt2vid.py index 51749d7..70a043a 100644 --- a/scripts/txt2vid.py +++ b/scripts/txt2vid.py @@ -946,6 +946,7 @@ def diffuse( num_inference_steps, cfg_scale, eta, + fps=30 ): torch_device = cond_latents.get_device() @@ -1055,8 +1056,8 @@ def diffuse( speed = "it/s" duration = 1 / duration - # - total_frames = (st.session_state.sampling_steps + st.session_state.num_inference_steps) * st.session_state.max_duration_in_seconds + # perhaps add an option to set fps within the ui eventually + total_frames = st.session_state.max_duration_in_seconds * fps total_steps = st.session_state.sampling_steps + st.session_state.num_inference_steps if i > st.session_state.sampling_steps: @@ -1482,7 +1483,7 @@ def txt2vid( #) # old code - total_frames = (st.session_state.sampling_steps + st.session_state.num_inference_steps) * st.session_state.max_duration_in_seconds + total_frames = st.session_state.max_duration_in_seconds * fps while frame_index+1 < total_frames: st.session_state["frame_duration"] = 0 @@ -1506,7 +1507,7 @@ def txt2vid( #init = slerp(gpu, float(t), init1, init2) with autocast("cuda"): - image = diffuse(server_state["pipe"], cond_embeddings, init, num_inference_steps, cfg_scale, eta) + image = diffuse(server_state["pipe"], cond_embeddings, init, num_inference_steps, cfg_scale, eta, fps=fps) if st.session_state["save_individual_images"] and not st.session_state["use_GFPGAN"] and not st.session_state["use_RealESRGAN"]: #im = Image.fromarray(image) From 5988532fc2ebbf06806ddf7d8f8a5a5703480478 Mon Sep 17 00:00:00 2001 From: Craulback <92492424+Craulback@users.noreply.github.com> Date: Mon, 21 Nov 2022 18:28:38 -0700 Subject: [PATCH 3/4] fix accidental deletion --- scripts/txt2vid.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/txt2vid.py b/scripts/txt2vid.py index 70a043a..5b008f5 100644 --- a/scripts/txt2vid.py +++ b/scripts/txt2vid.py @@ -1601,7 +1601,11 @@ def layout(): #prompt = st.text_area("Input Text","") placeholder = "A corgi wearing a top hat as an oil painting." prompt = st.text_area("Input Text","", placeholder=placeholder, height=54) - sygil_suggestions.suggestion_area(placeholder) + sygil_suggestions.suggestion_area(placeholder) + + if "defaults" in st.session_state: + if st.session_state['defaults'].admin.global_negative_prompt: + prompt += f"### {st.session_state['defaults'].admin.global_negative_prompt}" # Every form must have a submit button, the extra blank spaces is a temp way to align it with the input field. Needs to be done in CSS or some other way. generate_col1.write("") From ee0341aff29cd35425fcd4b9212c0c8d54b58ad6 Mon Sep 17 00:00:00 2001 From: Craulback <92492424+Craulback@users.noreply.github.com> Date: Mon, 21 Nov 2022 18:32:10 -0700 Subject: [PATCH 4/4] add 1 extra frame --- scripts/txt2vid.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/txt2vid.py b/scripts/txt2vid.py index 5b008f5..28b5c9b 100644 --- a/scripts/txt2vid.py +++ b/scripts/txt2vid.py @@ -1485,7 +1485,7 @@ def txt2vid( # old code total_frames = st.session_state.max_duration_in_seconds * fps - while frame_index+1 < total_frames: + while frame_index+1 <= total_frames: st.session_state["frame_duration"] = 0 st.session_state["frame_speed"] = 0 st.session_state["current_frame"] = frame_index @@ -1601,8 +1601,8 @@ def layout(): #prompt = st.text_area("Input Text","") placeholder = "A corgi wearing a top hat as an oil painting." prompt = st.text_area("Input Text","", placeholder=placeholder, height=54) - sygil_suggestions.suggestion_area(placeholder) - + sygil_suggestions.suggestion_area(placeholder) + if "defaults" in st.session_state: if st.session_state['defaults'].admin.global_negative_prompt: prompt += f"### {st.session_state['defaults'].admin.global_negative_prompt}"