Update app.py
Browse files4 unmodified lines5678910118 unmodified lines20212223242526272835 unmodified lines64656667686970714 unmodified linesfrom diffusers.pipelines.ltx.pipeline_ltx_condition import LTXVideoConditionfrom diffusers.utils import export_to_video, load_videopipe = LTXConditionPipeline.from_pretrained("a-r-r-o-w/LTX-Video-0.9.7-diffusers", torch_dtype=torch.bfloat16)pipe_upsample = LTXLatentUpsamplePipeline.from_pretrained("a-r-r-o-w/LTX-Video-0.9.7-Latent-Spatial-Upsampler-diffusers", vae=pipe.vae, torch_dtype=torch.bfloat16)pipe.to("cuda")pipe_upsample.to("cuda")8 unmodified lines@spaces.GPUdef generate(prompt,negative_prompt,steps,seed):returncss="""35 unmodified linesrandomize_seed = gr.Checkbox(label="randomize seed")with gr.Row():steps = gr.Slider(label="Steps", minimum=1, maximum=30, value=8, step=1)num_frames = gr.Slider(label="# frames", minimum=1, maximum=30, value=8, step=1)4 unmodified lines5678910118 unmodified lines202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868735 unmodified lines1231241251261271281291301314 unmodified linesfrom diffusers.pipelines.ltx.pipeline_ltx_condition import LTXVideoConditionfrom diffusers.utils import export_to_video, load_videopipe = LTXConditionPipeline.from_pretrained("linoyts/LTX-Video-0.9.7-distilled-diffusers", torch_dtype=torch.bfloat16)pipe_upsample = LTXLatentUpsamplePipeline.from_pretrained("a-r-r-o-w/LTX-Video-0.9.7-Latent-Spatial-Upsampler-diffusers", vae=pipe.vae, torch_dtype=torch.bfloat16)pipe.to("cuda")pipe_upsample.to("cuda")8 unmodified lines@spaces.GPUdef generate(prompt,negative_prompt,image,steps,num_frames,seed,randomize_seed):expected_height, expected_width = 768, 1152downscale_factor = 2 / 3if image is not None:condition1 = LTXVideoCondition(video=image, frame_index=0)else:condition1 = None# Part 1. Generate video at smaller resolution# Text-only conditioning is also supported without the need to pass `conditions`downscaled_height, downscaled_width = int(expected_height * downscale_factor), int(expected_width * downscale_factor)downscaled_height, downscaled_width = round_to_nearest_resolution_acceptable_by_vae(downscaled_height, downscaled_width)latents = pipe(conditions=condition1,prompt=prompt,negative_prompt=negative_prompt,width=downscaled_width,height=downscaled_height,num_frames=num_frames,num_inference_steps=steps,decode_timestep = 0.05,decode_noise_scale = 0.025,generator=torch.Generator().manual_seed(seed),output_type="latent",).frames# Part 2. Upscale generated video using latent upsampler with fewer inference steps# The available latent upsampler upscales the height/width by 2xupscaled_height, upscaled_width = downscaled_height * 2, downscaled_width * 2upscaled_latents = pipe_upsample(latents=latents,output_type="latent").frames# Part 3. Denoise the upscaled video with few steps to improve texture (optional, but recommended)video = pipe(conditions=condition1,prompt=prompt,negative_prompt=negative_prompt,width=upscaled_width,height=upscaled_height,num_frames=num_frames,denoise_strength=0.4, # Effectively, 4 inference steps out of 10num_inference_steps=10,latents=upscaled_latents,decode_timestep=0.05,image_cond_noise_scale=0.025,generator=torch.Generator().manual_seed(seed),output_type="pil",).frames[0]# Part 4. Downscale the video to the expected resolutionvideo = [frame.resize((expected_width, expected_height)) for frame in video]return videocss="""35 unmodified linesrandomize_seed = gr.Checkbox(label="randomize seed")with gr.Row():steps = gr.Slider(label="Steps", minimum=1, maximum=30, value=8, step=1)num_frames = gr.Slider(label="# frames", minimum=1, maximum=200, value=161, step=1)
app.py+65-5