Update app.py
This commit is contained in:
93
app.py
93
app.py
@@ -1,83 +1,102 @@
|
|||||||
import streamlit as st
|
import streamlit as st
|
||||||
import os
|
import os
|
||||||
from engine import SorterEngine
|
from engine import SorterEngine
|
||||||
import tab_time_discovery, tab_id_review, tab_unused_review, tab_category_sorter, tab_gallery_sorter
|
import tab_time_discovery
|
||||||
|
import tab_id_review
|
||||||
|
import tab_unused_review
|
||||||
|
import tab_category_sorter
|
||||||
|
import tab_gallery_sorter
|
||||||
|
|
||||||
# 1. Initialize DB FIRST
|
# 1. Initialize Database and Schema
|
||||||
try:
|
try:
|
||||||
SorterEngine.init_db()
|
SorterEngine.init_db()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
st.error(f"Database Initialization Error: {e}")
|
st.error(f"Database Error: {e}")
|
||||||
|
|
||||||
st.set_page_config(layout="wide", page_title="Turbo Sorter Pro v12.1")
|
st.set_page_config(layout="wide", page_title="Turbo Sorter Pro v12.5")
|
||||||
|
|
||||||
# 2. Session State Defaults
|
# 2. Global Session State Initialization
|
||||||
if 'history' not in st.session_state: st.session_state.history = []
|
if 'history' not in st.session_state: st.session_state.history = []
|
||||||
if 'idx_time' not in st.session_state: st.session_state.idx_time = 0
|
if 'idx_time' not in st.session_state: st.session_state.idx_time = 0
|
||||||
if 'idx_id' not in st.session_state: st.session_state.idx_id = 0
|
if 'idx_id' not in st.session_state: st.session_state.idx_id = 0
|
||||||
if 'idx_unused' not in st.session_state: st.session_state.idx_unused = 0
|
if 'idx_unused' not in st.session_state: st.session_state.idx_unused = 0
|
||||||
if 'idx_cat' not in st.session_state: st.session_state.idx_cat = 0
|
if 'idx_cat' not in st.session_state: st.session_state.idx_cat = 0
|
||||||
|
|
||||||
# 3. Load Profiles with Safety Fallback
|
# 3. Load Workspace Profiles
|
||||||
try:
|
try:
|
||||||
profiles = SorterEngine.load_profiles()
|
profiles = SorterEngine.load_profiles()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
st.warning("Database schema mismatch detected. Please delete /app/sorter_database.db and refresh.")
|
st.warning("Database schema mismatch. Please delete /app/sorter_database.db and refresh.")
|
||||||
st.stop()
|
st.stop()
|
||||||
|
|
||||||
# Ensure at least one profile exists
|
# Ensure at least one workspace exists
|
||||||
if not profiles:
|
if not profiles:
|
||||||
SorterEngine.save_tab_paths("Default")
|
SorterEngine.save_tab_paths("Default")
|
||||||
profiles = SorterEngine.load_profiles()
|
profiles = SorterEngine.load_profiles()
|
||||||
|
|
||||||
# --- SIDEBAR ---
|
# --- SIDEBAR: Workspace & Global Tools ---
|
||||||
with st.sidebar:
|
with st.sidebar:
|
||||||
st.divider()
|
st.title("⭐ Workspaces")
|
||||||
with st.expander("🔍 Path Debugger"):
|
selected_profile = st.selectbox("Active Workspace", list(profiles.keys()), key="active_profile")
|
||||||
st.write(f"**Active Workspace:** {selected_profile}")
|
p_data = profiles.get(selected_profile, {})
|
||||||
st.json(p_data) # Shows exactly what the DB sees for this profile
|
|
||||||
|
|
||||||
st.divider()
|
st.divider()
|
||||||
quality = st.slider("Display Quality", 5, 100, 40)
|
quality = st.slider("Display Quality", 5, 100, 40)
|
||||||
|
|
||||||
# Prefix Logic
|
# Calculate ID based on Tab 1 Target
|
||||||
disc_target = p_data.get("tab1_target", "/storage")
|
t1_target = p_data.get("tab1_target") or "/storage"
|
||||||
next_id_num = SorterEngine.get_max_id_number(disc_target) + 1
|
id_val = st.number_input("Next ID Number", value=SorterEngine.get_max_id_number(t1_target) + 1)
|
||||||
id_val = st.number_input("Next ID Number", value=next_id_num)
|
|
||||||
prefix = f"id{int(id_val):03d}_"
|
prefix = f"id{int(id_val):03d}_"
|
||||||
|
|
||||||
if st.button("↶ UNDO", use_container_width=True, disabled=not st.session_state.history):
|
if st.button("↶ UNDO LAST MOVE", use_container_width=True, disabled=not st.session_state.history):
|
||||||
SorterEngine.revert_action(st.session_state.history.pop())
|
SorterEngine.revert_action(st.session_state.history.pop())
|
||||||
st.rerun()
|
st.rerun()
|
||||||
|
|
||||||
# --- TABS ---
|
with st.expander("🔍 Workspace Path Debugger"):
|
||||||
t1, t2, t3, t4, t5 = st.tabs(["🕒 Discovery", "🆔 ID Review", "♻️ Unused", "📂 Categorizer", "🖼️ Gallery Staging"])
|
st.json(p_data)
|
||||||
|
|
||||||
|
# --- MAIN TAB SYSTEM ---
|
||||||
|
|
||||||
|
|
||||||
|
t1, t2, t3, t4, t5 = st.tabs([
|
||||||
|
"🕒 1. Discovery",
|
||||||
|
"🆔 2. ID Review",
|
||||||
|
"♻️ 3. Unused",
|
||||||
|
"📂 4. Category Sorter",
|
||||||
|
"🖼️ 5. Gallery Staged"
|
||||||
|
])
|
||||||
|
|
||||||
with t1:
|
with t1:
|
||||||
path_t1 = st.text_input("Discovery Target", value=p_data.get("tab1_target", "/storage"), key="t1_in")
|
st.header("Time-Sync Matcher")
|
||||||
if path_t1 != p_data.get("tab1_target"):
|
t1_p = st.text_input("Discovery Target", value=p_data.get("tab1_target") or "/storage", key="t1_in")
|
||||||
SorterEngine.save_tab_paths(selected_profile, t1_t=path_t1)
|
if t1_p != p_data.get("tab1_target"):
|
||||||
tab_time_discovery.render(path_t1, quality, 50, prefix)
|
SorterEngine.save_tab_paths(selected_profile, t1_t=t1_p)
|
||||||
|
tab_time_discovery.render(t1_p, quality, 50, prefix)
|
||||||
|
|
||||||
with t2:
|
with t2:
|
||||||
|
st.header("Collision Review")
|
||||||
c1, c2 = st.columns(2)
|
c1, c2 = st.columns(2)
|
||||||
path_t2_t = c1.text_input("Review Target", value=p_data.get("tab2_target", "/storage"), key="t2_t_in")
|
t2_t = c1.text_input("Review Target", value=p_data.get("tab2_target") or "/storage", key="t2_t_in")
|
||||||
path_t2_c = c2.text_input("Review Control", value=p_data.get("tab2_control", "/storage"), key="t2_c_in")
|
t2_c = c2.text_input("Review Control", value=p_data.get("tab2_control") or "/storage", key="t2_c_in")
|
||||||
if path_t2_t != p_data.get("tab2_target") or path_t2_c != p_data.get("tab2_control"):
|
if t2_t != p_data.get("tab2_target") or t2_c != p_data.get("tab2_control"):
|
||||||
SorterEngine.save_tab_paths(selected_profile, t2_t=path_t2_t, t2_c=path_t2_c)
|
SorterEngine.save_tab_paths(selected_profile, t2_t=t2_t, t2_c=t2_c)
|
||||||
tab_id_review.render(path_t2_t, path_t2_c, quality, prefix)
|
tab_id_review.render(t2_t, t2_c, quality, prefix)
|
||||||
|
|
||||||
with t3:
|
with t3:
|
||||||
tab_unused_review.render(path_t2_t, path_t2_c, quality)
|
st.header("Unused Archive")
|
||||||
|
# Uses paths from Tab 2
|
||||||
|
tab_unused_review.render(t2_t, t2_c, quality)
|
||||||
|
|
||||||
# Inside your app.py tabs section
|
|
||||||
with t4:
|
with t4:
|
||||||
# Ensure variables exist even if DB row is fresh
|
st.header("One-to-Many Categorizer")
|
||||||
p4_s = p_data.get("tab4_source") or "/storage"
|
c1, c2 = st.columns(2)
|
||||||
p4_o = p_data.get("tab4_out") or "/storage"
|
t4_s = c1.text_input("Source Folder", value=p_data.get("tab4_source") or "/storage", key="t4_s_in")
|
||||||
mode = p_data.get("mode") or "id"
|
t4_o = c2.text_input("Output Folder", value=p_data.get("tab4_out") or "/storage", key="t4_o_in")
|
||||||
tab_category_sorter.render(p4_s, p4_o, quality, mode)
|
mode = st.radio("Naming Mode", ["id", "original"], index=0 if p_data.get("mode") == "id" else 1, horizontal=True)
|
||||||
|
if t4_s != p_data.get("tab4_source") or t4_o != p_data.get("tab4_out") or mode != p_data.get("mode"):
|
||||||
|
SorterEngine.save_tab_paths(selected_profile, t4_s=t4_s, t4_o=t4_o, mode=mode)
|
||||||
|
tab_category_sorter.render(t4_s, t4_o, quality, mode)
|
||||||
|
|
||||||
with t5:
|
with t5:
|
||||||
# Tab 5 should not depend on Tab 4 paths at all
|
# Gallery Sorter handles its own path saving internally to prevent refresh loops
|
||||||
tab_gallery_sorter.render(quality, selected_profile)
|
tab_gallery_sorter.render(quality, selected_profile)
|
||||||
Reference in New Issue
Block a user