Merge timeline tabs into single polished tab with adaptive scaling
Combine stable and WIP timeline tabs into one with all features: view switcher, restore/rename/delete, and data preview panel. Add adaptive graph spacing based on node count, show full dates and branch names on node labels, increase label truncation to 25 chars, and drop streamlit-agraph dependency. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
5
app.py
5
app.py
@@ -11,7 +11,6 @@ from utils import (
|
|||||||
from tab_single import render_single_editor
|
from tab_single import render_single_editor
|
||||||
from tab_batch import render_batch_processor
|
from tab_batch import render_batch_processor
|
||||||
from tab_timeline import render_timeline_tab
|
from tab_timeline import render_timeline_tab
|
||||||
from tab_timeline_wip import render_timeline_wip
|
|
||||||
from tab_comfy import render_comfy_monitor
|
from tab_comfy import render_comfy_monitor
|
||||||
from tab_raw import render_raw_editor
|
from tab_raw import render_raw_editor
|
||||||
|
|
||||||
@@ -200,7 +199,6 @@ if selected_file_name:
|
|||||||
"📝 Single Editor",
|
"📝 Single Editor",
|
||||||
"🚀 Batch Processor",
|
"🚀 Batch Processor",
|
||||||
"🕒 Timeline",
|
"🕒 Timeline",
|
||||||
"🧪 Interactive Timeline",
|
|
||||||
"💻 Raw Editor"
|
"💻 Raw Editor"
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -227,9 +225,6 @@ if selected_file_name:
|
|||||||
elif current_tab == "🕒 Timeline":
|
elif current_tab == "🕒 Timeline":
|
||||||
render_timeline_tab(data, file_path)
|
render_timeline_tab(data, file_path)
|
||||||
|
|
||||||
elif current_tab == "🧪 Interactive Timeline":
|
|
||||||
render_timeline_wip(data, file_path)
|
|
||||||
|
|
||||||
elif current_tab == "💻 Raw Editor":
|
elif current_tab == "💻 Raw Editor":
|
||||||
render_raw_editor(data, file_path)
|
render_raw_editor(data, file_path)
|
||||||
|
|
||||||
|
|||||||
@@ -75,17 +75,27 @@ class HistoryTree:
|
|||||||
Generates Graphviz source.
|
Generates Graphviz source.
|
||||||
direction: "LR" (Horizontal) or "TB" (Vertical)
|
direction: "LR" (Horizontal) or "TB" (Vertical)
|
||||||
"""
|
"""
|
||||||
|
node_count = len(self.nodes)
|
||||||
|
if node_count <= 5:
|
||||||
|
nodesep, ranksep = 0.5, 0.6
|
||||||
|
elif node_count <= 15:
|
||||||
|
nodesep, ranksep = 0.3, 0.4
|
||||||
|
else:
|
||||||
|
nodesep, ranksep = 0.15, 0.25
|
||||||
|
|
||||||
|
# Build reverse lookup: branch tip -> branch name(s)
|
||||||
|
tip_to_branches: dict[str, list[str]] = {}
|
||||||
|
for b_name, tip_id in self.branches.items():
|
||||||
|
if tip_id:
|
||||||
|
tip_to_branches.setdefault(tip_id, []).append(b_name)
|
||||||
|
|
||||||
dot = [
|
dot = [
|
||||||
'digraph History {',
|
'digraph History {',
|
||||||
f' rankdir={direction};', # Dynamic Direction
|
f' rankdir={direction};',
|
||||||
' bgcolor="white";',
|
' bgcolor="white";',
|
||||||
' splines=ortho;',
|
' splines=ortho;',
|
||||||
|
f' nodesep={nodesep};',
|
||||||
# TIGHT SPACING
|
f' ranksep={ranksep};',
|
||||||
' nodesep=0.2;',
|
|
||||||
' ranksep=0.3;',
|
|
||||||
|
|
||||||
# GLOBAL STYLES
|
|
||||||
' node [shape=plain, fontname="Arial"];',
|
' node [shape=plain, fontname="Arial"];',
|
||||||
' edge [color="#888888", arrowsize=0.6, penwidth=1.0];'
|
' edge [color="#888888", arrowsize=0.6, penwidth=1.0];'
|
||||||
]
|
]
|
||||||
@@ -96,7 +106,14 @@ class HistoryTree:
|
|||||||
nid = n["id"]
|
nid = n["id"]
|
||||||
full_note = n.get('note', 'Step')
|
full_note = n.get('note', 'Step')
|
||||||
|
|
||||||
display_note = (full_note[:15] + '..') if len(full_note) > 15 else full_note
|
display_note = (full_note[:25] + '..') if len(full_note) > 25 else full_note
|
||||||
|
|
||||||
|
ts = time.strftime('%b %d %H:%M', time.localtime(n['timestamp']))
|
||||||
|
|
||||||
|
# Branch label for tip nodes
|
||||||
|
branch_label = ""
|
||||||
|
if nid in tip_to_branches:
|
||||||
|
branch_label = ", ".join(tip_to_branches[nid])
|
||||||
|
|
||||||
# COLORS
|
# COLORS
|
||||||
bg_color = "#f9f9f9"
|
bg_color = "#f9f9f9"
|
||||||
@@ -104,19 +121,25 @@ class HistoryTree:
|
|||||||
border_width = "1"
|
border_width = "1"
|
||||||
|
|
||||||
if nid == self.head_id:
|
if nid == self.head_id:
|
||||||
bg_color = "#fff6cd" # Yellow for Current
|
bg_color = "#fff6cd"
|
||||||
border_color = "#eebb00"
|
border_color = "#eebb00"
|
||||||
border_width = "2"
|
border_width = "2"
|
||||||
elif nid in self.branches.values():
|
elif nid in self.branches.values():
|
||||||
bg_color = "#e6ffe6" # Green for Tips
|
bg_color = "#e6ffe6"
|
||||||
border_color = "#66aa66"
|
border_color = "#66aa66"
|
||||||
|
|
||||||
# HTML LABEL
|
# HTML LABEL
|
||||||
|
rows = [
|
||||||
|
f'<TR><TD><B><FONT POINT-SIZE="10">{display_note}</FONT></B></TD></TR>',
|
||||||
|
f'<TR><TD><FONT POINT-SIZE="8" COLOR="#555555">{ts} • {nid[:4]}</FONT></TD></TR>',
|
||||||
|
]
|
||||||
|
if branch_label:
|
||||||
|
rows.append(f'<TR><TD><FONT POINT-SIZE="8" COLOR="#4488cc"><I>{branch_label}</I></FONT></TD></TR>')
|
||||||
|
|
||||||
label = (
|
label = (
|
||||||
f'<<TABLE BORDER="{border_width}" CELLBORDER="0" CELLSPACING="0" CELLPADDING="4" BGCOLOR="{bg_color}" COLOR="{border_color}">'
|
f'<<TABLE BORDER="{border_width}" CELLBORDER="0" CELLSPACING="0" CELLPADDING="4" BGCOLOR="{bg_color}" COLOR="{border_color}">'
|
||||||
f'<TR><TD><B><FONT POINT-SIZE="10">{display_note}</FONT></B></TD></TR>'
|
+ "".join(rows)
|
||||||
f'<TR><TD><FONT POINT-SIZE="8" COLOR="#555555">{nid[:4]}</FONT></TD></TR>'
|
+ '</TABLE>>'
|
||||||
f'</TABLE>>'
|
|
||||||
)
|
)
|
||||||
|
|
||||||
safe_tooltip = full_note.replace('"', "'")
|
safe_tooltip = full_note.replace('"', "'")
|
||||||
|
|||||||
193
tab_timeline.py
193
tab_timeline.py
@@ -1,11 +1,10 @@
|
|||||||
import streamlit as st
|
import streamlit as st
|
||||||
import copy
|
import copy
|
||||||
import json
|
|
||||||
import graphviz
|
|
||||||
import time
|
import time
|
||||||
from history_tree import HistoryTree
|
from history_tree import HistoryTree
|
||||||
from utils import save_json, KEY_BATCH_DATA, KEY_HISTORY_TREE
|
from utils import save_json, KEY_BATCH_DATA, KEY_HISTORY_TREE
|
||||||
|
|
||||||
|
|
||||||
def render_timeline_tab(data, file_path):
|
def render_timeline_tab(data, file_path):
|
||||||
tree_data = data.get(KEY_HISTORY_TREE, {})
|
tree_data = data.get(KEY_HISTORY_TREE, {})
|
||||||
if not tree_data:
|
if not tree_data:
|
||||||
@@ -28,6 +27,10 @@ def render_timeline_tab(data, file_path):
|
|||||||
label_visibility="collapsed"
|
label_visibility="collapsed"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# --- Build sorted node list (shared by all views) ---
|
||||||
|
all_nodes = list(htree.nodes.values())
|
||||||
|
all_nodes.sort(key=lambda x: x["timestamp"], reverse=True)
|
||||||
|
|
||||||
# --- RENDER GRAPH VIEWS ---
|
# --- RENDER GRAPH VIEWS ---
|
||||||
if view_mode in ["🌳 Horizontal", "🌲 Vertical"]:
|
if view_mode in ["🌳 Horizontal", "🌲 Vertical"]:
|
||||||
direction = "LR" if view_mode == "🌳 Horizontal" else "TB"
|
direction = "LR" if view_mode == "🌳 Horizontal" else "TB"
|
||||||
@@ -40,8 +43,6 @@ def render_timeline_tab(data, file_path):
|
|||||||
# --- RENDER LINEAR LOG VIEW ---
|
# --- RENDER LINEAR LOG VIEW ---
|
||||||
elif view_mode == "📜 Linear Log":
|
elif view_mode == "📜 Linear Log":
|
||||||
st.caption("A simple chronological list of all snapshots.")
|
st.caption("A simple chronological list of all snapshots.")
|
||||||
all_nodes = list(htree.nodes.values())
|
|
||||||
all_nodes.sort(key=lambda x: x["timestamp"], reverse=True)
|
|
||||||
|
|
||||||
for n in all_nodes:
|
for n in all_nodes:
|
||||||
is_head = (n["id"] == htree.head_id)
|
is_head = (n["id"] == htree.head_id)
|
||||||
@@ -51,41 +52,26 @@ def render_timeline_tab(data, file_path):
|
|||||||
st.markdown("### 📍" if is_head else "### ⚫")
|
st.markdown("### 📍" if is_head else "### ⚫")
|
||||||
with c2:
|
with c2:
|
||||||
note_txt = n.get('note', 'Step')
|
note_txt = n.get('note', 'Step')
|
||||||
ts = time.strftime('%H:%M:%S', time.localtime(n['timestamp']))
|
ts = time.strftime('%b %d %H:%M', time.localtime(n['timestamp']))
|
||||||
if is_head:
|
if is_head:
|
||||||
st.markdown(f"**{note_txt}** (Current)")
|
st.markdown(f"**{note_txt}** (Current)")
|
||||||
else:
|
else:
|
||||||
st.write(f"**{note_txt}**")
|
st.write(f"**{note_txt}**")
|
||||||
st.caption(f"ID: {n['id'][:6]} • Time: {ts}")
|
st.caption(f"ID: {n['id'][:6]} • {ts}")
|
||||||
with c3:
|
with c3:
|
||||||
if not is_head:
|
if not is_head:
|
||||||
if st.button("⏪", key=f"log_rst_{n['id']}", help="Restore this version"):
|
if st.button("⏪", key=f"log_rst_{n['id']}", help="Restore this version"):
|
||||||
# --- FIX: Cleanup 'batch_data' if restoring a Single File ---
|
_restore_node(data, n, htree, file_path)
|
||||||
if KEY_BATCH_DATA not in n["data"] and KEY_BATCH_DATA in data:
|
|
||||||
del data[KEY_BATCH_DATA]
|
|
||||||
# -------------------------------------------------------------
|
|
||||||
|
|
||||||
data.update(n["data"])
|
|
||||||
htree.head_id = n['id']
|
|
||||||
data[KEY_HISTORY_TREE] = htree.to_dict()
|
|
||||||
save_json(file_path, data)
|
|
||||||
st.session_state.ui_reset_token += 1
|
|
||||||
label = f"{n.get('note')} ({n['id'][:4]})"
|
|
||||||
st.session_state.restored_indicator = label
|
|
||||||
st.toast(f"Restored!", icon="🔄")
|
|
||||||
st.rerun()
|
|
||||||
st.divider()
|
st.divider()
|
||||||
|
|
||||||
st.markdown("---")
|
st.markdown("---")
|
||||||
|
|
||||||
# --- ACTIONS & SELECTION ---
|
# --- NODE SELECTOR ---
|
||||||
col_sel, col_act = st.columns([3, 1])
|
col_sel, col_act = st.columns([3, 1])
|
||||||
|
|
||||||
all_nodes = list(htree.nodes.values())
|
|
||||||
all_nodes.sort(key=lambda x: x["timestamp"], reverse=True)
|
|
||||||
|
|
||||||
def fmt_node(n):
|
def fmt_node(n):
|
||||||
return f"{n.get('note', 'Step')} ({n['id']})"
|
ts = time.strftime('%b %d %H:%M', time.localtime(n['timestamp']))
|
||||||
|
return f"{n.get('note', 'Step')} • {ts} ({n['id'][:6]})"
|
||||||
|
|
||||||
with col_sel:
|
with col_sel:
|
||||||
current_idx = 0
|
current_idx = 0
|
||||||
@@ -101,58 +87,119 @@ def render_timeline_tab(data, file_path):
|
|||||||
index=current_idx
|
index=current_idx
|
||||||
)
|
)
|
||||||
|
|
||||||
if selected_node:
|
if not selected_node:
|
||||||
node_data = selected_node["data"]
|
return
|
||||||
|
|
||||||
# --- ACTIONS ---
|
node_data = selected_node["data"]
|
||||||
with col_act:
|
|
||||||
st.write(""); st.write("")
|
|
||||||
if st.button("⏪ Restore Version", type="primary", use_container_width=True):
|
|
||||||
# --- FIX: Cleanup 'batch_data' if restoring a Single File ---
|
|
||||||
if KEY_BATCH_DATA not in node_data and KEY_BATCH_DATA in data:
|
|
||||||
del data[KEY_BATCH_DATA]
|
|
||||||
# -------------------------------------------------------------
|
|
||||||
|
|
||||||
data.update(node_data)
|
# --- RESTORE ---
|
||||||
htree.head_id = selected_node['id']
|
with col_act:
|
||||||
|
st.write(""); st.write("")
|
||||||
|
if st.button("⏪ Restore Version", type="primary", use_container_width=True):
|
||||||
|
_restore_node(data, selected_node, htree, file_path)
|
||||||
|
|
||||||
|
# --- RENAME ---
|
||||||
|
rn_col1, rn_col2 = st.columns([3, 1])
|
||||||
|
new_label = rn_col1.text_input("Rename Label", value=selected_node.get("note", ""))
|
||||||
|
if rn_col2.button("Update Label"):
|
||||||
|
selected_node["note"] = new_label
|
||||||
|
data[KEY_HISTORY_TREE] = htree.to_dict()
|
||||||
|
save_json(file_path, data)
|
||||||
|
st.rerun()
|
||||||
|
|
||||||
|
# --- DANGER ZONE ---
|
||||||
|
st.markdown("---")
|
||||||
|
with st.expander("⚠️ Danger Zone (Delete)"):
|
||||||
|
st.warning("Deleting a node cannot be undone.")
|
||||||
|
if st.button("🗑️ Delete This Node", type="primary"):
|
||||||
|
if selected_node['id'] in htree.nodes:
|
||||||
|
if "history_tree_backup" not in data:
|
||||||
|
data["history_tree_backup"] = []
|
||||||
|
data["history_tree_backup"].append(copy.deepcopy(htree.to_dict()))
|
||||||
|
del htree.nodes[selected_node['id']]
|
||||||
|
for b, tip in list(htree.branches.items()):
|
||||||
|
if tip == selected_node['id']:
|
||||||
|
del htree.branches[b]
|
||||||
|
if htree.head_id == selected_node['id']:
|
||||||
|
if htree.nodes:
|
||||||
|
fallback = sorted(htree.nodes.values(), key=lambda x: x["timestamp"])[-1]
|
||||||
|
htree.head_id = fallback["id"]
|
||||||
|
else:
|
||||||
|
htree.head_id = None
|
||||||
data[KEY_HISTORY_TREE] = htree.to_dict()
|
data[KEY_HISTORY_TREE] = htree.to_dict()
|
||||||
save_json(file_path, data)
|
save_json(file_path, data)
|
||||||
st.session_state.ui_reset_token += 1
|
st.toast("Node Deleted", icon="🗑️")
|
||||||
label = f"{selected_node.get('note')} ({selected_node['id'][:4]})"
|
|
||||||
st.session_state.restored_indicator = label
|
|
||||||
st.toast(f"Restored!", icon="🔄")
|
|
||||||
st.rerun()
|
st.rerun()
|
||||||
|
|
||||||
# --- RENAME ---
|
# --- DATA PREVIEW ---
|
||||||
rn_col1, rn_col2 = st.columns([3, 1])
|
st.markdown("---")
|
||||||
new_label = rn_col1.text_input("Rename Label", value=selected_node.get("note", ""))
|
with st.expander("🔍 Data Preview", expanded=False):
|
||||||
if rn_col2.button("Update Label"):
|
batch_list = node_data.get(KEY_BATCH_DATA, [])
|
||||||
selected_node["note"] = new_label
|
|
||||||
data[KEY_HISTORY_TREE] = htree.to_dict()
|
|
||||||
save_json(file_path, data)
|
|
||||||
st.rerun()
|
|
||||||
|
|
||||||
# --- DANGER ZONE ---
|
if batch_list and isinstance(batch_list, list) and len(batch_list) > 0:
|
||||||
st.markdown("---")
|
st.info(f"📚 This snapshot contains {len(batch_list)} sequences.")
|
||||||
with st.expander("⚠️ Danger Zone (Delete)"):
|
for i, seq_data in enumerate(batch_list):
|
||||||
st.warning("Deleting a node cannot be undone.")
|
seq_num = seq_data.get("sequence_number", i + 1)
|
||||||
if st.button("🗑️ Delete This Node", type="primary"):
|
with st.expander(f"🎬 Sequence #{seq_num}", expanded=(i == 0)):
|
||||||
if selected_node['id'] in htree.nodes:
|
prefix = f"p_{selected_node['id']}_s{i}"
|
||||||
# Backup current tree state before destructive operation
|
_render_preview_fields(seq_data, prefix)
|
||||||
if "history_tree_backup" not in data:
|
else:
|
||||||
data["history_tree_backup"] = []
|
prefix = f"p_{selected_node['id']}_single"
|
||||||
data["history_tree_backup"].append(copy.deepcopy(htree.to_dict()))
|
_render_preview_fields(node_data, prefix)
|
||||||
del htree.nodes[selected_node['id']]
|
|
||||||
for b, tip in list(htree.branches.items()):
|
|
||||||
if tip == selected_node['id']:
|
def _restore_node(data, node, htree, file_path):
|
||||||
del htree.branches[b]
|
"""Restore a history node as the current version."""
|
||||||
if htree.head_id == selected_node['id']:
|
node_data = node["data"]
|
||||||
if htree.nodes:
|
if KEY_BATCH_DATA not in node_data and KEY_BATCH_DATA in data:
|
||||||
fallback = sorted(htree.nodes.values(), key=lambda x: x["timestamp"])[-1]
|
del data[KEY_BATCH_DATA]
|
||||||
htree.head_id = fallback["id"]
|
data.update(node_data)
|
||||||
else:
|
htree.head_id = node['id']
|
||||||
htree.head_id = None
|
data[KEY_HISTORY_TREE] = htree.to_dict()
|
||||||
data[KEY_HISTORY_TREE] = htree.to_dict()
|
save_json(file_path, data)
|
||||||
save_json(file_path, data)
|
st.session_state.ui_reset_token += 1
|
||||||
st.toast("Node Deleted", icon="🗑️")
|
label = f"{node.get('note')} ({node['id'][:4]})"
|
||||||
st.rerun()
|
st.session_state.restored_indicator = label
|
||||||
|
st.toast("Restored!", icon="🔄")
|
||||||
|
st.rerun()
|
||||||
|
|
||||||
|
|
||||||
|
def _render_preview_fields(item_data, prefix):
|
||||||
|
"""Render a read-only preview of prompts, settings, and LoRAs."""
|
||||||
|
# Prompts
|
||||||
|
p_col1, p_col2 = st.columns(2)
|
||||||
|
with p_col1:
|
||||||
|
st.text_area("General Positive", value=item_data.get("general_prompt", ""), height=80, disabled=True, key=f"{prefix}_gp")
|
||||||
|
val_sp = item_data.get("current_prompt", "") or item_data.get("prompt", "")
|
||||||
|
st.text_area("Specific Positive", value=val_sp, height=80, disabled=True, key=f"{prefix}_sp")
|
||||||
|
with p_col2:
|
||||||
|
st.text_area("General Negative", value=item_data.get("general_negative", ""), height=80, disabled=True, key=f"{prefix}_gn")
|
||||||
|
st.text_area("Specific Negative", value=item_data.get("negative", ""), height=80, disabled=True, key=f"{prefix}_sn")
|
||||||
|
|
||||||
|
# Settings
|
||||||
|
s_col1, s_col2, s_col3 = st.columns(3)
|
||||||
|
s_col1.text_input("Camera", value=str(item_data.get("camera", "static")), disabled=True, key=f"{prefix}_cam")
|
||||||
|
s_col2.text_input("FLF", value=str(item_data.get("flf", "0.0")), disabled=True, key=f"{prefix}_flf")
|
||||||
|
s_col3.text_input("Seed", value=str(item_data.get("seed", "-1")), disabled=True, key=f"{prefix}_seed")
|
||||||
|
|
||||||
|
# LoRAs
|
||||||
|
with st.expander("💊 LoRA Configuration", expanded=False):
|
||||||
|
l1, l2, l3 = st.columns(3)
|
||||||
|
with l1:
|
||||||
|
st.text_input("L1 Name", value=item_data.get("lora 1 high", ""), disabled=True, key=f"{prefix}_l1h")
|
||||||
|
st.text_input("L1 Str", value=str(item_data.get("lora 1 low", "")), disabled=True, key=f"{prefix}_l1l")
|
||||||
|
with l2:
|
||||||
|
st.text_input("L2 Name", value=item_data.get("lora 2 high", ""), disabled=True, key=f"{prefix}_l2h")
|
||||||
|
st.text_input("L2 Str", value=str(item_data.get("lora 2 low", "")), disabled=True, key=f"{prefix}_l2l")
|
||||||
|
with l3:
|
||||||
|
st.text_input("L3 Name", value=item_data.get("lora 3 high", ""), disabled=True, key=f"{prefix}_l3h")
|
||||||
|
st.text_input("L3 Str", value=str(item_data.get("lora 3 low", "")), disabled=True, key=f"{prefix}_l3l")
|
||||||
|
|
||||||
|
# VACE
|
||||||
|
vace_keys = ["frame_to_skip", "vace schedule", "video file path"]
|
||||||
|
if any(k in item_data for k in vace_keys):
|
||||||
|
with st.expander("🎞️ VACE / I2V Settings", expanded=False):
|
||||||
|
v1, v2, v3 = st.columns(3)
|
||||||
|
v1.text_input("Skip Frames", value=str(item_data.get("frame_to_skip", "")), disabled=True, key=f"{prefix}_fts")
|
||||||
|
v2.text_input("Schedule", value=str(item_data.get("vace schedule", "")), disabled=True, key=f"{prefix}_vsc")
|
||||||
|
v3.text_input("Video Path", value=str(item_data.get("video file path", "")), disabled=True, key=f"{prefix}_vid")
|
||||||
|
|||||||
@@ -1,191 +0,0 @@
|
|||||||
import streamlit as st
|
|
||||||
import json
|
|
||||||
from history_tree import HistoryTree
|
|
||||||
from utils import save_json, KEY_BATCH_DATA, KEY_HISTORY_TREE
|
|
||||||
|
|
||||||
try:
|
|
||||||
from streamlit_agraph import agraph, Node, Edge, Config
|
|
||||||
_HAS_AGRAPH = True
|
|
||||||
except ImportError:
|
|
||||||
_HAS_AGRAPH = False
|
|
||||||
|
|
||||||
def render_timeline_wip(data, file_path):
|
|
||||||
if not _HAS_AGRAPH:
|
|
||||||
st.error("The `streamlit-agraph` package is required for this tab. Install it with: `pip install streamlit-agraph`")
|
|
||||||
return
|
|
||||||
tree_data = data.get(KEY_HISTORY_TREE, {})
|
|
||||||
if not tree_data:
|
|
||||||
st.info("No history timeline exists.")
|
|
||||||
return
|
|
||||||
|
|
||||||
htree = HistoryTree(tree_data)
|
|
||||||
|
|
||||||
# --- 1. BUILD GRAPH ---
|
|
||||||
nodes = []
|
|
||||||
edges = []
|
|
||||||
|
|
||||||
sorted_nodes = sorted(htree.nodes.values(), key=lambda x: x["timestamp"])
|
|
||||||
|
|
||||||
for n in sorted_nodes:
|
|
||||||
nid = n["id"]
|
|
||||||
note = n.get('note', 'Step')
|
|
||||||
short_note = (note[:15] + '..') if len(note) > 15 else note
|
|
||||||
|
|
||||||
color = "#ffffff"
|
|
||||||
border = "#666666"
|
|
||||||
|
|
||||||
if nid == htree.head_id:
|
|
||||||
color = "#fff6cd"
|
|
||||||
border = "#eebb00"
|
|
||||||
|
|
||||||
if nid in htree.branches.values():
|
|
||||||
if color == "#ffffff":
|
|
||||||
color = "#e6ffe6"
|
|
||||||
border = "#44aa44"
|
|
||||||
|
|
||||||
nodes.append(Node(
|
|
||||||
id=nid,
|
|
||||||
label=f"{short_note}\n({nid[:4]})",
|
|
||||||
size=25,
|
|
||||||
shape="box",
|
|
||||||
color=color,
|
|
||||||
borderWidth=1,
|
|
||||||
borderColor=border,
|
|
||||||
font={'color': 'black', 'face': 'Arial', 'size': 14}
|
|
||||||
))
|
|
||||||
|
|
||||||
if n["parent"] and n["parent"] in htree.nodes:
|
|
||||||
edges.append(Edge(
|
|
||||||
source=n["parent"],
|
|
||||||
target=nid,
|
|
||||||
color="#aaaaaa",
|
|
||||||
type="STRAIGHT"
|
|
||||||
))
|
|
||||||
|
|
||||||
# --- UPDATED CONFIGURATION ---
|
|
||||||
config = Config(
|
|
||||||
width="100%",
|
|
||||||
# Increased height from 400px to 600px for better visibility
|
|
||||||
height="600px",
|
|
||||||
directed=True,
|
|
||||||
physics=False,
|
|
||||||
hierarchical=True,
|
|
||||||
layout={
|
|
||||||
"hierarchical": {
|
|
||||||
"enabled": True,
|
|
||||||
# Increased separation to widen the tree structure
|
|
||||||
"levelSeparation": 200, # Was 150
|
|
||||||
"nodeSpacing": 150, # Was 100
|
|
||||||
"treeSpacing": 150, # Was 100
|
|
||||||
"direction": "LR",
|
|
||||||
"sortMethod": "directed"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
st.subheader("✨ Interactive Timeline")
|
|
||||||
st.caption("Click a node to view its settings below.")
|
|
||||||
|
|
||||||
# --- FIX: REMOVED 'key' ARGUMENT ---
|
|
||||||
selected_id = agraph(nodes=nodes, edges=edges, config=config)
|
|
||||||
|
|
||||||
st.markdown("---")
|
|
||||||
|
|
||||||
# --- 2. DETERMINE TARGET ---
|
|
||||||
target_node_id = selected_id if selected_id else htree.head_id
|
|
||||||
|
|
||||||
if target_node_id and target_node_id in htree.nodes:
|
|
||||||
selected_node = htree.nodes[target_node_id]
|
|
||||||
node_data = selected_node["data"]
|
|
||||||
|
|
||||||
# Header
|
|
||||||
c_h1, c_h2 = st.columns([3, 1])
|
|
||||||
c_h1.markdown(f"### 📄 Previewing: {selected_node.get('note', 'Step')}")
|
|
||||||
c_h1.caption(f"ID: {target_node_id}")
|
|
||||||
|
|
||||||
# Restore Button
|
|
||||||
with c_h2:
|
|
||||||
st.write(""); st.write("")
|
|
||||||
if st.button("⏪ Restore This Version", type="primary", use_container_width=True, key=f"rst_{target_node_id}"):
|
|
||||||
# --- FIX: Cleanup 'batch_data' if restoring a Single File ---
|
|
||||||
if KEY_BATCH_DATA not in node_data and KEY_BATCH_DATA in data:
|
|
||||||
del data[KEY_BATCH_DATA]
|
|
||||||
# -------------------------------------------------------------
|
|
||||||
|
|
||||||
data.update(node_data)
|
|
||||||
htree.head_id = target_node_id
|
|
||||||
|
|
||||||
data[KEY_HISTORY_TREE] = htree.to_dict()
|
|
||||||
save_json(file_path, data)
|
|
||||||
|
|
||||||
st.session_state.ui_reset_token += 1
|
|
||||||
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.rerun()
|
|
||||||
|
|
||||||
# --- 3. PREVIEW LOGIC (BATCH VS SINGLE) ---
|
|
||||||
|
|
||||||
# Helper to render one set of inputs
|
|
||||||
def render_preview_fields(item_data, prefix):
|
|
||||||
# A. Prompts
|
|
||||||
p_col1, p_col2 = st.columns(2)
|
|
||||||
with p_col1:
|
|
||||||
val_gp = item_data.get("general_prompt", "")
|
|
||||||
st.text_area("General Positive", value=val_gp, height=80, disabled=True, key=f"{prefix}_gp")
|
|
||||||
|
|
||||||
val_sp = item_data.get("current_prompt", "") or item_data.get("prompt", "")
|
|
||||||
st.text_area("Specific Positive", value=val_sp, height=80, disabled=True, key=f"{prefix}_sp")
|
|
||||||
with p_col2:
|
|
||||||
val_gn = item_data.get("general_negative", "")
|
|
||||||
st.text_area("General Negative", value=val_gn, height=80, disabled=True, key=f"{prefix}_gn")
|
|
||||||
|
|
||||||
val_sn = item_data.get("negative", "")
|
|
||||||
st.text_area("Specific Negative", value=val_sn, height=80, disabled=True, key=f"{prefix}_sn")
|
|
||||||
|
|
||||||
# B. Settings
|
|
||||||
s_col1, s_col2, s_col3 = st.columns(3)
|
|
||||||
s_col1.text_input("Camera", value=str(item_data.get("camera", "static")), disabled=True, key=f"{prefix}_cam")
|
|
||||||
s_col2.text_input("FLF", value=str(item_data.get("flf", "0.0")), disabled=True, key=f"{prefix}_flf")
|
|
||||||
s_col3.text_input("Seed", value=str(item_data.get("seed", "-1")), disabled=True, key=f"{prefix}_seed")
|
|
||||||
|
|
||||||
# C. LoRAs
|
|
||||||
with st.expander("💊 LoRA Configuration", expanded=False):
|
|
||||||
l1, l2, l3 = st.columns(3)
|
|
||||||
with l1:
|
|
||||||
st.text_input("L1 Name", value=item_data.get("lora 1 high", ""), disabled=True, key=f"{prefix}_l1h")
|
|
||||||
st.text_input("L1 Str", value=str(item_data.get("lora 1 low", "")), disabled=True, key=f"{prefix}_l1l")
|
|
||||||
with l2:
|
|
||||||
st.text_input("L2 Name", value=item_data.get("lora 2 high", ""), disabled=True, key=f"{prefix}_l2h")
|
|
||||||
st.text_input("L2 Str", value=str(item_data.get("lora 2 low", "")), disabled=True, key=f"{prefix}_l2l")
|
|
||||||
with l3:
|
|
||||||
st.text_input("L3 Name", value=item_data.get("lora 3 high", ""), disabled=True, key=f"{prefix}_l3h")
|
|
||||||
st.text_input("L3 Str", value=str(item_data.get("lora 3 low", "")), disabled=True, key=f"{prefix}_l3l")
|
|
||||||
|
|
||||||
# D. VACE
|
|
||||||
vace_keys = ["frame_to_skip", "vace schedule", "video file path"]
|
|
||||||
has_vace = any(k in item_data for k in vace_keys)
|
|
||||||
if has_vace:
|
|
||||||
with st.expander("🎞️ VACE / I2V Settings", expanded=False):
|
|
||||||
v1, v2, v3 = st.columns(3)
|
|
||||||
v1.text_input("Skip Frames", value=str(item_data.get("frame_to_skip", "")), disabled=True, key=f"{prefix}_fts")
|
|
||||||
v2.text_input("Schedule", value=str(item_data.get("vace schedule", "")), disabled=True, key=f"{prefix}_vsc")
|
|
||||||
v3.text_input("Video Path", value=str(item_data.get("video file path", "")), disabled=True, key=f"{prefix}_vid")
|
|
||||||
|
|
||||||
# --- DETECT BATCH VS SINGLE ---
|
|
||||||
batch_list = node_data.get(KEY_BATCH_DATA, [])
|
|
||||||
|
|
||||||
if batch_list and isinstance(batch_list, list) and len(batch_list) > 0:
|
|
||||||
st.info(f"📚 This snapshot contains {len(batch_list)} sequences.")
|
|
||||||
|
|
||||||
for i, seq_data in enumerate(batch_list):
|
|
||||||
seq_num = seq_data.get("sequence_number", i+1)
|
|
||||||
with st.expander(f"🎬 Sequence #{seq_num}", expanded=(i==0)):
|
|
||||||
# Unique prefix for every sequence in every node
|
|
||||||
prefix = f"p_{target_node_id}_s{i}"
|
|
||||||
render_preview_fields(seq_data, prefix)
|
|
||||||
else:
|
|
||||||
# Single File Preview
|
|
||||||
prefix = f"p_{target_node_id}_single"
|
|
||||||
render_preview_fields(node_data, prefix)
|
|
||||||
Reference in New Issue
Block a user