小智头像图片
AI编程教程 2025年06月10日
0 收藏 0 点赞 67 浏览 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

相关推荐

AI编程-10分钟生成Web原型神器Trae+Claude3.7: 本篇文章介绍用Trae设计web系统原型的实践。看看Tr…

小智头像图片
26

AI编程-Trae一键生成系统架构图新手教程: 系统功能模块图生成 1、根据《功能模块文档.md》的内容…

小智头像图片
67

AI编程-输入油管网址生成阅读网页船长案例分享: 输入油管网址生成阅读网页船长案例分享​​ ​ 生…

小智头像图片
67

AI编程-树人与鲁迅案例分享: 用trae写一个本地uv的文生图mcp服务器,直接边聊边出图边修改。​ 客…

小智头像图片
67

AI编程-使用MYSQL-MCP读取数据库数据: 简介​ MySQL MCP Server 是一个 Model Context Protocol (M…

小智头像图片
67

AI编程-Trae AI和Figma互相转换(方法二): 方式二:手动进行MCP代码的添加​ 在Trae中的MCP界面中…

小智头像图片
67

AI编程-Trae AI和Figma互相转换(方法一): Windows及Mac端皆可部署 参考Github源地址:https://g…

小智头像图片
67

AI编程-使用IDA-MCP进行逆向破解辅助: ida-pro-mcp 可用功能:check_connection:检查IDA插件是否…

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

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

助力原创内容

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

扫描二维码

手机访问本站

二维码
vip弹窗图片