Compare commits
27
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2cfdd0b3f5 | ||
|
|
9c06cc666c | ||
|
|
710917d507 | ||
|
|
16f4312c9e | ||
|
|
20801f4d3f | ||
|
|
ba2f942b29 | ||
|
|
0dfa83f486 | ||
|
|
edff5685f9 | ||
|
|
5954092f25 | ||
|
|
a2990ca833 | ||
|
|
d673c4a00b | ||
|
|
9fc0c2b4a2 | ||
|
|
d34e2e99b1 | ||
|
|
f85043db07 | ||
|
|
894d8e1503 | ||
|
|
08d631d1eb | ||
|
|
a1031487e1 | ||
|
|
ca41207192 | ||
|
|
507d5ef631 | ||
|
|
dd1d9df23f | ||
|
|
3a14e49ca5 | ||
|
|
8147c4bfb7 | ||
|
|
10268825d9 | ||
|
|
f6ea252652 | ||
|
|
98cd5ef79c | ||
|
|
4bce5cadfb | ||
|
|
f362671041 |
@@ -8,6 +8,16 @@ class ComfyUIDeployExternalBoolean:
|
|||||||
{"multiline": False, "default": "input_bool"},
|
{"multiline": False, "default": "input_bool"},
|
||||||
),
|
),
|
||||||
"default_value": ("BOOLEAN", {"default": False})
|
"default_value": ("BOOLEAN", {"default": False})
|
||||||
|
},
|
||||||
|
"optional": {
|
||||||
|
"display_name": (
|
||||||
|
"STRING",
|
||||||
|
{"multiline": False, "default": ""},
|
||||||
|
),
|
||||||
|
"description": (
|
||||||
|
"STRING",
|
||||||
|
{"multiline": True, "default": ""},
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -16,7 +26,7 @@ class ComfyUIDeployExternalBoolean:
|
|||||||
|
|
||||||
FUNCTION = "run"
|
FUNCTION = "run"
|
||||||
|
|
||||||
def run(self, input_id, default_value=None):
|
def run(self, input_id, default_value=None, display_name=None, description=None):
|
||||||
print(f"Node '{input_id}' processing with switch set to {default_value}")
|
print(f"Node '{input_id}' processing with switch set to {default_value}")
|
||||||
return [default_value]
|
return [default_value]
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,14 @@ class ComfyUIDeployExternalCheckpoint:
|
|||||||
},
|
},
|
||||||
"optional": {
|
"optional": {
|
||||||
"default_value": (folder_paths.get_filename_list("checkpoints"), ),
|
"default_value": (folder_paths.get_filename_list("checkpoints"), ),
|
||||||
|
"display_name": (
|
||||||
|
"STRING",
|
||||||
|
{"multiline": False, "default": ""},
|
||||||
|
),
|
||||||
|
"description": (
|
||||||
|
"STRING",
|
||||||
|
{"multiline": True, "default": ""},
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,7 +41,7 @@ class ComfyUIDeployExternalCheckpoint:
|
|||||||
|
|
||||||
CATEGORY = "deploy"
|
CATEGORY = "deploy"
|
||||||
|
|
||||||
def run(self, input_id, default_value=None):
|
def run(self, input_id, default_value=None, display_name=None, description=None):
|
||||||
import requests
|
import requests
|
||||||
import os
|
import os
|
||||||
import uuid
|
import uuid
|
||||||
|
|||||||
@@ -15,6 +15,14 @@ class ComfyUIDeployExternalImage:
|
|||||||
},
|
},
|
||||||
"optional": {
|
"optional": {
|
||||||
"default_value": ("IMAGE",),
|
"default_value": ("IMAGE",),
|
||||||
|
"display_name": (
|
||||||
|
"STRING",
|
||||||
|
{"multiline": False, "default": ""},
|
||||||
|
),
|
||||||
|
"description": (
|
||||||
|
"STRING",
|
||||||
|
{"multiline": True, "default": ""},
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,7 +33,7 @@ class ComfyUIDeployExternalImage:
|
|||||||
|
|
||||||
CATEGORY = "image"
|
CATEGORY = "image"
|
||||||
|
|
||||||
def run(self, input_id, default_value=None):
|
def run(self, input_id, default_value=None, display_name=None, description=None):
|
||||||
image = default_value
|
image = default_value
|
||||||
try:
|
try:
|
||||||
if input_id.startswith('http'):
|
if input_id.startswith('http'):
|
||||||
|
|||||||
@@ -15,6 +15,14 @@ class ComfyUIDeployExternalImageAlpha:
|
|||||||
},
|
},
|
||||||
"optional": {
|
"optional": {
|
||||||
"default_value": ("IMAGE",),
|
"default_value": ("IMAGE",),
|
||||||
|
"display_name": (
|
||||||
|
"STRING",
|
||||||
|
{"multiline": False, "default": ""},
|
||||||
|
),
|
||||||
|
"description": (
|
||||||
|
"STRING",
|
||||||
|
{"multiline": True, "default": ""},
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,7 +33,7 @@ class ComfyUIDeployExternalImageAlpha:
|
|||||||
|
|
||||||
CATEGORY = "image"
|
CATEGORY = "image"
|
||||||
|
|
||||||
def run(self, input_id, default_value=None):
|
def run(self, input_id, default_value=None, display_name=None, description=None):
|
||||||
image = default_value
|
image = default_value
|
||||||
try:
|
try:
|
||||||
if input_id.startswith('http'):
|
if input_id.startswith('http'):
|
||||||
|
|||||||
@@ -21,6 +21,14 @@ class ComfyUIDeployExternalImageBatch:
|
|||||||
},
|
},
|
||||||
"optional": {
|
"optional": {
|
||||||
"default_value": ("IMAGE",),
|
"default_value": ("IMAGE",),
|
||||||
|
"display_name": (
|
||||||
|
"STRING",
|
||||||
|
{"multiline": False, "default": ""},
|
||||||
|
),
|
||||||
|
"description": (
|
||||||
|
"STRING",
|
||||||
|
{"multiline": True, "default": ""},
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,7 +39,7 @@ class ComfyUIDeployExternalImageBatch:
|
|||||||
|
|
||||||
CATEGORY = "image"
|
CATEGORY = "image"
|
||||||
|
|
||||||
def run(self, input_id, images=None, default_value=None):
|
def run(self, input_id, images=None, default_value=None, display_name=None, description=None):
|
||||||
processed_images = []
|
processed_images = []
|
||||||
try:
|
try:
|
||||||
images_list = json.loads(images) # Assuming images is a JSON array string
|
images_list = json.loads(images) # Assuming images is a JSON array string
|
||||||
|
|||||||
@@ -29,6 +29,18 @@ class ComfyUIDeployExternalLora:
|
|||||||
"STRING",
|
"STRING",
|
||||||
{"multiline": False, "default": ""},
|
{"multiline": False, "default": ""},
|
||||||
),
|
),
|
||||||
|
"display_name": (
|
||||||
|
"STRING",
|
||||||
|
{"multiline": False, "default": ""},
|
||||||
|
),
|
||||||
|
"description": (
|
||||||
|
"STRING",
|
||||||
|
{"multiline": True, "default": ""},
|
||||||
|
),
|
||||||
|
"lora_url": (
|
||||||
|
"STRING",
|
||||||
|
{"multiline": False, "default": ""},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,12 +51,12 @@ class ComfyUIDeployExternalLora:
|
|||||||
|
|
||||||
CATEGORY = "deploy"
|
CATEGORY = "deploy"
|
||||||
|
|
||||||
def run(self, input_id, default_lora_name=None, lora_save_name=None):
|
def run(self, input_id, default_lora_name=None, lora_save_name=None, display_name=None, description=None, lora_url=None):
|
||||||
import requests
|
import requests
|
||||||
import os
|
import os
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
if default_lora_name.startswith("http"):
|
if lora_url and lora_url.startswith("http"):
|
||||||
if lora_save_name:
|
if lora_save_name:
|
||||||
existing_loras = folder_paths.get_filename_list("loras")
|
existing_loras = folder_paths.get_filename_list("loras")
|
||||||
# Check if lora_save_name exists in the list
|
# Check if lora_save_name exists in the list
|
||||||
|
|||||||
@@ -16,7 +16,15 @@ class ComfyUIDeployExternalNumber:
|
|||||||
"optional": {
|
"optional": {
|
||||||
"default_value": (
|
"default_value": (
|
||||||
"FLOAT",
|
"FLOAT",
|
||||||
{"multiline": True, "display": "number", "default": 0, "step": 0.01},
|
{"multiline": True, "display": "number", "default": 0, "min": -2147483647, "max": 2147483647, "step": 0.01},
|
||||||
|
),
|
||||||
|
"display_name": (
|
||||||
|
"STRING",
|
||||||
|
{"multiline": False, "default": ""},
|
||||||
|
),
|
||||||
|
"description": (
|
||||||
|
"STRING",
|
||||||
|
{"multiline": True, "default": ""},
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -28,7 +36,7 @@ class ComfyUIDeployExternalNumber:
|
|||||||
|
|
||||||
CATEGORY = "number"
|
CATEGORY = "number"
|
||||||
|
|
||||||
def run(self, input_id, default_value=None):
|
def run(self, input_id, default_value=None, display_name=None, description=None):
|
||||||
try:
|
try:
|
||||||
float_value = float(input_id)
|
float_value = float(input_id)
|
||||||
print("my number", float_value)
|
print("my number", float_value)
|
||||||
|
|||||||
@@ -16,7 +16,15 @@ class ComfyUIDeployExternalNumberInt:
|
|||||||
"optional": {
|
"optional": {
|
||||||
"default_value": (
|
"default_value": (
|
||||||
"INT",
|
"INT",
|
||||||
{"multiline": True, "display": "number", "default": 0},
|
{"multiline": True, "display": "number", "min": -2147483647, "max": 2147483647, "default": 0},
|
||||||
|
),
|
||||||
|
"display_name": (
|
||||||
|
"STRING",
|
||||||
|
{"multiline": False, "default": ""},
|
||||||
|
),
|
||||||
|
"description": (
|
||||||
|
"STRING",
|
||||||
|
{"multiline": True, "default": ""},
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -28,7 +36,7 @@ class ComfyUIDeployExternalNumberInt:
|
|||||||
|
|
||||||
CATEGORY = "number"
|
CATEGORY = "number"
|
||||||
|
|
||||||
def run(self, input_id, default_value=None):
|
def run(self, input_id, default_value=None, display_name=None, description=None):
|
||||||
if not input_id or (isinstance(input_id, str) and not input_id.strip().isdigit()):
|
if not input_id or (isinstance(input_id, str) and not input_id.strip().isdigit()):
|
||||||
return [default_value]
|
return [default_value]
|
||||||
return [int(input_id)]
|
return [int(input_id)]
|
||||||
|
|||||||
@@ -11,15 +11,23 @@ class ComfyUIDeployExternalNumberSlider:
|
|||||||
"optional": {
|
"optional": {
|
||||||
"default_value": (
|
"default_value": (
|
||||||
"FLOAT",
|
"FLOAT",
|
||||||
{"multiline": True, "display": "number", "default": 0.5, "step": 0.01},
|
{"multiline": True, "display": "number", "min": -2147483647, "max": 2147483647, "default": 0.5, "step": 0.01},
|
||||||
),
|
),
|
||||||
"min_value": (
|
"min_value": (
|
||||||
"FLOAT",
|
"FLOAT",
|
||||||
{"multiline": True, "display": "number", "default": 0, "step": 0.01},
|
{"multiline": True, "display": "number", "min": -2147483647, "max": 2147483647, "default": 0, "step": 0.01},
|
||||||
),
|
),
|
||||||
"max_value": (
|
"max_value": (
|
||||||
"FLOAT",
|
"FLOAT",
|
||||||
{"multiline": True, "display": "number", "default": 1, "step": 0.01},
|
{"multiline": True, "display": "number", "min": -2147483647, "max": 2147483647, "default": 1, "step": 0.01},
|
||||||
|
),
|
||||||
|
"display_name": (
|
||||||
|
"STRING",
|
||||||
|
{"multiline": False, "default": ""},
|
||||||
|
),
|
||||||
|
"description": (
|
||||||
|
"STRING",
|
||||||
|
{"multiline": True, "default": ""},
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -31,7 +39,7 @@ class ComfyUIDeployExternalNumberSlider:
|
|||||||
|
|
||||||
CATEGORY = "number"
|
CATEGORY = "number"
|
||||||
|
|
||||||
def run(self, input_id, default_value=None, min_value=0, max_value=1):
|
def run(self, input_id, default_value=None, min_value=0, max_value=1, display_name=None, description=None):
|
||||||
try:
|
try:
|
||||||
float_value = float(input_id)
|
float_value = float(input_id)
|
||||||
if min_value <= float_value <= max_value:
|
if min_value <= float_value <= max_value:
|
||||||
|
|||||||
@@ -18,6 +18,14 @@ class ComfyUIDeployExternalText:
|
|||||||
"STRING",
|
"STRING",
|
||||||
{"multiline": True, "default": ""},
|
{"multiline": True, "default": ""},
|
||||||
),
|
),
|
||||||
|
"display_name": (
|
||||||
|
"STRING",
|
||||||
|
{"multiline": False, "default": ""},
|
||||||
|
),
|
||||||
|
"description": (
|
||||||
|
"STRING",
|
||||||
|
{"multiline": True, "default": ""},
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,7 +36,7 @@ class ComfyUIDeployExternalText:
|
|||||||
|
|
||||||
CATEGORY = "text"
|
CATEGORY = "text"
|
||||||
|
|
||||||
def run(self, input_id, default_value=None):
|
def run(self, input_id, default_value=None, display_name=None, description=None):
|
||||||
return [default_value]
|
return [default_value]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,16 @@ class ComfyUIDeployExternalTextList:
|
|||||||
"STRING",
|
"STRING",
|
||||||
{"multiline": True, "default": "[]"},
|
{"multiline": True, "default": "[]"},
|
||||||
),
|
),
|
||||||
|
},
|
||||||
|
"optional": {
|
||||||
|
"display_name": (
|
||||||
|
"STRING",
|
||||||
|
{"multiline": False, "default": ""},
|
||||||
|
),
|
||||||
|
"description": (
|
||||||
|
"STRING",
|
||||||
|
{"multiline": True, "default": ""},
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,15 +39,14 @@ class ComfyUIDeployExternalTextList:
|
|||||||
|
|
||||||
CATEGORY = "text"
|
CATEGORY = "text"
|
||||||
|
|
||||||
def run(self, input_id, text=None):
|
def run(self, input_id, text=None, display_name=None, description=None):
|
||||||
text_list = []
|
text_list = []
|
||||||
try:
|
try:
|
||||||
text_list = json.loads(text) # Assuming text is a JSON array string
|
text_list = json.loads(text) # Assuming text is a JSON array string
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error processing images: {e}")
|
print(f"Error processing images: {e}")
|
||||||
pass
|
pass
|
||||||
return [text_list]
|
return ([text_list],)
|
||||||
|
|
||||||
|
|
||||||
NODE_CLASS_MAPPINGS = {"ComfyUIDeployExternalTextList": ComfyUIDeployExternalTextList}
|
NODE_CLASS_MAPPINGS = {"ComfyUIDeployExternalTextList": ComfyUIDeployExternalTextList}
|
||||||
NODE_DISPLAY_NAME_MAPPINGS = {"ComfyUIDeployExternalTextList": "External Text List (ComfyUI Deploy)"}
|
NODE_DISPLAY_NAME_MAPPINGS = {"ComfyUIDeployExternalTextList": "External Text List (ComfyUI Deploy)"}
|
||||||
|
|||||||
@@ -765,6 +765,14 @@ class ComfyUIDeployExternalVideo:
|
|||||||
"meta_batch": ("VHS_BatchManager",),
|
"meta_batch": ("VHS_BatchManager",),
|
||||||
"vae": ("VAE",),
|
"vae": ("VAE",),
|
||||||
"default_value": (sorted(files),),
|
"default_value": (sorted(files),),
|
||||||
|
"display_name": (
|
||||||
|
"STRING",
|
||||||
|
{"multiline": False, "default": ""},
|
||||||
|
),
|
||||||
|
"description": (
|
||||||
|
"STRING",
|
||||||
|
{"multiline": True, "default": ""},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
"hidden": {
|
"hidden": {
|
||||||
"unique_id": "UNIQUE_ID"
|
"unique_id": "UNIQUE_ID"
|
||||||
@@ -796,8 +804,6 @@ class ComfyUIDeployExternalVideo:
|
|||||||
meta_batch = kwargs.get("meta_batch")
|
meta_batch = kwargs.get("meta_batch")
|
||||||
unique_id = kwargs.get("unique_id")
|
unique_id = kwargs.get("unique_id")
|
||||||
|
|
||||||
video = kwargs.get("default_value")
|
|
||||||
video_path = folder_paths.get_annotated_filepath(video.strip('"'))
|
|
||||||
|
|
||||||
input_dir = folder_paths.get_input_directory()
|
input_dir = folder_paths.get_input_directory()
|
||||||
if input_id.startswith("http"):
|
if input_id.startswith("http"):
|
||||||
@@ -827,8 +833,11 @@ class ComfyUIDeployExternalVideo:
|
|||||||
leave=True,
|
leave=True,
|
||||||
):
|
):
|
||||||
out_file.write(chunk)
|
out_file.write(chunk)
|
||||||
|
else:
|
||||||
print("video path: ", video_path)
|
video = kwargs.get("default_value", "")
|
||||||
|
if video is None:
|
||||||
|
raise "No default video given and no external video provided"
|
||||||
|
video_path = folder_paths.get_annotated_filepath(video.strip('"'))
|
||||||
|
|
||||||
return load_video_cv(
|
return load_video_cv(
|
||||||
video=video_path,
|
video=video_path,
|
||||||
|
|||||||
+184
-48
@@ -1,4 +1,5 @@
|
|||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
from pprint import pprint
|
||||||
from aiohttp import web
|
from aiohttp import web
|
||||||
import os
|
import os
|
||||||
import requests
|
import requests
|
||||||
@@ -17,12 +18,13 @@ from urllib.parse import quote
|
|||||||
import threading
|
import threading
|
||||||
import hashlib
|
import hashlib
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
from aiohttp import ClientSession, web
|
||||||
import aiofiles
|
import aiofiles
|
||||||
from typing import Dict, List, Union, Any, Optional
|
from typing import Dict, List, Union, Any, Optional
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
import copy
|
import copy
|
||||||
import struct
|
import struct
|
||||||
from aiohttp import ClientError
|
from aiohttp import web, ClientSession, ClientError, ClientTimeout
|
||||||
import atexit
|
import atexit
|
||||||
|
|
||||||
# Global session
|
# Global session
|
||||||
@@ -50,28 +52,65 @@ def exit_handler():
|
|||||||
|
|
||||||
atexit.register(exit_handler)
|
atexit.register(exit_handler)
|
||||||
|
|
||||||
max_retries = int(os.environ.get('MAX_RETRIES', '3'))
|
max_retries = int(os.environ.get('MAX_RETRIES', '5'))
|
||||||
retry_delay_multiplier = float(os.environ.get('RETRY_DELAY_MULTIPLIER', '2'))
|
retry_delay_multiplier = float(os.environ.get('RETRY_DELAY_MULTIPLIER', '2'))
|
||||||
|
|
||||||
print(f"max_retries: {max_retries}, retry_delay_multiplier: {retry_delay_multiplier}")
|
print(f"max_retries: {max_retries}, retry_delay_multiplier: {retry_delay_multiplier}")
|
||||||
|
|
||||||
async def async_request_with_retry(method, url, **kwargs):
|
import time
|
||||||
|
|
||||||
|
async def async_request_with_retry(method, url, disable_timeout=False, **kwargs):
|
||||||
global client_session
|
global client_session
|
||||||
await ensure_client_session()
|
await ensure_client_session()
|
||||||
retry_delay = 1 # Start with 1 second delay
|
retry_delay = 1 # Start with 1 second delay
|
||||||
|
initial_timeout = 5 # 5 seconds timeout for the initial connection
|
||||||
|
|
||||||
|
start_time = time.time()
|
||||||
for attempt in range(max_retries):
|
for attempt in range(max_retries):
|
||||||
try:
|
try:
|
||||||
|
if not disable_timeout:
|
||||||
|
timeout = ClientTimeout(total=None, connect=initial_timeout)
|
||||||
|
kwargs['timeout'] = timeout
|
||||||
|
|
||||||
|
request_start = time.time()
|
||||||
async with client_session.request(method, url, **kwargs) as response:
|
async with client_session.request(method, url, **kwargs) as response:
|
||||||
|
request_end = time.time()
|
||||||
|
logger.info(f"Request attempt {attempt + 1} took {request_end - request_start:.2f} seconds")
|
||||||
|
|
||||||
|
if response.status != 200:
|
||||||
|
error_body = await response.text()
|
||||||
|
logger.error(f"Request failed with status {response.status} and body {error_body}")
|
||||||
|
# raise Exception(f"Request failed with status {response.status}")
|
||||||
|
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
|
if method.upper() == 'GET':
|
||||||
|
await response.read()
|
||||||
|
|
||||||
|
total_time = time.time() - start_time
|
||||||
|
logger.info(f"Request succeeded after {total_time:.2f} seconds (attempt {attempt + 1}/{max_retries})")
|
||||||
return response
|
return response
|
||||||
|
except asyncio.TimeoutError:
|
||||||
|
logger.warning(f"Request timed out after {initial_timeout} seconds (attempt {attempt + 1}/{max_retries})")
|
||||||
except ClientError as e:
|
except ClientError as e:
|
||||||
|
end_time = time.time()
|
||||||
|
logger.error(f"Request failed (attempt {attempt + 1}/{max_retries}): {e}")
|
||||||
|
logger.error(f"Time taken for failed attempt: {end_time - request_start:.2f} seconds")
|
||||||
|
logger.error(f"Total time elapsed: {end_time - start_time:.2f} seconds")
|
||||||
|
|
||||||
|
# Log the response body for ClientError as well
|
||||||
|
if hasattr(e, 'response') and e.response is not None:
|
||||||
|
error_body = await e.response.text()
|
||||||
|
logger.error(f"Error response body: {error_body}")
|
||||||
|
|
||||||
if attempt == max_retries - 1:
|
if attempt == max_retries - 1:
|
||||||
logger.error(f"Request failed after {max_retries} attempts: {e}")
|
logger.error(f"Request failed after {max_retries} attempts: {e}")
|
||||||
# raise
|
raise
|
||||||
logger.warning(f"Request failed (attempt {attempt + 1}/{max_retries}): {e}")
|
|
||||||
await asyncio.sleep(retry_delay)
|
await asyncio.sleep(retry_delay)
|
||||||
retry_delay *= retry_delay_multiplier # Exponential backoff
|
retry_delay *= retry_delay_multiplier
|
||||||
|
|
||||||
|
total_time = time.time() - start_time
|
||||||
|
raise Exception(f"Request failed after {max_retries} attempts and {total_time:.2f} seconds")
|
||||||
|
|
||||||
from logging import basicConfig, getLogger
|
from logging import basicConfig, getLogger
|
||||||
|
|
||||||
@@ -217,13 +256,30 @@ def apply_random_seed_to_workflow(workflow_api):
|
|||||||
workflow_api (dict): The workflow API dictionary to modify.
|
workflow_api (dict): The workflow API dictionary to modify.
|
||||||
"""
|
"""
|
||||||
for key in workflow_api:
|
for key in workflow_api:
|
||||||
if 'inputs' in workflow_api[key] and 'seed' in workflow_api[key]['inputs']:
|
if 'inputs' in workflow_api[key]:
|
||||||
if isinstance(workflow_api[key]['inputs']['seed'], list):
|
if 'seed' in workflow_api[key]['inputs']:
|
||||||
continue
|
if isinstance(workflow_api[key]['inputs']['seed'], list):
|
||||||
if workflow_api[key]['class_type'] == "PromptExpansion":
|
continue
|
||||||
workflow_api[key]['inputs']['seed'] = randomSeed(8);
|
if workflow_api[key]['class_type'] == "PromptExpansion":
|
||||||
continue
|
workflow_api[key]['inputs']['seed'] = randomSeed(8)
|
||||||
workflow_api[key]['inputs']['seed'] = randomSeed();
|
logger.info(f"Applied random seed {workflow_api[key]['inputs']['seed']} to PromptExpansion")
|
||||||
|
continue
|
||||||
|
workflow_api[key]['inputs']['seed'] = randomSeed()
|
||||||
|
logger.info(f"Applied random seed {workflow_api[key]['inputs']['seed']} to {workflow_api[key]['class_type']}")
|
||||||
|
|
||||||
|
if 'noise_seed' in workflow_api[key]['inputs']:
|
||||||
|
if workflow_api[key]['class_type'] == "RandomNoise":
|
||||||
|
workflow_api[key]['inputs']['noise_seed'] = randomSeed()
|
||||||
|
logger.info(f"Applied random noise_seed {workflow_api[key]['inputs']['noise_seed']} to RandomNoise")
|
||||||
|
continue
|
||||||
|
if workflow_api[key]['class_type'] == "KSamplerAdvanced":
|
||||||
|
workflow_api[key]['inputs']['noise_seed'] = randomSeed()
|
||||||
|
logger.info(f"Applied random noise_seed {workflow_api[key]['inputs']['noise_seed']} to KSamplerAdvanced")
|
||||||
|
continue
|
||||||
|
if workflow_api[key]['class_type'] == "SamplerCustom":
|
||||||
|
workflow_api[key]['inputs']['noise_seed'] = randomSeed()
|
||||||
|
logger.info(f"Applied random noise_seed {workflow_api[key]['inputs']['noise_seed']} to SamplerCustom")
|
||||||
|
continue
|
||||||
|
|
||||||
def apply_inputs_to_workflow(workflow_api: Any, inputs: Any, sid: str = None):
|
def apply_inputs_to_workflow(workflow_api: Any, inputs: Any, sid: str = None):
|
||||||
# Loop through each of the inputs and replace them
|
# Loop through each of the inputs and replace them
|
||||||
@@ -258,7 +314,7 @@ def apply_inputs_to_workflow(workflow_api: Any, inputs: Any, sid: str = None):
|
|||||||
value['inputs']["images"] = new_value
|
value['inputs']["images"] = new_value
|
||||||
|
|
||||||
if value["class_type"] == "ComfyUIDeployExternalLora":
|
if value["class_type"] == "ComfyUIDeployExternalLora":
|
||||||
value["inputs"]["default_lora_name"] = new_value
|
value["inputs"]["lora_url"] = new_value
|
||||||
|
|
||||||
if value["class_type"] == "ComfyUIDeployExternalSlider":
|
if value["class_type"] == "ComfyUIDeployExternalSlider":
|
||||||
value["inputs"]["default_value"] = new_value
|
value["inputs"]["default_value"] = new_value
|
||||||
@@ -349,7 +405,7 @@ async def comfy_deploy_run(request):
|
|||||||
|
|
||||||
status = 200
|
status = 200
|
||||||
|
|
||||||
if "node_errors" in res and res["node_errors"] is not None:
|
if "node_errors" in res and res["node_errors"] is not None and len(res["node_errors"]) > 0:
|
||||||
# Even tho there are node_errors it can still be run
|
# Even tho there are node_errors it can still be run
|
||||||
status = 400
|
status = 400
|
||||||
await update_run_with_output(prompt_id, {
|
await update_run_with_output(prompt_id, {
|
||||||
@@ -410,7 +466,7 @@ async def stream_prompt(data):
|
|||||||
|
|
||||||
status = 200
|
status = 200
|
||||||
|
|
||||||
if "node_errors" in res and res["node_errors"] is not None:
|
if "node_errors" in res and res["node_errors"] is not None and len(res["node_errors"]) > 0:
|
||||||
# Even tho there are node_errors it can still be run
|
# Even tho there are node_errors it can still be run
|
||||||
status = 400
|
status = 400
|
||||||
await update_run_with_output(prompt_id, {
|
await update_run_with_output(prompt_id, {
|
||||||
@@ -573,9 +629,10 @@ async def upload_file_endpoint(request):
|
|||||||
with open(file_path, 'rb') as f:
|
with open(file_path, 'rb') as f:
|
||||||
headers = {
|
headers = {
|
||||||
"Content-Type": file_type,
|
"Content-Type": file_type,
|
||||||
# "x-amz-acl": "public-read",
|
# "Content-Length": str(file_size)
|
||||||
"Content-Length": str(file_size)
|
|
||||||
}
|
}
|
||||||
|
if content.get('include_acl') is True:
|
||||||
|
headers["x-amz-acl"] = "public-read"
|
||||||
upload_response = await async_request_with_retry('PUT', upload_url, data=f, headers=headers)
|
upload_response = await async_request_with_retry('PUT', upload_url, data=f, headers=headers)
|
||||||
if upload_response.status == 200:
|
if upload_response.status == 200:
|
||||||
return web.json_response({
|
return web.json_response({
|
||||||
@@ -821,7 +878,51 @@ async def send(event, data, sid=None):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.info(f"Exception: {e}")
|
logger.info(f"Exception: {e}")
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
|
@server.PromptServer.instance.routes.get('/comfydeploy/{tail:.*}')
|
||||||
|
@server.PromptServer.instance.routes.post('/comfydeploy/{tail:.*}')
|
||||||
|
async def proxy_to_comfydeploy(request):
|
||||||
|
# Get the base URL
|
||||||
|
base_url = f'https://www.comfydeploy.com/{request.match_info["tail"]}'
|
||||||
|
|
||||||
|
# Get all query parameters
|
||||||
|
query_params = request.query_string
|
||||||
|
|
||||||
|
# Construct the full target URL with query parameters
|
||||||
|
target_url = f"{base_url}?{query_params}" if query_params else base_url
|
||||||
|
|
||||||
|
# print(f"Proxying request to: {target_url}")
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Create a new ClientSession for each request
|
||||||
|
async with ClientSession() as client_session:
|
||||||
|
# Forward the request
|
||||||
|
client_req = await client_session.request(
|
||||||
|
method=request.method,
|
||||||
|
url=target_url,
|
||||||
|
headers={k: v for k, v in request.headers.items() if k.lower() not in ('host', 'content-length')},
|
||||||
|
data=await request.read(),
|
||||||
|
allow_redirects=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Read the entire response content
|
||||||
|
content = await client_req.read()
|
||||||
|
|
||||||
|
# Try to decode the content as JSON
|
||||||
|
try:
|
||||||
|
json_data = json.loads(content)
|
||||||
|
# If successful, return a JSON response
|
||||||
|
return web.json_response(json_data, status=client_req.status)
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
# If it's not valid JSON, return the content as-is
|
||||||
|
return web.Response(body=content, status=client_req.status, headers=client_req.headers)
|
||||||
|
|
||||||
|
except ClientError as e:
|
||||||
|
print(f"Client error occurred while proxying request: {str(e)}")
|
||||||
|
return web.Response(status=502, text=f"Bad Gateway: {str(e)}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error occurred while proxying request: {str(e)}")
|
||||||
|
return web.Response(status=500, text=f"Internal Server Error: {str(e)}")
|
||||||
|
|
||||||
|
|
||||||
prompt_server = server.PromptServer.instance
|
prompt_server = server.PromptServer.instance
|
||||||
@@ -914,17 +1015,22 @@ async def send_json_override(self, event, data, sid=None):
|
|||||||
# await update_run_with_output(prompt_id, data)
|
# await update_run_with_output(prompt_id, data)
|
||||||
|
|
||||||
if event == 'executed' and 'node' in data and 'output' in data:
|
if event == 'executed' and 'node' in data and 'output' in data:
|
||||||
|
node_meta = None
|
||||||
if prompt_id in prompt_metadata:
|
if prompt_id in prompt_metadata:
|
||||||
node = data.get('node')
|
node = data.get('node')
|
||||||
class_type = prompt_metadata[prompt_id].workflow_api[node]['class_type']
|
class_type = prompt_metadata[prompt_id].workflow_api[node]['class_type']
|
||||||
logger.info(f"Executed {class_type} {data}")
|
logger.info(f"Executed {class_type} {data}")
|
||||||
|
node_meta = {
|
||||||
|
"node_id": node,
|
||||||
|
"node_class": class_type,
|
||||||
|
}
|
||||||
if class_type == "PreviewImage":
|
if class_type == "PreviewImage":
|
||||||
logger.info("Skipping preview image")
|
logger.info("Skipping preview image")
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
logger.info(f"Executed {data}")
|
logger.info(f"Executed {data}")
|
||||||
|
|
||||||
await update_run_with_output(prompt_id, data.get('output'), node_id=data.get('node'))
|
await update_run_with_output(prompt_id, data.get('output'), node_id=data.get('node'), node_meta=node_meta)
|
||||||
# await update_run_with_output(prompt_id, data.get('output'), node_id=data.get('node'))
|
# await update_run_with_output(prompt_id, data.get('output'), node_id=data.get('node'))
|
||||||
# update_run_with_output(prompt_id, data.get('output'))
|
# update_run_with_output(prompt_id, data.get('output'))
|
||||||
|
|
||||||
@@ -1044,7 +1150,7 @@ async def update_run(prompt_id: str, status: Status):
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
async def upload_file(prompt_id, filename, subfolder=None, content_type="image/png", type="output"):
|
async def upload_file(prompt_id, filename, subfolder=None, content_type="image/png", type="output", item=None):
|
||||||
"""
|
"""
|
||||||
Uploads file to S3 bucket using S3 client object
|
Uploads file to S3 bucket using S3 client object
|
||||||
:return: None
|
:return: None
|
||||||
@@ -1079,28 +1185,40 @@ async def upload_file(prompt_id, filename, subfolder=None, content_type="image/p
|
|||||||
prompt_id = quote(prompt_id)
|
prompt_id = quote(prompt_id)
|
||||||
content_type = quote(content_type)
|
content_type = quote(content_type)
|
||||||
|
|
||||||
target_url = f"{file_upload_endpoint}?file_name={filename}&run_id={prompt_id}&type={content_type}"
|
async with aiofiles.open(file, 'rb') as f:
|
||||||
|
data = await f.read()
|
||||||
|
size = str(len(data))
|
||||||
|
target_url = f"{file_upload_endpoint}?file_name={filename}&run_id={prompt_id}&type={content_type}&version=v2"
|
||||||
|
|
||||||
start_time = time.time() # Start timing here
|
start_time = time.time() # Start timing here
|
||||||
result = requests.get(target_url)
|
logger.info(f"Target URL: {target_url}")
|
||||||
end_time = time.time() # End timing after the request is complete
|
result = await async_request_with_retry("GET", target_url, disable_timeout=True)
|
||||||
logger.info("Time taken for getting file upload endpoint: {:.2f} seconds".format(end_time - start_time))
|
end_time = time.time() # End timing after the request is complete
|
||||||
ok = result.json()
|
logger.info("Time taken for getting file upload endpoint: {:.2f} seconds".format(end_time - start_time))
|
||||||
|
ok = await result.json()
|
||||||
|
|
||||||
|
logger.info(f"Result: {ok}")
|
||||||
|
|
||||||
start_time = time.time() # Start timing here
|
start_time = time.time() # Start timing here
|
||||||
|
|
||||||
with open(file, 'rb') as f:
|
|
||||||
data = f.read()
|
|
||||||
headers = {
|
headers = {
|
||||||
# "x-amz-acl": "public-read",
|
|
||||||
"Content-Type": content_type,
|
"Content-Type": content_type,
|
||||||
"Content-Length": str(len(data)),
|
# "Content-Length": size,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ok.get('include_acl') is True:
|
||||||
|
headers["x-amz-acl"] = "public-read"
|
||||||
|
|
||||||
# response = requests.put(ok.get("url"), headers=headers, data=data)
|
# response = requests.put(ok.get("url"), headers=headers, data=data)
|
||||||
response = await async_request_with_retry('PUT', ok.get("url"), headers=headers, data=data)
|
response = await async_request_with_retry('PUT', ok.get("url"), headers=headers, data=data)
|
||||||
logger.info(f"Upload file response status: {response.status}, status text: {response.reason}")
|
logger.info(f"Upload file response status: {response.status}, status text: {response.reason}")
|
||||||
end_time = time.time() # End timing after the request is complete
|
end_time = time.time() # End timing after the request is complete
|
||||||
logger.info("Upload time: {:.2f} seconds".format(end_time - start_time))
|
logger.info("Upload time: {:.2f} seconds".format(end_time - start_time))
|
||||||
|
|
||||||
|
if item is not None:
|
||||||
|
file_download_url = ok.get("download_url")
|
||||||
|
if file_download_url is not None:
|
||||||
|
item["url"] = file_download_url
|
||||||
|
item["upload_duration"] = end_time - start_time
|
||||||
|
|
||||||
def have_pending_upload(prompt_id):
|
def have_pending_upload(prompt_id):
|
||||||
if prompt_id in prompt_metadata and len(prompt_metadata[prompt_id].uploading_nodes) > 0:
|
if prompt_id in prompt_metadata and len(prompt_metadata[prompt_id].uploading_nodes) > 0:
|
||||||
@@ -1193,8 +1311,10 @@ async def update_file_status(prompt_id: str, data, uploading, have_error=False,
|
|||||||
|
|
||||||
async def handle_upload(prompt_id: str, data, key: str, content_type_key: str, default_content_type: str):
|
async def handle_upload(prompt_id: str, data, key: str, content_type_key: str, default_content_type: str):
|
||||||
items = data.get(key, [])
|
items = data.get(key, [])
|
||||||
|
upload_tasks = []
|
||||||
|
|
||||||
for item in items:
|
for item in items:
|
||||||
# # Skipping temp files
|
# Skipping temp files
|
||||||
if item.get("type") == "temp":
|
if item.get("type") == "temp":
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -1207,29 +1327,45 @@ async def handle_upload(prompt_id: str, data, key: str, content_type_key: str, d
|
|||||||
elif file_extension == '.webp':
|
elif file_extension == '.webp':
|
||||||
file_type = 'image/webp'
|
file_type = 'image/webp'
|
||||||
|
|
||||||
await upload_file(
|
upload_tasks.append(upload_file(
|
||||||
prompt_id,
|
prompt_id,
|
||||||
item.get("filename"),
|
item.get("filename"),
|
||||||
subfolder=item.get("subfolder"),
|
subfolder=item.get("subfolder"),
|
||||||
type=item.get("type"),
|
type=item.get("type"),
|
||||||
content_type=file_type
|
content_type=file_type,
|
||||||
)
|
item=item
|
||||||
|
))
|
||||||
|
|
||||||
|
# Execute all upload tasks concurrently
|
||||||
|
await asyncio.gather(*upload_tasks)
|
||||||
|
|
||||||
# Upload files in the background
|
# Upload files in the background
|
||||||
async def upload_in_background(prompt_id: str, data, node_id=None, have_upload=True):
|
async def upload_in_background(prompt_id: str, data, node_id=None, have_upload=True, node_meta=None):
|
||||||
try:
|
try:
|
||||||
await handle_upload(prompt_id, data, 'images', "content_type", "image/png")
|
upload_tasks = [
|
||||||
await handle_upload(prompt_id, data, 'files', "content_type", "image/png")
|
handle_upload(prompt_id, data, 'images', "content_type", "image/png"),
|
||||||
# This will also be mp4
|
handle_upload(prompt_id, data, 'files', "content_type", "image/png"),
|
||||||
await handle_upload(prompt_id, data, 'gifs', "format", "image/gif")
|
handle_upload(prompt_id, data, 'gifs', "format", "image/gif"),
|
||||||
await handle_upload(prompt_id, data, 'mesh', "format", "application/octet-stream")
|
handle_upload(prompt_id, data, 'mesh', "format", "application/octet-stream")
|
||||||
|
]
|
||||||
|
|
||||||
|
await asyncio.gather(*upload_tasks)
|
||||||
|
|
||||||
|
status_endpoint = prompt_metadata[prompt_id].status_endpoint
|
||||||
if have_upload:
|
if have_upload:
|
||||||
|
if status_endpoint is not None:
|
||||||
|
body = {
|
||||||
|
"run_id": prompt_id,
|
||||||
|
"output_data": data,
|
||||||
|
"node_meta": node_meta,
|
||||||
|
}
|
||||||
|
# pprint(body)
|
||||||
|
await async_request_with_retry('POST', status_endpoint, json=body)
|
||||||
await update_file_status(prompt_id, data, False, node_id=node_id)
|
await update_file_status(prompt_id, data, False, node_id=node_id)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
await handle_error(prompt_id, data, e)
|
await handle_error(prompt_id, data, e)
|
||||||
|
|
||||||
async def update_run_with_output(prompt_id, data, node_id=None):
|
async def update_run_with_output(prompt_id, data, node_id=None, node_meta=None):
|
||||||
if prompt_id not in prompt_metadata:
|
if prompt_id not in prompt_metadata:
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -1240,7 +1376,8 @@ async def update_run_with_output(prompt_id, data, node_id=None):
|
|||||||
|
|
||||||
body = {
|
body = {
|
||||||
"run_id": prompt_id,
|
"run_id": prompt_id,
|
||||||
"output_data": data
|
"output_data": data,
|
||||||
|
"node_meta": node_meta,
|
||||||
}
|
}
|
||||||
have_upload_media = 'images' in data or 'files' in data or 'gifs' in data or 'mesh' in data
|
have_upload_media = 'images' in data or 'files' in data or 'gifs' in data or 'mesh' in data
|
||||||
if bypass_upload and have_upload_media:
|
if bypass_upload and have_upload_media:
|
||||||
@@ -1254,14 +1391,13 @@ async def update_run_with_output(prompt_id, data, node_id=None):
|
|||||||
if have_upload_media:
|
if have_upload_media:
|
||||||
await update_file_status(prompt_id, data, True, node_id=node_id)
|
await update_file_status(prompt_id, data, True, node_id=node_id)
|
||||||
|
|
||||||
asyncio.create_task(upload_in_background(prompt_id, data, node_id=node_id, have_upload=have_upload_media))
|
asyncio.create_task(upload_in_background(prompt_id, data, node_id=node_id, have_upload=have_upload_media, node_meta=node_meta))
|
||||||
# await upload_in_background(prompt_id, data, node_id=node_id, have_upload=have_upload)
|
# await upload_in_background(prompt_id, data, node_id=node_id, have_upload=have_upload)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
await handle_error(prompt_id, data, e)
|
await handle_error(prompt_id, data, e)
|
||||||
|
|
||||||
# requests.post(status_endpoint, json=body)
|
# requests.post(status_endpoint, json=body)
|
||||||
if status_endpoint is not None:
|
elif status_endpoint is not None:
|
||||||
await async_request_with_retry('POST', status_endpoint, json=body)
|
await async_request_with_retry('POST', status_endpoint, json=body)
|
||||||
|
|
||||||
await send('outputs_uploaded', {
|
await send('outputs_uploaded', {
|
||||||
|
|||||||
@@ -2,4 +2,5 @@ aiofiles
|
|||||||
pydantic
|
pydantic
|
||||||
opencv-python
|
opencv-python
|
||||||
imageio-ffmpeg
|
imageio-ffmpeg
|
||||||
|
brotli
|
||||||
# logfire
|
# logfire
|
||||||
+1187
-1032
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user