fffiloni commited on
Commit
28f4872
1 Parent(s): 38a65dc

Resize input image

Browse files
Files changed (1) hide show
  1. app_gradio.py +18 -0
app_gradio.py CHANGED
@@ -163,6 +163,24 @@ def generate_output(image, apply_filter, prompt: str, num_seeds: int = 3, lambda
163
 
164
  # Save the input image temporarily
165
  temp_image_path = os.path.join(exp_dir, "temp_input.png")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
  image.save(temp_image_path)
167
 
168
  # Generate the GIFs
 
163
 
164
  # Save the input image temporarily
165
  temp_image_path = os.path.join(exp_dir, "temp_input.png")
166
+
167
+ # Get original dimensions
168
+ width, height = image.size
169
+
170
+ # Step 1: Make the image square if it's not already
171
+ if width != height:
172
+ # Use the smaller dimension to crop to a square
173
+ min_dim = min(width, height)
174
+ left = (width - min_dim) // 2
175
+ top = (height - min_dim) // 2
176
+ right = left + min_dim
177
+ bottom = top + min_dim
178
+ image = image.crop((left, top, right, bottom))
179
+
180
+ # Step 2: Resize to 512x512 if the image is larger
181
+ if image.size[0] > 512: # Image is square at this point
182
+ image = image.resize((512, 512), Image.LANCZOS)
183
+
184
  image.save(temp_image_path)
185
 
186
  # Generate the GIFs