@@ -45,22 +45,46 @@ async def main():
4545asyncio.run(main())
4646```
4747
48- ### Video Transformation
48+ ### Async Processing (Queue API)
49+
50+ For video generation jobs, use the queue API to submit jobs and poll for results:
4951
5052``` python
5153async with DecartClient(api_key = os.getenv(" DECART_API_KEY" )) as client:
52- # Transform a video file
53- with open (" input.mp4" , " rb" ) as video_file:
54- result = await client.process({
55- " model" : models.video(" lucy-pro-v2v" ),
56- " prompt" : " Anime style with vibrant colors" ,
57- " data" : video_file,
58- " enhance_prompt" : True ,
59- })
54+ # Submit and poll automatically
55+ result = await client.queue.submit_and_poll({
56+ " model" : models.video(" lucy-pro-t2v" ),
57+ " prompt" : " A cat playing piano" ,
58+ " on_status_change" : lambda job : print (f " Status: { job.status} " ),
59+ })
60+
61+ if result.status == " completed" :
62+ with open (" output.mp4" , " wb" ) as f:
63+ f.write(result.data)
64+ else :
65+ print (f " Job failed: { result.error} " )
66+ ```
6067
61- # Save the result
62- with open (" output.mp4" , " wb" ) as f:
63- f.write(result)
68+ Or manage the polling manually:
69+
70+ ``` python
71+ async with DecartClient(api_key = os.getenv(" DECART_API_KEY" )) as client:
72+ # Submit the job
73+ job = await client.queue.submit({
74+ " model" : models.video(" lucy-pro-t2v" ),
75+ " prompt" : " A cat playing piano" ,
76+ })
77+ print (f " Job ID: { job.job_id} " )
78+
79+ # Poll for status
80+ status = await client.queue.status(job.job_id)
81+ print (f " Status: { status.status} " )
82+
83+ # Get result when completed
84+ if status.status == " completed" :
85+ data = await client.queue.result(job.job_id)
86+ with open (" output.mp4" , " wb" ) as f:
87+ f.write(data)
6488```
6589
6690## Development
0 commit comments