Lupara90 commited on
Commit
a49802e
·
verified ·
1 Parent(s): 0699858

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -3
app.py CHANGED
@@ -7,11 +7,11 @@ import torch
7
  import spaces # Required for Hugging Face ZeroGPU decoration
8
 
9
  # ==========================================
10
- # 1. Exhaustive Self-Install Dependency Check
11
  # ==========================================
12
- # This fully covers DB, tensor operations, Hugging Face Hub, and media/video decoders
13
  required_packages = [
14
  "comfy-aimdo",
 
15
  "sqlalchemy",
16
  "alembic",
17
  "safetensors",
@@ -33,7 +33,6 @@ required_packages = [
33
  print("Verifying and fixing runtime environment packages...")
34
  for package in required_packages:
35
  try:
36
- # Convert package names (e.g., 'comfy-aimdo') to Python import names ('comfy_aimdo')
37
  import_name = package.replace("-", "_")
38
  __import__(import_name)
39
  except ImportError:
@@ -62,6 +61,10 @@ if not os.path.exists(COMFYUI_DIR):
62
  if COMFYUI_DIR not in sys.path:
63
  sys.path.insert(0, COMFYUI_DIR)
64
 
 
 
 
 
65
  # Safe to import the main engine now
66
  import main as comfy_main
67
 
@@ -83,6 +86,11 @@ def generate_image(user_prompt):
83
  # Replace '6' with your specific text prompt node ID if different.
84
  prompt_workflow["6"]["inputs"]["text"] = user_prompt
85
 
 
 
 
 
 
86
  # Execute the workflow using ComfyUI's internal API handler
87
  output_images = comfy_main.execute_workflow_directly(prompt_workflow)
88
 
 
7
  import spaces # Required for Hugging Face ZeroGPU decoration
8
 
9
  # ==========================================
10
+ # 1. Complete Self-Install Core Dependencies
11
  # ==========================================
 
12
  required_packages = [
13
  "comfy-aimdo",
14
+ "comfy-kitchen",
15
  "sqlalchemy",
16
  "alembic",
17
  "safetensors",
 
33
  print("Verifying and fixing runtime environment packages...")
34
  for package in required_packages:
35
  try:
 
36
  import_name = package.replace("-", "_")
37
  __import__(import_name)
38
  except ImportError:
 
61
  if COMFYUI_DIR not in sys.path:
62
  sys.path.insert(0, COMFYUI_DIR)
63
 
64
+ # Crucial ZeroGPU Fix: Mock command line arguments so ComfyUI doesn't try
65
+ # to initialize CUDA/comfy-aimdo during python file parsing on startup.
66
+ sys.argv = [sys.argv[0], "--cpu"]
67
+
68
  # Safe to import the main engine now
69
  import main as comfy_main
70
 
 
86
  # Replace '6' with your specific text prompt node ID if different.
87
  prompt_workflow["6"]["inputs"]["text"] = user_prompt
88
 
89
+ # Temporarily switch ComfyUI to CUDA execution during ZeroGPU allocation
90
+ # override the global device variables safely inside the GPU context
91
+ import comfy.model_management
92
+ comfy.model_management.get_torch_device = lambda: torch.device("cuda")
93
+
94
  # Execute the workflow using ComfyUI's internal API handler
95
  output_images = comfy_main.execute_workflow_directly(prompt_workflow)
96