Skip to content

Commit f6bdf4c

Browse files
committed
update requirements and video_actions zoom
1 parent 8f6e8c1 commit f6bdf4c

File tree

4 files changed

+82
-46
lines changed

4 files changed

+82
-46
lines changed

‎logs/logs.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Running on local URL: http://127.0.0.1:7860
2+
3+
To create a public link, set `share=True` in `launch()`.
4+
action: create_image(args={"prompt":"a scary monster surrounded by happy children carrying a sign with a positive affirmation","model":"dall-e-3","size":"1024x1024","quality":"standard"}) -> a_scary_monster_surrounded_by_happy_children_carry.png
5+
assistant > Moviepy - Building video assistants_working_folder\monster_zoom.mp4.
6+
Moviepy - Writing video assistants_working_folder\monster_zoom.mp4
7+
8+
Moviepy - Done !
9+
Moviepy - video ready assistants_working_folder\monster_zoom.mp4
10+
action: zoom_to(args={"image_filename":"a_scary_monster_surrounded_by_happy_children_carry.png","output_filename":"monster_zoom.mp4","duration":"10","zoom_factor_from":"2.0","zoom_factor_to":"1.0","zoom_start_position":"(0.5, 0.2)","zoom_end_position":"(0.5, 0.5)"}) -> monster_zoom.mp4
11+
assistant > MoviePy - Building file assistants_working_folder\monster_zoom.gif with imageio.
12+
action: create_gif_from_clip(args={"clip_filename":"monster_zoom.mp4","size":"512x512","fps":"15"}) -> GIF created: monster_zoom.gif
13+
assistant >

‎playground/assistant_actions/video_actions.py

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -109,38 +109,76 @@ def zoom(image, zoom_factor, center=None):
109109
return resized
110110

111111

