-
Notifications
You must be signed in to change notification settings - Fork 1
/
luma_generate.py
41 lines (32 loc) · 1.19 KB
/
luma_generate.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
import os
import time
from lumaai import LumaAI
import requests
import streamlit as st
def generate_video(session_id, prompt):
client = LumaAI(
auth_token=os.environ.get("LUMA_API_KEY"),
)
generation = client.generations.create(
prompt=prompt,
)
completed = False
with st.spinner(text=f"Status: Dreaming..."):
while not completed:
generation = client.generations.get(id=generation.id) # type: ignore
if generation.state == "completed":
completed = True
elif generation.state == "failed":
raise RuntimeError(f"Generation failed: {generation.failure_reason}")
# st.info(f"Status: {generation.state}")
print(f"Status: {generation.state}")
time.sleep(3)
st.success(f"Status: {generation.state}")
video_url = generation.assets.video # type: ignore
# download the video
response = requests.get(video_url, stream=True) # type: ignore
file_path = f"stories/{session_id}/{generation.id}.mp4"
with open(file_path, "wb") as file:
file.write(response.content)
print(f"File downloaded as {generation.id}.mp4")
return file_path