视频大模型
基本介绍
视频大模型包括文生视频和图生视频。文生视频是指通过输入文本描述生成对应的 视频内容,而图生视频则是通过输入图片生成相关的视频。视频大模型的应用场景包括影视制作、广告创意、教育培训等领域。
视频模型列表
目前模型广场已上线的的视频生成模型包括:
加载 Serverless API 服务列表...
使用方法
在模型使用界面输入文本描述,模型将生成对应的视频内容。以下是使用 Wan2.1-T2V-14B
模型的示例:
示例代码
模力方舟上所有的视频模型皆使用异步接口方式调用,详情请看模型体验页面的示例代码,或者参考 异步接口使用指南。
python
import requests
import time
import json
import webbrowser
API_URL = "https://ai.gitee.com/v1/async/videos/generations"
API_TOKEN = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" # 请替换为您的令牌
headers = {
"Authorization": f"Bearer {API_TOKEN}"
}
def query(payload):
response = requests.post(API_URL, headers=headers, json=payload)
return response.json()
def poll_task(task_id):
status_url = f"https://ai.gitee.com/v1/task/{task_id}"
timeout = 30 * 60
retry_interval = 10
attempts = 0
max_attempts = int(timeout / retry_interval)
while attempts < max_attempts:
attempts += 1
print(f"Checking task status [{attempts}]...", end="")
response = requests.get(status_url, headers=headers, timeout=10)
result = response.json()
if result.get("error"):
print('error')
raise ValueError(f"{result['error']}: {result.get('message', 'Unknown error')}")
status = result.get("status", "unknown")
print(status)
if status == "success":
if "output" in result and "file_url" in result["output"]:
file_url = result["output"]["file_url"]
duration = (result.get('completed_at', 0) - result.get('started_at', 0)) / 1000
print(f"🔗 Donwload link: {file_url}")
print(f"⏱️ Task duration: {duration:.2f} seconds")
# Open the result URL in the browser
webbrowser.open(file_url)
else:
print("⚠️ No output URL found")
elif status in ["failed", "cancelled"]:
print(f"❌ Task {status}")
else:
time.sleep(retry_interval)
continue
task_file = f"task_{task_id}.json"
with open(task_file, "w") as f:
json.dump(result, f, indent=4)
print(f"Task was saved to file {task_file}")
return result
print(f"⏰ Maximum attempts reached ({max_attempts})")
return {"status": "timeout", "message": "maximum wait time exceeded"}
if __name__ == "__main__":
print("Creating task...")
result = query({
"model": "Wan2.1-T2V-1.3B",
"num_inferenece_steps": 50,
"num_frames": 81
})
task_id = result.get("task_id")
if not task_id:
raise ValueError("Task ID not found in the response")
print(f"Task ID: {task_id}")
task = poll_task(task_id)
if task.get("status") == "success":
# Do something with the task result here
print("Task completed successfully!")