Spaces:
Runtime error
Runtime error
Commit Β·
294a061
1
Parent(s): aeacc98
Update app.py
Browse files62 unmodified lines63646566676869185 unmodified lines25525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929062 unmodified lines)def sample(image: Image.Image,num_frames: Optional[int] = 25,num_steps: Optional[int] = 30,version: str = "svd_xt",185 unmodified linesimport gradio as grimport uuiddef resize_image(image, output_size=(1024, 576)):# Calculate aspect ratiostarget_aspect = output_size[0] / output_size[1] # Aspect ratio of the desired sizeimage_aspect = image.width / image.height # Aspect ratio of the original image# Resize then crop if the original image is largerif image_aspect > target_aspect:# Resize the image to match the target height, maintaining aspect rationew_height = output_size[1]new_width = int(new_height * image_aspect)resized_image = image.resize((new_width, new_height), Image.Resampling.LANCZOS)# Calculate coordinates for croppingleft = (new_width - output_size[0]) / 2top = 0right = (new_width + output_size[0]) / 2bottom = output_size[1]else:# Resize the image to match the target width, maintaining aspect rationew_width = output_size[0]new_height = int(new_width / image_aspect)resized_image = image.resize((new_width, new_height), Image.Resampling.LANCZOS)# Calculate coordinates for croppingleft = 0top = (new_height - output_size[1]) / 2right = output_size[0]bottom = (new_height + output_size[1]) / 2# Crop the imagecropped_image = resized_image.crop((left, top, right, bottom))return cropped_image62 unmodified lines63646566676869185 unmodified lines25525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929062 unmodified lines)def sample(image: str,num_frames: Optional[int] = 25,num_steps: Optional[int] = 30,version: str = "svd_xt",185 unmodified linesimport gradio as grimport uuiddef resize_image(image_path, output_size=(1024, 576)):with Image.open(image_path) as image:# Calculate aspect ratiostarget_aspect = output_size[0] / output_size[1] # Aspect ratio of the desired sizeimage_aspect = image.width / image.height # Aspect ratio of the original image# Resize then crop if the original image is largerif image_aspect > target_aspect:# Resize the image to match the target height, maintaining aspect rationew_height = output_size[1]new_width = int(new_height * image_aspect)resized_image = image.resize((new_width, new_height), Image.Resampling.LANCZOS)# Calculate coordinates for croppingleft = (new_width - output_size[0]) / 2top = 0right = (new_width + output_size[0]) / 2bottom = output_size[1]else:# Resize the image to match the target width, maintaining aspect rationew_width = output_size[0]new_height = int(new_width / image_aspect)resized_image = image.resize((new_width, new_height), Image.Resampling.LANCZOS)# Calculate coordinates for croppingleft = 0top = (new_height - output_size[1]) / 2right = output_size[0]bottom = (new_height + output_size[1]) / 2# Crop the imagecropped_image = resized_image.crop((left, top, right, bottom))return cropped_image
app.py+31-31