-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy path__init__.py
More file actions
65 lines (51 loc) · 2.45 KB
/
__init__.py
File metadata and controls
65 lines (51 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import os
import importlib
import sys
from pathlib import Path
current_dir = Path(__file__).parent
NODE_CLASS_MAPPINGS = {}
NODE_DISPLAY_NAME_MAPPINGS = {}
EXCLUDE_FILES = ['__init__.py', '__pycache__']
# Enable Windows color support
if sys.platform == 'win32':
os.system('color')
# Check if llama-cpp-python is available for GGUF functionality
GGUF_AVAILABLE = False
try:
import llama_cpp
GGUF_AVAILABLE = True
except ImportError:
print("\033[93m⚠️ GGUF functionality unavailable - install llama-cpp-python for GGUF support\033[0m")
print("\033[96m📖 Installation guide: https://github.com/1038lab/ComfyUI-MiniCPM/tree/main/llama_cpp_install\033[0m")
except Exception as e:
print(f"\033[91m❌ GGUF loading error: {str(e)}\033[0m")
print("\033[96m📖 Installation guide: https://github.com/1038lab/ComfyUI-MiniCPM/tree/main/llama_cpp_install\033[0m")
# Process all Python files in the directory (auto-registration functionality)
loaded_modules = []
skipped_modules = []
for file in current_dir.glob('*.py'):
if file.name not in EXCLUDE_FILES:
try:
module_name = file.stem
spec = importlib.util.spec_from_file_location(module_name, str(file))
module = importlib.util.module_from_spec(spec)
sys.modules[module_name] = module
# Skip GGUF module if llama-cpp-python is not available
if not GGUF_AVAILABLE and 'GGUF' in module_name:
skipped_modules.append(module_name)
continue
spec.loader.exec_module(module)
if hasattr(module, 'NODE_CLASS_MAPPINGS'):
NODE_CLASS_MAPPINGS.update(module.NODE_CLASS_MAPPINGS)
loaded_modules.append(module_name)
if hasattr(module, 'NODE_DISPLAY_NAME_MAPPINGS'):
NODE_DISPLAY_NAME_MAPPINGS.update(module.NODE_DISPLAY_NAME_MAPPINGS)
except Exception as e:
print(f"\033[91m❌ Failed to load {module_name}: {str(e)}\033[0m")
skipped_modules.append(module_name)
# Summary output
if loaded_modules:
print(f"\033[92m✅ MiniCPM loaded: {len(NODE_CLASS_MAPPINGS)} nodes from {len(loaded_modules)} modules\033[0m")
if skipped_modules:
print(f"\033[93m⏭️ Skipped: {', '.join(skipped_modules)}\033[0m")
__all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS']