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