-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy path__init__.py
More file actions
125 lines (106 loc) · 4.45 KB
/
__init__.py
File metadata and controls
125 lines (106 loc) · 4.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
"""
ComfyUI-KikoTools: Modular collection of custom ComfyUI nodes
All nodes are grouped under the "ComfyAssets" category
"""
import re
from pathlib import Path
try:
from .kikotools import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS
except ImportError:
# Fallback for testing environment
from kikotools import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS
# Tell ComfyUI where to find our JavaScript extensions
import os
WEB_DIRECTORY = os.path.join(os.path.dirname(os.path.abspath(__file__)), "web")
# Import server components at module level to ensure they're available
try:
from aiohttp import web
from server import PromptServer
import folder_paths
print("[KikoTools] Server imports successful")
# Register autocomplete endpoints directly
@PromptServer.instance.routes.get("/kikotools/autocomplete/embeddings")
async def get_embeddings(request):
"""API endpoint for getting list of embeddings with full paths."""
print("[KikoTools] Embeddings endpoint called")
try:
embedding_files = folder_paths.get_filename_list("embeddings")
print(f"[KikoTools] Found {len(embedding_files)} embedding files")
# Return embeddings with their subdirectory paths, without extensions
embeddings = []
for f in embedding_files:
# Remove extension but keep subdirectory path
clean_path = os.path.splitext(f)[0]
embeddings.append(
{
"file_name": clean_path,
"model_name": clean_path,
"name": os.path.basename(clean_path),
"path": clean_path,
}
)
if len(embeddings) > 0:
print(f"[KikoTools] Sample embedding: {embeddings[0]}")
print(f"[KikoTools] Returning {len(embeddings)} embeddings with paths")
return web.json_response(embeddings)
except Exception as e:
print(f"[KikoTools] Error getting embeddings: {e}")
import traceback
traceback.print_exc()
return web.json_response([])
@PromptServer.instance.routes.get("/kikotools/autocomplete/loras")
async def get_loras(request):
"""API endpoint for getting list of LoRAs."""
print("[KikoTools] LoRA endpoint called")
try:
lora_files = folder_paths.get_filename_list("loras")
print(f"[KikoTools] Found {len(lora_files)} LoRA files")
# Return LoRAs with paths
loras = []
for f in lora_files:
clean_path = os.path.splitext(f)[0]
loras.append(
{
"name": os.path.basename(clean_path),
"path": clean_path,
"file": f,
}
)
print(f"[KikoTools] Returning {len(loras)} LoRAs")
return web.json_response(loras)
except Exception as e:
print(f"[KikoTools] Error getting LoRAs: {e}")
import traceback
traceback.print_exc()
return web.json_response([])
print("[KikoTools] Autocomplete API endpoints registered successfully")
print(
"[KikoTools] Routes available: /kikotools/autocomplete/embeddings and /kikotools/autocomplete/loras"
)
except ImportError as e:
print(f"[KikoTools] Could not import server components: {e}")
except Exception as e:
print(f"[KikoTools] Unexpected error setting up API: {e}")
import traceback
traceback.print_exc()
# API endpoints are registered above at module import time
def get_version():
"""Parse version from pyproject.toml"""
try:
pyproject_path = Path(__file__).parent / "pyproject.toml"
if pyproject_path.exists():
content = pyproject_path.read_text()
match = re.search(r'version\s*=\s*["\']([^"\']+)["\']', content)
if match:
return match.group(1)
except Exception:
pass
return "unknown"
# Print startup message with loaded tools
print()
print(f"\033[94m[ComfyUI-KikoTools] Version:\033[0m {get_version()}")
for node_key, display_name in NODE_DISPLAY_NAME_MAPPINGS.items():
print(f"🫶 \033[94mLoaded:\033[0m {display_name}")
print(f"\033[94mTotal: {len(NODE_CLASS_MAPPINGS)} tools loaded\033[0m")
print()
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS", "WEB_DIRECTORY"]