Spaces:
Running
Running
add
Browse files
app.py
CHANGED
|
@@ -24,11 +24,46 @@ ROOT_DIR = os.getcwd()
|
|
| 24 |
COMFYUI_DIR = os.path.join(ROOT_DIR, "ComfyUI")
|
| 25 |
BYPASS_REPO_DIR = os.path.join(ROOT_DIR, "reference_repo")
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
def setup():
|
| 28 |
"""Environment setup for Hugging Face Space"""
|
| 29 |
# Check if a known model file exists to skip setup
|
| 30 |
-
|
|
|
|
|
|
|
| 31 |
print("--- ENVIRONMENT ALREADY INITIALIZED ---")
|
|
|
|
|
|
|
| 32 |
return
|
| 33 |
|
| 34 |
print("--- FIRST TIME SETUP STARTING ---")
|
|
@@ -70,6 +105,9 @@ def setup():
|
|
| 70 |
subprocess.run(["git", "checkout", "db90fe5012f94c6aef406d743292daf76b4477a6"], cwd=node_dest, check=True, capture_output=True)
|
| 71 |
print("✓ Custom nodes installed")
|
| 72 |
|
|
|
|
|
|
|
|
|
|
| 73 |
# Install performance optimizations (SageAttention, Flash Attention)
|
| 74 |
print("Installing performance optimizations...")
|
| 75 |
subprocess.run([
|
|
|
|
| 24 |
COMFYUI_DIR = os.path.join(ROOT_DIR, "ComfyUI")
|
| 25 |
BYPASS_REPO_DIR = os.path.join(ROOT_DIR, "reference_repo")
|
| 26 |
|
| 27 |
+
def _apply_seedvr2_patch():
|
| 28 |
+
"""Apply MIG GPU compatibility patch to SeedVR2 custom node"""
|
| 29 |
+
compat_file = os.path.join(COMFYUI_DIR, "custom_nodes/ComfyUI-SeedVR2_VideoUpscaler/src/optimization/compatibility.py")
|
| 30 |
+
if not os.path.exists(compat_file):
|
| 31 |
+
return
|
| 32 |
+
|
| 33 |
+
with open(compat_file, 'r') as f:
|
| 34 |
+
content = f.read()
|
| 35 |
+
|
| 36 |
+
# Check if patch already applied
|
| 37 |
+
if 'Handle CUDA errors on MIG GPUs' in content or 'Failed to probe bfloat16 support' in content:
|
| 38 |
+
print("✓ SeedVR2 MIG GPU patch already applied")
|
| 39 |
+
return
|
| 40 |
+
|
| 41 |
+
# Wrap the module-level probe call in try-except
|
| 42 |
+
patched_content = content.replace(
|
| 43 |
+
'BFLOAT16_SUPPORTED = _probe_bfloat16_support()',
|
| 44 |
+
'''try:
|
| 45 |
+
BFLOAT16_SUPPORTED = _probe_bfloat16_support()
|
| 46 |
+
except Exception as e:
|
| 47 |
+
print(f"[SeedVR2] Failed to probe bfloat16 support: {e}")
|
| 48 |
+
BFLOAT16_SUPPORTED = False'''
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
if patched_content != content:
|
| 52 |
+
with open(compat_file, 'w') as f:
|
| 53 |
+
f.write(patched_content)
|
| 54 |
+
print("✓ Applied MIG GPU compatibility patch to SeedVR2")
|
| 55 |
+
else:
|
| 56 |
+
print("⚠ SeedVR2 patch pattern not found (may already be fixed)")
|
| 57 |
+
|
| 58 |
def setup():
|
| 59 |
"""Environment setup for Hugging Face Space"""
|
| 60 |
# Check if a known model file exists to skip setup
|
| 61 |
+
already_initialized = os.path.exists(os.path.join(COMFYUI_DIR, "models/vae/ae.safetensors"))
|
| 62 |
+
|
| 63 |
+
if already_initialized:
|
| 64 |
print("--- ENVIRONMENT ALREADY INITIALIZED ---")
|
| 65 |
+
# Still apply critical patches even if already initialized
|
| 66 |
+
_apply_seedvr2_patch()
|
| 67 |
return
|
| 68 |
|
| 69 |
print("--- FIRST TIME SETUP STARTING ---")
|
|
|
|
| 105 |
subprocess.run(["git", "checkout", "db90fe5012f94c6aef406d743292daf76b4477a6"], cwd=node_dest, check=True, capture_output=True)
|
| 106 |
print("✓ Custom nodes installed")
|
| 107 |
|
| 108 |
+
# Apply SeedVR2 MIG GPU compatibility patch
|
| 109 |
+
_apply_seedvr2_patch()
|
| 110 |
+
|
| 111 |
# Install performance optimizations (SageAttention, Flash Attention)
|
| 112 |
print("Installing performance optimizations...")
|
| 113 |
subprocess.run([
|