Spaces:
Runtime error
Runtime error
Update app.py
Browse files40 unmodified lines41424344454627 unmodified lines747576777879187 unmodified lines2672682692702712723 unmodified lines2762772782792802812821 unmodified line28428528628728828965 unmodified lines3553563573583593606 unmodified lines36736836937037137278 unmodified lines45145245345445545658 unmodified lines51551651751851952052140 unmodified linesimport gradio as grimport numpy as npfrom huggingface_hub import hf_hub_download, snapshot_downloadfrom ltx_core.components.diffusion_steps import EulerDiffusionStepfrom ltx_core.components.noisers import GaussianNoiser27 unmodified lineslogging.getLogger().setLevel(logging.INFO)MAX_SEED = np.iinfo(np.int32).maxDEFAULT_PROMPT = ("An astronaut hatches from a fragile egg on the surface of the Moon, "187 unmodified linesspatial_upsampler_path = hf_hub_download(repo_id=LTX_MODEL_REPO, filename="ltx-2.3-spatial-upscaler-x2-1.0.safetensors")gemma_root = snapshot_download(repo_id=GEMMA_REPO)print(f"Checkpoint: {checkpoint_path}")print(f"Spatial upsampler: {spatial_upsampler_path}")print(f"Gemma root: {gemma_root}")3 unmodified linesdistilled_checkpoint_path=checkpoint_path,spatial_upsampler_path=spatial_upsampler_path,gemma_root=gemma_root,loras=[],quantization=QuantizationPolicy.fp8_cast(),)1 unmodified lineprint("Preloading all models (including Gemma and audio components)...")ledger = pipeline.model_ledger_transformer = ledger.transformer()_video_encoder = ledger.video_encoder()_video_decoder = ledger.video_decoder()_audio_encoder = ledger.audio_encoder()65 unmodified linesinput_audio,prompt: str,duration: float,enhance_prompt: bool = True,seed: int = 42,randomize_seed: bool = True,6 unmodified lineslog_memory("start")current_seed = random.randint(0, MAX_SEED) if randomize_seed else int(seed)frame_rate = DEFAULT_FRAME_RATEnum_frames = int(duration * frame_rate) + 178 unmodified linesplaceholder="Describe the motion and animation you want...",)duration = gr.Slider(label="Duration (seconds)", minimum=1.0, maximum=10.0, value=3.0, step=0.1)generate_btn = gr.Button("Generate Video", variant="primary", size="lg")58 unmodified linesgenerate_btn.click(fn=generate_video,inputs=[first_image, last_image, input_audio, prompt, duration, enhance_prompt,seed, randomize_seed, height, width,],outputs=[output_video, seed],40 unmodified lines4142434445464727 unmodified lines7576777879808182187 unmodified lines2702712722732742752762772782792803 unmodified lines2842852862872882892902912922932942952961 unmodified line29829930030130230330430530630730830931031131231331431531631765 unmodified lines3833843853863873883896 unmodified lines39639739839940040140240378 unmodified lines48248348448548648748848949049149249349458 unmodified lines55355455555655755855940 unmodified linesimport gradio as grimport numpy as npfrom huggingface_hub import hf_hub_download, snapshot_downloadfrom ltx_core.loader import LoraPathStrengthAndSDOps, LTXV_LORA_COMFY_RENAMING_MAPfrom ltx_core.components.diffusion_steps import EulerDiffusionStepfrom ltx_core.components.noisers import GaussianNoiser27 unmodified lineslogging.getLogger().setLevel(logging.INFO)LORA_RUNTIME_SCALE = 1.0MAX_SEED = np.iinfo(np.int32).maxDEFAULT_PROMPT = ("An astronaut hatches from a fragile egg on the surface of the Moon, "187 unmodified linesspatial_upsampler_path = hf_hub_download(repo_id=LTX_MODEL_REPO, filename="ltx-2.3-spatial-upscaler-x2-1.0.safetensors")gemma_root = snapshot_download(repo_id=GEMMA_REPO)lora_path = hf_hub_download(repo_id="dagloop5/LoRA",filename="LoRA2.safetensors")print(f"Checkpoint: {checkpoint_path}")print(f"Spatial upsampler: {spatial_upsampler_path}")print(f"Gemma root: {gemma_root}")3 unmodified linesdistilled_checkpoint_path=checkpoint_path,spatial_upsampler_path=spatial_upsampler_path,gemma_root=gemma_root,loras=[LoraPathStrengthAndSDOps(lora_path,1.0, # fixed internal strengthLTXV_LORA_COMFY_RENAMING_MAP)],quantization=QuantizationPolicy.fp8_cast(),)1 unmodified lineprint("Preloading all models (including Gemma and audio components)...")ledger = pipeline.model_ledger_transformer = ledger.transformer()_original_forward = _transformer.forwarddef _lora_scaled_forward(*args, **kwargs):out = _original_forward(*args, **kwargs)# Apply runtime scaling to LoRA-influenced output# (LTX merges LoRA into attention residuals, so we scale output delta)if isinstance(out, tuple):return tuple(o * LORA_RUNTIME_SCALE if torch.is_tensor(o) else o for o in out)elif torch.is_tensor(out):return out * LORA_RUNTIME_SCALEreturn out_transformer.forward = _lora_scaled_forward_video_encoder = ledger.video_encoder()_video_decoder = ledger.video_decoder()_audio_encoder = ledger.audio_encoder()65 unmodified linesinput_audio,prompt: str,duration: float,lora_strength: floatenhance_prompt: bool = True,seed: int = 42,randomize_seed: bool = True,6 unmodified lineslog_memory("start")current_seed = random.randint(0, MAX_SEED) if randomize_seed else int(seed)global LORA_RUNTIME_SCALELORA_RUNTIME_SCALE = lora_strengthframe_rate = DEFAULT_FRAME_RATEnum_frames = int(duration * frame_rate) + 178 unmodified linesplaceholder="Describe the motion and animation you want...",)duration = gr.Slider(label="Duration (seconds)", minimum=1.0, maximum=10.0, value=3.0, step=0.1)lora_strength = gr.Slider(label="LoRA Strength",minimum=0.0,maximum=1.5,value=1.0,step=0.05,)generate_btn = gr.Button("Generate Video", variant="primary", size="lg")58 unmodified linesgenerate_btn.click(fn=generate_video,inputs=[first_image, last_image, input_audio, prompt, duration, lora_strength, enhance_prompt,seed, randomize_seed, height, width,],outputs=[output_video, seed],
app.py+40-2