Compare commits
25
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e2fcf67aec | ||
|
|
69f63f4869 | ||
|
|
50860cd500 | ||
|
|
2eb02fc92e | ||
|
|
5c6defbe62 | ||
|
|
d1c54b2b6d | ||
|
|
3a6c3b1ae9 | ||
|
|
aea456cba9 | ||
|
|
8c5e5c4277 | ||
|
|
02430ee62d | ||
|
|
764a8fee82 | ||
|
|
61acffd355 | ||
|
|
aa47f3523f | ||
|
|
7ed4284a6f | ||
|
|
a403daa314 | ||
|
|
ba9b187dcc | ||
|
|
1243fa4e58 | ||
|
|
0d1537963c | ||
|
|
0083b38dcc | ||
|
|
b8dded1535 | ||
|
|
4927d81e73 | ||
|
|
fb6bb2357a | ||
|
|
086d642360 | ||
|
|
5a78ca97bd | ||
|
|
1f5a88b888 |
@@ -0,0 +1,108 @@
|
|||||||
|
from PIL import Image, ImageOps
|
||||||
|
import numpy as np
|
||||||
|
import torch
|
||||||
|
import folder_paths
|
||||||
|
|
||||||
|
|
||||||
|
class AnyType(str):
|
||||||
|
def __ne__(self, __value: object) -> bool:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
WILDCARD = AnyType("*")
|
||||||
|
|
||||||
|
|
||||||
|
class ComfyUIDeployExternalFaceModel:
|
||||||
|
@classmethod
|
||||||
|
def INPUT_TYPES(s):
|
||||||
|
return {
|
||||||
|
"required": {
|
||||||
|
"input_id": (
|
||||||
|
"STRING",
|
||||||
|
{"multiline": False, "default": "input_reactor_face_model"},
|
||||||
|
),
|
||||||
|
},
|
||||||
|
"optional": {
|
||||||
|
"default_face_model_name": (
|
||||||
|
"STRING",
|
||||||
|
{"multiline": False, "default": ""},
|
||||||
|
),
|
||||||
|
"face_model_save_name": ( # if `default_face_model_name` is a link to download a file, we will attempt to save it with this name
|
||||||
|
"STRING",
|
||||||
|
{"multiline": False, "default": ""},
|
||||||
|
),
|
||||||
|
"display_name": (
|
||||||
|
"STRING",
|
||||||
|
{"multiline": False, "default": ""},
|
||||||
|
),
|
||||||
|
"description": (
|
||||||
|
"STRING",
|
||||||
|
{"multiline": True, "default": ""},
|
||||||
|
),
|
||||||
|
"face_model_url": (
|
||||||
|
"STRING",
|
||||||
|
{"multiline": False, "default": ""},
|
||||||
|
),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
RETURN_TYPES = (WILDCARD,)
|
||||||
|
RETURN_NAMES = ("path",)
|
||||||
|
|
||||||
|
FUNCTION = "run"
|
||||||
|
|
||||||
|
CATEGORY = "deploy"
|
||||||
|
|
||||||
|
def run(
|
||||||
|
self,
|
||||||
|
input_id,
|
||||||
|
default_face_model_name=None,
|
||||||
|
face_model_save_name=None,
|
||||||
|
display_name=None,
|
||||||
|
description=None,
|
||||||
|
face_model_url=None,
|
||||||
|
):
|
||||||
|
import requests
|
||||||
|
import os
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
if face_model_url and face_model_url.startswith("http"):
|
||||||
|
if face_model_save_name:
|
||||||
|
existing_face_models = folder_paths.get_filename_list("reactor/faces")
|
||||||
|
# Check if face_model_save_name exists in the list
|
||||||
|
if face_model_save_name in existing_face_models:
|
||||||
|
print(f"using face model: {face_model_save_name}")
|
||||||
|
return (face_model_save_name,)
|
||||||
|
else:
|
||||||
|
face_model_save_name = str(uuid.uuid4()) + ".safetensors"
|
||||||
|
print(face_model_save_name)
|
||||||
|
print(folder_paths.folder_names_and_paths["reactor/faces"][0][0])
|
||||||
|
destination_path = os.path.join(
|
||||||
|
folder_paths.folder_names_and_paths["reactor/faces"][0][0],
|
||||||
|
face_model_save_name,
|
||||||
|
)
|
||||||
|
|
||||||
|
print(destination_path)
|
||||||
|
print(
|
||||||
|
"Downloading external face model - "
|
||||||
|
+ face_model_url
|
||||||
|
+ " to "
|
||||||
|
+ destination_path
|
||||||
|
)
|
||||||
|
response = requests.get(
|
||||||
|
face_model_url,
|
||||||
|
headers={"User-Agent": "Mozilla/5.0"},
|
||||||
|
allow_redirects=True,
|
||||||
|
)
|
||||||
|
with open(destination_path, "wb") as out_file:
|
||||||
|
out_file.write(response.content)
|
||||||
|
return (face_model_save_name,)
|
||||||
|
else:
|
||||||
|
print(f"using face model: {default_face_model_name}")
|
||||||
|
return (default_face_model_name,)
|
||||||
|
|
||||||
|
|
||||||
|
NODE_CLASS_MAPPINGS = {"ComfyUIDeployExternalFaceModel": ComfyUIDeployExternalFaceModel}
|
||||||
|
NODE_DISPLAY_NAME_MAPPINGS = {
|
||||||
|
"ComfyUIDeployExternalFaceModel": "External Face Model (ComfyUI Deploy)"
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
class AnyType(str):
|
||||||
|
def __ne__(self, __value: object) -> bool:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
WILDCARD = AnyType("*")
|
||||||
|
|
||||||
|
class ComfyUIDeployExternalTextAny:
|
||||||
|
@classmethod
|
||||||
|
def INPUT_TYPES(s):
|
||||||
|
return {
|
||||||
|
"required": {
|
||||||
|
"input_id": (
|
||||||
|
"STRING",
|
||||||
|
{"multiline": False, "default": "input_text"},
|
||||||
|
),
|
||||||
|
},
|
||||||
|
"optional": {
|
||||||
|
"default_value": (
|
||||||
|
"STRING",
|
||||||
|
{"multiline": True, "default": ""},
|
||||||
|
),
|
||||||
|
"display_name": (
|
||||||
|
"STRING",
|
||||||
|
{"multiline": False, "default": ""},
|
||||||
|
),
|
||||||
|
"description": (
|
||||||
|
"STRING",
|
||||||
|
{"multiline": True, "default": ""},
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RETURN_TYPES = (WILDCARD,)
|
||||||
|
RETURN_NAMES = ("text",)
|
||||||
|
|
||||||
|
FUNCTION = "run"
|
||||||
|
|
||||||
|
CATEGORY = "text"
|
||||||
|
|
||||||
|
def run(self, input_id, default_value=None, display_name=None, description=None):
|
||||||
|
return [default_value]
|
||||||
|
|
||||||
|
|
||||||
|
NODE_CLASS_MAPPINGS = {"ComfyUIDeployExternalTextAny": ComfyUIDeployExternalTextAny}
|
||||||
|
NODE_DISPLAY_NAME_MAPPINGS = {"ComfyUIDeployExternalTextAny": "External Text Any (ComfyUI Deploy)"}
|
||||||
+162
-54
@@ -24,7 +24,7 @@ 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 web, ClientSession, ClientError, ClientTimeout
|
from aiohttp import web, ClientSession, ClientError, ClientTimeout, ClientResponseError
|
||||||
import atexit
|
import atexit
|
||||||
|
|
||||||
# Global session
|
# Global session
|
||||||
@@ -80,11 +80,11 @@ async def async_request_with_retry(method, url, disable_timeout=False, token=Non
|
|||||||
request_start = time.time()
|
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()
|
request_end = time.time()
|
||||||
logger.info(f"Request attempt {attempt + 1} took {request_end - request_start:.2f} seconds")
|
# logger.info(f"Request attempt {attempt + 1} took {request_end - request_start:.2f} seconds")
|
||||||
|
|
||||||
if response.status != 200:
|
if response.status != 200:
|
||||||
error_body = await response.text()
|
error_body = await response.text()
|
||||||
logger.error(f"Request failed with status {response.status} and body {error_body}")
|
# logger.error(f"Request failed with status {response.status} and body {error_body}")
|
||||||
# raise Exception(f"Request failed with status {response.status}")
|
# raise Exception(f"Request failed with status {response.status}")
|
||||||
|
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
@@ -92,7 +92,7 @@ async def async_request_with_retry(method, url, disable_timeout=False, token=Non
|
|||||||
await response.read()
|
await response.read()
|
||||||
|
|
||||||
total_time = time.time() - start_time
|
total_time = time.time() - start_time
|
||||||
logger.info(f"Request succeeded after {total_time:.2f} seconds (attempt {attempt + 1}/{max_retries})")
|
# logger.info(f"Request succeeded after {total_time:.2f} seconds (attempt {attempt + 1}/{max_retries})")
|
||||||
return response
|
return response
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
logger.warning(f"Request timed out after {initial_timeout} seconds (attempt {attempt + 1}/{max_retries})")
|
logger.warning(f"Request timed out after {initial_timeout} seconds (attempt {attempt + 1}/{max_retries})")
|
||||||
@@ -193,6 +193,9 @@ bypass_upload = os.environ.get('CD_BYPASS_UPLOAD', 'false').lower() == 'true'
|
|||||||
|
|
||||||
logger.info(f"CD_BYPASS_UPLOAD {bypass_upload}")
|
logger.info(f"CD_BYPASS_UPLOAD {bypass_upload}")
|
||||||
|
|
||||||
|
create_native_run_endpoint = None
|
||||||
|
status_endpoint = None
|
||||||
|
file_upload_endpoint = None
|
||||||
|
|
||||||
def clear_current_prompt(sid):
|
def clear_current_prompt(sid):
|
||||||
prompt_server = server.PromptServer.instance
|
prompt_server = server.PromptServer.instance
|
||||||
@@ -309,7 +312,7 @@ def apply_inputs_to_workflow(workflow_api: Any, inputs: Any, sid: str = None):
|
|||||||
value['inputs']["input_id"] = new_value
|
value['inputs']["input_id"] = new_value
|
||||||
|
|
||||||
# Fix for external text default value
|
# Fix for external text default value
|
||||||
if (value["class_type"] == "ComfyUIDeployExternalText"):
|
if (value["class_type"] == "ComfyUIDeployExternalText" or value["class_type"] == "ComfyUIDeployExternalTextAny"):
|
||||||
value['inputs']["default_value"] = new_value
|
value['inputs']["default_value"] = new_value
|
||||||
|
|
||||||
if (value["class_type"] == "ComfyUIDeployExternalCheckpoint"):
|
if (value["class_type"] == "ComfyUIDeployExternalCheckpoint"):
|
||||||
@@ -327,9 +330,13 @@ def apply_inputs_to_workflow(workflow_api: Any, inputs: Any, sid: str = None):
|
|||||||
if value["class_type"] == "ComfyUIDeployExternalBoolean":
|
if value["class_type"] == "ComfyUIDeployExternalBoolean":
|
||||||
value["inputs"]["default_value"] = new_value
|
value["inputs"]["default_value"] = new_value
|
||||||
|
|
||||||
|
if value["class_type"] == "ComfyUIDeployExternalFaceModel":
|
||||||
|
value["inputs"]["face_model_url"] = new_value
|
||||||
|
|
||||||
def send_prompt(sid: str, inputs: StreamingPrompt):
|
def send_prompt(sid: str, inputs: StreamingPrompt):
|
||||||
# workflow_api = inputs.workflow_api
|
# workflow_api = inputs.workflow_api
|
||||||
workflow_api = copy.deepcopy(inputs.workflow_api)
|
workflow_api = copy.deepcopy(inputs.workflow_api)
|
||||||
|
workflow = copy.deepcopy(inputs.workflow)
|
||||||
|
|
||||||
# Random seed
|
# Random seed
|
||||||
apply_random_seed_to_workflow(workflow_api)
|
apply_random_seed_to_workflow(workflow_api)
|
||||||
@@ -345,7 +352,8 @@ def send_prompt(sid: str, inputs: StreamingPrompt):
|
|||||||
prompt = {
|
prompt = {
|
||||||
"prompt": workflow_api,
|
"prompt": workflow_api,
|
||||||
"client_id": sid, #"comfy_deploy_instance", #api.client_id
|
"client_id": sid, #"comfy_deploy_instance", #api.client_id
|
||||||
"prompt_id": prompt_id
|
"prompt_id": prompt_id,
|
||||||
|
"extra_data": {"extra_pnginfo": {"workflow": workflow}},
|
||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -364,23 +372,55 @@ def send_prompt(sid: str, inputs: StreamingPrompt):
|
|||||||
logger.info(f"error: {error_type}, {e}")
|
logger.info(f"error: {error_type}, {e}")
|
||||||
logger.info(f"stack trace: {stack_trace_short}")
|
logger.info(f"stack trace: {stack_trace_short}")
|
||||||
|
|
||||||
|
|
||||||
|
# # Add custom logic here
|
||||||
|
# if 'prompt_id' in response:
|
||||||
|
# prompt_id = response['prompt_id']
|
||||||
|
# if prompt_id in prompt_metadata:
|
||||||
|
# metadata = prompt_metadata[prompt_id]
|
||||||
|
|
||||||
|
# # Add additional information to the response
|
||||||
|
# response['status_endpoint'] = metadata.status_endpoint
|
||||||
|
# response['file_upload_endpoint'] = metadata.file_upload_endpoint
|
||||||
|
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
@server.PromptServer.instance.routes.post("/comfyui-deploy/run")
|
@server.PromptServer.instance.routes.post("/comfyui-deploy/run")
|
||||||
async def comfy_deploy_run(request):
|
async def comfy_deploy_run(request):
|
||||||
# Extract the bearer token from the Authorization header
|
# Extract the bearer token from the Authorization header
|
||||||
auth_header = request.headers.get('Authorization')
|
|
||||||
token = None
|
|
||||||
if auth_header:
|
|
||||||
parts = auth_header.split()
|
|
||||||
if len(parts) == 2 and parts[0].lower() == 'bearer':
|
|
||||||
token = parts[1]
|
|
||||||
|
|
||||||
data = await request.json()
|
data = await request.json()
|
||||||
|
|
||||||
|
client_id = data.get("client_id")
|
||||||
|
# We proxy the request to Comfy Deploy, this is a native run
|
||||||
|
if "is_native_run" in data:
|
||||||
|
async with aiohttp.ClientSession() as session:
|
||||||
|
pprint(data)
|
||||||
|
# headers = request.headers.copy()
|
||||||
|
# headers['Content-Type'] = 'application/json'
|
||||||
|
async with session.post(data.get("native_run_api_endpoint"), json=data, headers={
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': request.headers.get('Authorization')
|
||||||
|
}) as response:
|
||||||
|
data = await response.json()
|
||||||
|
print(data)
|
||||||
|
|
||||||
|
if "cd_token" in data:
|
||||||
|
token = data["cd_token"]
|
||||||
|
else:
|
||||||
|
auth_header = request.headers.get('Authorization')
|
||||||
|
token = None
|
||||||
|
if auth_header:
|
||||||
|
parts = auth_header.split()
|
||||||
|
if len(parts) == 2 and parts[0].lower() == 'bearer':
|
||||||
|
token = parts[1]
|
||||||
|
|
||||||
# In older version, we use workflow_api, but this has inputs already swapped in nextjs frontend, which is tricky
|
# In older version, we use workflow_api, but this has inputs already swapped in nextjs frontend, which is tricky
|
||||||
workflow_api = data.get("workflow_api_raw")
|
workflow_api = data.get("workflow_api_raw")
|
||||||
# The prompt id generated from comfy deploy, can be None
|
# The prompt id generated from comfy deploy, can be None
|
||||||
prompt_id = data.get("prompt_id")
|
prompt_id = data.get("prompt_id")
|
||||||
inputs = data.get("inputs")
|
inputs = data.get("inputs")
|
||||||
|
workflow = data.get("workflow")
|
||||||
|
|
||||||
# Now it handles directly in here
|
# Now it handles directly in here
|
||||||
apply_random_seed_to_workflow(workflow_api)
|
apply_random_seed_to_workflow(workflow_api)
|
||||||
@@ -388,8 +428,9 @@ async def comfy_deploy_run(request):
|
|||||||
|
|
||||||
prompt = {
|
prompt = {
|
||||||
"prompt": workflow_api,
|
"prompt": workflow_api,
|
||||||
"client_id": "comfy_deploy_instance", #api.client_id
|
"client_id": "comfy_deploy_instance" if client_id is None else client_id,
|
||||||
"prompt_id": prompt_id,
|
"prompt_id": prompt_id,
|
||||||
|
"extra_data": {"extra_pnginfo": {"workflow": workflow}}
|
||||||
}
|
}
|
||||||
|
|
||||||
prompt_metadata[prompt_id] = SimplePrompt(
|
prompt_metadata[prompt_id] = SimplePrompt(
|
||||||
@@ -440,6 +481,7 @@ async def stream_prompt(data, token):
|
|||||||
# The prompt id generated from comfy deploy, can be None
|
# The prompt id generated from comfy deploy, can be None
|
||||||
prompt_id = data.get("prompt_id")
|
prompt_id = data.get("prompt_id")
|
||||||
inputs = data.get("inputs")
|
inputs = data.get("inputs")
|
||||||
|
workflow = data.get("workflow")
|
||||||
|
|
||||||
# Now it handles directly in here
|
# Now it handles directly in here
|
||||||
apply_random_seed_to_workflow(workflow_api)
|
apply_random_seed_to_workflow(workflow_api)
|
||||||
@@ -448,7 +490,8 @@ async def stream_prompt(data, token):
|
|||||||
prompt = {
|
prompt = {
|
||||||
"prompt": workflow_api,
|
"prompt": workflow_api,
|
||||||
"client_id": "comfy_deploy_instance", #api.client_id
|
"client_id": "comfy_deploy_instance", #api.client_id
|
||||||
"prompt_id": prompt_id
|
"prompt_id": prompt_id,
|
||||||
|
"extra_data": {"extra_pnginfo": {"workflow": workflow}},
|
||||||
}
|
}
|
||||||
|
|
||||||
prompt_metadata[prompt_id] = SimplePrompt(
|
prompt_metadata[prompt_id] = SimplePrompt(
|
||||||
@@ -782,6 +825,7 @@ async def websocket_handler(request):
|
|||||||
inputs={},
|
inputs={},
|
||||||
status_endpoint=status_endpoint,
|
status_endpoint=status_endpoint,
|
||||||
file_upload_endpoint=request.rel_url.query.get('file_upload_endpoint', None),
|
file_upload_endpoint=request.rel_url.query.get('file_upload_endpoint', None),
|
||||||
|
workflow=workflow["workflow"],
|
||||||
)
|
)
|
||||||
|
|
||||||
await update_realtime_run_status(realtime_id, status_endpoint, Status.RUNNING)
|
await update_realtime_run_status(realtime_id, status_endpoint, Status.RUNNING)
|
||||||
@@ -1196,6 +1240,47 @@ async def update_run(prompt_id: str, status: Status):
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
async def file_sender(file_object, chunk_size):
|
||||||
|
while True:
|
||||||
|
chunk = await file_object.read(chunk_size)
|
||||||
|
if not chunk:
|
||||||
|
break
|
||||||
|
yield chunk
|
||||||
|
|
||||||
|
|
||||||
|
chunk_size = 1024 * 1024 # 1MB chunks, adjust as needed
|
||||||
|
|
||||||
|
async def upload_with_retry(session, url, headers, data, max_retries=3, initial_delay=1):
|
||||||
|
start_time = time.time() # Start timing here
|
||||||
|
for attempt in range(max_retries):
|
||||||
|
try:
|
||||||
|
async with session.put(url, headers=headers, data=data) as response:
|
||||||
|
upload_duration = time.time() - start_time
|
||||||
|
logger.info(f"Upload attempt {attempt + 1} completed in {upload_duration:.2f} seconds")
|
||||||
|
logger.info(f"Upload response status: {response.status}")
|
||||||
|
|
||||||
|
response.raise_for_status() # This will raise an exception for 4xx and 5xx status codes
|
||||||
|
|
||||||
|
response_text = await response.text()
|
||||||
|
logger.info(f"Response body: {response_text[:1000]}...")
|
||||||
|
|
||||||
|
logger.info("Upload successful")
|
||||||
|
return response # Successful upload, exit the retry loop
|
||||||
|
|
||||||
|
except (ClientError, ClientResponseError) as e:
|
||||||
|
logger.error(f"Upload attempt {attempt + 1} failed: {str(e)}")
|
||||||
|
if attempt < max_retries - 1: # If it's not the last attempt
|
||||||
|
delay = initial_delay * (2 ** attempt) # Exponential backoff
|
||||||
|
logger.info(f"Retrying in {delay} seconds...")
|
||||||
|
await asyncio.sleep(delay)
|
||||||
|
else:
|
||||||
|
logger.error("Max retries reached. Upload failed.")
|
||||||
|
raise # Re-raise the last exception if all retries are exhausted
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Unexpected error during upload: {str(e)}")
|
||||||
|
logger.error(traceback.format_exc())
|
||||||
|
raise # Re-raise unexpected exceptions immediately
|
||||||
|
|
||||||
async def upload_file(prompt_id, filename, subfolder=None, content_type="image/png", type="output", item=None):
|
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
|
||||||
@@ -1231,42 +1316,55 @@ 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}&version=v2"
|
||||||
|
|
||||||
|
start_time = time.time() # Start timing here
|
||||||
|
logger.info(f"Target URL: {target_url}")
|
||||||
|
result = await async_request_with_retry("GET", target_url, disable_timeout=True, token=token)
|
||||||
|
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 = await result.json()
|
||||||
|
|
||||||
|
logger.info(f"Result: {ok}")
|
||||||
|
|
||||||
async with aiofiles.open(file, 'rb') as f:
|
async with aiofiles.open(file, 'rb') as f:
|
||||||
data = await f.read()
|
data = await f.read()
|
||||||
size = str(len(data))
|
size = str(len(data))
|
||||||
target_url = f"{file_upload_endpoint}?file_name={filename}&run_id={prompt_id}&type={content_type}&version=v2"
|
# logger.info(f"Image size: {size}")
|
||||||
|
|
||||||
start_time = time.time() # Start timing here
|
|
||||||
logger.info(f"Target URL: {target_url}")
|
|
||||||
result = await async_request_with_retry("GET", target_url, disable_timeout=True, token=token)
|
|
||||||
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 = await result.json()
|
|
||||||
|
|
||||||
logger.info(f"Result: {ok}")
|
|
||||||
|
|
||||||
start_time = time.time() # Start timing here
|
start_time = time.time() # Start timing here
|
||||||
headers = {
|
headers = {
|
||||||
"Content-Type": content_type,
|
"Content-Type": content_type,
|
||||||
# "Content-Length": size,
|
"Content-Length": size,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.info(headers)
|
||||||
|
|
||||||
if ok.get('include_acl') is True:
|
if ok.get('include_acl') is True:
|
||||||
headers["x-amz-acl"] = "public-read"
|
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}")
|
||||||
|
|
||||||
|
async with aiohttp.ClientSession() as session:
|
||||||
|
try:
|
||||||
|
response = await upload_with_retry(session, ok.get("url"), headers, data)
|
||||||
|
# Process successful response...
|
||||||
|
except Exception as e:
|
||||||
|
# Handle final failure...
|
||||||
|
logger.error(f"Upload ultimately failed: {str(e)}")
|
||||||
|
|
||||||
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:
|
if item is not None:
|
||||||
file_download_url = ok.get("download_url")
|
file_download_url = ok.get("download_url")
|
||||||
if file_download_url is not None:
|
if file_download_url is not None:
|
||||||
item["url"] = file_download_url
|
item["url"] = file_download_url
|
||||||
item["upload_duration"] = end_time - start_time
|
item["upload_duration"] = end_time - start_time
|
||||||
if ok.get("is_public") is not None:
|
if ok.get("is_public") is not None:
|
||||||
item["is_public"] = ok.get("is_public")
|
item["is_public"] = ok.get("is_public")
|
||||||
|
|
||||||
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:
|
||||||
@@ -1359,7 +1457,7 @@ 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 = []
|
upload_tasks = []
|
||||||
|
|
||||||
for item in items:
|
for item in items:
|
||||||
# Skipping temp files
|
# Skipping temp files
|
||||||
@@ -1375,33 +1473,43 @@ 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'
|
||||||
|
|
||||||
# upload_tasks.append(upload_file(
|
upload_tasks.append(upload_file(
|
||||||
# prompt_id,
|
|
||||||
# item.get("filename"),
|
|
||||||
# subfolder=item.get("subfolder"),
|
|
||||||
# type=item.get("type"),
|
|
||||||
# content_type=file_type,
|
|
||||||
# item=item
|
|
||||||
# ))
|
|
||||||
await 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
|
item=item
|
||||||
)
|
))
|
||||||
|
# await upload_file(
|
||||||
|
# prompt_id,
|
||||||
|
# item.get("filename"),
|
||||||
|
# subfolder=item.get("subfolder"),
|
||||||
|
# type=item.get("type"),
|
||||||
|
# content_type=file_type,
|
||||||
|
# item=item
|
||||||
|
# )
|
||||||
|
|
||||||
# Execute all upload tasks concurrently
|
# Execute all upload tasks concurrently
|
||||||
# await asyncio.gather(*upload_tasks)
|
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, node_meta=None):
|
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")
|
# await handle_upload(prompt_id, data, 'images', "content_type", "image/png")
|
||||||
await handle_upload(prompt_id, data, 'files', "content_type", "image/png")
|
# await handle_upload(prompt_id, data, 'files', "content_type", "image/png")
|
||||||
await handle_upload(prompt_id, data, 'gifs', "format", "image/gif")
|
# await handle_upload(prompt_id, data, 'gifs', "format", "image/gif")
|
||||||
await handle_upload(prompt_id, data, 'mesh', "format", "application/octet-stream")
|
# 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)
|
||||||
|
|
||||||
status_endpoint = prompt_metadata[prompt_id].status_endpoint
|
status_endpoint = prompt_metadata[prompt_id].status_endpoint
|
||||||
token = prompt_metadata[prompt_id].token
|
token = prompt_metadata[prompt_id].token
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ class StreamingPrompt(BaseModel):
|
|||||||
running_prompt_ids: set[str] = set()
|
running_prompt_ids: set[str] = set()
|
||||||
status_endpoint: Optional[str]
|
status_endpoint: Optional[str]
|
||||||
file_upload_endpoint: Optional[str]
|
file_upload_endpoint: Optional[str]
|
||||||
|
workflow: Any
|
||||||
|
|
||||||
class SimplePrompt(BaseModel):
|
class SimplePrompt(BaseModel):
|
||||||
status_endpoint: Optional[str]
|
status_endpoint: Optional[str]
|
||||||
|
|||||||
+113
-41
@@ -83,6 +83,23 @@ function dispatchAPIEventData(data) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const context = {
|
||||||
|
selectedWorkflowInfo: null,
|
||||||
|
};
|
||||||
|
// let selectedWorkflowInfo = {
|
||||||
|
// workflow_id: "05da8f2b-63af-4c0c-86dd-08d01ec512b7",
|
||||||
|
// machine_id: "45ac5f85-b7b6-436f-8d97-2383b25485f3",
|
||||||
|
// native_run_api_endpoint: "http://localhost:3011/api/run",
|
||||||
|
// };
|
||||||
|
|
||||||
|
function getSelectedWorkflowInfo() {
|
||||||
|
return context.selectedWorkflowInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
function setSelectedWorkflowInfo(info) {
|
||||||
|
context.selectedWorkflowInfo = info;
|
||||||
|
}
|
||||||
|
|
||||||
/** @typedef {import('../../../web/types/comfy.js').ComfyExtension} ComfyExtension*/
|
/** @typedef {import('../../../web/types/comfy.js').ComfyExtension} ComfyExtension*/
|
||||||
/** @type {ComfyExtension} */
|
/** @type {ComfyExtension} */
|
||||||
const ext = {
|
const ext = {
|
||||||
@@ -103,10 +120,10 @@ const ext = {
|
|||||||
|
|
||||||
sendEventToCD("cd_plugin_onInit");
|
sendEventToCD("cd_plugin_onInit");
|
||||||
|
|
||||||
app.queuePrompt = ((originalFunction) => async () => {
|
// app.queuePrompt = ((originalFunction) => async () => {
|
||||||
// const prompt = await app.graphToPrompt();
|
// // const prompt = await app.graphToPrompt();
|
||||||
sendEventToCD("cd_plugin_onQueuePromptTrigger");
|
// sendEventToCD("cd_plugin_onQueuePromptTrigger");
|
||||||
})(app.queuePrompt);
|
// })(app.queuePrompt);
|
||||||
|
|
||||||
// // Intercept the onkeydown event
|
// // Intercept the onkeydown event
|
||||||
// window.addEventListener(
|
// window.addEventListener(
|
||||||
@@ -213,7 +230,7 @@ const ext = {
|
|||||||
(v) => {
|
(v) => {
|
||||||
this.properties.workflow_name = v;
|
this.properties.workflow_name = v;
|
||||||
},
|
},
|
||||||
{ multiline: false }
|
{ multiline: false },
|
||||||
);
|
);
|
||||||
|
|
||||||
this.addWidget(
|
this.addWidget(
|
||||||
@@ -223,7 +240,7 @@ const ext = {
|
|||||||
(v) => {
|
(v) => {
|
||||||
this.properties.workflow_id = v;
|
this.properties.workflow_id = v;
|
||||||
},
|
},
|
||||||
{ multiline: false }
|
{ multiline: false },
|
||||||
);
|
);
|
||||||
|
|
||||||
this.addWidget(
|
this.addWidget(
|
||||||
@@ -233,7 +250,7 @@ const ext = {
|
|||||||
(v) => {
|
(v) => {
|
||||||
this.properties.version = v;
|
this.properties.version = v;
|
||||||
},
|
},
|
||||||
{ multiline: false }
|
{ multiline: false },
|
||||||
);
|
);
|
||||||
|
|
||||||
this.widgets_start_y = 10;
|
this.widgets_start_y = 10;
|
||||||
@@ -270,11 +287,14 @@ const ext = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Register the node type
|
// Register the node type
|
||||||
LiteGraph.registerNodeType("ComfyDeploy", Object.assign(ComfyDeploy, {
|
LiteGraph.registerNodeType(
|
||||||
title: "Comfy Deploy",
|
"ComfyDeploy",
|
||||||
title_mode: LiteGraph.NORMAL_TITLE,
|
Object.assign(ComfyDeploy, {
|
||||||
collapsable: true,
|
title: "Comfy Deploy",
|
||||||
}));
|
title_mode: LiteGraph.NORMAL_TITLE,
|
||||||
|
collapsable: true,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
ComfyDeploy.category = "deploy";
|
ComfyDeploy.category = "deploy";
|
||||||
},
|
},
|
||||||
@@ -293,6 +313,14 @@ const ext = {
|
|||||||
// This part of the code would depend on how the ComfyUI expects to receive and process the workflow data
|
// This part of the code would depend on how the ComfyUI expects to receive and process the workflow data
|
||||||
// For demonstration, let's assume there's a loadWorkflow method in the ComfyUI API
|
// For demonstration, let's assume there's a loadWorkflow method in the ComfyUI API
|
||||||
if (comfyUIWorkflow && app && app.loadGraphData) {
|
if (comfyUIWorkflow && app && app.loadGraphData) {
|
||||||
|
try {
|
||||||
|
await window["app"].ui.settings.setSettingValueAsync(
|
||||||
|
"Comfy.Validation.Workflows",
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
console.warning("Error setting validation to false, is fine to ignore this", error);
|
||||||
|
}
|
||||||
console.log("loadGraphData");
|
console.log("loadGraphData");
|
||||||
app.loadGraphData(comfyUIWorkflow);
|
app.loadGraphData(comfyUIWorkflow);
|
||||||
}
|
}
|
||||||
@@ -380,6 +408,8 @@ const ext = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
animate();
|
animate();
|
||||||
|
} else if (message.type === "workflow_info") {
|
||||||
|
setSelectedWorkflowInfo(message.data);
|
||||||
}
|
}
|
||||||
// else if (message.type === "refresh") {
|
// else if (message.type === "refresh") {
|
||||||
// sendEventToCD("cd_plugin_onRefresh");
|
// sendEventToCD("cd_plugin_onRefresh");
|
||||||
@@ -443,10 +473,10 @@ function createDynamicUIHtml(data) {
|
|||||||
<h3 style="font-size: 14px; font-weight: semibold; margin-bottom: 8px;">Missing Nodes</h3>
|
<h3 style="font-size: 14px; font-weight: semibold; margin-bottom: 8px;">Missing Nodes</h3>
|
||||||
<p style="font-size: 12px;">These nodes are not found with any matching custom_nodes in the ComfyUI Manager Database</p>
|
<p style="font-size: 12px;">These nodes are not found with any matching custom_nodes in the ComfyUI Manager Database</p>
|
||||||
${data.missing_nodes
|
${data.missing_nodes
|
||||||
.map((node) => {
|
.map((node) => {
|
||||||
return `<p style="font-size: 14px; color: #d69e2e;">${node}</p>`;
|
return `<p style="font-size: 14px; color: #d69e2e;">${node}</p>`;
|
||||||
})
|
})
|
||||||
.join("")}
|
.join("")}
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
@@ -454,14 +484,17 @@ function createDynamicUIHtml(data) {
|
|||||||
Object.values(data.custom_nodes).forEach((node) => {
|
Object.values(data.custom_nodes).forEach((node) => {
|
||||||
html += `
|
html += `
|
||||||
<div style="border-bottom: 1px solid #e2e8f0; padding-top: 16px;">
|
<div style="border-bottom: 1px solid #e2e8f0; padding-top: 16px;">
|
||||||
<a href="${node.url
|
<a href="${
|
||||||
}" target="_blank" style="font-size: 18px; font-weight: semibold; color: white; text-decoration: none;">${node.name
|
node.url
|
||||||
}</a>
|
}" target="_blank" style="font-size: 18px; font-weight: semibold; color: white; text-decoration: none;">${
|
||||||
|
node.name
|
||||||
|
}</a>
|
||||||
<p style="font-size: 14px; color: #4b5563;">${node.hash}</p>
|
<p style="font-size: 14px; color: #4b5563;">${node.hash}</p>
|
||||||
${node.warning
|
${
|
||||||
? `<p style="font-size: 14px; color: #d69e2e;">${node.warning}</p>`
|
node.warning
|
||||||
: ""
|
? `<p style="font-size: 14px; color: #d69e2e;">${node.warning}</p>`
|
||||||
}
|
: ""
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
});
|
});
|
||||||
@@ -475,8 +508,9 @@ function createDynamicUIHtml(data) {
|
|||||||
Object.entries(data.models).forEach(([section, items]) => {
|
Object.entries(data.models).forEach(([section, items]) => {
|
||||||
html += `
|
html += `
|
||||||
<div style="border-bottom: 1px solid #e2e8f0; padding-top: 8px; padding-bottom: 8px;">
|
<div style="border-bottom: 1px solid #e2e8f0; padding-top: 8px; padding-bottom: 8px;">
|
||||||
<h3 style="font-size: 18px; font-weight: semibold; margin-bottom: 8px;">${section.charAt(0).toUpperCase() + section.slice(1)
|
<h3 style="font-size: 18px; font-weight: semibold; margin-bottom: 8px;">${
|
||||||
}</h3>`;
|
section.charAt(0).toUpperCase() + section.slice(1)
|
||||||
|
}</h3>`;
|
||||||
items.forEach((item) => {
|
items.forEach((item) => {
|
||||||
html += `<p style="font-size: 14px; color: ${textColor};">${item.name}</p>`;
|
html += `<p style="font-size: 14px; color: ${textColor};">${item.name}</p>`;
|
||||||
});
|
});
|
||||||
@@ -492,8 +526,9 @@ function createDynamicUIHtml(data) {
|
|||||||
Object.entries(data.files).forEach(([section, items]) => {
|
Object.entries(data.files).forEach(([section, items]) => {
|
||||||
html += `
|
html += `
|
||||||
<div style="border-bottom: 1px solid #e2e8f0; padding-top: 8px; padding-bottom: 8px;">
|
<div style="border-bottom: 1px solid #e2e8f0; padding-top: 8px; padding-bottom: 8px;">
|
||||||
<h3 style="font-size: 18px; font-weight: semibold; margin-bottom: 8px;">${section.charAt(0).toUpperCase() + section.slice(1)
|
<h3 style="font-size: 18px; font-weight: semibold; margin-bottom: 8px;">${
|
||||||
}</h3>`;
|
section.charAt(0).toUpperCase() + section.slice(1)
|
||||||
|
}</h3>`;
|
||||||
items.forEach((item) => {
|
items.forEach((item) => {
|
||||||
html += `<p style="font-size: 14px; color: ${textColor};">${item.name}</p>`;
|
html += `<p style="font-size: 14px; color: ${textColor};">${item.name}</p>`;
|
||||||
});
|
});
|
||||||
@@ -1013,12 +1048,14 @@ export class LoadingDialog extends ComfyDialog {
|
|||||||
showLoading(title, message) {
|
showLoading(title, message) {
|
||||||
this.show(`
|
this.show(`
|
||||||
<div style="width: 400px; display: flex; gap: 18px; flex-direction: column; overflow: unset">
|
<div style="width: 400px; display: flex; gap: 18px; flex-direction: column; overflow: unset">
|
||||||
<h3 style="margin: 0px; display: flex; align-items: center; justify-content: center; gap: 12px;">${title} ${this.loadingIcon
|
<h3 style="margin: 0px; display: flex; align-items: center; justify-content: center; gap: 12px;">${title} ${
|
||||||
}</h3>
|
this.loadingIcon
|
||||||
${message
|
}</h3>
|
||||||
? `<label style="max-width: 100%; white-space: pre-wrap; word-wrap: break-word;">${message}</label>`
|
${
|
||||||
: ""
|
message
|
||||||
}
|
? `<label style="max-width: 100%; white-space: pre-wrap; word-wrap: break-word;">${message}</label>`
|
||||||
|
: ""
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
`);
|
`);
|
||||||
}
|
}
|
||||||
@@ -1284,17 +1321,21 @@ export class ConfigDialog extends ComfyDialog {
|
|||||||
</label>
|
</label>
|
||||||
<label style="color: white; width: 100%;">
|
<label style="color: white; width: 100%;">
|
||||||
Endpoint:
|
Endpoint:
|
||||||
<input id="endpoint" style="margin-top: 8px; width: 100%; height:40px; box-sizing: border-box; padding: 0px 6px;" type="text" value="${data.endpoint
|
<input id="endpoint" style="margin-top: 8px; width: 100%; height:40px; box-sizing: border-box; padding: 0px 6px;" type="text" value="${
|
||||||
}">
|
data.endpoint
|
||||||
|
}">
|
||||||
</label>
|
</label>
|
||||||
<div style="color: white;">
|
<div style="color: white;">
|
||||||
API Key: User / Org <button style="font-size: 18px;">${data.displayName ?? ""
|
API Key: User / Org <button style="font-size: 18px;">${
|
||||||
}</button>
|
data.displayName ?? ""
|
||||||
<input id="apiKey" style="margin-top: 8px; width: 100%; height:40px; box-sizing: border-box; padding: 0px 6px;" type="password" value="${data.apiKey
|
}</button>
|
||||||
}">
|
<input id="apiKey" style="margin-top: 8px; width: 100%; height:40px; box-sizing: border-box; padding: 0px 6px;" type="password" value="${
|
||||||
|
data.apiKey
|
||||||
|
}">
|
||||||
<button id="loginButton" style="margin-top: 8px; width: 100%; height:40px; box-sizing: border-box; padding: 0px 6px;">
|
<button id="loginButton" style="margin-top: 8px; width: 100%; height:40px; box-sizing: border-box; padding: 0px 6px;">
|
||||||
${data.apiKey ? "Re-login with ComfyDeploy" : "Login with ComfyDeploy"
|
${
|
||||||
}
|
data.apiKey ? "Re-login with ComfyDeploy" : "Login with ComfyDeploy"
|
||||||
|
}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -1483,3 +1524,34 @@ async function loadWorkflowApi(versionId) {
|
|||||||
// Show an error message to the user
|
// Show an error message to the user
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const orginal_fetch_api = api.fetchApi;
|
||||||
|
api.fetchApi = async (route, options) => {
|
||||||
|
console.log("Fetch API called with args:", route, options);
|
||||||
|
|
||||||
|
const info = getSelectedWorkflowInfo();
|
||||||
|
if (info && route.startsWith("/prompt")) {
|
||||||
|
const body = JSON.parse(options.body);
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
client_id: body.client_id,
|
||||||
|
workflow_api_json: body.prompt,
|
||||||
|
workflow: body?.extra_data?.extra_pnginfo?.workflow,
|
||||||
|
is_native_run: true,
|
||||||
|
machine_id: info.machine_id,
|
||||||
|
workflow_id: info.workflow_id,
|
||||||
|
native_run_api_endpoint: info.native_run_api_endpoint,
|
||||||
|
};
|
||||||
|
|
||||||
|
return await fetch("/comfyui-deploy/run", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${info.cd_token}`,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return await orginal_fetch_api.call(api, route, options);
|
||||||
|
};
|
||||||
|
|||||||
@@ -6,4 +6,5 @@ export const customInputNodes: Record<string, string> = {
|
|||||||
ComfyUIDeployExternalNumberInt: "integer",
|
ComfyUIDeployExternalNumberInt: "integer",
|
||||||
ComfyUIDeployExternalLora: "string - (public lora download url)",
|
ComfyUIDeployExternalLora: "string - (public lora download url)",
|
||||||
ComfyUIDeployExternalCheckpoint: "string - (public checkpoints download url)",
|
ComfyUIDeployExternalCheckpoint: "string - (public checkpoints download url)",
|
||||||
|
ComfyUIDeployExternalFaceModel: "string - (public face model download url)",
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user