Compare commits

...
Author SHA1 Message Date
nick 649b61c580 default vid 2024-08-26 13:46:01 -07:00
nick edff5685f9 fix: random seed 2024-08-22 17:39:03 -07:00
bennykok 9fc0c2b4a2 chore: upload node data 2024-08-21 16:34:25 -07:00
bennykok d34e2e99b1 fix: external lora for new comfyui 2024-08-21 09:46:13 -07:00
bennykok f85043db07 fix: remove default value 2024-08-20 19:14:43 -07:00
bennykok 894d8e1503 Merge branch 'benny/async-upload-file' into public-main 2024-08-20 18:02:57 -07:00
bennykok 08d631d1eb feat: async file upload for the same node 2024-08-20 17:07:50 -07:00
13 changed files with 94 additions and 69 deletions
+2 -2
View File
@@ -12,11 +12,11 @@ class ComfyUIDeployExternalBoolean:
"optional": {
"display_name": (
"STRING",
{"multiline": False, "default": "Name of the node (optional)"},
{"multiline": False, "default": ""},
),
"description": (
"STRING",
{"multiline": True, "default": "Description of the node (optional)"},
{"multiline": True, "default": ""},
),
}
}
+2 -2
View File
@@ -25,11 +25,11 @@ class ComfyUIDeployExternalCheckpoint:
"default_value": (folder_paths.get_filename_list("checkpoints"), ),
"display_name": (
"STRING",
{"multiline": False, "default": "Name of the node (optional)"},
{"multiline": False, "default": ""},
),
"description": (
"STRING",
{"multiline": True, "default": "Description of the node (optional)"},
{"multiline": True, "default": ""},
),
}
}
+2 -2
View File
@@ -17,11 +17,11 @@ class ComfyUIDeployExternalImage:
"default_value": ("IMAGE",),
"display_name": (
"STRING",
{"multiline": False, "default": "Name of the node (optional)"},
{"multiline": False, "default": ""},
),
"description": (
"STRING",
{"multiline": True, "default": "Description of the node (optional)"},
{"multiline": True, "default": ""},
),
}
}
+2 -2
View File
@@ -17,11 +17,11 @@ class ComfyUIDeployExternalImageAlpha:
"default_value": ("IMAGE",),
"display_name": (
"STRING",
{"multiline": False, "default": "Name of the node (optional)"},
{"multiline": False, "default": ""},
),
"description": (
"STRING",
{"multiline": True, "default": "Description of the node (optional)"},
{"multiline": True, "default": ""},
),
}
}
+2 -2
View File
@@ -23,11 +23,11 @@ class ComfyUIDeployExternalImageBatch:
"default_value": ("IMAGE",),
"display_name": (
"STRING",
{"multiline": False, "default": "Name of the node (optional)"},
{"multiline": False, "default": ""},
),
"description": (
"STRING",
{"multiline": True, "default": "Description of the node (optional)"},
{"multiline": True, "default": ""},
),
}
}
+8 -4
View File
@@ -31,11 +31,15 @@ class ComfyUIDeployExternalLora:
),
"display_name": (
"STRING",
{"multiline": False, "default": "Name of the node (optional)"},
{"multiline": False, "default": ""},
),
"description": (
"STRING",
{"multiline": True, "default": "Description of the node (optional)"},
{"multiline": True, "default": ""},
),
"lora_url": (
"STRING",
{"multiline": False, "default": ""},
),
},
}
@@ -47,12 +51,12 @@ class ComfyUIDeployExternalLora:
CATEGORY = "deploy"
def run(self, input_id, default_lora_name=None, lora_save_name=None, display_name=None, description=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 os
import uuid
if default_lora_name.startswith("http"):
if lora_url and lora_url.startswith("http"):
if lora_save_name:
existing_loras = folder_paths.get_filename_list("loras")
# Check if lora_save_name exists in the list
+2 -2
View File
@@ -20,11 +20,11 @@ class ComfyUIDeployExternalNumber:
),
"display_name": (
"STRING",
{"multiline": False, "default": "Name of the node (optional)"},
{"multiline": False, "default": ""},
),
"description": (
"STRING",
{"multiline": True, "default": "Description of the node (optional)"},
{"multiline": True, "default": ""},
),
}
}
+2 -2
View File
@@ -20,11 +20,11 @@ class ComfyUIDeployExternalNumberInt:
),
"display_name": (
"STRING",
{"multiline": False, "default": "Name of the node (optional)"},
{"multiline": False, "default": ""},
),
"description": (
"STRING",
{"multiline": True, "default": "Description of the node (optional)"},
{"multiline": True, "default": ""},
),
}
}
+2 -2
View File
@@ -23,11 +23,11 @@ class ComfyUIDeployExternalNumberSlider:
),
"display_name": (
"STRING",
{"multiline": False, "default": "Name of the node (optional)"},
{"multiline": False, "default": ""},
),
"description": (
"STRING",
{"multiline": True, "default": "Description of the node (optional)"},
{"multiline": True, "default": ""},
),
}
}
+2 -2
View File
@@ -20,11 +20,11 @@ class ComfyUIDeployExternalText:
),
"display_name": (
"STRING",
{"multiline": False, "default": "Name of the node (optional)"},
{"multiline": False, "default": ""},
),
"description": (
"STRING",
{"multiline": True, "default": "Description of the node (optional)"},
{"multiline": True, "default": ""},
),
}
}
+2 -2
View File
@@ -21,11 +21,11 @@ class ComfyUIDeployExternalTextList:
"optional": {
"display_name": (
"STRING",
{"multiline": False, "default": "Name of the node (optional)"},
{"multiline": False, "default": ""},
),
"description": (
"STRING",
{"multiline": True, "default": "Description of the node (optional)"},
{"multiline": True, "default": ""},
),
}
}
+4 -4
View File
@@ -764,14 +764,14 @@ class ComfyUIDeployExternalVideo:
"optional": {
"meta_batch": ("VHS_BatchManager",),
"vae": ("VAE",),
"default_value": (sorted(files),),
"default_video": (sorted(files),),
"display_name": (
"STRING",
{"multiline": False, "default": "Name of the node (optional)"},
{"multiline": False, "default": ""},
),
"description": (
"STRING",
{"multiline": True, "default": "Description of the node (optional)"},
{"multiline": True, "default": ""},
),
},
"hidden": {
@@ -834,7 +834,7 @@ class ComfyUIDeployExternalVideo:
):
out_file.write(chunk)
else:
video = kwargs.get("default_value", "")
video = kwargs.get("default_video", "")
if video is None:
raise "No default video given and no external video provided"
video_path = folder_paths.get_annotated_filepath(video.strip('"'))
+62 -41
View File
@@ -56,20 +56,24 @@ retry_delay_multiplier = float(os.environ.get('RETRY_DELAY_MULTIPLIER', '2'))
print(f"max_retries: {max_retries}, retry_delay_multiplier: {retry_delay_multiplier}")
async def async_request_with_retry(method, url, **kwargs):
async def async_request_with_retry(method, url, disable_timeout=False, **kwargs):
global client_session
await ensure_client_session()
# async with aiohttp.ClientSession() as client_session:
retry_delay = 1 # Start with 1 second delay
initial_timeout = 5 # 5 seconds timeout for the initial connection
for attempt in range(max_retries):
try:
# Set a timeout for the initial connection
timeout = ClientTimeout(total=None, connect=initial_timeout)
kwargs['timeout'] = timeout
if not disable_timeout:
timeout = ClientTimeout(total=None, connect=initial_timeout)
kwargs['timeout'] = timeout
async with client_session.request(method, url, **kwargs) as response:
response.raise_for_status()
if method.upper() == 'GET':
await response.read()
return response
except asyncio.TimeoutError:
logger.warning(f"Request timed out after {initial_timeout} seconds (attempt {attempt + 1}/{max_retries})")
@@ -230,27 +234,30 @@ def apply_random_seed_to_workflow(workflow_api):
workflow_api (dict): The workflow API dictionary to modify.
"""
for key in workflow_api:
if 'inputs' in workflow_api[key] and 'seed' in workflow_api[key]['inputs']:
if isinstance(workflow_api[key]['inputs']['seed'], list):
continue
if workflow_api[key]['class_type'] == "PromptExpansion":
workflow_api[key]['inputs']['seed'] = randomSeed(8)
logger.info(f"Applied random seed {workflow_api[key]['inputs']['seed']} to PromptExpansion")
continue
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
workflow_api[key]['inputs']['seed'] = randomSeed()
logger.info(f"Applied random seed {workflow_api[key]['inputs']['seed']} to {workflow_api[key]['class_type']}")
if 'inputs' in workflow_api[key]:
if 'seed' in workflow_api[key]['inputs']:
if isinstance(workflow_api[key]['inputs']['seed'], list):
continue
if workflow_api[key]['class_type'] == "PromptExpansion":
workflow_api[key]['inputs']['seed'] = randomSeed(8)
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):
# Loop through each of the inputs and replace them
@@ -285,7 +292,7 @@ def apply_inputs_to_workflow(workflow_api: Any, inputs: Any, sid: str = None):
value['inputs']["images"] = new_value
if value["class_type"] == "ComfyUIDeployExternalLora":
value["inputs"]["default_lora_name"] = new_value
value["inputs"]["lora_url"] = new_value
if value["class_type"] == "ComfyUIDeployExternalSlider":
value["inputs"]["default_value"] = new_value
@@ -985,17 +992,22 @@ async def send_json_override(self, event, data, sid=None):
# await update_run_with_output(prompt_id, data)
if event == 'executed' and 'node' in data and 'output' in data:
node_meta = None
if prompt_id in prompt_metadata:
node = data.get('node')
class_type = prompt_metadata[prompt_id].workflow_api[node]['class_type']
logger.info(f"Executed {class_type} {data}")
node_meta = {
"node_id": node,
"node_class": class_type,
}
if class_type == "PreviewImage":
logger.info("Skipping preview image")
return
else:
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'))
# update_run_with_output(prompt_id, data.get('output'))
@@ -1150,18 +1162,18 @@ async def upload_file(prompt_id, filename, subfolder=None, content_type="image/p
prompt_id = quote(prompt_id)
content_type = quote(content_type)
target_url = f"{file_upload_endpoint}?file_name={filename}&run_id={prompt_id}&type={content_type}"
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
result = requests.get(target_url)
result = await async_request_with_retry("GET", target_url, disable_timeout=True)
end_time = time.time() # End timing after the request is complete
logger.info("Time taken for getting file upload endpoint: {:.2f} seconds".format(end_time - start_time))
ok = result.json()
ok = await result.json()
start_time = time.time() # Start timing here
with open(file, 'rb') as f:
data = f.read()
async with aiofiles.open(file, 'rb') as f:
data = await f.read()
headers = {
# "x-amz-acl": "public-read",
"Content-Type": content_type,
@@ -1264,8 +1276,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):
items = data.get(key, [])
upload_tasks = []
for item in items:
# # Skipping temp files
# Skipping temp files
if item.get("type") == "temp":
continue
@@ -1278,29 +1292,35 @@ async def handle_upload(prompt_id: str, data, key: str, content_type_key: str, d
elif file_extension == '.webp':
file_type = 'image/webp'
await upload_file(
upload_tasks.append(upload_file(
prompt_id,
item.get("filename"),
subfolder=item.get("subfolder"),
type=item.get("type"),
content_type=file_type
)
))
# Execute all upload tasks concurrently
await asyncio.gather(*upload_tasks)
# Upload files in the background
async def upload_in_background(prompt_id: str, data, node_id=None, have_upload=True):
try:
await handle_upload(prompt_id, data, 'images', "content_type", "image/png")
await handle_upload(prompt_id, data, 'files', "content_type", "image/png")
# This will also be mp4
await handle_upload(prompt_id, data, 'gifs', "format", "image/gif")
await handle_upload(prompt_id, data, 'mesh', "format", "application/octet-stream")
upload_tasks = [
handle_upload(prompt_id, data, 'images', "content_type", "image/png"),
handle_upload(prompt_id, data, 'files', "content_type", "image/png"),
handle_upload(prompt_id, data, 'gifs', "format", "image/gif"),
handle_upload(prompt_id, data, 'mesh', "format", "application/octet-stream")
]
await asyncio.gather(*upload_tasks)
if have_upload:
await update_file_status(prompt_id, data, False, node_id=node_id)
except Exception as 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:
return
@@ -1311,7 +1331,8 @@ async def update_run_with_output(prompt_id, data, node_id=None):
body = {
"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
if bypass_upload and have_upload_media: