Spaces:
Runtime error
Runtime error
Update app.py
Browse files22 unmodified lines23242526272829303132333435363738394041424344454647484950515253545556575899 unmodified lines1581591601611621631641651661671681691701711721731741751761776 unmodified lines18418518618718818919019119219319419519619719819920020120220322 unmodified linesheight = height - (height % pipe.vae_temporal_compression_ratio)width = width - (width % pipe.vae_temporal_compression_ratio)return height, width@spaces.GPUdef generate(prompt,negative_prompt,image,video,steps,num_frames,seed,randomize_seed,t2v, improve_texture=False, progress=gr.Progress(track_tqdm=True)):if randomize_seed:seed = random.randint(0, MAX_SEED)# 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)condition = image is not None or video is not Noneif video:frames_to_use = 21video = load_video(video)[:frames_to_use]else:video = [image]if condition and (not t2v):condition1 = LTXVideoCondition(video=video, frame_index=0)latents = pipe(conditions=condition1,99 unmodified lineswith gr.Blocks(css=css, theme=gr.themes.Ocean()) as demo:gr.Markdown("# LTX Video 0.9.7 Distilled")with gr.Row():with gr.Column():with gr.Group():with gr.Tab("text-to-video"):image = gr.Image(label="", visible=False)#prompt = gr.Textbox(label="prompt")with gr.Tab("image-to-video"):image = gr.Image(label="")#prompt = gr.Textbox(label="prompt")with gr.Tab("video-to-video"):video = gr.Video(label="")prompt = gr.Textbox(label="prompt")t2v = gr.Checkbox(label="t2v", value=False)run_button = gr.Button()with gr.Column():output = gr.Video(interactive=False)6 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)run_button.click(fn=generate,inputs=[prompt,negative_prompt,image,video,steps,num_frames,seed,randomize_seed, t2v],outputs=[output])demo.launch()22 unmodified lines2324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707199 unmodified lines1711721731741751761771781791801811821831841851861871881896 unmodified lines19619719819920020120220320420520620720820921021121221321421521621721821922022122 unmodified linesheight = height - (height % pipe.vae_temporal_compression_ratio)width = width - (width % pipe.vae_temporal_compression_ratio)return height, widthdef change_mode_to_text():return gr.update(value="text-to-video")def change_mode_to_image():return gr.update(value="image-to-video")def change_mode_to_video():return gr.update(value="video-to-video")@spaces.GPUdef generate(prompt,negative_prompt,image,video,mode,steps,num_frames,seed,randomize_seed,improve_texture=False, progress=gr.Progress(track_tqdm=True)):if randomize_seed:seed = random.randint(0, MAX_SEED)# Part 1. Generate video at smaller resolution# Text-only conditioning is also supported without the need to pass `conditions`expected_height, expected_width = 768, 1152 #todo make configurabledownscale_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 mode == "text-to-video" and video is not None:frames_to_use = 21 #todo make configurablevideo = load_video(video)[:frames_to_use]condition = Trueelif mode == "image-to-video" and image is not None:video = [image]condition = Trueelse:condition=Falseif condition:condition1 = LTXVideoCondition(video=video, frame_index=0)latents = pipe(conditions=condition1,99 unmodified lineswith gr.Blocks(css=css, theme=gr.themes.Ocean()) as demo:gr.Markdown("# LTX Video 0.9.7 Distilled")mode = gr.State(value="text-to-video")with gr.Row():with gr.Column():with gr.Group():with gr.Tab("text-to-video") as text_tab:image = gr.Image(label="", visible=False)#prompt = gr.Textbox(label="prompt")with gr.Tab("image-to-video") as image_tab:image = gr.Image(label="")#prompt = gr.Textbox(label="prompt")with gr.Tab("video-to-video") as video_tab:video = gr.Video(label="")prompt = gr.Textbox(label="prompt")run_button = gr.Button()with gr.Column():output = gr.Video(interactive=False)6 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=161, value=96, step=1)text_tab.select(fn=change_mode_to_text, inputs=[], outputs=[mode])image_tab.select(fn=change_mode_to_image, inputs=[], outputs=[mode])video_tab.select(fn=change_mode_to_video, inputs=[], outputs=[mode])run_button.click(fn=generate,inputs=[prompt,negative_prompt,image,video,mode,steps,num_frames,seed,randomize_seed],outputs=[output])demo.launch()
app.py+34-16