Spaces:
Running
on
Zero
Running
on
Zero
Commit
•
e794908
1
Parent(s):
d1c7480
Update app.py
Browse files
app.py
CHANGED
@@ -171,34 +171,33 @@ def infer(image, width=1024, height=1024, overlap_width=18, num_inference_steps=
|
|
171 |
yield background, cnet_image
|
172 |
|
173 |
def create_zoom_animation(previous_frame, next_frame, steps):
|
174 |
-
|
175 |
# List to store all frames
|
176 |
interpolated_frames = []
|
177 |
|
178 |
-
for i in range(steps
|
179 |
-
t = i / steps # Normalized time between 0 and 1
|
180 |
|
181 |
# Compute zoom factor (from 1 to 2)
|
182 |
z = 1 + t # Zoom factor increases from 1 to 2
|
183 |
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
resized_frame =
|
198 |
else:
|
199 |
-
|
200 |
-
resized_frame =
|
201 |
-
|
202 |
interpolated_frames.append(resized_frame)
|
203 |
|
204 |
return interpolated_frames
|
@@ -251,15 +250,18 @@ def loop_outpainting(image, width=1024, height=1024, overlap_width=6, num_infere
|
|
251 |
|
252 |
# Create interpolated frames
|
253 |
final_frame_list = []
|
|
|
254 |
for i in range(len(reverse_image_list) - 1):
|
255 |
larger_frame = reverse_image_list[i]
|
256 |
smaller_frame = reverse_image_list[i + 1]
|
257 |
interpolated_frames = create_zoom_animation(larger_frame, smaller_frame, num_interpolation_frames)
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
|
|
|
|
263 |
|
264 |
# Create video from the final frame list
|
265 |
video_path = create_video_from_images(final_frame_list, fps)
|
|
|
171 |
yield background, cnet_image
|
172 |
|
173 |
def create_zoom_animation(previous_frame, next_frame, steps):
|
|
|
174 |
# List to store all frames
|
175 |
interpolated_frames = []
|
176 |
|
177 |
+
for i in range(steps):
|
178 |
+
t = i / (steps - 1) # Normalized time between 0 and 1
|
179 |
|
180 |
# Compute zoom factor (from 1 to 2)
|
181 |
z = 1 + t # Zoom factor increases from 1 to 2
|
182 |
|
183 |
+
if i < steps - 1:
|
184 |
+
# Compute crop size
|
185 |
+
crop_size = int(1024 / z)
|
186 |
+
|
187 |
+
# Compute crop coordinates to center the crop
|
188 |
+
x0 = (1024 - crop_size) // 2
|
189 |
+
y0 = (1024 - crop_size) // 2
|
190 |
+
x1 = x0 + crop_size
|
191 |
+
y1 = y0 + crop_size
|
192 |
+
|
193 |
+
# Crop the previous_frame
|
194 |
+
cropped_prev = previous_frame.crop((x0, y0, x1, y1))
|
195 |
+
# Resize to 512x512
|
196 |
+
resized_frame = cropped_prev.resize((512, 512), Image.LANCZOS)
|
197 |
else:
|
198 |
+
# For the last frame, use the next_frame resized to 512x512
|
199 |
+
resized_frame = next_frame.resize((512, 512), Image.LANCZOS)
|
200 |
+
|
201 |
interpolated_frames.append(resized_frame)
|
202 |
|
203 |
return interpolated_frames
|
|
|
250 |
|
251 |
# Create interpolated frames
|
252 |
final_frame_list = []
|
253 |
+
|
254 |
for i in range(len(reverse_image_list) - 1):
|
255 |
larger_frame = reverse_image_list[i]
|
256 |
smaller_frame = reverse_image_list[i + 1]
|
257 |
interpolated_frames = create_zoom_animation(larger_frame, smaller_frame, num_interpolation_frames)
|
258 |
+
|
259 |
+
if i == 0:
|
260 |
+
# Include all frames for the first sequence
|
261 |
+
final_frame_list.extend(interpolated_frames)
|
262 |
+
else:
|
263 |
+
# Exclude the first frame to avoid duplication
|
264 |
+
final_frame_list.extend(interpolated_frames[1:])
|
265 |
|
266 |
# Create video from the final frame list
|
267 |
video_path = create_video_from_images(final_frame_list, fps)
|