Spaces:
Runtime error
Runtime error
Update app.py
Browse files1234567891021 unmodified lines323334353637383940414 unmodified lines46474849505152535455565758596061626364656667686970717273747576777811 unmodified lines90919293949596979899100101102103104105106107108109110111112113114115116117118119120121import gradio as grimport spacesimport torchfrom pipeline_ltx_condition import LTXVideoCondition, LTXConditionPipelinefrom diffusers import LTXLatentUpsamplePipeline#from diffusers import LTXConditionPipeline, LTXLatentUpsamplePipeline#from diffusers.pipelines.ltx.pipeline_ltx_condition import LTXVideoConditionfrom diffusers.utils import export_to_video, load_videoimport numpy as np21 unmodified linesnum_frames,seed,randomize_seed,t2v, progress=gr.Progress(track_tqdm=True)):expected_height, expected_width = 768, 1152downscale_factor = 2 / 3if randomize_seed:seed = random.randint(0, MAX_SEED)4 unmodified linesconditions=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(device="cuda").manual_seed(seed),#output_type="latent",).frameselse:latents = pipe(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(device="cuda").manual_seed(seed),#output_type="latent",).frames# 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,11 unmodified lines# Part 2. Upscale generated video using latent upsampler with fewer inference steps# The available latent upsampler upscales the height/width by 2x# upscaled_height, upscaled_width = downscaled_height * 2, downscaled_width * 2# upscaled_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 10# num_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 resolution#video = [frame.resize((expected_width, expected_height)) for frame in video]video = [frame.resize((expected_width, expected_height)) for frame in latents[0]]export_to_video(video, "output.mp4", fps=24)return "output.mp4"1234567891021 unmodified lines3233343536373839404142434445464 unmodified lines51525354555657585960616263646566676869707172737475767778798011 unmodified lines9293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130import gradio as grimport spacesimport torch# from pipeline_ltx_condition import LTXVideoCondition, LTXConditionPipeline# from diffusers import LTXLatentUpsamplePipelinefrom diffusers import LTXConditionPipeline, LTXLatentUpsamplePipelinefrom diffusers.pipelines.ltx.pipeline_ltx_condition import LTXVideoConditionfrom diffusers.utils import export_to_video, load_videoimport numpy as np21 unmodified linesnum_frames,seed,randomize_seed,t2v, improve_texture=False, progress=gr.Progress(track_tqdm=True)):# Part 1. Generate video at smaller resolution# Text-only conditioning is also supported without the need to pass `conditions`expected_height, expected_width = 768, 1152downscale_factor = 2 / 3downscaled_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)if randomize_seed:seed = random.randint(0, MAX_SEED)4 unmodified linesconditions=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(device="cuda").manual_seed(seed),output_type="latent",).frameselse:latents = pipe(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(device="cuda").manual_seed(seed),output_type="latent",).frames# latents = pipe(# conditions=condition1,11 unmodified lines# Part 2. Upscale generated video using latent upsampler with fewer inference steps# The available latent upsampler upscales the height/width by 2xif improve_texture:upscaled_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]else:upscaled_height, upscaled_width = downscaled_height * 2, downscaled_width * 2video = pipe_upsample(latents=latents,# output_type="latent").frames[0]# Part 4. Downscale the video to the expected resolutionvideo = [frame.resize((expected_width, expected_height)) for frame in video]export_to_video(video, "output.mp4", fps=24)return "output.mp4"
app.py+47-38