112+
# def zoom(image, factor, center):
113+
# height, width, _ = image.shape
114+
# if center is None:
115+
# center = (width // 2, height // 2)
116+
117+
# x, y = center
118+
# new_width = int(width / factor)
119+
# new_height = int(height / factor)
120+
# left = max(0, x - new_width // 2)
121+
# right = min(width, x + new_width // 2)
122+
# top = max(0, y - new_height // 2)
123+
# bottom = min(height, y + new_height // 2)
124+
# cropped_image = image[top:bottom, left:right]
125+
# resized_image = cv2.resize(cropped_image, (width, height), interpolation=cv2.INTER_LINEAR)
126+
# return resized_image
127+
128+
112129
@agent_action
113-
def zoom_at(
114-
image_filename, duration, zoom_factor, output_filename, center=None, fps=30
130+
def zoom_to(
131+
image_filename,
132+
output_filename,
133+
duration,
134+
zoom_factor_from,
135+
zoom_factor_to,
136+
zoom_start_position,
137+
zoom_end_position,
138+
fps=30,
115139
):
116140
"""
117141
Creates a zoom-in video clip from an image.
118142
119143
Args:
120144
image_filename (str): Path to the input image.
121-
duration (int): Duration of the video in seconds.
122-
zoom_factor (float): Maximum zoom factor.
123145
output_filename (str): Path to save the output video.
124-
center (tuple, optional): Center point for zooming. Defaults to image center, is in pixels (512, 512) or as a ratio (0.5, 0.5).
146+
duration (int): Duration of the video in seconds.
147+
zoom_factor_from (float): Starting zoom factor.
148+
zoom_factor_to (float): Ending zoom factor.
149+
zoom_start_position (tuple): Starting center point for zooming.
150+
zoom_end_position (tuple): Ending center point for zooming.
125151
fps (int): Frames per second. Defaults to 30.
126152
127153
Returns:
128154
str: Path to the saved video clip.
129155
"""
130-
zoom_factor = float(zoom_factor)
156+
zoom_factor_from = float(zoom_factor_from)
157+
zoom_factor_to = float(zoom_factor_to)
131158
duration = int(duration)
132159
fps = int(fps)
133160
image_path = os.path.join(GlobalValues.ASSISTANTS_WORKING_FOLDER, image_filename)
134161
image = cv2.imread(image_path)
135162
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
136163
height, width, _ = image.shape
137164
image_dim = (width, height)
138-
if center:
139-
center = convert_and_validate(center, image_dim)
165+
if zoom_start_position:
166+
zoom_start_position = convert_and_validate(zoom_start_position, image_dim)
167+
if zoom_end_position:
168+
zoom_end_position = convert_and_validate(zoom_end_position, image_dim)
140169

141170
def make_frame(t):
142171
frame_num = int(t * fps)
143-
factor = 1 + (zoom_factor - 1) * frame_num / (fps * duration)
172+
factor = zoom_factor_from + (zoom_factor_to - zoom_factor_from) * frame_num / (
173+
fps * duration
174+
)
175+
center_x = zoom_start_position[0] + (
176+
zoom_end_position[0] - zoom_start_position[0]
177+
) * frame_num / (fps * duration)
178+
center_y = zoom_start_position[1] + (
179+
zoom_end_position[1] - zoom_start_position[1]
180+
) * frame_num / (fps * duration)
181+
center = (int(center_x), int(center_y))
144182
return zoom(image, factor, center)
145183

146184
clip = VideoClip(make_frame, duration=duration)
@@ -227,43 +265,6 @@ def make_frame(t):
227265
return output_filename
228266

229267

230-
@agent_action
231-
def zoom_from(
232-
image_filename, duration, zoom_factor, output_filename, center=None, fps=30
233-
):
234-
"""
235-
Creates a zoom-out video clip from an image.
236-
237-
Args:
238-
image_filename (str): Path to the input image.
239-
duration (int): Duration of the video in seconds.
240-
zoom_factor (float): Initial zoom factor.
241-
output_filename (str): Path to save the output video.
242-
center (tuple, optional): Center point for zooming. Defaults to image center, is in pixels (512, 512) or as a ratio (0.5, 0.5).
243-
fps (int): Frames per second. Defaults to 30.
244-
245-
Returns:
246-
str: Path to the saved video clip.
247-
"""
248-
duration = int(duration)
249-
zoom_factor = float(zoom_factor)
250-
fps = int(fps)
251-
image_path = os.path.join(GlobalValues.ASSISTANTS_WORKING_FOLDER, image_filename)
252-
image = cv2.imread(image_path)
253-
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
254-
height, width, _ = image.shape
255-
256-
def make_frame(t):
257-
frame_num = int(t * fps)
258-
factor = zoom_factor - (zoom_factor - 1) * frame_num / (fps * duration)
259-
return zoom(image, factor, center)
260-
261-
clip = VideoClip(make_frame, duration=duration)
262-
output_path = os.path.join(GlobalValues.ASSISTANTS_WORKING_FOLDER, output_filename)
263-
clip.write_videofile(output_path, fps=fps)
264-
return output_filename
265-
266-
267268
@agent_action
268269
def boom_to(
269270
image_filename, duration, start_center, end_center, output_filename, fps=30

‎playground/global_values.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import os
2+
3+
14
class GlobalValues:
25
ASSISTANTS_WORKING_FOLDER = "assistants_working_folder"
36

@@ -14,3 +17,18 @@ def get_value(cls, var_name):
1417
return getattr(cls, var_name)
1518
else:
1619
raise AttributeError(f"{var_name} not found in GlobalValues")
20+
21+
22+
# Configure globals
23+
class GlobalSetup:
24+
@staticmethod
25+
def setup_global_values():
26+
# Check and create directories
27+
working_folder = GlobalValues.get_value("ASSISTANTS_WORKING_FOLDER")
28+
if not os.path.exists(working_folder):
29+
os.makedirs(working_folder)
30+
print(f"Created folder: {working_folder}")
31+
32+
33+
# Example usage
34+
GlobalSetup.setup_global_values()

‎requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ python-dotenv
66
pytest
77
youtube-transcript-api
88
py-trees
9+
python-pptx
10+
markdown
11+
moviepy
12+
opencv-python

0 commit comments

Comments
 (0)