multimodalart HF staff commited on
Commit
294a061
1 Parent(s): aeacc98

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -31
app.py CHANGED
@@ -63,7 +63,7 @@ model, filter = load_model(
63
  )
64
 
65
  def sample(
66
- image: Image.Image,
67
  num_frames: Optional[int] = 25,
68
  num_steps: Optional[int] = 30,
69
  version: str = "svd_xt",
@@ -255,36 +255,36 @@ def get_batch(keys, value_dict, N, T, device):
255
 
256
  import gradio as gr
257
  import uuid
258
- def resize_image(image, output_size=(1024, 576)):
259
-
260
- # Calculate aspect ratios
261
- target_aspect = output_size[0] / output_size[1] # Aspect ratio of the desired size
262
- image_aspect = image.width / image.height # Aspect ratio of the original image
263
-
264
- # Resize then crop if the original image is larger
265
- if image_aspect > target_aspect:
266
- # Resize the image to match the target height, maintaining aspect ratio
267
- new_height = output_size[1]
268
- new_width = int(new_height * image_aspect)
269
- resized_image = image.resize((new_width, new_height), Image.Resampling.LANCZOS)
270
- # Calculate coordinates for cropping
271
- left = (new_width - output_size[0]) / 2
272
- top = 0
273
- right = (new_width + output_size[0]) / 2
274
- bottom = output_size[1]
275
- else:
276
- # Resize the image to match the target width, maintaining aspect ratio
277
- new_width = output_size[0]
278
- new_height = int(new_width / image_aspect)
279
- resized_image = image.resize((new_width, new_height), Image.Resampling.LANCZOS)
280
- # Calculate coordinates for cropping
281
- left = 0
282
- top = (new_height - output_size[1]) / 2
283
- right = output_size[0]
284
- bottom = (new_height + output_size[1]) / 2
285
-
286
- # Crop the image
287
- cropped_image = resized_image.crop((left, top, right, bottom))
288
 
289
  return cropped_image
290
 
 
63
  )
64
 
65
  def sample(
66
+ image: str,
67
  num_frames: Optional[int] = 25,
68
  num_steps: Optional[int] = 30,
69
  version: str = "svd_xt",
 
255
 
256
  import gradio as gr
257
  import uuid
258
+ def resize_image(image_path, output_size=(1024, 576)):
259
+ with Image.open(image_path) as image:
260
+ # Calculate aspect ratios
261
+ target_aspect = output_size[0] / output_size[1] # Aspect ratio of the desired size
262
+ image_aspect = image.width / image.height # Aspect ratio of the original image
263
+
264
+ # Resize then crop if the original image is larger
265
+ if image_aspect > target_aspect:
266
+ # Resize the image to match the target height, maintaining aspect ratio
267
+ new_height = output_size[1]
268
+ new_width = int(new_height * image_aspect)
269
+ resized_image = image.resize((new_width, new_height), Image.Resampling.LANCZOS)
270
+ # Calculate coordinates for cropping
271
+ left = (new_width - output_size[0]) / 2
272
+ top = 0
273
+ right = (new_width + output_size[0]) / 2
274
+ bottom = output_size[1]
275
+ else:
276
+ # Resize the image to match the target width, maintaining aspect ratio
277
+ new_width = output_size[0]
278
+ new_height = int(new_width / image_aspect)
279
+ resized_image = image.resize((new_width, new_height), Image.Resampling.LANCZOS)
280
+ # Calculate coordinates for cropping
281
+ left = 0
282
+ top = (new_height - output_size[1]) / 2
283
+ right = output_size[0]
284
+ bottom = (new_height + output_size[1]) / 2
285
+
286
+ # Crop the image
287
+ cropped_image = resized_image.crop((left, top, right, bottom))
288
 
289
  return cropped_image
290