markury commited on
Commit
ca11d33
·
1 Parent(s): d3f7898

feat: test 2nd pass

Browse files
Files changed (1) hide show
  1. app.py +208 -15
app.py CHANGED
@@ -5,6 +5,8 @@ from diffusers.utils import export_to_video
5
  from diffusers import AutoencoderKLWan, WanPipeline
6
  from diffusers.schedulers.scheduling_unipc_multistep import UniPCMultistepScheduler
7
  from diffusers.schedulers.scheduling_flow_match_euler_discrete import FlowMatchEulerDiscreteScheduler
 
 
8
 
9
  # Define model options
10
  MODEL_OPTIONS = {
@@ -33,7 +35,14 @@ def generate_video(
33
  num_frames,
34
  guidance_scale,
35
  num_inference_steps,
36
- output_fps
 
 
 
 
 
 
 
37
  ):
38
  # Get model ID from selection
39
  model_id = MODEL_OPTIONS[model_choice]
@@ -76,35 +85,123 @@ def generate_video(
76
  # Enable CPU offload for low VRAM
77
  pipe.enable_model_cpu_offload()
78
 
79
- # Generate video
80
- output = pipe(
 
 
 
 
81
  prompt=prompt,
82
  negative_prompt=negative_prompt,
83
  height=height,
84
  width=width,
85
  num_frames=num_frames,
86
  guidance_scale=guidance_scale,
87
- num_inference_steps=num_inference_steps
88
- ).frames[0]
 
 
89
 
90
- # Export to video
91
- temp_file = "output.mp4"
92
- export_to_video(output, temp_file, fps=output_fps)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
 
94
- return temp_file
 
 
 
 
 
 
95
 
96
  # Create the Gradio interface
97
  with gr.Blocks() as demo:
98
  gr.HTML("""
99
  <p align="center">
100
  <svg version="1.1" viewBox="0 0 1200 295" xmlns="http://www.w3.org/2000/svg" xmlns:v="https://vecta.io/nano" width="400">
101
- <path d='M195.43 109.93a.18.18 0 0 1-.27-.03l-.17-.26a.13.12-43.2 0 1 .01-.16q21.87-21.98 42.02-37.95c17.57-13.93 36.61-26.36 57.23-34.01q13.26-4.92 24.23-4.1c10.91.81 18.01 8.05 19.12 18.82.79 7.76-.64 15.73-3.29 23.37q-5.87 16.92-15.46 32.47a1.05 1.02-40.3 0 0-.09.91q11.79 32.3 2.48 63.6c-13.06 43.95-53.78 72.83-99.49 71.06q-16.32-.64-30.92-6.27a1.88 1.88 0 0 0-1.65.15c-12.54 7.69-26.93 14.55-41.16 17.68-4.99 1.1-9.54.6-16.14.62a6.31 6.04 50.1 0 1-1.35-.15c-19.69-4.51-18.03-25.43-12.71-40.65q5.95-17.05 15.9-32.34a.89.88 50.1 0 0 .07-.82c-13.76-32.93-7.8-71.64 14.32-99.05q20.75-25.73 51.75-33.99 29.88-7.96 59.38 2.25a.18.18 0 0 1 .04.32l-11.17 7.52a1.18 1.17-55 0 1-.93.17q-26.82-6.3-51.8 2.83c-24.65 9.02-43.94 28.53-52.73 53.27q-8.3 23.33-2.99 48.49.7 3.32 3.15 10.35c7.87 22.55 24.1 40.02 45.62 50.35a.52.51 43.2 0 1 .03.91l-10.31 5.96a.7.68-44.3 0 1-.69 0q-27.53-15.57-41.3-43.86a.1.09-44.1 0 0-.17 0q-6.59 11.46-11.16 23.67c-4.39 11.73-11.35 38.04 10.45 38.5q6.38.13 11.55-1.22c17.2-4.51 32.86-13.33 47.66-23.11q24.23-16.04 49.48-39.51c28.57-26.55 55.11-56.92 74.11-90.87q5.96-10.65 10.32-23.77c2.38-7.15 5.16-20.81-.67-27.03q-3.67-3.92-8.08-4.48-10.87-1.39-22.3 2.5-11.06 3.77-18.33 7.43c-30.93 15.54-58.11 36.9-83.59 60.43zm100.11-36.16q10.18 9.98 17.31 22.67a.6.59 46.1 0 1-.01.59l-6.17 10.69a.34.33-42.8 0 1-.59-.02q-7.06-14.92-18.34-25.98-11.28-11.06-26.34-17.82a.34.33-48.4 0 1-.03-.59l10.56-6.38a.6.59 42.7 0 1 .59-.02q12.83 6.88 23.02 16.86zm430.69 78.36h10a1.13 1.12-74.2 0 0 .96-.54q11.1-17.8 23.93-38.19 1.8-2.85 5.39-3.1 3.42-.23 11.73-.11 1.88.02 2.61.66a2.23 2.08-54 0 1 .34 2.77q-12.01 19.41-29.2 46.98a.86.85 45.5 0 0 0 .93q12.8 20.23 28.66 46.12.22.36.29 1.09a1.98 1.97 85.7 0 1-1.85 2.16q-7.51.45-13.91-.05c-2.52-.2-4.25-2.09-5.57-4.24q-8.26-13.5-22.19-36.26a.74.72-15 0 0-.63-.35H726.2a.62.61 0 0 0-.62.61q-.03 31.31.02 35.17.07 5.25-5.02 5.31-7.87.1-10.26-.19-3.72-.45-3.71-4.69.05-35.54-.02-135.71c0-3.87.67-6.1 4.77-6.12q7.55-.05 10.37.06c3.4.13 3.94 3.29 3.92 6.34q-.22 43.68-.02 80.75a.6.6 0 0 0 .6.6zM191.9 74.2l1.52.2a.33.33 0 0 1 0 .65l-1.52.22a.33.33 0 0 0-.28.29l-.2 1.52a.33.33 0 0 1-.65 0l-.22-1.52a.33.33 0 0 0-.29-.28l-1.52-.2a.33.33 0 0 1 0-.65l1.52-.22a.33.33 0 0 0 .28-.29l.2-1.52a.33.33 0 0 1 .65 0l.22 1.52a.33.33 0 0 0 .29.28zm64.12 2.96l2.78.37a.33.33 0 0 1 0 .65l-2.78.39a.33.33 0 0 0-.28.29l-.37 2.78a.33.33 0 0 1-.65 0l-.39-2.78a.33.33 0 0 0-.29-.28l-2.78-.37a.33.33 0 0 1 0-.65l2.78-.39a.33.33 0 0 0 .28-.29l.37-2.78a.33.33 0 0 1 .65 0l.39 2.78a.33.33 0 0 0 .29.28zm150.31 27.5q-.37 2.75-.37 5.59.1 55.28.07 95.29-.01 5.69-4.97 5.57-4.23-.1-9.06-.04-4.92.06-4.92-4.56-.03-47.02-.01-122.76c0-4.45 2.16-5.1 6.27-5.1q17.99.04 19.41.04c4.14-.01 5.19 2.26 6.29 6.06q6.68 23.18 28.31 98.03a.22.22 0 0 0 .42-.01q26.48-97.12 26.96-99.03 1.26-5.01 5.72-5.05 9.8-.09 22.27.08c3.29.04 3.71 3.1 3.7 5.88q-.07 58.05-.18 118.23c-.01 4.45.51 7.92-4.69 8.13q-3.32.14-7.06.02c-5.17-.17-7.18.03-7.18-6.18q.01-66.62.01-100.28a.141.141 0 0 0-.28-.04q-20.97 79.04-26.98 101.79-1.27 4.8-5.99 4.76-4.96-.03-13.08-.01c-4.08.01-5.44-1.81-6.54-5.76q-17.37-62.23-27.98-100.66a.07.07 0 0 0-.14.01zm-172.34 1.26l2.49.36a.32.32 0 0 1 0 .63l-2.49.37a.32.32 0 0 0-.27.27l-.36 2.49a.32.32 0 0 1-.63 0l-.37-2.49a.32.32 0 0 0-.27-.27l-2.49-.36a.32.32 0 0 1 0-.63l2.49-.37a.32.32 0 0 0 .27-.27l.36-2.49a.32.32 0 0 1 .63 0l.37 2.49a.32.32 0 0 0 .27.27zm46.8 2.66l2.5.41a.34.34 0 0 1 0 .67l-2.5.4a.34.34 0 0 0-.28.28l-.41 2.5a.34.34 0 0 1-.67 0l-.4-2.5a.34.34 0 0 0-.28-.28l-2.5-.41a.34.34 0 0 1 0-.67l2.5-.4a.34.34 0 0 0 .28-.28l.41-2.5a.34.34 0 0 1 .67 0l.4 2.5a.34.34 0 0 0 .28.28zm311.55 38.61q.18-12.55-.16-15.38c-.44-3.69-4.05-3.64-6.93-3.64q-18.53.03-52.88-.01c-3.01 0-3.94-2.46-3.95-5.32q-.01-5.13.04-8.35.08-4.18 4.29-4.26 5.99-.11 59.86-.05c13.05.02 18.7 5.13 18.7 18.33q.01 61.89.01 63.24c.03 15.73-6.4 19.32-21.07 19.32q-30.49.01-43.5-.02c-14.08-.04-20.24-3.83-20.35-18.8q-.12-16.77.08-27.74c.21-12.16 6.75-16.58 18.27-16.58q22.02.01 46.85-.01a.74.74 0 0 0 .74-.73zm-.66 18.75q-26.48-.05-41.68.04-4.64.03-4.77 4.52-.22 8.08-.06 16.74c.12 6.3 2.92 5.93 8.53 5.94q14.25.01 34.08-.03c4.89-.02 4.57-4.12 4.6-8.32q.08-11.72-.06-18.26a.65.64 89.1 0 0-.64-.63zm45.34 45.09c-2.82.02-4.77-1.44-4.77-4.22q-.01-73.72.01-78.31c.05-12.96 5.29-18.22 18.24-18.3q11.13-.06 38.25-.02 4.76.01 4.86 4.11.13 4.95.08 8.97c-.05 3.99-1.85 4.93-5.85 4.92q-24.69-.01-26.97 0c-5.43 0-9.69-.88-9.69 5.79q-.01 66 .02 70.71.02 3.45-.84 4.58-1.47 1.96-4.11 1.92-9.21-.15-9.23-.15zm200.71-17.86q16.73 0 18.8-.04c5.15-.13 4.81-3.81 4.8-8.15q-.01-10.05.01-70.24 0-4.51 4.92-4.56 7.92-.08 10 .09 3.9.31 3.9 4.48.02 60.37-.01 77.78c-.02 15.09-6.99 18.68-20.65 18.54q-.42 0-21.77 0-21.35 0-21.77 0c-13.66.14-20.63-3.45-20.65-18.54q-.03-17.41-.01-77.78 0-4.17 3.9-4.48 2.08-.17 10-.09 4.92.05 4.92 4.56.02 60.19.01 70.24c-.01 4.34-.35 8.02 4.79 8.14q2.08.05 18.81.05zm63.52 13.64q-.01-73.72.01-78.31c.05-12.96 5.29-18.22 18.24-18.3q11.13-.06 38.25-.02 4.76.01 4.86 4.11.13 4.95.08 8.97c-.05 3.99-1.85 4.93-5.85 4.92q-24.69-.01-26.97 0c-5.43 0-9.69-.88-9.69 5.79q-.01 66 .02 70.71.02 3.45-.84 4.58-1.47 1.96-4.11 1.92-9.21-.15-9.23-.15c-2.82.02-4.77-1.44-4.77-4.22zm109.52-25.57q18.81-60.07 20.5-65.73 1.57-5.27 6.17-5.34 3.67-.05 10.57.07c2.6.05 3.39 2.42 2.65 4.66q-11.68 35.64-41.85 128.15-1.51 4.61-6.26 4.65-4.38.03-7.66-.07c-3.83-.12-3.5-3.08-2.61-6.07q3.74-12.68 8.78-29.76a1.97 1.91-47.2 0 0-.03-1.2q-19.47-53.62-34.46-94.88c-.96-2.65-1.38-5.23 2.18-5.46q1.66-.11 11.3-.09 4.8 0 6.58 4.96 13.98 38.91 23.84 66.12a.16.16 0 0 0 .3-.01zm-767.05-7.85q-.03-28.67.01-36.09.03-4-1.39-6.63c-2.4-4.47-7.99-5.48-11.98-2.79q-4.8 3.23-4.86 9.16-.17 16.69-.02 24.3a.47.47 0 0 1-.47.48h-10.36a.46.46 0 0 1-.46-.46q.02-21.54 0-23.86-.03-2.66-.94-5.2c-2.63-7.33-11.73-8.07-15.95-1.8q-1.99 2.96-1.98 7.75.05 21.93.01 22.99a.59.58-89 0 1-.58.57h-10.14a.57.57 0 0 1-.57-.57v-43.73a1.04 1.04 0 0 1 1.04-1.04h8.41a1.25 1.24-2.5 0 1 1.24 1.13l.3 3.59a.27.27 0 0 0 .44.19q.06-.06 1.28-1.44c2.92-3.32 7.69-4.52 12.01-4.15q8.1.68 11.68 7.78a.37.37 0 0 0 .64.03c4.8-7.6 13.82-9.19 22.01-6.61 8.67 2.72 11.91 11.02 11.96 19.52q.07 14.44.05 24.75a1.29 1.26 66.4 0 1-.32.85l-10.44 11.52a.36.36 0 0 1-.62-.24zm-87.22-51.13l1.95.24a.34.34 0 0 1 0 .67l-1.96.22a.34.34 0 0 0-.3.3l-.24 1.95a.34.34 0 0 1-.67 0l-.22-1.96a.34.34 0 0 0-.3-.3l-1.95-.24a.34.34 0 0 1 0-.67l1.96-.22a.34.34 0 0 0 .3-.3l.24-1.95a.34.34 0 0 1 .67 0l.22 1.96a.34.34 0 0 0 .3.3zm13.88 41.55q.18 0 .43.34a.87.82 79.1 0 0 .45.33l.6.17a.362.362 0 0 1-.14.71q-.38-.05-.48-.08-.04-.02-.4.44-.26.33-.45.33-.19 0-.45-.32-.37-.46-.41-.44-.1.03-.48.09a.363.363 0 0 1-.15-.71l.6-.18a.87.82-79.8 0 0 .45-.33q.24-.35.43-.35zm25.81 35.05q.01.16-.38.69a.6.59 33.3 0 1-.79.16q-1.23-.74-1.23-.8 0-.05 1.19-.85a.6.59-36.1 0 1 .79.12q.42.51.42.68z' fill="#100c6d" />
102
  </svg>
103
  <p align="center">
104
  💻 <a href="https://www.markury.dev/"><b>Website</b></a> &nbsp&nbsp | &nbsp&nbsp 🤗 <a href="https://huggingface.co/markury"><b>Hugging Face</b></a> &nbsp&nbsp | &nbsp&nbsp 💿 <a href="https://thebulge.xyz"><b>Discord</b></a>
105
  </p>
106
  """)
107
- gr.Markdown("# Wan 2.1 T2V 1.3B with LoRA")
108
 
109
  with gr.Row():
110
  with gr.Column(scale=1):
@@ -209,13 +306,92 @@ with gr.Blocks() as demo:
209
  step=1
210
  )
211
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
212
  generate_btn = gr.Button("Generate Video")
213
 
214
  with gr.Column(scale=1):
215
- output_video = gr.Video(label="Generated Video")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
216
 
 
 
 
 
 
 
 
 
 
 
217
  generate_btn.click(
218
- fn=generate_video,
219
  inputs=[
220
  model_choice,
221
  prompt,
@@ -230,9 +406,20 @@ with gr.Blocks() as demo:
230
  num_frames,
231
  guidance_scale,
232
  num_inference_steps,
233
- output_fps
 
 
 
 
 
 
 
234
  ],
235
- outputs=output_video
 
 
 
 
236
  )
237
 
238
  gr.Markdown("""
@@ -242,6 +429,12 @@ with gr.Blocks() as demo:
242
  - Number of frames should be of the form 4k+1 (e.g., 33, 81)
243
  - Stick to lower frame counts. Even at 480p, an 81 frame sequence at 30 steps will nearly time out the request in this space.
244
 
 
 
 
 
 
 
245
  ## Using LoRAs with multiple safetensors files:
246
  If you encounter an error stating "more than one weights file", you need to specify the exact weight file name in the "LoRA Weight Name" field.
247
  You can find this by browsing the repository on Hugging Face and looking for the safetensors files (common names include: adapter_model.safetensors, pytorch_lora_weights.safetensors).
 
5
  from diffusers import AutoencoderKLWan, WanPipeline
6
  from diffusers.schedulers.scheduling_unipc_multistep import UniPCMultistepScheduler
7
  from diffusers.schedulers.scheduling_flow_match_euler_discrete import FlowMatchEulerDiscreteScheduler
8
+ import os
9
+ import tempfile
10
 
11
  # Define model options
12
  MODEL_OPTIONS = {
 
35
  num_frames,
36
  guidance_scale,
37
  num_inference_steps,
38
+ output_fps,
39
+ # Second pass parameters
40
+ enable_second_pass,
41
+ second_pass_scale,
42
+ second_pass_denoise,
43
+ second_pass_flow_shift,
44
+ second_pass_cfg,
45
+ show_both_outputs
46
  ):
47
  # Get model ID from selection
48
  model_id = MODEL_OPTIONS[model_choice]
 
85
  # Enable CPU offload for low VRAM
86
  pipe.enable_model_cpu_offload()
87
 
88
+ # Keep track of output files for return
89
+ output_files = []
90
+
91
+ # First pass - generate base video
92
+ print("Running first pass...")
93
+ first_pass = pipe(
94
  prompt=prompt,
95
  negative_prompt=negative_prompt,
96
  height=height,
97
  width=width,
98
  num_frames=num_frames,
99
  guidance_scale=guidance_scale,
100
+ num_inference_steps=num_inference_steps,
101
+ output_type="latent" if enable_second_pass else "pt", # Only return latents if doing second pass
102
+ return_dict=True
103
+ )
104
 
105
+ # Get the latents from the first pass output
106
+ latents = first_pass.frames[0]
107
+
108
+ # If we're not doing a second pass or need to display both outputs, decode the first pass
109
+ if not enable_second_pass or (enable_second_pass and show_both_outputs):
110
+ # Decode the latents to frames with the VAE (only needed if we requested latents)
111
+ if enable_second_pass:
112
+ print("Decoding first pass latents...")
113
+ with torch.no_grad():
114
+ first_pass_frames = pipe.vae.decode(latents / pipe.vae.config.scaling_factor).sample
115
+ else:
116
+ first_pass_frames = latents
117
+
118
+ # Export first pass to video
119
+ first_pass_file = "output_first_pass.mp4"
120
+ export_to_video(first_pass_frames, first_pass_file, fps=output_fps)
121
+ output_files.append(first_pass_file)
122
+
123
+ # Second pass - upscale and refine if enabled
124
+ second_pass_file = None
125
+ if enable_second_pass:
126
+ print("Running second pass with scale factor:", second_pass_scale)
127
+
128
+ # Resize latents for second pass (upscale)
129
+ new_height = int(height * second_pass_scale)
130
+ new_width = int(width * second_pass_scale)
131
+
132
+ # Ensure dimensions are multiples of 8
133
+ new_height = (new_height // 8) * 8
134
+ new_width = (new_width // 8) * 8
135
+
136
+ print(f"Upscaling latents from {height}x{width} to {new_height}x{new_width}")
137
+
138
+ # Upscale latents using interpolate
139
+ upscaled_latents = torch.nn.functional.interpolate(
140
+ latents,
141
+ size=(num_frames, new_height // 8, new_width // 8), # VAE downsamples by factor of 8
142
+ mode="trilinear",
143
+ align_corners=False
144
+ )
145
+
146
+ # Update scheduler for second pass if using different flow shift
147
+ if scheduler_type == "UniPCMultistepScheduler":
148
+ pipe.scheduler = UniPCMultistepScheduler.from_config(
149
+ pipe.scheduler.config,
150
+ flow_shift=second_pass_flow_shift
151
+ )
152
+ else:
153
+ pipe.scheduler = FlowMatchEulerDiscreteScheduler(shift=second_pass_flow_shift)
154
+
155
+ # Calculate noise level for partial denoising
156
+ # For noise scheduler, 0 means no noise (final step) and 1 means full noise (first step)
157
+ # So we convert our denoise strength to a timestep in the schedule
158
+ start_step = int(second_pass_denoise * num_inference_steps)
159
+
160
+ # Run second pass with the upscaled latents and partial denoising
161
+ print(f"Denoising from step {start_step} of {num_inference_steps} (denoise strength: {second_pass_denoise})")
162
+
163
+ # Use the second pass CFG value
164
+ second_pass_guidance = second_pass_cfg if second_pass_cfg > 0 else guidance_scale
165
+
166
+ second_pass = pipe(
167
+ prompt=prompt,
168
+ negative_prompt=negative_prompt,
169
+ height=new_height,
170
+ width=new_width,
171
+ num_frames=num_frames,
172
+ guidance_scale=second_pass_guidance,
173
+ num_inference_steps=num_inference_steps,
174
+ latents=upscaled_latents, # Use the upscaled latents
175
+ strength=second_pass_denoise, # Partial denoising
176
+ output_type="pt",
177
+ return_dict=True
178
+ )
179
+
180
+ # Export second pass to video
181
+ second_pass_file = "output_second_pass.mp4"
182
+ export_to_video(second_pass.frames[0], second_pass_file, fps=output_fps)
183
+ output_files.append(second_pass_file)
184
 
185
+ # Return the appropriate video output(s)
186
+ if enable_second_pass and not show_both_outputs:
187
+ return second_pass_file
188
+ elif enable_second_pass and show_both_outputs:
189
+ return [first_pass_file, second_pass_file]
190
+ else:
191
+ return first_pass_file
192
 
193
  # Create the Gradio interface
194
  with gr.Blocks() as demo:
195
  gr.HTML("""
196
  <p align="center">
197
  <svg version="1.1" viewBox="0 0 1200 295" xmlns="http://www.w3.org/2000/svg" xmlns:v="https://vecta.io/nano" width="400">
198
+ ...
199
  </svg>
200
  <p align="center">
201
  💻 <a href="https://www.markury.dev/"><b>Website</b></a> &nbsp&nbsp | &nbsp&nbsp 🤗 <a href="https://huggingface.co/markury"><b>Hugging Face</b></a> &nbsp&nbsp | &nbsp&nbsp 💿 <a href="https://thebulge.xyz"><b>Discord</b></a>
202
  </p>
203
  """)
204
+ gr.Markdown("# Wan 2.1 T2V 1.3B with LoRA and Second Pass Refinement")
205
 
206
  with gr.Row():
207
  with gr.Column(scale=1):
 
306
  step=1
307
  )
308
 
309
+ # Add Second Pass options
310
+ with gr.Accordion("Second Pass Refinement (HiresFix)", open=False):
311
+ enable_second_pass = gr.Checkbox(
312
+ label="Enable Second Pass Refinement",
313
+ value=False,
314
+ info="Scale up and refine the video with a second denoising pass"
315
+ )
316
+
317
+ with gr.Row():
318
+ second_pass_scale = gr.Slider(
319
+ label="Scale Factor",
320
+ minimum=1.0,
321
+ maximum=2.0,
322
+ value=1.25,
323
+ step=0.05,
324
+ info="How much to upscale the video for refinement"
325
+ )
326
+ second_pass_denoise = gr.Slider(
327
+ label="Denoise Strength",
328
+ minimum=0.1,
329
+ maximum=1.0,
330
+ value=0.6,
331
+ step=0.05,
332
+ info="Lower values preserve more of the original details"
333
+ )
334
+
335
+ with gr.Row():
336
+ second_pass_flow_shift = gr.Slider(
337
+ label="Second Pass Flow Shift",
338
+ minimum=1.0,
339
+ maximum=12.0,
340
+ value=3.0,
341
+ step=0.5,
342
+ info="Flow shift value for the second pass (optional)"
343
+ )
344
+ second_pass_cfg = gr.Slider(
345
+ label="Second Pass CFG",
346
+ minimum=0.0,
347
+ maximum=15.0,
348
+ value=0.0,
349
+ step=0.5,
350
+ info="Set to 0 to use the same value as first pass"
351
+ )
352
+
353
+ show_both_outputs = gr.Checkbox(
354
+ label="Show Both Outputs",
355
+ value=False,
356
+ info="Display both original and refined videos"
357
+ )
358
+
359
  generate_btn = gr.Button("Generate Video")
360
 
361
  with gr.Column(scale=1):
362
+ # Updated output to handle multiple videos if both outputs are selected
363
+ with gr.Group():
364
+ output_video = gr.Video(label="Generated Video")
365
+ second_output_video = gr.Video(label="Second Pass Video", visible=False)
366
+
367
+ # Show/hide second video based on checkbox
368
+ def update_second_video_visibility(enable_pass, show_both):
369
+ return {"visible": enable_pass and show_both}
370
+
371
+ enable_second_pass.change(
372
+ fn=update_second_video_visibility,
373
+ inputs=[enable_second_pass, show_both_outputs],
374
+ outputs=[second_output_video]
375
+ )
376
+
377
+ show_both_outputs.change(
378
+ fn=update_second_video_visibility,
379
+ inputs=[enable_second_pass, show_both_outputs],
380
+ outputs=[second_output_video]
381
+ )
382
 
383
+ # Updated function to handle the second pass and multiple outputs
384
+ def process_generation(*args):
385
+ result = generate_video(*args)
386
+ if isinstance(result, list) and len(result) > 1:
387
+ return [result[0], result[1], {"visible": True}]
388
+ elif isinstance(result, list) and len(result) == 1:
389
+ return [result[0], None, {"visible": False}]
390
+ else:
391
+ return [result, None, {"visible": False}]
392
+
393
  generate_btn.click(
394
+ fn=process_generation,
395
  inputs=[
396
  model_choice,
397
  prompt,
 
406
  num_frames,
407
  guidance_scale,
408
  num_inference_steps,
409
+ output_fps,
410
+ # Second pass parameters
411
+ enable_second_pass,
412
+ second_pass_scale,
413
+ second_pass_denoise,
414
+ second_pass_flow_shift,
415
+ second_pass_cfg,
416
+ show_both_outputs
417
  ],
418
+ outputs=[
419
+ output_video,
420
+ second_output_video,
421
+ second_output_video # Update visibility
422
+ ]
423
  )
424
 
425
  gr.Markdown("""
 
429
  - Number of frames should be of the form 4k+1 (e.g., 33, 81)
430
  - Stick to lower frame counts. Even at 480p, an 81 frame sequence at 30 steps will nearly time out the request in this space.
431
 
432
+ ## Second Pass Refinement Tips:
433
+ - The second pass (similar to HiresFix) can enhance details by upscaling and refining the video
434
+ - Start with a scale factor around 1.25 and denoise strength of 0.6
435
+ - Lower denoise values preserve more of the original video structure
436
+ - The second pass will increase generation time substantially - use with caution!
437
+
438
  ## Using LoRAs with multiple safetensors files:
439
  If you encounter an error stating "more than one weights file", you need to specify the exact weight file name in the "LoRA Weight Name" field.
440
  You can find this by browsing the repository on Hugging Face and looking for the safetensors files (common names include: adapter_model.safetensors, pytorch_lora_weights.safetensors).