ford442 commited on
Commit
a14165c
·
verified ·
1 Parent(s): a597ecf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +119 -59
app.py CHANGED
@@ -15,6 +15,7 @@ import torch
15
  # --- NEW ---
16
  # Import the OpenCV library
17
  import cv2
 
18
 
19
  torch.backends.cuda.matmul.allow_tf32 = False
20
  torch.backends.cuda.matmul.allow_bf16_reduced_precision_reduction = False
@@ -37,6 +38,27 @@ from PIL import Image
37
  from huggingface_hub import hf_hub_download
38
  import shutil
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  from inference import (
41
  create_ltx_video_pipeline,
42
  create_latent_upsampler,
@@ -87,58 +109,64 @@ def calculate_new_dimensions(orig_w, orig_h):
87
  new_w, new_h = 768, round((768 * (orig_h / orig_w)) / 32) * 32
88
  return int(max(256, min(new_h, MAX_IMAGE_SIZE))), int(max(256, min(new_w, MAX_IMAGE_SIZE)))
89
 
 
90
  def get_duration(*args, **kwargs):
91
  duration_ui = kwargs.get('duration_ui', 5.0)
92
- if duration_ui > 20.0: return 120
93
- if duration_ui > 13.0: return 90
94
- if duration_ui > 7.0: return 75
95
- if duration_ui > 5.0: return 60
96
- return 45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
 
98
- # --- MODIFIED ---
99
- # This function is now completely rewritten to use the more robust OpenCV library
100
- # instead of imageio. This should definitively fix the FFmpeg error.
101
- def use_last_frame_as_input(video_filepath):
102
  if not video_filepath or not os.path.exists(video_filepath):
103
- gr.Warning("No video available to get the last frame from.")
104
  return None, gr.update()
105
-
106
  try:
107
- print(f"Reading last frame from {video_filepath} using OpenCV...")
108
  cap = cv2.VideoCapture(video_filepath)
109
-
110
- # Get the total number of frames
111
  frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
112
- if frame_count < 1:
113
- raise ValueError("Video file could not be read or contains no frames.")
114
-
115
- # Set the position to the last frame (frame indices are 0-based)
116
  cap.set(cv2.CAP_PROP_POS_FRAMES, frame_count - 1)
117
-
118
- # Read the frame
119
  ret, frame = cap.read()
120
-
121
- if not ret or frame is None:
122
- raise ValueError("Failed to read the last frame from the video.")
123
-
124
- # OpenCV reads frames in BGR format, so we convert it to RGB for saving with PIL
125
- frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
126
-
127
- pil_image = Image.fromarray(frame_rgb)
128
- output_image_path = os.path.join(tempfile.mkdtemp(), f"last_frame_{random.randint(10000,99999)}.png")
129
- pil_image.save(output_image_path)
130
-
131
- print("Successfully extracted last frame.")
132
- return output_image_path, gr.update(selected="i2v_tab")
133
-
134
  except Exception as e:
135
- print(f"Error extracting last frame with OpenCV: {e}")
136
- gr.Error(f"Failed to extract the last frame: {e}")
137
  return None, gr.update()
138
  finally:
139
- # Release the video capture object
140
- if 'cap' in locals() and cap.isOpened():
141
- cap.release()
142
 
143
 
144
  def stitch_videos(clips_list):
@@ -156,19 +184,22 @@ def stitch_videos(clips_list):
156
  except Exception as e:
157
  raise gr.Error(f"Failed to stitch videos: {e}")
158
 
 
159
  def clear_clips():
160
  return [], "Clips created: 0", None, None
161
 
 
162
  @spaces.GPU(duration=get_duration)
163
  def generate(prompt, negative_prompt, clips_list, input_image_filepath, input_video_filepath,
164
  height_ui, width_ui, mode, duration_ui, ui_frames_to_use,
165
  seed_ui, randomize_seed, ui_guidance_scale, improve_texture_flag, num_steps, fps,
166
  progress=gr.Progress(track_tqdm=True)):
167
-
168
- # ... (the rest of the generate function is unchanged) ...
169
- if mode not in ["text-to-video", "image-to-video", "video-to-video"]: raise gr.Error(f"Invalid mode: {mode}.")
170
- if mode == "image-to-video" and not input_image_filepath: raise gr.Error("input_image_filepath is required for image-to-video mode")
171
- elif mode == "video-to-video" and not input_video_filepath: raise gr.Error("input_video_filepath is required for video-to-video mode")
 
172
  if randomize_seed: seed_ui = random.randint(0, 2**32 - 1)
173
  seed_everething(int(seed_ui))
174
  actual_num_frames = max(9, min(MAX_NUM_FRAMES, int(round((max(1, round(duration_ui * fps)) - 1.0) / 8.0) * 8 + 1)))
@@ -205,11 +236,16 @@ def generate(prompt, negative_prompt, clips_list, input_image_filepath, input_vi
205
  counter_text = f"Clips created: {len(updated_clips_list)}"
206
  return output_video_path, seed_ui, gr.update(visible=True), updated_clips_list, counter_text
207
 
208
- # ... (UI layout and other event handlers are unchanged) ...
209
- def update_task_image(): return "image-to-video"
210
- def update_task_text(): return "text-to-video"
211
- def update_task_video(): return "video-to-video"
 
 
 
 
212
  css="""#col-container{margin:0 auto;max-width:900px;}"""
 
213
  with gr.Blocks(css=css) as demo:
214
  clips_state = gr.State([])
215
  gr.Markdown("# LTX Video Clip Stitcher")
@@ -218,13 +254,23 @@ with gr.Blocks(css=css) as demo:
218
  with gr.Column():
219
  with gr.Tabs() as tabs:
220
  with gr.Tab("image-to-video", id="i2v_tab") as image_tab:
221
- video_i_hidden = gr.Textbox(visible=False); image_i2v = gr.Image(label="Input Image", type="filepath", sources=["upload", "webcam", "clipboard"]); i2v_prompt = gr.Textbox(label="Prompt", value="The creature from the image starts to move", lines=3); i2v_button = gr.Button("Generate Image-to-Video Clip", variant="primary")
 
 
 
222
  with gr.Tab("text-to-video", id="t2v_tab") as text_tab:
223
- image_n_hidden = gr.Textbox(visible=False); video_n_hidden = gr.Textbox(visible=False); t2v_prompt = gr.Textbox(label="Prompt", value="A majestic dragon flying over a medieval castle", lines=3); t2v_button = gr.Button("Generate Text-to-Video Clip", variant="primary")
 
 
224
  with gr.Tab("video-to-video", id="v2v_tab") as video_tab:
225
- image_v_hidden = gr.Textbox(visible=False); video_v2v = gr.Video(label="Input Video", sources=["upload", "webcam"]); frames_to_use = gr.Slider(label="Frames to use from input video", minimum=9, maximum=120, value=9, step=8, info="Must be N*8+1."); v2v_prompt = gr.Textbox(label="Prompt", value="Change the style to cinematic anime", lines=3); v2v_button = gr.Button("Generate Video-to-Video Clip", variant="primary")
 
 
 
 
226
  duration_input = gr.Slider(label="Clip Duration (seconds)", minimum=1.0, maximum=10.0, value=2.0, step=0.1)
227
  improve_texture = gr.Checkbox(label="Improve Texture (multi-scale)", value=True)
 
228
  with gr.Column():
229
  output_video = gr.Video(label="Last Generated Clip", interactive=False)
230
  use_last_frame_button = gr.Button("Use Last Frame as Input Image", visible=False)
@@ -233,26 +279,40 @@ with gr.Blocks(css=css) as demo:
233
  with gr.Row(): stitch_button = gr.Button("🎬 Stitch All Clips"); clear_button = gr.Button("🗑️ Clear All Clips")
234
  final_video_output = gr.Video(label="Final Stitched Video", interactive=False)
235
  with gr.Accordion("Advanced settings", open=False):
236
- mode = gr.Dropdown(["text-to-video", "image-to-video", "video-to-video"], label="task", value="image-to-video", visible=False); negative_prompt_input = gr.Textbox(label="Negative Prompt", value="worst quality, inconsistent motion, blurry, jittery, distorted", lines=2)
237
- with gr.Row(): seed_input = gr.Number(label="Seed", value=42, precision=0); randomize_seed_input = gr.Checkbox(label="Randomize Seed", value=True)
238
- with gr.Row(visible=False): guidance_scale_input = gr.Slider(label="Guidance Scale (CFG)", minimum=1.0, maximum=10.0, value=PIPELINE_CONFIG_YAML.get("first_pass", {}).get("guidance_scale", 1.0), step=0.1)
239
- with gr.Row(): height_input = gr.Slider(label="Height", value=768, step=32, minimum=32, maximum=MAX_IMAGE_SIZE); width_input = gr.Slider(label="Width", value=768, step=32, minimum=32, maximum=MAX_IMAGE_SIZE); num_steps = gr.Slider(label="Steps", value=20, step=1, minimum=1, maximum=420); fps = gr.Slider(label="FPS", value=30.0, step=1.0, minimum=4.0, maximum=60.0)
 
 
 
 
 
 
 
 
240
  def handle_image_upload_for_dims(f, h, w):
241
  if not f: return gr.update(value=h), gr.update(value=w)
242
  img = Image.open(f); new_h, new_w = calculate_new_dimensions(img.width, img.height); return gr.update(value=new_h), gr.update(value=new_w)
243
  def handle_video_upload_for_dims(f, h, w):
244
  if not f or not os.path.exists(str(f)): return gr.update(value=h), gr.update(value=w)
245
  with imageio.get_reader(str(f)) as reader:
246
- meta = reader.get_meta_data(); orig_w, orig_h = meta.get('size', (reader.get_data(0).shape[1], reader.get_data(0).shape[0])); new_h, new_w = calculate_new_dimensions(orig_w, orig_h); return gr.update(value=new_h), gr.update(value=new_w)
247
- image_i2v.upload(handle_image_upload_for_dims, [image_i2v, height_input, width_input], [height_input, width_input]); video_v2v.upload(handle_video_upload_for_dims, [video_v2v, height_input, width_input], [height_input, width_input]); image_tab.select(update_task_image, outputs=[mode]); text_tab.select(update_task_text, outputs=[mode]); video_tab.select(update_task_video, outputs=[mode])
 
 
 
 
248
  common_params = [height_input, width_input, mode, duration_input, frames_to_use, seed_input, randomize_seed_input, guidance_scale_input, improve_texture, num_steps, fps]
249
- t2v_inputs = [t2v_prompt, negative_prompt_input, clips_state, image_n_hidden, video_n_hidden] + common_params; i2v_inputs = [i2v_prompt, negative_prompt_input, clips_state, image_i2v, video_i_hidden] + common_params; v2v_inputs = [v2v_prompt, negative_prompt_input, clips_state, image_v_hidden, video_v2v] + common_params
 
 
250
  gen_outputs = [output_video, seed_input, use_last_frame_button, clips_state, clip_counter_display]
251
  hide_btn = lambda: gr.update(visible=False)
252
  t2v_button.click(hide_btn, outputs=[use_last_frame_button], queue=False).then(fn=generate, inputs=t2v_inputs, outputs=gen_outputs, api_name="text_to_video")
253
  i2v_button.click(hide_btn, outputs=[use_last_frame_button], queue=False).then(fn=generate, inputs=i2v_inputs, outputs=gen_outputs, api_name="image_to_video")
254
  v2v_button.click(hide_btn, outputs=[use_last_frame_button], queue=False).then(fn=generate, inputs=v2v_inputs, outputs=gen_outputs, api_name="video_to_video")
255
- use_last_frame_button.click(fn=use_last_frame_as_input, inputs=[output_video], outputs=[image_i2v, tabs])
256
  stitch_button.click(fn=stitch_videos, inputs=[clips_state], outputs=[final_video_output])
257
  clear_button.click(fn=clear_clips, outputs=[clips_state, clip_counter_display, output_video, final_video_output])
258
  if __name__ == "__main__":
 
15
  # --- NEW ---
16
  # Import the OpenCV library
17
  import cv2
18
+ import gc
19
 
20
  torch.backends.cuda.matmul.allow_tf32 = False
21
  torch.backends.cuda.matmul.allow_bf16_reduced_precision_reduction = False
 
38
  from huggingface_hub import hf_hub_download
39
  import shutil
40
 
41
+ MAX_SEED = np.iinfo(np.int32).max
42
+
43
+ #import diffusers
44
+ from diffusers import StableDiffusionXLImg2ImgPipeline, AutoencoderKL
45
+ print("Loading SDXL Image-to-Image pipeline...")
46
+ #vaeX = AutoencoderKL.from_pretrained('stabilityai/stable-diffusion-xl-refiner-1.0',subfolder='vae')
47
+ enhancer_pipeline = StableDiffusionXLImg2ImgPipeline.from_pretrained(
48
+ #"stabilityai/stable-diffusion-xl-base-1.0",
49
+ "ford442/stable-diffusion-xl-refiner-1.0-bf16",
50
+ #torch_dtype=torch.bfloat16,
51
+ #variant="fp16",
52
+ #use_safetensors=True,
53
+ requires_aesthetics_score=True,
54
+ #vae=None
55
+ )
56
+ #enhancer_pipeline.vae=vaeX
57
+ enhancer_pipeline.vae.set_default_attn_processor()
58
+
59
+ enhancer_pipeline.to("cpu")
60
+ print("SDXL Image-to-Image pipeline loaded successfully.")
61
+
62
  from inference import (
63
  create_ltx_video_pipeline,
64
  create_latent_upsampler,
 
109
  new_w, new_h = 768, round((768 * (orig_h / orig_w)) / 32) * 32
110
  return int(max(256, min(new_h, MAX_IMAGE_SIZE))), int(max(256, min(new_w, MAX_IMAGE_SIZE)))
111
 
112
+
113
  def get_duration(*args, **kwargs):
114
  duration_ui = kwargs.get('duration_ui', 5.0)
115
+ if duration_ui > 7.0: return 120
116
+ if duration_ui > 5.0: return 100
117
+ return 90
118
+
119
+
120
+ @spaces.GPU()
121
+ def enhance_frame(image_to_enhance: Image.Image):
122
+ try:
123
+ print("Moving enhancer pipeline to GPU...")
124
+ seed = random.randint(0, MAX_SEED)
125
+ generator = torch.Generator(device='cpu').manual_seed(seed)
126
+ enhancer_pipeline.to("cuda",torch.bfloat16)
127
+ refine_prompt = "cinematic, high detail, sharp focus, 8k, professional photography"
128
+ enhanced_image = enhancer_pipeline(prompt=refine_prompt, image=image_to_enhance, strength=0.125, generator=generator, num_inference_steps=100).images[0]
129
+ print("Frame enhancement successful.")
130
+ except Exception as e:
131
+ print(f"Error during frame enhancement: {e}")
132
+ gr.Warning("Frame enhancement failed. Using original frame.")
133
+ return image_to_enhance
134
+ finally:
135
+ print("Moving enhancer pipeline to CPU...")
136
+ enhancer_pipeline.to("cpu")
137
+ gc.collect()
138
+ torch.cuda.empty_cache()
139
+ return enhanced_image
140
 
141
+
142
+ def use_last_frame_as_input(video_filepath, do_enhance):
 
 
143
  if not video_filepath or not os.path.exists(video_filepath):
144
+ gr.Warning("No video clip available.")
145
  return None, gr.update()
146
+ cap = None
147
  try:
 
148
  cap = cv2.VideoCapture(video_filepath)
 
 
149
  frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
 
 
 
 
150
  cap.set(cv2.CAP_PROP_POS_FRAMES, frame_count - 1)
 
 
151
  ret, frame = cap.read()
152
+ if not ret: raise ValueError("Failed to read frame.")
153
+ pil_image = Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
154
+ # 1. Immediately yield the original frame to the UI
155
+ print("Displaying original last frame...")
156
+ yield pil_image, gr.update()
157
+ if do_enhance:
158
+ enhanced_image = enhance_frame(pil_image)
159
+ # 2. Yield the enhanced frame and switch the tab
160
+ print("Displaying enhanced frame and switching tab...")
161
+ yield enhanced_image, gr.update(selected="i2v_tab")
162
+ else:
163
+ # If not enhancing, just switch the tab
164
+ yield pil_image, gr.update(selected="i2v_tab")
 
165
  except Exception as e:
166
+ gr.Error(f"Failed to extract frame: {e}")
 
167
  return None, gr.update()
168
  finally:
169
+ if cap: cap.release()
 
 
170
 
171
 
172
  def stitch_videos(clips_list):
 
184
  except Exception as e:
185
  raise gr.Error(f"Failed to stitch videos: {e}")
186
 
187
+
188
  def clear_clips():
189
  return [], "Clips created: 0", None, None
190
 
191
+
192
  @spaces.GPU(duration=get_duration)
193
  def generate(prompt, negative_prompt, clips_list, input_image_filepath, input_video_filepath,
194
  height_ui, width_ui, mode, duration_ui, ui_frames_to_use,
195
  seed_ui, randomize_seed, ui_guidance_scale, improve_texture_flag, num_steps, fps,
196
  progress=gr.Progress(track_tqdm=True)):
197
+ if mode not in ["text-to-video", "image-to-video", "video-to-video"]:
198
+ raise gr.Error(f"Invalid mode: {mode}.")
199
+ if mode == "image-to-video" and not input_image_filepath:
200
+ raise gr.Error("input_image_filepath is required for image-to-video mode")
201
+ elif mode == "video-to-video" and not input_video_filepath:
202
+ raise gr.Error("input_video_filepath is required for video-to-video mode")
203
  if randomize_seed: seed_ui = random.randint(0, 2**32 - 1)
204
  seed_everething(int(seed_ui))
205
  actual_num_frames = max(9, min(MAX_NUM_FRAMES, int(round((max(1, round(duration_ui * fps)) - 1.0) / 8.0) * 8 + 1)))
 
236
  counter_text = f"Clips created: {len(updated_clips_list)}"
237
  return output_video_path, seed_ui, gr.update(visible=True), updated_clips_list, counter_text
238
 
239
+
240
+ def update_task_image():
241
+ return "image-to-video"
242
+ def update_task_text():
243
+ return "text-to-video"
244
+ def update_task_video():
245
+ return "video-to-video"
246
+
247
  css="""#col-container{margin:0 auto;max-width:900px;}"""
248
+
249
  with gr.Blocks(css=css) as demo:
250
  clips_state = gr.State([])
251
  gr.Markdown("# LTX Video Clip Stitcher")
 
254
  with gr.Column():
255
  with gr.Tabs() as tabs:
256
  with gr.Tab("image-to-video", id="i2v_tab") as image_tab:
257
+ video_i_hidden = gr.Textbox(visible=False);
258
+ image_i2v = gr.Image(label="Input Image", type="filepath", sources=["upload", "webcam", "clipboard"]);
259
+ i2v_prompt = gr.Textbox(label="Prompt", value="The creature from the image starts to move", lines=3);
260
+ i2v_button = gr.Button("Generate Image-to-Video Clip", variant="primary")
261
  with gr.Tab("text-to-video", id="t2v_tab") as text_tab:
262
+ image_n_hidden = gr.Textbox(visible=False);
263
+ video_n_hidden = gr.Textbox(visible=False); t2v_prompt = gr.Textbox(label="Prompt", value="A majestic dragon flying over a medieval castle", lines=3);
264
+ t2v_button = gr.Button("Generate Text-to-Video Clip", variant="primary")
265
  with gr.Tab("video-to-video", id="v2v_tab") as video_tab:
266
+ image_v_hidden = gr.Textbox(visible=False);
267
+ video_v2v = gr.Video(label="Input Video", sources=["upload", "webcam"]);
268
+ frames_to_use = gr.Slider(label="Frames to use from input video", minimum=9, maximum=120, value=9, step=8, info="Must be N*8+1.");
269
+ v2v_prompt = gr.Textbox(label="Prompt", value="Change the style to cinematic anime", lines=3);
270
+ v2v_button = gr.Button("Generate Video-to-Video Clip", variant="primary")
271
  duration_input = gr.Slider(label="Clip Duration (seconds)", minimum=1.0, maximum=10.0, value=2.0, step=0.1)
272
  improve_texture = gr.Checkbox(label="Improve Texture (multi-scale)", value=True)
273
+ enhance_checkbox = gr.Checkbox(label="Improve Frame (SDXL Refiner)", value=True)
274
  with gr.Column():
275
  output_video = gr.Video(label="Last Generated Clip", interactive=False)
276
  use_last_frame_button = gr.Button("Use Last Frame as Input Image", visible=False)
 
279
  with gr.Row(): stitch_button = gr.Button("🎬 Stitch All Clips"); clear_button = gr.Button("🗑️ Clear All Clips")
280
  final_video_output = gr.Video(label="Final Stitched Video", interactive=False)
281
  with gr.Accordion("Advanced settings", open=False):
282
+ mode = gr.Dropdown(["text-to-video", "image-to-video", "video-to-video"], label="task", value="image-to-video", visible=False);
283
+ negative_prompt_input = gr.Textbox(label="Negative Prompt", value="worst quality, inconsistent motion, blurry, jittery, distorted", lines=2)
284
+ with gr.Row():
285
+ seed_input = gr.Number(label="Seed", value=42, precision=0);
286
+ randomize_seed_input = gr.Checkbox(label="Randomize Seed", value=True)
287
+ with gr.Row(visible=False):
288
+ guidance_scale_input = gr.Slider(label="Guidance Scale (CFG)", minimum=1.0, maximum=10.0, value=PIPELINE_CONFIG_YAML.get("first_pass", {}).get("guidance_scale", 1.0), step=0.1)
289
+ with gr.Row():
290
+ height_input = gr.Slider(label="Height", value=768, step=32, minimum=32, maximum=MAX_IMAGE_SIZE);
291
+ width_input = gr.Slider(label="Width", value=768, step=32, minimum=32, maximum=MAX_IMAGE_SIZE);
292
+ num_steps = gr.Slider(label="Steps", value=20, step=1, minimum=1, maximum=420);
293
+ fps = gr.Slider(label="FPS", value=30.0, step=1.0, minimum=4.0, maximum=60.0)
294
  def handle_image_upload_for_dims(f, h, w):
295
  if not f: return gr.update(value=h), gr.update(value=w)
296
  img = Image.open(f); new_h, new_w = calculate_new_dimensions(img.width, img.height); return gr.update(value=new_h), gr.update(value=new_w)
297
  def handle_video_upload_for_dims(f, h, w):
298
  if not f or not os.path.exists(str(f)): return gr.update(value=h), gr.update(value=w)
299
  with imageio.get_reader(str(f)) as reader:
300
+ meta = reader.get_meta_data(); orig_w, orig_h = meta.get('size', (reader.get_data(0).shape[1], reader.get_data(0).shape[0]));
301
+ new_h, new_w = calculate_new_dimensions(orig_w, orig_h); return gr.update(value=new_h), gr.update(value=new_w)
302
+ image_i2v.upload(handle_image_upload_for_dims, [image_i2v, height_input, width_input], [height_input, width_input]);
303
+ video_v2v.upload(handle_video_upload_for_dims, [video_v2v, height_input, width_input], [height_input, width_input]);
304
+ image_tab.select(update_task_image, outputs=[mode]); text_tab.select(update_task_text, outputs=[mode]);
305
+ video_tab.select(update_task_video, outputs=[mode])
306
  common_params = [height_input, width_input, mode, duration_input, frames_to_use, seed_input, randomize_seed_input, guidance_scale_input, improve_texture, num_steps, fps]
307
+ t2v_inputs = [t2v_prompt, negative_prompt_input, clips_state, image_n_hidden, video_n_hidden] + common_params;
308
+ i2v_inputs = [i2v_prompt, negative_prompt_input, clips_state, image_i2v, video_i_hidden] + common_params;
309
+ v2v_inputs = [v2v_prompt, negative_prompt_input, clips_state, image_v_hidden, video_v2v] + common_params
310
  gen_outputs = [output_video, seed_input, use_last_frame_button, clips_state, clip_counter_display]
311
  hide_btn = lambda: gr.update(visible=False)
312
  t2v_button.click(hide_btn, outputs=[use_last_frame_button], queue=False).then(fn=generate, inputs=t2v_inputs, outputs=gen_outputs, api_name="text_to_video")
313
  i2v_button.click(hide_btn, outputs=[use_last_frame_button], queue=False).then(fn=generate, inputs=i2v_inputs, outputs=gen_outputs, api_name="image_to_video")
314
  v2v_button.click(hide_btn, outputs=[use_last_frame_button], queue=False).then(fn=generate, inputs=v2v_inputs, outputs=gen_outputs, api_name="video_to_video")
315
+ use_last_frame_button.click(fn=use_last_frame_as_input, inputs=[output_video,enhance_checkbox], outputs=[image_i2v, tabs])
316
  stitch_button.click(fn=stitch_videos, inputs=[clips_state], outputs=[final_video_output])
317
  clear_button.click(fn=clear_clips, outputs=[clips_state, clip_counter_display, output_video, final_video_output])
318
  if __name__ == "__main__":