ceoedu-pro主题已启用,当前站点还没有验证正版主题授权,暂不可使用 前往授权激活 获取正版授权
AI编程-用Trae开发 驱动Comfyui进行AI绘画(基Flux.1模型) - AI智研社
小智头像图片
AI编程教程 2025年06月10日
0 收藏 0 点赞 91 浏览 4384 个字
摘要 :

AI编程-用Trae开发 驱动Comfyui进行AI绘画(基Flux.1模型): 注明:以下的代码目前只是基础版本,只能够驱动Comfyui进行启动,而无法通过代码进行调整ComfyuI绘画参数……

哈喽!伙伴们,我是小智,你们的AI向导。欢迎来到每日的AI学习时间。今天,我们将一起深入AI的奇妙世界,探索“AI编程-用Trae开发 驱动Comfyui进行AI绘画(基Flux.1模型)”,并学会本篇文章中所讲的全部知识点。还是那句话“不必远征未知,只需唤醒你的潜能!”跟着小智的步伐,我们终将学有所成,学以致用,并发现自身的更多可能性。话不多说,现在就让我们开始这场激发潜能的AI学习之旅吧。

AI编程-用Trae开发 驱动Comfyui进行AI绘画(基Flux.1模型)

AI编程-用Trae开发 驱动Comfyui进行AI绘画(基Flux.1模型):

注明:以下的代码目前只是基础版本,只能够驱动Comfyui进行启动,而无法通过代码进行调整ComfyuI绘画参数,后期会迭代优化

用到的工作流文件:

{
“6”: {
“inputs”: {
“text”: “This image is a digitally edited photograph depicting a large crowd of people walking in formation towards the central sunlit area amidst a hilly, rural landscape. The people are dressed in white robes or garments, creating a stark visual contrast with the warm orange and gold hues of the sunlight seeping through a cloudy sky. The sunlight forms a bright, almost divine, pathway over the heads of the crowd, guiding their direction towards a distant point and emphasizing the sense of unity and purpose.nnThe photograph appears to be a digitally enhanced and stylized version, utilizing filters and lighting effects to evoke a timeless, almost biblical or celestial quality. The hills and buildings in the distance include a mix of stone and wooden structures with red roofs, likely indicative of a rural European or Mediterranean setting. The horizon stretches out, blending into the clouds and sky, which is painted in varying shades of blue and grey with golden beams breaking through.nnThe crowd is composed of diverse individuals, but they are uniform in their attire and movement, contributing to the sense of collective spirituality or journey”,
“clip”: [
“30”,
1
]
},
“class_type”: “CLIPTextEncode”,
“_meta”: {
“title”: “CLIP Text Encode (Positive Prompt)”
}
},
“8”: {
“inputs”: {
“samples”: [
“31”,
0
],
“vae”: [
“30”,
2
]
},
“class_type”: “VAEDecode”,
“_meta”: {
“title”: “VAE解码”
}
},
“9”: {
“inputs”: {
“filename_prefix”: “ComfyUI”,
“images”: [
“8”,
0
]
},
“class_type”: “SaveImage”,
“_meta”: {
“title”: “保存图像”
}
},
“27”: {
“inputs”: {
“width”: 720,
“height”: 1280,
“batch_size”: 1
},
“class_type”: “EmptySD3LatentImage”,
“_meta”: {
“title”: “空Latent图像(SD3)”
}
},
“30”: {
“inputs”: {
“ckpt_name”: “flux1-dev-fp8.safetensors”
},
“class_type”: “CheckpointLoaderSimple”,
“_meta”: {
“title”: “Checkpoint加载器(简易)”
}
},
“31”: {
“inputs”: {
“seed”: -1,
“steps”: 25,
“cfg”: 0.5,
“sampler_name”: “euler”,
“scheduler”: “simple”,
“denoise”: 1,
“model”: [
“30”,
0
],
“positive”: [
“35”,
0
],
“negative”: [
“33”,
0
],
“latent_image”: [
“27”,
0
]
},
“class_type”: “KSampler”,
“_meta”: {
“title”: “K采样器”
}
},
“33”: {
“inputs”: {
“text”: “”,
“clip”: [
“30”,
1
]
},
“class_type”: “CLIPTextEncode”,
“_meta”: {
“title”: “CLIP Text Encode (Negative Prompt)”
}
},
“35”: {
“inputs”: {
“guidance”: 3,
“conditioning”: [
“6”,
0
]
},
“class_type”: “FluxGuidance”,
“_meta”: {
“title”: “Flux引导”
}
}
}

工作流详情图如下​

AI编程-用Trae开发 驱动Comfyui进行AI绘画(基Flux.1模型)

本地调用comfyui生图参考初始版本代码(不推荐拷贝,测试用)​

import requests​
import json​
import time​

# 这个改成本地Comfyui启动端的IP地址以及端口号​
server_url = “http://26.55.222.77:8188″​


def queue_prompt(prompt):​
response = requests.post(f”{server_url}/prompt”, json={“prompt”: prompt})​
return response.json()​


with open(“flux_dev.json”, “r”, encoding=”utf-8″) as f:​
prompt_data = json.load(f)​

result = queue_prompt(prompt_data)​
prompt_id = result.get(‘prompt_id’)​
print(f”[状态] 任务已提交,Prompt ID: {prompt_id}n”)​

