Bläddra i källkod

chore: make comfy workflow can generate image with a random seed (#10462)

tags/0.11.1
非法操作 11 månader sedan
förälder
incheckning
7903ba0297
Inget konto är kopplat till bidragsgivarens mejladress

+ 12
- 1
api/core/tools/provider/builtin/comfyui/tools/comfyui_client.py Visa fil

@@ -48,7 +48,6 @@ class ComfyUiClient:
prompt = origin_prompt.copy()
id_to_class_type = {id: details["class_type"] for id, details in prompt.items()}
k_sampler = [key for key, value in id_to_class_type.items() if value == "KSampler"][0]
prompt.get(k_sampler)["inputs"]["seed"] = random.randint(10**14, 10**15 - 1)
positive_input_id = prompt.get(k_sampler)["inputs"]["positive"][0]
prompt.get(positive_input_id)["inputs"]["text"] = positive_prompt

@@ -72,6 +71,18 @@ class ComfyUiClient:
prompt.get(load_image)["inputs"]["image"] = image_name
return prompt

def set_prompt_seed_by_id(self, origin_prompt: dict, seed_id: str) -> dict:
prompt = origin_prompt.copy()
if seed_id not in prompt:
raise Exception("Not a valid seed node")
if "seed" in prompt[seed_id]["inputs"]:
prompt[seed_id]["inputs"]["seed"] = random.randint(10**14, 10**15 - 1)
elif "noise_seed" in prompt[seed_id]["inputs"]:
prompt[seed_id]["inputs"]["noise_seed"] = random.randint(10**14, 10**15 - 1)
else:
raise Exception("Not a valid seed node")
return prompt

def track_progress(self, prompt: dict, ws: WebSocket, prompt_id: str):
node_ids = list(prompt.keys())
finished_nodes = []

+ 3
- 0
api/core/tools/provider/builtin/comfyui/tools/comfyui_workflow.py Visa fil

@@ -70,6 +70,9 @@ class ComfyUIWorkflowTool(BuiltinTool):
else:
prompt = comfyui.set_prompt_images_by_default(prompt, image_names)

if seed_id := tool_parameters.get("seed_id"):
prompt = comfyui.set_prompt_seed_by_id(prompt, seed_id)

images = comfyui.generate_image_by_prompt(prompt)
result = []
for img in images:

+ 9
- 0
api/core/tools/provider/builtin/comfyui/tools/comfyui_workflow.yaml Visa fil

@@ -52,3 +52,12 @@ parameters:
en_US: When the workflow has multiple image nodes, enter the ID list of these nodes, and the images will be passed to ComfyUI in the order of the list.
zh_Hans: 当工作流有多个图片节点时,输入这些节点的ID列表,图片将按列表顺序传给ComfyUI
form: form
- name: seed_id
type: string
label:
en_US: Seed Node Id
zh_Hans: 种子节点ID
human_description:
en_US: If you need to generate different images each time, you need to enter the ID of the seed node.
zh_Hans: 如果需要每次生成时使用不同的种子,需要输入包含种子的节点的ID
form: form

Laddar…
Avbryt
Spara