-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdashboard_node.py
More file actions
69 lines (60 loc) · 2.77 KB
/
Copy pathdashboard_node.py
File metadata and controls
69 lines (60 loc) · 2.77 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
import re
import os
import json
import folder_paths
from .html_generator import get_html_template
class SamplerConfigDashboardViewer:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"session_name": ("STRING", {"default": "my_session"}),
},
"optional": {
"dashboard_html": ("STRING", {"forceInput": True}),
},
"hidden": {"unique_id": "UNIQUE_ID"},
}
RETURN_TYPES = ()
FUNCTION = "view"
OUTPUT_NODE = True
CATEGORY = "sampling/testing"
def view(self, session_name, unique_id, dashboard_html=None):
# 1. If connected to Sampler (Fresh Generation)
if dashboard_html:
# --- MAGIC: EXTRACT SESSION NAME FROM HTML ---
match = re.search(r'id="session-input" class="session-input" value="(.*?)"', dashboard_html)
found_session = match.group(1) if match else None
# --- CRITICAL FIX: INJECT CORRECT DASHBOARD NODE ID ---
# The HTML coming from Sampler might have the Sampler's ID or a placeholder.
# We must overwrite it with THIS dashboard node's ID so listeners work.
# We look for the const TARGET_NODE_ID = "..." line in the JS.
fixed_html = re.sub(
r'const TARGET_NODE_ID = ".*?";',
f'const TARGET_NODE_ID = "{unique_id}";',
dashboard_html
)
return {
"ui": {
"html": [fixed_html],
"update_session_name": [found_session] if found_session else []
}
}
# 2. View Mode (Load from Disk)
session_name = re.sub(r'[^\w\-]', '', session_name)
if not session_name: session_name = "default_session"
base_dir = os.path.join(folder_paths.get_output_directory(), "benchmarks", session_name)
manifest_path = os.path.join(base_dir, "manifest.json")
if os.path.exists(manifest_path):
try:
with open(manifest_path, "r") as f:
manifest = json.load(f)
# Pass unique_id here, which get_html_template uses correctly
html = get_html_template(session_name, manifest, unique_id)
return {"ui": {"html": [html]}}
except Exception as e:
return {"ui": {"html": [f"Error loading session: {e}"]}}
# No session found — show full template with empty manifest so landing page can display
empty_manifest = {"items": [], "meta": {"model": "", "positive": "", "negative": ""}, "session_name": session_name}
html = get_html_template(session_name, empty_manifest, unique_id)
return {"ui": {"html": [html]}}