# 添加超时和计时器​
start_time = time.time()​
timeout = 1000 # 最长等待300秒(5分钟)​
poll_interval = 1 # 轮询间隔(秒)​

while True:​
try:​
# 获取任务状态​
response = requests.get(f”{server_url}/history/{prompt_id}”)​
history = response.json()​

# 计算已等待时间​
elapsed_time = int(time.time() – start_time)​

if prompt_id in history:​
outputs = history[prompt_id][‘outputs’]​
print(f”n[成功] 生成完成!耗时: {elapsed_time}秒”)​

# 提取图片信息​
if ‘9’ in outputs: # 对应SaveImage节点​
images = outputs[‘9’][‘images’]​
for img in images:​
print(f” → 图片路径: {img[‘filename’]}”)​
print(f” → 尺寸: {img[‘width’]}x{img[‘height’]}”)​
print(f” → 类型: {img[‘type’]}n”)​
else:​
print(“[警告] 未找到图片输出,请检查SaveImage节点配置”)​
break​
else:​
# 实时输出等待状态​
print(f”[等待中] 已等待 {elapsed_time}秒…”, end=’r’) # r实现原地刷新​

# 超时检测​
if time.time() – start_time > timeout:​
print(“n[错误] 生成超时,请检查ComfyUI日志或调整超时时间”)​
break​

time.sleep(poll_interval)

本地调用comfyui生图参考最终版本代码(推荐拷贝)​
直接可用,需要改一下Comfyui启动的IP地址​

import requests​
import json​
import time​

# 这个改成本地Comfyui启动端的IP地址以及端口号​
server_url = “http://26.55.222.77:8188″​


def queue_prompt(prompt):​
response = requests.post(f”{server_url}/prompt”, json={“prompt”: prompt})​
return response.json()​


with open(“flux_dev.json”, “r”, encoding=”utf-8″) as f:​
prompt_data = json.load(f)​

result = queue_prompt(prompt_data)​
prompt_id = result.get(‘prompt_id’)​
print(f”[状态] 任务已提交,Prompt ID: {prompt_id}n”)​

# 添加超时和计时器​
start_time = time.time()​
timeout = 1000 # 最长等待300秒(5分钟)​
poll_interval = 1 # 轮询间隔(秒)​

while True:​
try:​
# 获取任务状态​
response = requests.get(f”{server_url}/history/{prompt_id}”)​
history = response.json()​

# 计算已等待时间​
elapsed_time = int(time.time() – start_time)​

if prompt_id in history:​
outputs = history[prompt_id][‘outputs’]​
print(f”n[成功] 生成完成!耗时: {elapsed_time}秒”)​

# 提取图片信息​
if ‘9’ in outputs: # 对应SaveImage节点​
images = outputs[‘9’][‘images’]​
for img in images:​
print(f” → 图片路径: {img[‘filename’]}”)​
print(f” → 尺寸: {img[‘width’]}x{img[‘height’]}”)​

AI编程-使用IDA-MCP进行逆向破解辅助
AI编程-使用IDA-MCP进行逆向破解辅助:ida-pro-mcp 可用功能:check_connection:检查IDA插件是否正在运行。 get_metadata():获取有关...

嘿,伙伴们,今天我们的AI探索之旅已经圆满结束。关于“AI编程-用Trae开发 驱动Comfyui进行AI绘画(基Flux.1模型)”的内容已经分享给大家了。感谢你们的陪伴,希望这次旅程让你对AI能够更了解、更喜欢。谨记,精准提问是解锁AI潜能的钥匙哦!如果有小伙伴想要了解学习更多的AI知识,请关注我们的官网“AI智研社”,保证让你收获满满呦!

微信打赏二维码 微信扫一扫

支付宝打赏二维码 支付宝扫一扫

版权: 转载请注明出处:https://www.ai-blog.cn/17707.html

相关推荐

Kimi K2 发布并开源,擅长代码与 Agentic 任务: 今天,我们正式发布 Kimi K2 模型,并同步开源。 …

小智头像图片
152

AI编程-trae使用教程:IDE 设置: 常规设置​ 在设置中心,你可以修改通用设置,包括修改主题和语言…

小智头像图片
91

AI编程-trae使用教程:源代码管理: 在 Trae 中,你可以使用源代码管理功能(Source Control)来管…

小智头像图片
91

AI编程-trae使用教程:多模态输入​: 你可以在会话中添加图片,例如报错截图、设计稿、参考样式等…

小智头像图片
91

AI编程-trae使用教程:代码自动补全​: Trae 内置原生的 AI 代码补全功能,无需手动开启。在编辑器…

小智头像图片
91

AI编程-trae使用教程:智能问答指南: 侧边对话(Chat 模式)​ 侧边对话(Chat 模式)是编码过程中…

小智头像图片
91

谷歌Gemini CLI彻底火了,平替Claude Code: 谷歌 Gemini CLI 彻底火了。 这是一款开源的、能够运…

小智头像图片
91

AI编程-trae官方指南大全: 什么是 Trae?​ Trae(/treɪ/)与 AI 深度集成,提供智能问答、代码自…

小智头像图片
209
发表评论
暂无评论

还没有评论呢,快来抢沙发~

助力原创内容

快速提升站内名气成为大牛

扫描二维码

手机访问本站

二维码
vip弹窗图片