即梦ai 火山方舟api调用踩坑实战

目录

doubao-seedream-5-0-260128 调用代码

doubao-seedream-4-5-251128 调研代码:

图生3d测试

文生3d资产:


火山方舟api

https://console.volcengine.com/ark/region:ark+cn-beijing/apikey

https://console.volcengine.com/ark/region:cn-beijing/docs/82379/1399008?lang=zh

查看api key:

点击眼睛,

doubao-seedream-5-0-260128 调用代码

import time
# Install SDK:  pip install 'volcengine-python-sdk[ark]' .
from volcenginesdkarkruntime import Ark


client = Ark(
    base_url="https://ark.cn-beijing.volces.com/api/v3", # Get API Key:https://console.volcengine.com/ark/region:ark+cn-beijing/apikey
    api_key=api_key)

prompt_str="""
        Pop Mart blind box style turnaround sheet of a kawaii chibi figure wearing a bear onesie, 
        multi-angle views (front, side, back, high/low angle), dark grey studio background, 
        soft diffused lighting, smooth matte vinyl toy texture, strictly divided 4-color scheme 
        for detachable modular parts, each component uses a single solid color: 
        1. golden yellow main bear suit, 2. ivory white paw cuffs, 3. bright orange backpack, 
        4. light pink cloak, smooth surface, gradient orange tips on the ears and feet, 
        bear-shaped hood with rounded ears and cute snout, character with big sparkling eyes, 
        pink blush, tiny pout expression, white paw cuffs, chibi proportions, ultra cute and 
        cuddly vibe, equipped with a detachable mini backpack mounted on the back, 
        plus a separate independent detachable cloak, all accessories and body parts are 
        fully modular and removable accessories, clean product shot, high detail, 
        smooth shadows, hyper-detailed sculpt details --ar 16:9 --style expressive --v 6.0
        """
prompt_str = """
        turnaround character sheet of an ultra-cute chubby and dull-witted designer toy shark figure, extra soft and naive facial expression, cuter dumb squinted round eyes to boost呆萌 vibe, 8 orthographic views (front, 3/4, side, back, top, bottom), neutral dark grey seamless studio background, soft gentle rim lighting, PBR high-quality vinyl toy texture, smooth glossy finish, super chubby round plump body with no sharp edges, exaggerated friendly gentle grin with huge oversized fully detachable teeth (each tooth independent and removable separately), bold clean color blocking with 4 distinct vibrant colors assigned to separate modular parts: 1. rich ocean blue for upper body/back, 2. clean cloud white for underbelly, 3. soft coral orange for inner mouth/gums, 4. bright bone white for extra large teeth, simplified soft gill slits without sharp lines, a short cute solid color cloak attached to the shark's back, a mini compact modular backpack fixed firmly on the outer surface of the cloak, no shoulder straps at all, no straps looping over shoulders, no shoulder-mounted parts, backpack completely integrated and fixed on the cloak only, no extra hanging straps, product photography style, hyper-realistic delicate vinyl textures, ultra sharp clean details, soft diffused clean shadows, full clear turnaround display for all angles, no messy background elements --ar 16:9 --style expressive --v 6.0
"""

model_name="doubao-seedream-5-0-260128"
size="2K"

start=time.time()
imagesResponse = client.images.generate(
    model=model_name, prompt=prompt_str,
    size=size, output_format="png", response_format="url", watermark=False)

print(imagesResponse.data[0].url)

print('time',time.time()-start)

doubao-seedream-4-5-251128 调研代码:

import time
import requests
from volcenginesdkarkruntime import Ark

client = Ark(base_url="https://ark.cn-beijing.volces.com/api/v3", api_key=api_key)

model_name = 'doubao-seedream-4-5-251128'

start = time.time()

