Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -145,11 +145,27 @@ setup_environment()
|
|
| 145 |
|
| 146 |
# --- ComfyUI Imports ---
|
| 147 |
# Configure Execution Arguments for ComfyUI
|
| 148 |
-
if not
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
|
| 154 |
# These must happen AFTER setup because ComfyUI folder might not exist before
|
| 155 |
try:
|
|
|
|
| 145 |
|
| 146 |
# --- ComfyUI Imports ---
|
| 147 |
# Configure Execution Arguments for ComfyUI
|
| 148 |
+
# Aggressively force CPU if CUDA is not available or if we want to ensure no crashes on CPU Spaces
|
| 149 |
+
try:
|
| 150 |
+
if not torch.cuda.is_available():
|
| 151 |
+
print("β οΈ CUDA not available, forcing CPU mode for ComfyUI...")
|
| 152 |
+
|
| 153 |
+
# 1. Force environment variable
|
| 154 |
+
os.environ["CUDA_VISIBLE_DEVICES"] = ""
|
| 155 |
+
|
| 156 |
+
# 2. Inject --cpu argument
|
| 157 |
+
if "--cpu" not in sys.argv:
|
| 158 |
+
sys.argv.append("--cpu")
|
| 159 |
+
|
| 160 |
+
# 3. Monkeypatch torch.cuda to ensure ComfyUI doesn't try to initialize CUDA
|
| 161 |
+
# This is necessary because some ComfyUI versions checks might be aggressive
|
| 162 |
+
torch.cuda.is_available = lambda: False
|
| 163 |
+
torch.cuda.device_count = lambda: 0
|
| 164 |
+
torch.cuda.current_device = lambda: None
|
| 165 |
+
|
| 166 |
+
print("β
Applied CPU enforcement patches.")
|
| 167 |
+
except Exception as e:
|
| 168 |
+
print(f"β οΈ Error applying CPU patches: {e}")
|
| 169 |
|
| 170 |
# These must happen AFTER setup because ComfyUI folder might not exist before
|
| 171 |
try:
|