ilya94prok
commited on
Commit
•
853f8ba
1
Parent(s):
907bec5
Upload 4 files
Browse files- .env +2 -0
- app.py +103 -0
- requirements.txt +110 -0
- workflow_api.json +119 -0
.env
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
URL=http://127.0.0.1:8188/prompt
|
2 |
+
OUTPUT_DIR=ComfyUI\\output
|
app.py
ADDED
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
import random
|
4 |
+
import multiprocessing
|
5 |
+
import subprocess
|
6 |
+
import sys
|
7 |
+
import time
|
8 |
+
import signal
|
9 |
+
import json
|
10 |
+
import os
|
11 |
+
import requests
|
12 |
+
|
13 |
+
from loguru import logger
|
14 |
+
from decouple import config
|
15 |
+
|
16 |
+
URL = config('URL')
|
17 |
+
OUTPUT_DIR = config('OUTPUT_DIR')
|
18 |
+
|
19 |
+
|
20 |
+
def get_latest_image(folder):
|
21 |
+
files = os.listdir(folder)
|
22 |
+
image_files = [f for f in files if f.lower().endswith(('.png', '.jpg', '.jpeg'))]
|
23 |
+
image_files.sort(key=lambda x: os.path.getmtime(os.path.join(folder, x)))
|
24 |
+
latest_image = os.path.join(folder, image_files[-1]) if image_files else None
|
25 |
+
return latest_image
|
26 |
+
|
27 |
+
|
28 |
+
def start_queue(prompt_workflow):
|
29 |
+
p = {"prompt": prompt_workflow}
|
30 |
+
data = json.dumps(p).encode('utf-8')
|
31 |
+
requests.post(URL, data=data)
|
32 |
+
|
33 |
+
def generate_image(prompt_text):
|
34 |
+
with open("workflow_api.json", "r", encoding="utf-8") as file_json:
|
35 |
+
prompt = json.load(file_json)
|
36 |
+
|
37 |
+
prompt["6"]["inputs"]["text"] = f"digital artwork of a {prompt_text}"
|
38 |
+
|
39 |
+
previous_image = get_latest_image(OUTPUT_DIR)
|
40 |
+
|
41 |
+
start_queue(prompt)
|
42 |
+
|
43 |
+
|
44 |
+
while True:
|
45 |
+
latest_image = get_latest_image(OUTPUT_DIR)
|
46 |
+
if latest_image != previous_image:
|
47 |
+
return latest_image
|
48 |
+
|
49 |
+
time.sleep(1)
|
50 |
+
|
51 |
+
|
52 |
+
def run_main_script(exit_event):
|
53 |
+
process = subprocess.Popen([sys.executable, "C:\\Users\\ilya9\\comfyui_gradio\\ComfyUI\main.py"])
|
54 |
+
logger.info(f"Скрипт main.py запущен в отдельном процессе с PID: {process.pid}")
|
55 |
+
|
56 |
+
while not exit_event.is_set():
|
57 |
+
if process.poll() is not None:
|
58 |
+
logger.info("Процесс main.py завершился самостоятельно")
|
59 |
+
break
|
60 |
+
time.sleep(0.1)
|
61 |
+
|
62 |
+
if process.poll() is None:
|
63 |
+
logger.info("Завершаем процесс main.py")
|
64 |
+
process.terminate()
|
65 |
+
process.wait(timeout=5)
|
66 |
+
if process.poll() is None:
|
67 |
+
logger.info("Процесс main.py не завершился, применяем SIGKILL")
|
68 |
+
process.kill()
|
69 |
+
|
70 |
+
|
71 |
+
def signal_handler(signum, frame):
|
72 |
+
logger.info(f"Получен сигнал {signum}, завершаем работу")
|
73 |
+
exit_event.set()
|
74 |
+
|
75 |
+
|
76 |
+
if __name__ == "__main__":
|
77 |
+
exit_event = multiprocessing.Event()
|
78 |
+
|
79 |
+
# Устанавливаем обработчик сигналов
|
80 |
+
signal.signal(signal.SIGINT, signal_handler)
|
81 |
+
signal.signal(signal.SIGTERM, signal_handler)
|
82 |
+
|
83 |
+
# Создаем и запускаем процесс
|
84 |
+
process = multiprocessing.Process(target=run_main_script, args=(exit_event,))
|
85 |
+
process.start()
|
86 |
+
|
87 |
+
try:
|
88 |
+
demo = gr.Interface(fn=generate_image, inputs=["text"], outputs=["image"])
|
89 |
+
demo.launch(share=True)
|
90 |
+
finally:
|
91 |
+
logger.info("Ожидаем завершения дочернего процесса")
|
92 |
+
exit_event.set()
|
93 |
+
process.join(timeout=10)
|
94 |
+
if process.is_alive():
|
95 |
+
logger.info("Дочерний процесс не завершился, применяем terminate()")
|
96 |
+
process.terminate()
|
97 |
+
process.join(timeout=5)
|
98 |
+
if process.is_alive():
|
99 |
+
logger.info("Дочерний процесс все еще жив, применяем kill()")
|
100 |
+
process.kill()
|
101 |
+
process.join()
|
102 |
+
|
103 |
+
logger.info("Основной скрипт завершил работу.")
|
requirements.txt
ADDED
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
absl-py==2.1.0
|
2 |
+
aiofiles==23.2.1
|
3 |
+
aiohttp==3.9.5
|
4 |
+
aiosignal==1.3.1
|
5 |
+
altair==5.3.0
|
6 |
+
annotated-types==0.7.0
|
7 |
+
anyio==4.4.0
|
8 |
+
async-timeout==4.0.3
|
9 |
+
attrs==23.2.0
|
10 |
+
certifi==2024.6.2
|
11 |
+
cffi==1.16.0
|
12 |
+
charset-normalizer==3.3.2
|
13 |
+
click==8.1.7
|
14 |
+
colorama==0.4.6
|
15 |
+
contourpy==1.2.1
|
16 |
+
cycler==0.12.1
|
17 |
+
dnspython==2.6.1
|
18 |
+
einops==0.8.0
|
19 |
+
email_validator==2.2.0
|
20 |
+
exceptiongroup==1.2.1
|
21 |
+
fastapi==0.111.0
|
22 |
+
fastapi-cli==0.0.4
|
23 |
+
ffmpy==0.3.2
|
24 |
+
filelock==3.15.4
|
25 |
+
fonttools==4.53.0
|
26 |
+
frozenlist==1.4.1
|
27 |
+
fsspec==2024.6.1
|
28 |
+
gradio==4.37.2
|
29 |
+
gradio_client==1.0.2
|
30 |
+
h11==0.14.0
|
31 |
+
httpcore==1.0.5
|
32 |
+
httptools==0.6.1
|
33 |
+
httpx==0.27.0
|
34 |
+
huggingface-hub==0.23.4
|
35 |
+
idna==3.7
|
36 |
+
importlib_resources==6.4.0
|
37 |
+
intel-openmp==2021.4.0
|
38 |
+
Jinja2==3.1.4
|
39 |
+
jsonschema==4.22.0
|
40 |
+
jsonschema-specifications==2023.12.1
|
41 |
+
kiwisolver==1.4.5
|
42 |
+
kornia==0.7.3
|
43 |
+
kornia_rs==0.1.3
|
44 |
+
loguru==0.7.2
|
45 |
+
markdown-it-py==3.0.0
|
46 |
+
MarkupSafe==2.1.5
|
47 |
+
matplotlib==3.9.0
|
48 |
+
mdurl==0.1.2
|
49 |
+
mediapipe==0.10.9
|
50 |
+
mkl==2021.4.0
|
51 |
+
mpmath==1.3.0
|
52 |
+
multidict==6.0.5
|
53 |
+
networkx==3.3
|
54 |
+
numpy==1.26.4
|
55 |
+
opencv-contrib-python==4.9.0.80
|
56 |
+
orjson==3.10.5
|
57 |
+
packaging==24.1
|
58 |
+
pandas==2.2.2
|
59 |
+
pillow==10.3.0
|
60 |
+
psutil==6.0.0
|
61 |
+
pycparser==2.22
|
62 |
+
pydantic==2.7.4
|
63 |
+
pydantic_core==2.18.4
|
64 |
+
pydub==0.25.1
|
65 |
+
Pygments==2.18.0
|
66 |
+
pyparsing==3.1.2
|
67 |
+
python-dateutil==2.9.0.post0
|
68 |
+
python-decouple==3.8
|
69 |
+
python-dotenv==1.0.1
|
70 |
+
python-multipart==0.0.9
|
71 |
+
pytz==2024.1
|
72 |
+
PyYAML==6.0.1
|
73 |
+
referencing==0.35.1
|
74 |
+
regex==2024.5.15
|
75 |
+
requests==2.32.3
|
76 |
+
rich==13.7.1
|
77 |
+
rpds-py==0.18.1
|
78 |
+
ruff==0.5.0
|
79 |
+
safetensors==0.4.3
|
80 |
+
scipy==1.14.0
|
81 |
+
semantic-version==2.10.0
|
82 |
+
shellingham==1.5.4
|
83 |
+
six==1.16.0
|
84 |
+
sniffio==1.3.1
|
85 |
+
sounddevice==0.4.6
|
86 |
+
soundfile==0.12.1
|
87 |
+
spandrel==0.3.4
|
88 |
+
starlette==0.37.2
|
89 |
+
sympy==1.12.1
|
90 |
+
tbb==2021.13.0
|
91 |
+
tokenizers==0.19.1
|
92 |
+
tomlkit==0.12.0
|
93 |
+
toolz==0.12.1
|
94 |
+
torch==2.3.1+cu121
|
95 |
+
torchaudio==2.3.1+cu121
|
96 |
+
torchsde==0.2.6
|
97 |
+
torchvision==0.18.1+cu121
|
98 |
+
tqdm==4.66.4
|
99 |
+
trampoline==0.1.2
|
100 |
+
transformers==4.42.3
|
101 |
+
typer==0.12.3
|
102 |
+
typing_extensions==4.12.2
|
103 |
+
tzdata==2024.1
|
104 |
+
ujson==5.10.0
|
105 |
+
urllib3==2.2.2
|
106 |
+
uvicorn==0.30.1
|
107 |
+
watchfiles==0.22.0
|
108 |
+
websockets==11.0.3
|
109 |
+
win32-setctime==1.1.0
|
110 |
+
yarl==1.9.4
|
workflow_api.json
ADDED
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"4": {
|
3 |
+
"inputs": {
|
4 |
+
"ckpt_name": "realisticVisionV51_v51VAE.safetensors"
|
5 |
+
},
|
6 |
+
"class_type": "CheckpointLoaderSimple",
|
7 |
+
"_meta": {
|
8 |
+
"title": "Load Checkpoint - BASE"
|
9 |
+
}
|
10 |
+
},
|
11 |
+
"5": {
|
12 |
+
"inputs": {
|
13 |
+
"width": 1024,
|
14 |
+
"height": 1024,
|
15 |
+
"batch_size": 1
|
16 |
+
},
|
17 |
+
"class_type": "EmptyLatentImage",
|
18 |
+
"_meta": {
|
19 |
+
"title": "Empty Latent Image"
|
20 |
+
}
|
21 |
+
},
|
22 |
+
"6": {
|
23 |
+
"inputs": {
|
24 |
+
"text": "evening sunset scenery blue sky nature, glass bottle with a galaxy in it",
|
25 |
+
"clip": [
|
26 |
+
"4",
|
27 |
+
1
|
28 |
+
]
|
29 |
+
},
|
30 |
+
"class_type": "CLIPTextEncode",
|
31 |
+
"_meta": {
|
32 |
+
"title": "CLIP Text Encode (Prompt)"
|
33 |
+
}
|
34 |
+
},
|
35 |
+
"7": {
|
36 |
+
"inputs": {
|
37 |
+
"text": "text, watermark",
|
38 |
+
"clip": [
|
39 |
+
"4",
|
40 |
+
1
|
41 |
+
]
|
42 |
+
},
|
43 |
+
"class_type": "CLIPTextEncode",
|
44 |
+
"_meta": {
|
45 |
+
"title": "CLIP Text Encode (Prompt)"
|
46 |
+
}
|
47 |
+
},
|
48 |
+
"17": {
|
49 |
+
"inputs": {
|
50 |
+
"samples": [
|
51 |
+
"51",
|
52 |
+
0
|
53 |
+
],
|
54 |
+
"vae": [
|
55 |
+
"4",
|
56 |
+
2
|
57 |
+
]
|
58 |
+
},
|
59 |
+
"class_type": "VAEDecode",
|
60 |
+
"_meta": {
|
61 |
+
"title": "VAE Decode"
|
62 |
+
}
|
63 |
+
},
|
64 |
+
"49": {
|
65 |
+
"inputs": {
|
66 |
+
"images": [
|
67 |
+
"17",
|
68 |
+
0
|
69 |
+
]
|
70 |
+
},
|
71 |
+
"class_type": "PreviewImage",
|
72 |
+
"_meta": {
|
73 |
+
"title": "Preview Image"
|
74 |
+
}
|
75 |
+
},
|
76 |
+
"50": {
|
77 |
+
"inputs": {
|
78 |
+
"filename_prefix": "ComfyUI",
|
79 |
+
"images": [
|
80 |
+
"17",
|
81 |
+
0
|
82 |
+
]
|
83 |
+
},
|
84 |
+
"class_type": "SaveImage",
|
85 |
+
"_meta": {
|
86 |
+
"title": "Save Image"
|
87 |
+
}
|
88 |
+
},
|
89 |
+
"51": {
|
90 |
+
"inputs": {
|
91 |
+
"seed": 649530258978181,
|
92 |
+
"steps": 20,
|
93 |
+
"cfg": 8,
|
94 |
+
"sampler_name": "euler",
|
95 |
+
"scheduler": "normal",
|
96 |
+
"denoise": 1,
|
97 |
+
"model": [
|
98 |
+
"4",
|
99 |
+
0
|
100 |
+
],
|
101 |
+
"positive": [
|
102 |
+
"6",
|
103 |
+
0
|
104 |
+
],
|
105 |
+
"negative": [
|
106 |
+
"7",
|
107 |
+
0
|
108 |
+
],
|
109 |
+
"latent_image": [
|
110 |
+
"5",
|
111 |
+
0
|
112 |
+
]
|
113 |
+
},
|
114 |
+
"class_type": "KSampler",
|
115 |
+
"_meta": {
|
116 |
+
"title": "KSampler"
|
117 |
+
}
|
118 |
+
}
|
119 |
+
}
|