cbensimon HF Staff commited on
Commit
23723da
·
verified ·
1 Parent(s): dcc178a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -5
app.py CHANGED
@@ -27,12 +27,12 @@ MULTIPLE_OF = 16
27
  MAX_SEED = np.iinfo(np.int32).max
28
 
29
  FIXED_FPS = 16
30
- MIN_FRAMES_MODEL = 9
31
- MAX_FRAMES_MODEL = 121
32
 
 
33
  MIN_DURATION = round(MIN_FRAMES_MODEL/FIXED_FPS,1)
34
  MAX_DURATION = round(MAX_FRAMES_MODEL/FIXED_FPS,1)
35
- DEFAULT_DURATION = 5.1
36
 
37
 
38
  pipe = WanImageToVideoPipeline.from_pretrained(MODEL_ID,
@@ -123,6 +123,14 @@ def resize_image(image: Image.Image) -> Image.Image:
123
  return image_to_resize.resize((final_w, final_h), Image.LANCZOS)
124
 
125
 
 
 
 
 
 
 
 
 
126
  def get_duration(
127
  input_image,
128
  prompt,
@@ -135,7 +143,13 @@ def get_duration(
135
  randomize_seed,
136
  progress,
137
  ):
138
- return int(steps) * 15
 
 
 
 
 
 
139
 
140
  @spaces.GPU(duration=get_duration)
141
  def generate_video(
@@ -193,7 +207,7 @@ def generate_video(
193
  if input_image is None:
194
  raise gr.Error("Please upload an input image.")
195
 
196
- num_frames = np.clip(int(round(duration_seconds * FIXED_FPS)), MIN_FRAMES_MODEL, MAX_FRAMES_MODEL)
197
  current_seed = random.randint(0, MAX_SEED) if randomize_seed else int(seed)
198
  resized_image = resize_image(input_image)
199
 
 
27
  MAX_SEED = np.iinfo(np.int32).max
28
 
29
  FIXED_FPS = 16
30
+ MIN_FRAMES_MODEL = 8
31
+ MAX_FRAMES_MODEL = 120
32
 
33
+ DEFAULT_DURATION = 5.0
34
  MIN_DURATION = round(MIN_FRAMES_MODEL/FIXED_FPS,1)
35
  MAX_DURATION = round(MAX_FRAMES_MODEL/FIXED_FPS,1)
 
36
 
37
 
38
  pipe = WanImageToVideoPipeline.from_pretrained(MODEL_ID,
 
123
  return image_to_resize.resize((final_w, final_h), Image.LANCZOS)
124
 
125
 
126
+ def get_num_frames(duration_seconds: float):
127
+ return 1 + int(np.clip(
128
+ int(round(duration_seconds * FIXED_FPS)),
129
+ MIN_FRAMES_MODEL,
130
+ MAX_FRAMES_MODEL,
131
+ ))
132
+
133
+
134
  def get_duration(
135
  input_image,
136
  prompt,
 
143
  randomize_seed,
144
  progress,
145
  ):
146
+ BASE_FRAMES_HEIGHT_WIDTH = 81 * 832 * 624
147
+ BASE_STEP_DURATION = 15
148
+ width, height = input_image.size
149
+ frames = get_num_frames(duration_seconds)
150
+ factor = frames * width * height / BASE_FRAMES_HEIGHT_WIDTH
151
+ step_duration = BASE_STEP_DURATION * factor ** 1.5
152
+ return 10 + int(steps) * step_duration
153
 
154
  @spaces.GPU(duration=get_duration)
155
  def generate_video(
 
207
  if input_image is None:
208
  raise gr.Error("Please upload an input image.")
209
 
210
+ num_frames = get_num_frames(duration_seconds)
211
  current_seed = random.randint(0, MAX_SEED) if randomize_seed else int(seed)
212
  resized_image = resize_image(input_image)
213