Update tab_timeline_wip.py
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import streamlit as st
|
import streamlit as st
|
||||||
import json
|
import json
|
||||||
from history_tree import HistoryTree
|
from history_tree import HistoryTree
|
||||||
from utils import save_json, DEFAULTS
|
from utils import save_json
|
||||||
from streamlit_agraph import agraph, Node, Edge, Config
|
from streamlit_agraph import agraph, Node, Edge, Config
|
||||||
|
|
||||||
def render_timeline_wip(data, file_path):
|
def render_timeline_wip(data, file_path):
|
||||||
@@ -12,9 +12,7 @@ def render_timeline_wip(data, file_path):
|
|||||||
|
|
||||||
htree = HistoryTree(tree_data)
|
htree = HistoryTree(tree_data)
|
||||||
|
|
||||||
# ==========================================
|
# --- 1. GRAPH NODES ---
|
||||||
# 1. BUILD GRAPH DATA (NODES & EDGES)
|
|
||||||
# ==========================================
|
|
||||||
nodes = []
|
nodes = []
|
||||||
edges = []
|
edges = []
|
||||||
|
|
||||||
@@ -25,16 +23,12 @@ def render_timeline_wip(data, file_path):
|
|||||||
note = n.get('note', 'Step')
|
note = n.get('note', 'Step')
|
||||||
short_note = (note[:15] + '..') if len(note) > 15 else note
|
short_note = (note[:15] + '..') if len(note) > 15 else note
|
||||||
|
|
||||||
# Default Styles
|
# Colors
|
||||||
color = "#ffffff"
|
color = "#ffffff"
|
||||||
border = "#666666"
|
border = "#666666"
|
||||||
|
|
||||||
# Highlight Head (Current Pointer)
|
|
||||||
if nid == htree.head_id:
|
if nid == htree.head_id:
|
||||||
color = "#fff6cd"
|
color = "#fff6cd"
|
||||||
border = "#eebb00"
|
border = "#eebb00"
|
||||||
|
|
||||||
# Highlight Tips (Ends of branches)
|
|
||||||
if nid in htree.branches.values():
|
if nid in htree.branches.values():
|
||||||
if color == "#ffffff":
|
if color == "#ffffff":
|
||||||
color = "#e6ffe6"
|
color = "#e6ffe6"
|
||||||
@@ -59,37 +53,19 @@ def render_timeline_wip(data, file_path):
|
|||||||
type="STRAIGHT"
|
type="STRAIGHT"
|
||||||
))
|
))
|
||||||
|
|
||||||
# ==========================================
|
|
||||||
# 2. RENDER INTERACTIVE GRAPH
|
|
||||||
# ==========================================
|
|
||||||
config = Config(
|
config = Config(
|
||||||
width="100%",
|
width="100%", height="500px", directed=True, physics=False, hierarchical=True,
|
||||||
height="500px",
|
layout={"hierarchical": {"enabled": True, "levelSeparation": 150, "nodeSpacing": 100, "treeSpacing": 100, "direction": "LR", "sortMethod": "directed"}}
|
||||||
directed=True,
|
|
||||||
physics=False,
|
|
||||||
hierarchical=True,
|
|
||||||
layout={
|
|
||||||
"hierarchical": {
|
|
||||||
"enabled": True,
|
|
||||||
"levelSeparation": 150,
|
|
||||||
"nodeSpacing": 100,
|
|
||||||
"treeSpacing": 100,
|
|
||||||
"direction": "LR",
|
|
||||||
"sortMethod": "directed"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
st.subheader("✨ Interactive Timeline")
|
st.subheader("✨ Interactive Timeline")
|
||||||
st.caption("Click any node to preview its settings and compare changes.")
|
st.caption("Click any node to preview its prompts and settings.")
|
||||||
|
|
||||||
clicked_node_id = agraph(nodes=nodes, edges=edges, config=config)
|
clicked_node_id = agraph(nodes=nodes, edges=edges, config=config)
|
||||||
|
|
||||||
st.markdown("---")
|
st.markdown("---")
|
||||||
|
|
||||||
# ==========================================
|
# --- 2. INSPECTOR ---
|
||||||
# 3. INSPECTION PANEL
|
|
||||||
# ==========================================
|
|
||||||
target_node_id = clicked_node_id if clicked_node_id else htree.head_id
|
target_node_id = clicked_node_id if clicked_node_id else htree.head_id
|
||||||
|
|
||||||
if target_node_id and target_node_id in htree.nodes:
|
if target_node_id and target_node_id in htree.nodes:
|
||||||
@@ -100,37 +76,23 @@ def render_timeline_wip(data, file_path):
|
|||||||
c_h1.markdown(f"### 🔎 Inspecting: {selected_node.get('note', 'Step')}")
|
c_h1.markdown(f"### 🔎 Inspecting: {selected_node.get('note', 'Step')}")
|
||||||
c_h1.caption(f"ID: {target_node_id}")
|
c_h1.caption(f"ID: {target_node_id}")
|
||||||
|
|
||||||
# --- A. COMPARE CHANGES (DIFF) ---
|
# --- COMPARE (Only here) ---
|
||||||
with st.expander(f"📊 Compare Changes", expanded=False):
|
with st.expander(f"📊 Compare Changes", expanded=False):
|
||||||
diffs = []
|
diffs = []
|
||||||
all_keys = set(data.keys()) | set(node_data.keys())
|
all_keys = set(data.keys()) | set(node_data.keys())
|
||||||
|
ignore_keys = {"history_tree", "prompt_history", "batch_data", "ui_reset_token", "sequence_number"}
|
||||||
# Keys to ignore in diff view to reduce noise
|
|
||||||
ignore_keys = {
|
|
||||||
"history_tree", "prompt_history", "batch_data",
|
|
||||||
"ui_reset_token", "sequence_number",
|
|
||||||
"input_a_frames", "input_b_frames"
|
|
||||||
}
|
|
||||||
|
|
||||||
for k in all_keys:
|
for k in all_keys:
|
||||||
if k in ignore_keys: continue
|
if k in ignore_keys: continue
|
||||||
val_now = data.get(k, "")
|
val_now = str(data.get(k, "")).strip()
|
||||||
val_then = node_data.get(k, "")
|
val_then = str(node_data.get(k, "")).strip()
|
||||||
|
|
||||||
# Convert to string and strip whitespace for clean comparison
|
if val_now != val_then:
|
||||||
str_now = str(val_now).strip()
|
# Ignore tiny float differences
|
||||||
str_then = str(val_then).strip()
|
|
||||||
|
|
||||||
if str_now != str_then:
|
|
||||||
# Fuzzy match for numbers (ignore 1 vs 1.0)
|
|
||||||
try:
|
try:
|
||||||
f_now = float(str_now)
|
if abs(float(val_now) - float(val_then)) < 0.001: continue
|
||||||
f_then = float(str_then)
|
except: pass
|
||||||
if abs(f_now - f_then) < 0.001: continue
|
diffs.append((k, val_now, val_then))
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
diffs.append((k, str_now, str_then))
|
|
||||||
|
|
||||||
if not diffs:
|
if not diffs:
|
||||||
st.caption("✅ Identical to current state")
|
st.caption("✅ Identical to current state")
|
||||||
@@ -138,60 +100,62 @@ def render_timeline_wip(data, file_path):
|
|||||||
for k, v_now, v_then in diffs:
|
for k, v_now, v_then in diffs:
|
||||||
dc1, dc2, dc3 = st.columns([1, 2, 2])
|
dc1, dc2, dc3 = st.columns([1, 2, 2])
|
||||||
dc1.markdown(f"**{k}**")
|
dc1.markdown(f"**{k}**")
|
||||||
dc2.markdown(f"🔴 `{str(v_now)[:30]}`")
|
dc2.markdown(f"🔴 `{v_now[:30]}`")
|
||||||
dc3.markdown(f"🟢 `{str(v_then)[:30]}`")
|
dc3.markdown(f"🟢 `{v_then[:30]}`")
|
||||||
|
|
||||||
# --- B. RESTORE ACTION ---
|
# --- RESTORE ACTION ---
|
||||||
with c_h2:
|
with c_h2:
|
||||||
st.write(""); st.write("")
|
st.write(""); st.write("")
|
||||||
if st.button("⏪ Restore This Version", type="primary", use_container_width=True):
|
if st.button("⏪ Restore This Version", type="primary", use_container_width=True):
|
||||||
data.update(node_data)
|
data.update(node_data)
|
||||||
htree.head_id = target_node_id
|
htree.head_id = target_node_id
|
||||||
|
|
||||||
data["history_tree"] = htree.to_dict()
|
data["history_tree"] = htree.to_dict()
|
||||||
save_json(file_path, data)
|
save_json(file_path, data)
|
||||||
|
|
||||||
st.session_state.ui_reset_token += 1
|
st.session_state.ui_reset_token += 1
|
||||||
|
st.session_state.restored_indicator = f"{selected_node.get('note')} ({target_node_id[:4]})"
|
||||||
label = f"{selected_node.get('note')} ({target_node_id[:4]})"
|
|
||||||
st.session_state.restored_indicator = label
|
|
||||||
|
|
||||||
st.toast(f"Restored {target_node_id}!", icon="🔄")
|
st.toast(f"Restored {target_node_id}!", icon="🔄")
|
||||||
st.rerun()
|
st.rerun()
|
||||||
|
|
||||||
# --- C. SNAPSHOT PREVIEW (READ ONLY FORM) ---
|
# --- PREVIEW (CORRECTED SCHEMA) ---
|
||||||
st.markdown("#### 📄 Snapshot Preview")
|
st.markdown("#### 📄 Snapshot Preview")
|
||||||
|
|
||||||
# 1. Prompts (Handles both old 'positive_prompt' and new 'general_prompt' keys)
|
# 1. Prompts
|
||||||
p_col1, p_col2 = st.columns(2)
|
p_col1, p_col2 = st.columns(2)
|
||||||
with p_col1:
|
with p_col1:
|
||||||
val_p = node_data.get("positive_prompt", "") or node_data.get("general_prompt", "")
|
val = node_data.get("general_prompt", "")
|
||||||
st.text_area("Positive Prompt", value=val_p, height=100, disabled=True, key="prev_pp")
|
st.text_area("General Prompt", value=val, height=80, disabled=True, key="prev_gp")
|
||||||
|
|
||||||
|
val_sp = node_data.get("current_prompt", "") or node_data.get("prompt", "")
|
||||||
|
st.text_area("Specific Prompt", value=val_sp, height=80, disabled=True, key="prev_sp")
|
||||||
|
|
||||||
with p_col2:
|
with p_col2:
|
||||||
val_n = node_data.get("negative_prompt", "") or node_data.get("general_negative", "")
|
val = node_data.get("general_negative", "")
|
||||||
st.text_area("Negative Prompt", value=val_n, height=100, disabled=True, key="prev_np")
|
st.text_area("General Negative", value=val, height=80, disabled=True, key="prev_gn")
|
||||||
|
|
||||||
|
val_sn = node_data.get("negative", "")
|
||||||
|
st.text_area("Specific Negative", value=val_sn, height=80, disabled=True, key="prev_sn")
|
||||||
|
|
||||||
# 2. Key Settings
|
# 2. Key Settings (Camera / FLF / Seed)
|
||||||
s_col1, s_col2, s_col3, s_col4 = st.columns(4)
|
st.caption("Settings")
|
||||||
s_col1.text_input("Seed", value=str(node_data.get("seed", "")), disabled=True, key="prev_seed")
|
s_col1, s_col2, s_col3 = st.columns(3)
|
||||||
s_col2.text_input("Steps", value=str(node_data.get("steps", "")), disabled=True, key="prev_steps")
|
s_col1.text_input("Camera", value=str(node_data.get("camera", "")), disabled=True, key="prev_cam")
|
||||||
s_col3.text_input("CFG", value=str(node_data.get("cfg", "")), disabled=True, key="prev_cfg")
|
s_col2.text_input("FLF", value=str(node_data.get("flf", "")), disabled=True, key="prev_flf")
|
||||||
s_col4.text_input("Denoise", value=str(node_data.get("denoise", "")), disabled=True, key="prev_den")
|
s_col3.text_input("Seed", value=str(node_data.get("seed", "")), disabled=True, key="prev_seed")
|
||||||
|
|
||||||
# 3. Models
|
# 3. VACE / I2V Specifics (Conditional)
|
||||||
m_col1, m_col2 = st.columns(2)
|
vace_keys = ["frame_to_skip", "vace schedule", "video file path"]
|
||||||
m_col1.text_input("Checkpoint", value=node_data.get("model_name", ""), disabled=True, key="prev_ckpt")
|
has_vace = any(k in node_data for k in vace_keys)
|
||||||
m_col2.text_input("VAE", value=node_data.get("vae_name", ""), disabled=True, key="prev_vae")
|
|
||||||
|
if has_vace:
|
||||||
|
with st.expander("VACE / I2V Settings", expanded=True):
|
||||||
|
v1, v2, v3 = st.columns(3)
|
||||||
|
v1.text_input("Skip Frames", value=str(node_data.get("frame_to_skip", "")), disabled=True, key="prev_fts")
|
||||||
|
v2.text_input("Schedule", value=str(node_data.get("vace schedule", "")), disabled=True, key="prev_vsc")
|
||||||
|
v3.text_input("Video Path", value=str(node_data.get("video file path", "")), disabled=True, key="prev_vid")
|
||||||
|
|
||||||
# 4. LoRAs
|
# 4. LoRAs
|
||||||
with st.expander("💊 LoRA Configuration"):
|
with st.expander("💊 LoRA Configuration"):
|
||||||
l1, l2, l3 = st.columns(3)
|
l1, l2, l3 = st.columns(3)
|
||||||
with l1:
|
l1.text_input("L1", value=f"{node_data.get('lora 1 high','')} : {node_data.get('lora 1 low','')}", disabled=True, key="prev_l1")
|
||||||
st.text_input("L1 Name", value=node_data.get("lora 1 high", ""), disabled=True, key="prev_l1h")
|
l2.text_input("L2", value=f"{node_data.get('lora 2 high','')} : {node_data.get('lora 2 low','')}", disabled=True, key="prev_l2")
|
||||||
st.text_input("L1 Str", value=str(node_data.get("lora 1 low", "")), disabled=True, key="prev_l1l")
|
l3.text_input("L3", value=f"{node_data.get('lora 3 high','')} : {node_data.get('lora 3 low','')}", disabled=True, key="prev_l3")
|
||||||
with l2:
|
|
||||||
st.text_input("L2 Name", value=node_data.get("lora 2 high", ""), disabled=True, key="prev_l2h")
|
|
||||||
st.text_input("L2 Str", value=str(node_data.get("lora 2 low", "")), disabled=True, key="prev_l2l")
|
|
||||||
with l3:
|
|
||||||
st.text_input("L3 Name", value=node_data.get("lora 3 high", ""), disabled=True, key="prev_l3h")
|
|
||||||
st.text_input("L3 Str", value=str(node_data.get("lora 3 low", "")), disabled=True, key="prev_l3l")
|
|
||||||
|
|||||||
Reference in New Issue
Block a user