-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqueue_example.py
More file actions
52 lines (40 loc) · 1.38 KB
/
queue_example.py
File metadata and controls
52 lines (40 loc) · 1.38 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
48
49
50
51
52
"""Seedance 2.0 — async queue example with polling.
Use the queue API when you want to submit a long-running job, do other work,
and pick up the result later (or hand off to a webhook).
"""
import os
import sys
import time
import fal_client
MODEL_ID = "bytedance/seedance-2.0/fast/text-to-video"
def main() -> int:
if not os.environ.get("FAL_KEY"):
print("Error: FAL_KEY environment variable is not set.", file=sys.stderr)
return 1
handle = fal_client.submit(
MODEL_ID,
arguments={
"prompt": (
"Aerial drone shot sweeping over a misty alpine lake at sunrise, "
"lone kayaker paddling across glassy water, ambient birdsong."
),
"resolution": "720p",
"duration": "6",
"aspect_ratio": "21:9",
"generate_audio": True,
},
)
request_id = handle.request_id
print(f"Submitted. request_id={request_id}")
while True:
status = fal_client.status(MODEL_ID, request_id, with_logs=True)
print(f"status: {type(status).__name__}")
if isinstance(status, fal_client.Completed):
break
time.sleep(3)
result = fal_client.result(MODEL_ID, request_id)
print("Video URL:", result["video"]["url"])
print("Seed: ", result["seed"])
return 0
if __name__ == "__main__":
raise SystemExit(main())