Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

animation fix #614

Merged
merged 2 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions exo/apputil/anim.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import numpy as np
import cv2
import sys

def draw_rounded_rectangle(draw, coords, radius, fill):
left, top, right, bottom = coords
Expand Down Expand Up @@ -80,14 +81,20 @@ def create_animation_mp4(
font = ImageFont.load_default()
promptfont = ImageFont.load_default()

# Get the base directory for images when running as a bundled app
if hasattr(sys, '_MEIPASS'):
base_dir = os.path.join(sys._MEIPASS, "exo", "apputil", "baseimages")
else:
base_dir = os.path.join(os.path.dirname(__file__), "baseimages")

# Process first frame
base_img = Image.open(os.path.join(os.path.dirname(__file__), "baseimages", "image1.png"))
base_img = Image.open(os.path.join(base_dir, "image1.png"))
draw = ImageDraw.Draw(base_img)
draw_centered_text_rounded(draw, device_name, font, device_coords)
frames.extend([crop_image(base_img)] * 30) # 1 second at 30fps

# Process second frame with typing animation
base_img2 = Image.open(os.path.join(os.path.dirname(__file__), "baseimages", "image2.png"))
base_img2 = Image.open(os.path.join(base_dir, "image2.png"))
for i in range(len(prompt_text) + 1):
current_frame = base_img2.copy()
draw = ImageDraw.Draw(current_frame)
Expand All @@ -101,7 +108,7 @@ def create_animation_mp4(

# Create blur sequence
replacement_img = Image.open(replacement_image_path)
base_img = Image.open(os.path.join(os.path.dirname(__file__), "baseimages", "image3.png"))
base_img = Image.open(os.path.join(base_dir, "image3.png"))
blur_steps = [int(80 * (1 - i/8)) for i in range(9)]

for i, blur_amount in enumerate(blur_steps):
Expand All @@ -123,7 +130,7 @@ def create_animation_mp4(
frames.extend([crop_image(new_frame)] * 15) # 0.5 seconds at 30fps

# Create and add final frame (image4)
final_base = Image.open(os.path.join(os.path.dirname(__file__), "baseimages", "image4.png"))
final_base = Image.open(os.path.join(base_dir, "image4.png"))
draw = ImageDraw.Draw(final_base)

draw_centered_text_rounded(draw, device_name, font, device_coords)
Expand Down Expand Up @@ -158,4 +165,4 @@ def create_animation_mp4(
out.write(frame_array)

out.release()
print(f"Video saved successfully to {output_path}")
print(f"Video saved successfully to {output_path}")
6 changes: 5 additions & 1 deletion scripts/build_exo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

def run():
site_packages = site.getsitepackages()[0]
base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
baseimages_dir = os.path.join(base_dir, "exo", "apputil", "baseimages")

command = [
f"{sys.executable}", "-m", "nuitka", "exo/main.py",
"--company-name=exolabs",
Expand All @@ -15,7 +18,8 @@ def run():
"--standalone",
"--output-filename=exo",
"--python-flag=no_site",
"--onefile"
"--onefile",
f"--include-data-dir={baseimages_dir}=exo/apputil/baseimages"
]

if sys.platform == "darwin":
Expand Down