-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmovie.py
56 lines (39 loc) · 1.82 KB
/
movie.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import openai
from dalle_pytorch import dalle_v2
import io
import os
from google.cloud import texttospeech
from google.oauth2 import service_account
from moviepy.editor import *
def generate_movie(topic):
prompt = f"Create a movie script and image descriptions with the topic: {topic}. Use the format 'SCENE: <scene_description> IMAGE: <image_description>' for each scene."
response = openai.Completion.create(
engine="davinci-codex",
prompt=prompt,
max_tokens=2048,
n=1,
stop=None,
temperature=0.7,
)
text = response.choices[0].text.strip()
scenes = [{"scene": s.split(" IMAGE: ")[0].strip(), "image": s.split(" IMAGE: ")[1].strip()} for s in text.split("SCENE: ")[1:]]
# TODO: Initialize DALLE-2, Google Text-to-Speech and MoviePy
movie_clips = []
for scene in scenes:
# TODO: Generate image with DALLE-2 using scene['image'] as prompt
generated_image = generate_image_with_dalle(scene['image'])
# TODO: Generate voice with Google Text-to-Speech using scene['scene'] as input text
generated_voice = generate_voice_with_google_tts(scene['scene'])
# TODO: Create an AudioClip using the generated_voice
audio_clip = create_audio_clip_with_voice(generated_voice)
# TODO: Create a video slide with the generated_image and audio_clip
video_slide = create_video_slide(generated_image, audio_clip)
# Add the video slide to the movie_clips list
movie_clips.append(video_slide)
# Concatenate all movie clips
final_movie = concatenate_videoclips(movie_clips)
# TODO: Save and return the final movie file
movie_file = os.path.join("output", f"{topic}_movie.mp4")
final_movie.write_videofile(movie_file)
return movie_file
generate_movie("a dolphin befriending an octopus")