-
Notifications
You must be signed in to change notification settings - Fork 1
/
singleframegen.py
58 lines (43 loc) · 1.2 KB
/
singleframegen.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
57
import os
from lumaai import LumaAI
import time
import requests
from dotenv import load_dotenv
load_dotenv()
# ------------------------------
# Configuration
# ------------------------------
LUMA_API_KEY = os.getenv("LUMA_API_KEY")
client = LumaAI(
auth_token=LUMA_API_KEY,
)
# Create a generation
generation = client.generations.create(
prompt="Cyborg doing a backflip",
keyframes={
"frame1": {
"type": "image",
"url": "https://sigil.b-cdn.net/cyborgb.jpeg"
}
}
)
# Get the generation ID
generation_id = generation.id
video_url = ""
print("Waiting for video generation...")
while True:
generation = client.generations.get(id=generation_id)
if generation.assets != None:
if generation.assets.video != None:
video_url = generation.assets.video
print(generation)
break
time.sleep(5) # Wait for 5 seconds before checking again
print("Polling Again")
print("Video generated. Downloading...")
print(video_url)
response = requests.get(video_url, stream=True)
file_name = f"luma_video_{generation_id}.mp4"
with open(file_name, 'wb') as file:
file.write(response.content)
print(f"Video downloaded as {file_name}")