From c21db5e5e709a524a100ffcdb04bf7ebcf1322fb Mon Sep 17 00:00:00 2001 From: colomi <1421901449@qq.com> Date: Fri, 11 Jul 2025 13:37:48 +0800 Subject: [PATCH] save code --- basic_api_example.py | 2 +- task_test.py | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 task_test.py diff --git a/basic_api_example.py b/basic_api_example.py index 212ec2c..8566cce 100644 --- a/basic_api_example.py +++ b/basic_api_example.py @@ -26,7 +26,7 @@ def queue_prompt(prompt): request.urlopen(req) -with open('/home/szlc/basic_api.json', 'r', encoding='utf-8') as file: +with open('/home/szlc/code/ComfyUI/change_cloth/basic_api.json', 'r', encoding='utf-8') as file: prompt_text = file.read() prompt = json.loads(prompt_text) diff --git a/task_test.py b/task_test.py new file mode 100644 index 0000000..6f065b7 --- /dev/null +++ b/task_test.py @@ -0,0 +1,38 @@ +import requests +import time +import json + +# 1. 提交任务 + +with open('/home/szlc/code/ComfyUI/change_cloth/basic_api.json', 'r', encoding='utf-8') as file: + prompt_text = file.read() + +prompt = json.loads(prompt_text) +#set the text prompt for our positive CLIPTextEncode +prompt["6"]["inputs"]["text"] = "one girl" + +#set the seed for our KSampler node +prompt["3"]["inputs"]["seed"] = 5 + +p = {"prompt": prompt} + +data = json.dumps(p).encode('utf-8') + +response = requests.post("http://localhost:8188/prompt", data=data) +prompt_id = response.json()["prompt_id"] + + + +# 2. 轮询队列,直到任务完成 +while True: + queue = requests.get("http://localhost:8188/queue").json() + print(queue) + if not queue["queue_running"] and not queue["queue_pending"]: + break # 队列为空,任务已完成 + time.sleep(0.5) # 避免频繁请求 + +# 3. 从历史记录中获取结果 +history = requests.get("http://localhost:8188/history").json() +print("History:", history) +outputs = history[prompt_id]["outputs"] +print("Generated outputs:", outputs) \ No newline at end of file