comfyui 工作流生成图片使用history接口获取返回时 outputs为空 问题请教,希望有大佬可以帮忙解答一下

comfyui github地址: GitHub - comfyanonymous/ComfyUI: The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface.The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. - comfyanonymous/ComfyUIicon-default.png?t=O83Ahttps://github.com/comfyanonymous/ComfyUI

github上提供了生成的python代码 ComfyUI/script_examples at master · comfyanonymous/ComfyUI · GitHub

使用提供的案例代码 上传到comfyui服务器上,把prompt换成自己的prompt 等任务完成之后 使用history获取生成的图片结果为空

而使用同样的prompt 在同一个服务上使用web页面生成图片就可以成功, 有大佬碰到过这样的问题吗?

脚步代码如下:

import logging

#This is an example that uses the websockets api to know when a prompt execution is done
#Once the prompt execution is done it downloads the images using the /history endpoint

import websocket #NOTE: websocket-client (https://github.com/websocket-client/websocket-client)
import uuid
import json
import urllib.request
import urllib.parse

server_address = "127.0.0.1:8188"
client_id = str(uuid.uuid4())

def queue_prompt(prompt):
    p = {"prompt": prompt, "client_id": client_id}
    data = json.dumps(p).encode('utf-8')
    req =  urllib.request.Request("http://{}/prompt".format(server_address), data=data)
    return json.loads(urllib.request.urlopen(req).read())

def get_image(filename, subfolder, folder_type):
    data = {"filename": filename, "subfolder": subfolder, "type": folder_type}
    url_values = urllib.parse.urlencode(data)
    with urllib.request.urlopen("http://{}/view?{}".format(server_address, url_values)) as response:
        return response.read()

def get_history(prompt_id):
    with urllib.request.urlopen("http://{}/history/{}".format(server_address, prompt_id)) as response:
        return json.loads(response.read())

def get_history_all():
    with urllib.request.urlopen("http://{}/history".format(server_address)) as response:
        return json.loads(response.read())

def get_extensions():
    with urllib.request.urlopen("http://{}/extensions".format(server_address)) as response:
        return json.loads(response.read())

def get_queue():
    with urllib.request.urlopen("http://{}/queue".format(server_address)) as response:
        return json.loads(response.read())

def get_images(ws, prompt):
    queue = queue_prompt(prompt)
    print("queue_prompt, {}".format(queue))
    prompt_id = queue['prompt_id']
    output_images = {}
    while True:
        out = ws.recv()
        print("wx接收响应, out: {}".format(out))
        if isinstance(out, str):
            message = json.loads(out)
            if message['type'] == 'executing':
                data = message['data']
                if data['node'] is None and data['prompt_id'] == prompt_id:
                    break #Execution is done
        else:
            # If you want to be able to decode the binary stream for latent previews, here is how you can do it:
            # bytesIO = BytesIO(out[8:])
            # preview_image = Image.open(bytesIO) # This is your preview in PIL image format, store it in a global
            continue #previews are binary data

    getHistory = get_history(prompt_id)
    print("getHistory, gethistory: {}".format(getHistory))
    history = getHistory[prompt_id]
    for node_id in history['outputs']:
        node_output = history['outputs'][node_id]
        print("node_output, {}".format(node_output))
        images_output = []
        if 'images' in node_output:
            for image in node_output['images']:
                image_data = get_image(image['filename'], image['subfolder'], image['type'])
                images_output.append(image_data)
        output_images[node_id] = images_output

    # resp = get_extensions()
    # print('extensions_resp', resp)
    resp = get_queue()
    print('queue', resp)

    historyAll = get_history_all()
    print('historyAll', historyAll)

    return output_images

prompt_text = """
{
    "3": {
        "class_type": "K
### 使用ComfyUI生成汉字的工作流与教程 #### 背景介绍 ComfyUI 是一款基于节点化的图形界面工具,广泛应用于图像生成领域。它通过灵活的节点配置实现了高度自定义的功能,适用于多种复杂任务,包括但不限于艺术字体设计、图片编辑和风格迁移等[^1]。 #### 汉字生成的关键技术要点 在使用 ComfyUI 进行汉字生成,主要依赖以下几个关键技术点: 1. **Lora 风格模型的应用** - Lora(Low-Rank Adaptation)是一种轻量级微调方法,能够有效捕捉特定的艺术风格或字符特征。对于汉字生成而言,可以加载经过训练的中文书法或印刷体风格的 Lora 模型来增强生成效果[^3]。 2. **ControlNet 的外形控制** - ControlNet 提供了额外的条件输入能力,允许用户指定草稿图或其他形式的引导信息。这使得生成过程更加可控,尤其是在处理复杂的笔画结构如汉字尤为重要[^3]。 3. **Prompt 设计优化** - Prompt 文本提示词的设计直接影响最终输出的质量。针对汉字生成的任务,建议采用详细的描述方式,例如:“一幅具有传统毛笔书写质感的‘福’字”,以便让算法更精准地理解目标样式[^2]。 4. **工作流构建技巧** - 利用 ComfyUI 中丰富的节点组件,合理安排数据流动路径。通常情况下会涉及文本编码器(Text Encoder)、VAE 解码器(Variational Autoencoder Decoder)等多个核心模块,并结合外部插件完成定制化操作[^4]。 #### 实际案例解析——以端午节主题为例 假设我们要创建一张带有“粽叶飘香过端午”的创意字体海报,则具体实施步骤如下所示: 1. 准备素材:收集相关背景图案(如粽子形状轮廓线),作为后续 ControlNet 输入的一部分; 2. 设置参数:调整采样步数(Sampling Steps)至适当范围(推荐值为20~50之间),同设置噪声强度(Noise Level)适配不同清晰度需求; 3. 编写脚本:编写 Python 脚本来自动化部分重复劳动环节,比如循环读取多个不同的文案内容进行批量化生产; ```python import comfy.sd as sd from PIL import Image def generate_chinese_character(prompt_text, output_path): # 初始化 Stable Diffusion 对象 model = sd.load_model('path_to_your_pretrained_model') # 构建基础请求对象 request_data = { 'prompt': prompt_text, 'steps': 30, 'cfg_scale': 7.5, ... } result_image = model.process(request_data) # 存储结果文件 img_pil = Image.fromarray(result_image) img_pil.save(output_path) if __name__ == '__main__': texts = ["龙舟竞渡迎端阳", "艾蒿挂门避邪气"] outputs_dir = "./output_images/" for idx, txt in enumerate(texts): file_name = f"{outputs_dir}char_{idx}.png" generate_chinese_character(txt, file_name) ``` 4. 执行渲染:运行上述代码片段即可得到一系列按照设定规格绘制而成的新颖汉字形象; 5. 后期修饰:最后再借助 Photoshop 或其他平面设计软件稍加润色完善整体布局构图即大功告成! --- ### 注意事项 尽管 ComfyUI 功能强大,但在实际应用过程中仍需注意以下几点: - 确保所使用的硬件设备满足最低性能要求,尤其是 GPU 显卡型号及其驱动版本号要匹配官方文档说明; - 不同类型的预训练权重可能带来截然相反的效果表现,请务必仔细甄选最适合自己项目方向的那一款; - 如果遇到某些特殊场景下的兼容性问题或者效率瓶颈现象,不妨尝试切换到 CPU 计算模式下重新验证一遍逻辑正确与否。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值