antonelli commited on
Commit
d7ba2ea
·
1 Parent(s): d1074e2
Files changed (1) hide show
  1. video_generator.py +18 -48
video_generator.py CHANGED
@@ -1,57 +1,27 @@
1
- from stability_sdk import api
2
- from stability_sdk.animation import AnimationArgs, Animator
3
 
4
- STABILITY_HOST = "grpc.stability.ai:443"
5
- STABILITY_KEY = "sk-7ApKEBZKcV1uOPQTWLyihtqaBXxV7iRdbM6rNlxRZSEPHzaj" # API key from https://platform.stability.ai/account/keys
6
- context = api.Context(STABILITY_HOST, STABILITY_KEY)
 
7
 
8
- def generate_video(prompt, last_frame_image, max_frames=48):
9
- # Configure the animation
10
- args = AnimationArgs()
11
- args.interpolate_prompts = True
12
- args.locked_seed = True
13
- args.max_frames = max_frames
14
- args.seed = 42
15
- args.strength_curve = "0:(0)"
16
- args.diffusion_cadence_curve = "0:(4)"
17
- args.cadence_interp = "film"
18
 
19
- animation_prompts = {
20
- 0: prompt,
21
- max_frames//2: prompt # Repeat the same prompt for the middle frame
22
- }
23
- negative_prompt = ""
24
 
25
- # Create Animator object to orchestrate the rendering
26
- animator = Animator(
27
- api_context=context,
28
- animation_prompts=animation_prompts,
29
- negative_prompt=negative_prompt,
30
- args=args
31
- )
32
 
33
  frames = []
34
- # Render each frame of animation
35
- for idx, frame in enumerate(animator.render()):
36
- frame_path = f"frame_{idx:05d}.png"
37
- frame.save(frame_path)
38
- frames.append(frame_path)
39
-
40
- # Combine frames into a video (replace with your preferred method)
41
- video = combine_frames_into_video(frames)
42
-
43
- return video
44
-
45
- def extract_last_frame(video):
46
- # Extract the last frame from the video (replace with your preferred method)
47
- last_frame_image = extract_last_frame_from_video(video)
48
-
49
- return last_frame_image
50
-
51
- def combine_frames_into_video(frames):
52
- # Your code to combine the frames into a video
53
- video = None # Replace with actual video object
54
- return video
55
 
56
  def extract_last_frame_from_video(video):
57
  # Your code to extract the last frame from the video
 
1
+ from PIL import Image, ImageDraw, ImageFont
 
2
 
3
+ def generate_lyric_frame(text, image_size):
4
+ # Create an image object
5
+ image = Image.new('RGB', image_size, color='black')
6
+ draw = ImageDraw.Draw(image)
7
 
8
+ # Define font and text alignment
9
+ font = ImageFont.load_default()
10
+ text_width, text_height = draw.textsize(text, font=font)
11
+ text_x = (image_size[0] - text_width) / 2
12
+ text_y = (image_size[1] - text_height) / 2
 
 
 
 
 
13
 
14
+ # Draw the text on the image
15
+ draw.text((text_x, text_y), text, font=font, fill='white')
16
+ return image
 
 
17
 
18
+ def generate_video(lyrics_with_timing, image_size=(800, 600), max_frames=48):
19
+ # Placeholder for configuring the animation
20
+ # ...
 
 
 
 
21
 
22
  frames = []
23
+ for start_time, end_time, lyric in lyrics_with_timing:
24
+ # Calculate the number of frames for this lyric segment
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
  def extract_last_frame_from_video(video):
27
  # Your code to extract the last frame from the video