欢迎光临
我们一直在努力

Python 豆包AI实战:通过文字一键生成短视频

介绍

下面介绍火山方舟豆包AI通过文字一键生成短视频并保存到本地的完整python代码,生成短视频的逻辑是,先提交再等待生成完成再下载

准备

  • 安装python3.14
    • 夸克网盘:https://pan.quark.cn/s/b88e55905e7b
    • 百度网盘:https://pan.baidu.com/s/1d22gCHP_qWq5_L_Ik-tvNg?pwd=f8ah
  • 火山引擎注册账号,地址:https://console.volcengine.com/home
    • 火山方舟创建API Key,https://console.volcengine.com/ark/region:ark+cn-beijing/apiKey
    • 火山方舟开通模型:https://console.volcengine.com/ark/region:ark+cn-beijing/openManagement

开始

  • 安装依赖包
    • 火山方舟:pip install ‘volcengine-python-sdk[ark]’
    • OpenAI:pip install openai
    • 其他:pip install requests
  • 项目配置,config.py 配置文件,未配置或配置错误无法运行
    • api_key,刚创建的火山方舟 API Key
  • 项目执行,main.py 主文件
    • python main.py

代码

  • 配置,config.py
  • # 火山方舟 API Key
    api_key = \”\”

    # 模型ID
    model_id = \”doubao-seedance-1-5-pro-251215\”

  • 模型调用,model.py
  • from datetime import datetime

    import config as config
    import uuid
    import os
    import requests
    import time

    base_url = \”https://ark.cn-beijing.volces.com/api/v3\”

    def execute(text: str):
    try:
    response = requests.post(
    url=f\”{

    base_url}/contents/generations/tasks\”,
    headers={

    \”Authorization\”: f\”Bearer {

    config.api_key}\”, \”Content-Type\”: \”application/json\”},
    json={


    \”model\”: config.model_id,
    \”content\”: [{

    \”type\”: \”text\”, \”text\”: text}],
    \”resolution\”: \”480p\”,
    \”duration\”

    赞(0)
    未经允许不得转载:171主机测评 » Python 豆包AI实战:通过文字一键生成短视频
    分享到: 更多 (0)

    评论 抢沙发

    • 昵称 (必填)
    • 邮箱 (必填)
    • 网址