-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvideo.py
More file actions
47 lines (43 loc) · 1.2 KB
/
Copy pathvideo.py
File metadata and controls
47 lines (43 loc) · 1.2 KB
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
"""Video generation via NovAI (Doubao Seedance 2.0, async submit + poll).
pip install requests
export NOVAI_API_KEY=sk-...
python video.py
"""
import os
import time
import requests
BASE = "https://aiapi-pro.com/v1"
MODEL = "doubao-seedance-2.0" # or doubao-seedance-2.0-fast
HEADERS = {
"Authorization": f"Bearer {os.environ['NOVAI_API_KEY']}",
"Content-Type": "application/json",
}
# 1) submit the generation job
job = requests.post(
f"{BASE}/video/generations",
headers=HEADERS,
json={
"model": MODEL,
"prompt": "a paper plane flying over a neon city at night, cinematic",
"resolution": "720p",
"duration": 5,
},
).json()
task_id = job["id"]
print("submitted:", task_id)
# 2) poll until the video is ready
for _ in range(90):
r = requests.get(
f"{BASE}/video/generations/{task_id}",
headers=HEADERS,
params={"model": MODEL},
).json()
status = r.get("status")
if status == "succeeded":
content = r.get("content", {})
print("video:", content.get("video_url") or content.get("url"))
break
if status == "failed":
raise RuntimeError(r)
print("...", status)
time.sleep(4)