Spaces:
Runtime error
Runtime error
zfff
Browse files- video_generator.py +18 -48
video_generator.py
CHANGED
|
@@ -1,57 +1,27 @@
|
|
| 1 |
-
from
|
| 2 |
-
from stability_sdk.animation import AnimationArgs, Animator
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
|
|
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 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 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
}
|
| 23 |
-
negative_prompt = ""
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
animation_prompts=animation_prompts,
|
| 29 |
-
negative_prompt=negative_prompt,
|
| 30 |
-
args=args
|
| 31 |
-
)
|
| 32 |
|
| 33 |
frames = []
|
| 34 |
-
|
| 35 |
-
|
| 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
|