prompt_str = """
        turnaround character sheet of an ultra-cute chubby and dull-witted designer toy shark figure, extra soft and naive facial expression, cuter dumb squinted round eyes to boost呆萌 vibe, 8 orthographic views (front, 3/4, side, back, top, bottom), neutral dark grey seamless studio background, soft gentle rim lighting, PBR high-quality vinyl toy texture, smooth glossy finish, super chubby round plump body with no sharp edges, exaggerated friendly gentle grin with huge oversized fully detachable teeth (each tooth independent and removable separately), bold clean color blocking with 4 distinct vibrant colors assigned to separate modular parts: 1. rich ocean blue for upper body/back, 2. clean cloud white for underbelly, 3. soft coral orange for inner mouth/gums, 4. bright bone white for extra large teeth, simplified soft gill slits without sharp lines, a short cute solid color cloak attached to the shark's back, a mini compact modular backpack fixed firmly on the outer surface of the cloak, no shoulder straps at all, no straps looping over shoulders, no shoulder-mounted parts, backpack completely integrated and fixed on the cloak only, no extra hanging straps, product photography style, hyper-realistic delicate vinyl textures, ultra sharp clean details, soft diffused clean shadows, full clear turnaround display for all angles, no messy background elements --ar 16:9 --style expressive --v 6.0
"""

size="1920x1920"
try:
    imagesResponse = client.images.generate(model=model_name, prompt=prompt_str, size=size, watermark=False)

    if imagesResponse.data and len(imagesResponse.data) > 0:
        image_url = imagesResponse.data[0].url
        print(f"生成图片URL: {image_url}")

        # 下载图片
        img_data = requests.get(image_url).content
        with open(f"image_{int(time.time())}.png", "wb") as f:
            f.write(img_data)
        print("图片已保存")
    else:
        print("未生成图片")

except Exception as e:
    print(f"生成失败: {e}")

print(f'耗时: {time.time() - start:.2f}秒')

图生3d测试

Doubao-Seed3D-2.0 不支持多图直接生成一个3D模型

文生3d资产:

import requests
import json
import os
import time
from typing import Optional, Dict, Any
import requests
import json
import time

api_key = "ark-223393fc-e15e-4c15-bf56-702dc71dc85f-8b7fc"

url = "https://ark.cn-beijing.volces.com/api/v3/contents/generations/tasks"


headers = {"Content-Type": "application/json", "Authorization": f"Bearer {api_key}"}

payload = {"model": "hyper3d-gen2-260112", "content": [{"type": "text",
    # "text": "Complete full-body quadrupedal mech robot, orange and black armored, rounded head with glowing blue sensors, 4 articulated mechanical legs, hard-surface sci-fi design, high-detail joints, photorealistic 8K, fully assembled, no missing parts. --mesh_mode Raw --hd_texture true --material PBR --addons HighPack --quality_override 1000000 --use_original_alpha false --bbox_condition [100,100,100] --TAPose false"}]}
    "text": """Pop Mart blind box style kawaii chibi figure wearing a bear onesie, multi-angle turnaround sheet (front, 3/4, side, back, top, bottom views), dark grey seamless studio background, soft diffused lighting, smooth matte vinyl toy texture. Strictly divided 4-color scheme for detachable modular parts, each component uses a single solid color: 1. marigold yellow for main bear suit, 2. ivory white for paw cuffs, 3. bright orange for mini backpack, 4. light pink for cloak. Smooth surface with orange gradient tips on ears and feet. Bear-shaped hood with rounded ears and cute snout, character with big sparkling eyes, pink blush, pout expression, chibi proportions, ultra cute and cuddly vibe. Detachable mini backpack mounted on the back, plus independent detachable cloak, all accessories and body parts fully modular and removable. Clean product photography style, high detail, smooth shadows, hyper-detailed sculpt. --mesh_mode Raw --hd_texture true --material PBR --addons HighPack --quality_override 1000000 --use_original_alpha false --bbox_condition [100,100,100] --TAPose false"""}]}

# 提交任务
response = requests.post(url, headers=headers, json=payload)
response.raise_for_status()
task_result = response.json()
task_id = task_result.get("id")  # 或者根据实际返回字段调整
print(f"任务已提交,ID: {task_id}")

# 轮询任务状态(如果需要)
status_url = f"https://ark.cn-beijing.volces.com/api/v3/contents/generations/tasks/{task_id}"
while True:
    status_response = requests.get(status_url, headers=headers)
    status_data = status_response.json()

    status = status_data.get("status")
    print(f"当前状态: {status}")

    if status in ["completed", "succeeded", "failed"]:
        break

    time.sleep(2)  # 等待2秒后再次查询

print("最终结果:")
print(json.dumps(status_data, indent=2, ensure_ascii=False))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AI算法网奇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值