From e280938e7914fec27e019f2de77089ae59ef48a3 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Tue, 28 Jul 2026 13:11:21 +0200 Subject: [PATCH] add prompt enhance to ltx and fix audio Signed-off-by: Vladimir Mandic --- modules/ltx/ltx_process.py | 4 +++- modules/ltx/ltx_ui.py | 16 ++++++++-------- modules/ltx/ltx_util.py | 8 ++++---- modules/video_models/video_save.py | 4 ++-- scripts/prompt_enhance/template.py | 1 - scripts/prompt_enhance_ext.py | 1 - 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/modules/ltx/ltx_process.py b/modules/ltx/ltx_process.py index a9ab9fe22..8c4634407 100644 --- a/modules/ltx/ltx_process.py +++ b/modules/ltx/ltx_process.py @@ -341,7 +341,9 @@ def run_ltx(task_id, try: if needs_latent_path: - prompt_final, negative_final, networks = get_prompts(prompt, negative, styles) + if p.scripts is not None and isinstance(p.scripts, scripts_manager.ScriptRunner): + p.scripts.before_process(p) + prompt_final, negative_final, networks = get_prompts(p) extra_networks.activate(p, networks) # Encode once and reuse across stages; encode_prompt short-circuits when # embeds are passed to __call__. CPU park keeps them off GPU between stages. diff --git a/modules/ltx/ltx_ui.py b/modules/ltx/ltx_ui.py index 44db16690..bb326ad68 100644 --- a/modules/ltx/ltx_ui.py +++ b/modules/ltx/ltx_ui.py @@ -67,8 +67,8 @@ def create_ui(prompt, negative, styles, overrides, script_inputs, mp4_fps, mp4_i with gr.Accordion(open=False, label='Size', elem_id='ltx_size_accordion'): width, height = ui_sections.create_resolution_inputs('ltx', default_width=832, default_height=480) with gr.Row(): - frames = gr.Slider(label='LTX Frames', minimum=1, maximum=1024, step=1, value=121, elem_id='ltx_frames') - seed = gr.Number(label='Initial seed', value=-1, elem_id='ltx_seed', container=True) + frames = gr.Slider(label='LTX frames', minimum=1, maximum=1024, step=1, value=121, elem_id='ltx_frames') + seed = gr.Number(label='LTX seed', value=-1, elem_id='ltx_seed', container=True) random_seed = ToolButton(ui_symbols.random, elem_id='ltx_seed_random') random_seed.click(fn=lambda: -1, show_progress='hidden', inputs=[], outputs=[seed]) input_media_accordion = gr.Accordion(open=False, label="Input media", elem_id='ltx_input_media_accordion', visible=False) @@ -88,16 +88,16 @@ def create_ui(prompt, negative, styles, overrides, script_inputs, mp4_fps, mp4_i condition_video_skip = gr.Slider(label='LTX frames skip', minimum=0, maximum=1024, step=1, value=0, elem_id="ltx_condition_video_sip") with gr.Tab('Gallery prefix', id='ltx_condition_batch_tab'): condition_files = gr.Files(label="Image Batch", interactive=True, elem_id="ltx_condition_batch") - upsample_accordion = gr.Accordion(open=False, label="Upsample", elem_id='ltx_upsample_accordion') + upsample_accordion = gr.Accordion(open=False, label="Upscale", elem_id='ltx_upsample_accordion') with upsample_accordion: with gr.Row(): - upsample_enable = gr.Checkbox(label='LTX enable upsampling', value=False, elem_id="ltx_upsample_enable") - upsample_ratio = gr.Slider(label='LTX upsample ratio', minimum=1.0, maximum=4.0, step=0.1, value=2.0, elem_id="ltx_upsample_ratio") + upsample_enable = gr.Checkbox(label='LTX upscale', value=False, elem_id="ltx_upsample_enable") + upsample_ratio = gr.Slider(label='LTX scale', minimum=1.0, maximum=4.0, step=0.1, value=2.0, elem_id="ltx_upsample_ratio") refine_accordion = gr.Accordion(open=False, label="Refine", elem_id='ltx_refine_accordion') with refine_accordion: with gr.Row(): - refine_enable = gr.Checkbox(label='LTX enable refine', value=False, elem_id="ltx_refine_enable") - refine_strength = gr.Slider(label='LTX refine strength', minimum=0.1, maximum=1.0, step=0.05, value=0.4, elem_id="ltx_refine_strength") + refine_enable = gr.Checkbox(label='LTX refine', value=False, elem_id="ltx_refine_enable") + refine_strength = gr.Slider(label='LTX strength', minimum=0.1, maximum=1.0, step=0.05, value=0.4, elem_id="ltx_refine_strength") parameters_accordion = gr.Accordion(open=False, label="Advanced", elem_id='ltx_parameters_accordion') with parameters_accordion: steps, sampler_index = ui_sections.create_sampler_and_steps_selection(None, "ltx", default_steps=50) @@ -108,7 +108,7 @@ def create_ui(prompt, negative, styles, overrides, script_inputs, mp4_fps, mp4_i dynamic_shift = gr.Checkbox(label='LTX dynamic shift', value=False, elem_id="ltx_dynamic_shift") with gr.Row(): decode_timestep = gr.Slider(label='LTX decode timestep', minimum=0.0, maximum=1.0, step=0.01, value=0.05, elem_id="ltx_decode_timestep") - image_cond_noise_scale = gr.Slider(label='LTX image cond noise scale', minimum=0.0, maximum=1.0, step=0.005, value=0.025, elem_id="ltx_image_cond_noise_scale") + image_cond_noise_scale = gr.Slider(label='LTX image cond', minimum=0.0, maximum=1.0, step=0.005, value=0.025, elem_id="ltx_image_cond_noise_scale") audio_accordion = gr.Accordion(open=False, label="Audio", elem_id='ltx_audio_accordion', visible=False) with audio_accordion: with gr.Row(): diff --git a/modules/ltx/ltx_util.py b/modules/ltx/ltx_util.py index 032bc04b8..11afb0b1c 100644 --- a/modules/ltx/ltx_util.py +++ b/modules/ltx/ltx_util.py @@ -123,7 +123,7 @@ def ltx_scheduler_opts(sd_model, *, dynamic_shift=None, sampler_shift=None): if orig_flow_shift is not None and hasattr(sd_model.scheduler.config, 'flow_shift'): sd_model.scheduler.config.flow_shift = orig_flow_shift sd_model.scheduler.register_to_config(flow_shift=orig_flow_shift) - log.debug(f'LTX: scheduler/opts restored dynamic_shift={orig_dynamic_shift} sampler_shift={orig_sampler_shift}') + # log.debug(f'LTX: scheduler/opts restored dynamic_shift={orig_dynamic_shift} sampler_shift={orig_sampler_shift}') def _condition_cls(family: str): @@ -201,9 +201,9 @@ def get_conditions(width, height, condition_strength, condition_images, conditio return conditions -def get_prompts(prompt, negative, styles): - prompt = shared.prompt_styles.apply_styles_to_prompt(prompt, styles) - negative = shared.prompt_styles.apply_negative_styles_to_prompt(negative, styles) +def get_prompts(p): + prompt = shared.prompt_styles.apply_styles_to_prompt(p.prompt, p.styles) + negative = shared.prompt_styles.apply_negative_styles_to_prompt(p.negative_prompt, p.styles) prompts, networks = extra_networks.parse_prompts([prompt]) prompt = prompts[0] if len(prompts) > 0 else prompt return prompt, negative, networks diff --git a/modules/video_models/video_save.py b/modules/video_models/video_save.py index 2ce0fc6ad..b14274ee6 100644 --- a/modules/video_models/video_save.py +++ b/modules/video_models/video_save.py @@ -144,7 +144,7 @@ def add_audio_packets(container, audio_stream, audio: dict): def add_audio_tensor(container, audio_stream, audio: torch.Tensor, sample_rate: int): av = check_av() if torch.is_tensor(audio): - audio = audio.detach().cpu().numpy() + audio = audio.detach().float().cpu().numpy() if audio.ndim > 2: audio = np.squeeze(audio) if audio.ndim == 1: @@ -156,7 +156,7 @@ def add_audio_tensor(container, audio_stream, audio: torch.Tensor, sample_rate: if audio.dtype != np.int16: audio = np.clip(audio, -1.0, 1.0) audio = (audio * 32767.0).astype(np.int16) - audio_frame = av.AudioFrame.from_ndarray(np.ascontiguousarray(audio.T), format="s16", layout=layout) + audio_frame = av.AudioFrame.from_ndarray(audio, format="s16p", layout=layout) audio_frame.sample_rate = sample_rate add_audio_packets(container, audio_stream, {"sr": sample_rate, "layout": layout, "frames": [audio_frame]}) diff --git a/scripts/prompt_enhance/template.py b/scripts/prompt_enhance/template.py index 8f41e1189..365508bf3 100644 --- a/scripts/prompt_enhance/template.py +++ b/scripts/prompt_enhance/template.py @@ -97,5 +97,4 @@ def set_template( else: chat_template = get_text_template(system, prompt, options, nsfw, has_system, has_prompt, has_processor, is_video, image) - print('HERE2', chat_template) return chat_template diff --git a/scripts/prompt_enhance_ext.py b/scripts/prompt_enhance_ext.py index 75a543d7b..1d3c4e0f5 100644 --- a/scripts/prompt_enhance_ext.py +++ b/scripts/prompt_enhance_ext.py @@ -389,7 +389,6 @@ class PromptEnhanceScript(scripts_manager.Script): current_image = current_image.convert('RGB') debug_log('Prompt enhance: Converted image to RGB mode') - print('HERE1', self.parent) chat_template = set_template( system=system, prompt=prompt_text,