import requests
import json
import time
配置SDXL大模型的API接口地址和密钥
API_URL = "YOUR_SDXL_API_ENDPOINT"
API_KEY = "YOUR_API_KEY"
定义英歌舞蛋糕的核心Prompt提示词
def generate_yingge_cake(prompt_suffix):
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
data = {
"prompt": f"A luxurious modern cake design, blue starry ocean waves frosting, top decorated with traditional Chaoshan Yingge dance figures and lion dance, 3D rendering, C4D style, intricate details, commercial IP design, {prompt_suffix}",
"negative_prompt": "low quality, blurry, watermark, text",
"width": 1024,
"height": 1024,
"num_inference_steps": 30
}
try:
response = requests.post(API_URL, json=data, headers=headers)
response.raise_for_status()
result = response.json()
下载并保存图片
image_url = result'image_url'
image_data = requests.get(image_url).content
file_name = f"yingge_cake_{prompt_suffix}.jpg"
with open(file_name, "wb") as f:
f.write(image_data)
print(f"成功生成并保存: {file_name}")
except Exception as e:
print(f"生成失败: {e}")
批量生成不同风格后缀的蛋糕
if name == "main":
suffix_list = "with neon light effect", "in traditional paper-cut style", "as a minimalist vector logo"
for suffix in suffix_list:
generate_yingge_cake(suffix)
time.sleep(2) # 避免请求过于频繁
