-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_nested_loop.py
More file actions
57 lines (39 loc) · 1.62 KB
/
example_nested_loop.py
File metadata and controls
57 lines (39 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import json
import os
import time
import random
import numpy as np
import requests
from PIL import Image
URL = "http://127.0.0.1:8188/prompt"
INPUT_DIR = r"E:\ComfyUI_windows_portable\ComfyUI\input"
OUTPUT_DIR = r"E:\ComfyUI_windows_portable\ComfyUI\output"
def get_latest_image(folder):
files = os.listdir(folder)
image_files = [f for f in files if f.lower().endswith(('.png', '.jpg', '.jpeg'))]
image_files.sort(key=lambda x: os.path.getmtime(os.path.join(folder, x)))
latest_image = os.path.join(folder, image_files[-1]) if image_files else None
return latest_image
def start_queue(prompt_workflow):
p = {"prompt": prompt_workflow}
data = json.dumps(p).encode('utf-8')
requests.post(URL, data=data)
def generate_image(promt):
previous_image = get_latest_image(OUTPUT_DIR)
start_queue(prompt)
while True:
latest_image = get_latest_image(OUTPUT_DIR)
if latest_image != previous_image:
return latest_image
time.sleep(1)
with open("workflow_api.json", "r") as file_json:
prompt = json.load(file_json)
for model in ["Model 1", "Model 2", "Model 3"]: # replace with model names like this: aniverse_thxEd14Pruned.safetensors
for i in range(11): # replace with number of iteration
prompt["4"]["inputs"]["ckpt_name"] = model # the values may be different based on your workflow
merge_ratio = 0 + (i * 0.1)
print(f"Merge Ratio: {merge_ratio}")
prompt["10"]["inputs"]["ratio"] = merge_ratio # the values may be different based on your workflow
generate_image(prompt)
print(f"{i} - Completed...")
print("\n\nDONE.")