Lemonator commited on
Commit
7a5570e
Β·
verified Β·
1 Parent(s): 5117d6d

Update app_lora.py

Browse files
Files changed (1) hide show
  1. app_lora.py +29 -4
app_lora.py CHANGED
@@ -105,9 +105,9 @@ def get_duration(input_image, prompt, height, width,
105
 
106
  @spaces.GPU(duration=get_duration)
107
  def generate_video(input_image, prompt, height, width,
108
- negative_prompt=default_negative_prompt, duration_seconds = 2,
109
- guidance_scale = 1, steps = 4,
110
- seed = 42, randomize_seed = False,
111
  progress=gr.Progress(track_tqdm=True)):
112
 
113
  if input_image is None:
@@ -132,7 +132,32 @@ def generate_video(input_image, prompt, height, width,
132
 
133
  with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as tmpfile:
134
  video_path = tmpfile.name
135
- export_to_video(output_frames_list, video_path, fps=FIXED_FPS)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
  return video_path, current_seed
137
 
138
  with gr.Blocks() as demo:
 
105
 
106
  @spaces.GPU(duration=get_duration)
107
  def generate_video(input_image, prompt, height, width,
108
+ negative_prompt=default_negative_prompt, duration_seconds=2,
109
+ guidance_scale=1, steps=4,
110
+ seed=42, randomize_seed=False,
111
  progress=gr.Progress(track_tqdm=True)):
112
 
113
  if input_image is None:
 
132
 
133
  with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as tmpfile:
134
  video_path = tmpfile.name
135
+
136
+ # Use imageio as the preferred backend with optimized settings
137
+ export_to_video(
138
+ output_frames_list,
139
+ video_path,
140
+ fps=FIXED_FPS,
141
+ codec="libx264",
142
+ output_params=[
143
+ "-pix_fmt", "yuv420p", # Most compatible pixel format
144
+ "-movflags", "+faststart", # Enable streaming
145
+ "-profile:v", "main", # Broad compatibility profile
146
+ "-tune", "film" # Optimize for high quality video
147
+ ]
148
+ )
149
+
150
+ # Verify video can be read (basic sanity check)
151
+ try:
152
+ import imageio
153
+ with imageio.get_reader(video_path) as reader:
154
+ if len(reader) < 1: # Check if video has frames
155
+ raise ValueError("Empty video generated")
156
+ except Exception as e:
157
+ print(f"Video validation failed, regenerating: {str(e)}")
158
+ # Fallback to simple export if validation fails
159
+ export_to_video(output_frames_list, video_path, fps=FIXED_FPS)
160
+
161
  return video_path, current_seed
162
 
163
  with gr.Blocks() as demo: