【SDXL实战】Python自动化生成3D潮汕美食IP,附ComfyUI工作流与商用变现思路

import requests

import json

import os

1. 配置 Stable Diffusion WebUI 的 API 地址

API_URL = "http://127.0.0.1:7860/sdapi/v1/txt2img"

2. 定义核心 Prompt (提示词) - 这里融入了我们的潮汕美食元素

base_prompt = """

(masterpiece, best quality, 3d render, c4d style),

cute blocky cat character wearing denim hat and sunglasses,

eating Puning rice noodles (普宁粿条),

steaming hot food, cinematic lighting, depth of field,

blurred background of traditional Chaoshan street.

"""

negative_prompt = "low quality, blurry, deformed hands, extra limbs"

3. 设置生成参数 (模拟 ComfyUI/SDXL 的设置)

payload = {

"prompt": base_prompt,

"negative_prompt": negative_prompt,

"steps": 30, # 步数

"width": 1024, # SDXL 推荐分辨率

"height": 1024,

"cfg_scale": 7,

"sampler_name": "DPM++ 2M Karras",

"batch_size": 4 # 一次生成4张,提高效率

}

4. 发送请求并保存图片

def generate_ip_art():

print("🚀 正在启动 AI 绘图引擎...")

try:

response = requests.post(url=API_URL, json=payload)

response.raise_for_status()

r = response.json()

创建保存目录

if not os.path.exists('output_ip'):

os.makedirs('output_ip')

遍历返回的图片数据并保存

for i, img_str in enumerate(r'images'):

import base64

image_data = base64.b64decode(img_str)

file_path = f"output_ip/puning_cat_{i+1}.png"

with open(file_path, 'wb') as f:

f.write(image_data)

print(f"✅ 成功生成并保存: {file_path}")

except Exception as e:

print(f"❌ 生成失败: {e}")

if name == "main":

generate_ip_art()

相关推荐
墨染天姬1 小时前
[AI]BERT 详解:从起源到实战
人工智能
tellmewhoisi1 小时前
python的鬼畜写法(从js角度看)
python
qyr67891 小时前
全球无硅导热垫片市场调研分析
大数据·人工智能·能源·无硅导热垫片
Evanfu02161 小时前
商业短剧上传 AI 工具前,要检查哪些安全与删除规则?
自然语言处理·aigc·音视频·视频·机器翻译·自动翻译
盼小辉丶1 小时前
PyTorch强化学习实战——分布式策略梯度
人工智能·pytorch·深度学习·强化学习
qq7422349841 小时前
OpenCV 之外的另一半工具箱:Supervision 视觉工程实战
人工智能·opencv·计算机视觉
doiito(Do It Together)1 小时前
【Agent Harness】Gliding Horse 最新进化:从“能学习”到“可验证的自主进化”
人工智能·rust·系统架构·开源
weixin_511840471 小时前
2026年9月19日 NVIDIA H200 企业级AI服务器学习
人工智能
此生决int1 小时前
深入理解C++系列(19)——C++11(上)
开发语言·c++