mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-02-14 15:32:35 +08:00
Fix all Python linting issues - clean whitespace and formatting
This commit is contained in:
parent
2a6c31f4fb
commit
dc5a696d3b
@ -29,13 +29,13 @@ class ComfyUIServerlessHandler:
|
|||||||
self.comfyui_process = None
|
self.comfyui_process = None
|
||||||
self.setup_paths()
|
self.setup_paths()
|
||||||
self.start_comfyui()
|
self.start_comfyui()
|
||||||
|
|
||||||
def setup_paths(self):
|
def setup_paths(self):
|
||||||
"""Setup required paths for serverless operation"""
|
"""Setup required paths for serverless operation"""
|
||||||
os.makedirs("/tmp/inputs", exist_ok=True)
|
os.makedirs("/tmp/inputs", exist_ok=True)
|
||||||
os.makedirs("/tmp/outputs", exist_ok=True)
|
os.makedirs("/tmp/outputs", exist_ok=True)
|
||||||
os.makedirs("/tmp/comfyui", exist_ok=True)
|
os.makedirs("/tmp/comfyui", exist_ok=True)
|
||||||
|
|
||||||
def start_comfyui(self):
|
def start_comfyui(self):
|
||||||
"""Start ComfyUI server in background"""
|
"""Start ComfyUI server in background"""
|
||||||
try:
|
try:
|
||||||
@ -51,7 +51,7 @@ class ComfyUIServerlessHandler:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Failed to start ComfyUI: {str(e)}")
|
logger.error(f"Failed to start ComfyUI: {str(e)}")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def wait_for_comfyui(self, timeout: int = 120) -> bool:
|
def wait_for_comfyui(self, timeout: int = 120) -> bool:
|
||||||
"""Wait for ComfyUI to be ready"""
|
"""Wait for ComfyUI to be ready"""
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
@ -67,7 +67,7 @@ class ComfyUIServerlessHandler:
|
|||||||
|
|
||||||
logger.error(f"ComfyUI not ready after {timeout} seconds")
|
logger.error(f"ComfyUI not ready after {timeout} seconds")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def download_input_files(self, input_data: Dict[str, Any]) -> Dict[str, str]:
|
def download_input_files(self, input_data: Dict[str, Any]) -> Dict[str, str]:
|
||||||
"""Download input files and return local paths"""
|
"""Download input files and return local paths"""
|
||||||
local_files = {}
|
local_files = {}
|
||||||
@ -92,9 +92,9 @@ class ComfyUIServerlessHandler:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Failed to download {file_key}: {str(e)}")
|
logger.error(f"Failed to download {file_key}: {str(e)}")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
return local_files
|
return local_files
|
||||||
|
|
||||||
def execute_workflow(self, workflow: Dict[str, Any]) -> Dict[str, Any]:
|
def execute_workflow(self, workflow: Dict[str, Any]) -> Dict[str, Any]:
|
||||||
"""Execute ComfyUI workflow"""
|
"""Execute ComfyUI workflow"""
|
||||||
try:
|
try:
|
||||||
@ -114,11 +114,11 @@ class ComfyUIServerlessHandler:
|
|||||||
|
|
||||||
# Wait for completion
|
# Wait for completion
|
||||||
return self.wait_for_completion(prompt_id)
|
return self.wait_for_completion(prompt_id)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Failed to execute workflow: {str(e)}")
|
logger.error(f"Failed to execute workflow: {str(e)}")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def wait_for_completion(self, prompt_id: str, timeout: int = 300) -> Dict[str, Any]:
|
def wait_for_completion(self, prompt_id: str, timeout: int = 300) -> Dict[str, Any]:
|
||||||
"""Wait for workflow completion and return results"""
|
"""Wait for workflow completion and return results"""
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
@ -146,9 +146,9 @@ class ComfyUIServerlessHandler:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error checking completion: {str(e)}")
|
logger.error(f"Error checking completion: {str(e)}")
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
raise TimeoutError(f"Workflow {prompt_id} timed out after {timeout} seconds")
|
raise TimeoutError(f"Workflow {prompt_id} timed out after {timeout} seconds")
|
||||||
|
|
||||||
def process_results(self, history_data: Dict[str, Any]) -> Dict[str, Any]:
|
def process_results(self, history_data: Dict[str, Any]) -> Dict[str, Any]:
|
||||||
"""Process and upload results"""
|
"""Process and upload results"""
|
||||||
results = {
|
results = {
|
||||||
@ -187,9 +187,9 @@ class ComfyUIServerlessHandler:
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Failed to process image {image_info['filename']}: {str(e)}")
|
logger.error(f"Failed to process image {image_info['filename']}: {str(e)}")
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
def cleanup(self):
|
def cleanup(self):
|
||||||
"""Clean up temporary files"""
|
"""Clean up temporary files"""
|
||||||
try:
|
try:
|
||||||
@ -205,15 +205,15 @@ class ComfyUIServerlessHandler:
|
|||||||
def handler(job: Dict[str, Any]) -> Dict[str, Any]:
|
def handler(job: Dict[str, Any]) -> Dict[str, Any]:
|
||||||
"""Main serverless handler function"""
|
"""Main serverless handler function"""
|
||||||
handler_instance = ComfyUIServerlessHandler()
|
handler_instance = ComfyUIServerlessHandler()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Wait for ComfyUI to be ready
|
# Wait for ComfyUI to be ready
|
||||||
if not handler_instance.wait_for_comfyui():
|
if not handler_instance.wait_for_comfyui():
|
||||||
return {"error": "ComfyUI failed to start"}
|
return {"error": "ComfyUI failed to start"}
|
||||||
|
|
||||||
# Get job input
|
# Get job input
|
||||||
job_input = job.get("input", {})
|
job_input = job.get("input", {})
|
||||||
|
|
||||||
# Download input files if any
|
# Download input files if any
|
||||||
local_files = handler_instance.download_input_files(job_input)
|
local_files = handler_instance.download_input_files(job_input)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user