From 5265451556f978add42d89b3208a96040b3966f9 Mon Sep 17 00:00:00 2001 From: Ethanfel Date: Sat, 17 Jan 2026 12:57:06 +0100 Subject: [PATCH] Update tab_id_review.py --- tab_id_review.py | 66 +++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 35 deletions(-) diff --git a/tab_id_review.py b/tab_id_review.py index 26cfa9a..f5e566b 100644 --- a/tab_id_review.py +++ b/tab_id_review.py @@ -1,38 +1,34 @@ import streamlit as st -import os +import os, shutil from engine import SorterEngine -import tab_id_review, tab_time_discovery -st.set_page_config(layout="wide", page_title="Turbo Sorter Pro") - -# --- Session State --- -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 - -# --- Status Bar --- -matches_this_session = len([h for h in st.session_state.history if 'link' in h['type']]) -moves_to_unused = len([h for h in st.session_state.history if h['type'] == 'unused']) - -st.info(f"📊 **Session Stats:** {matches_this_session} Matches Created | {moves_to_unused} Sent to Unused") - -# --- Sidebar --- -BASE_PATH = "/storage" -favs = SorterEngine.load_favorites() -selected_fav = st.sidebar.selectbox("⭐ Favorites", ["None"] + list(favs.keys())) - -path_t = st.sidebar.text_input("Path 1 (Target)", value=favs[selected_fav]['target'] if selected_fav != "None" else BASE_PATH) -path_c = st.sidebar.text_input("Path 2 (Control)", value=favs[selected_fav]['control'] if selected_fav != "None" else BASE_PATH) - -quality = st.sidebar.slider("Bandwidth Compression", 5, 100, 40) -threshold = st.sidebar.number_input("Time Threshold (s)", value=50) -next_id_val = st.sidebar.number_input("Next ID Number", value=SorterEngine.get_max_id_number(path_t) + 1) -id_prefix = f"id{next_id_val:03d}_" - -if st.sidebar.button("↶ UNDO", use_container_width=True, disabled=not st.session_state.history): - SorterEngine.revert_action(st.session_state.history.pop()) - st.rerun() - -# --- Tabs --- -t1, t2 = st.tabs(["🆔 ID Match Review", "🕒 Time Discovery"]) -with t1: tab_id_review.render(path_t, path_c, quality) -with t2: tab_time_discovery.render(path_t, path_c, quality, threshold, id_prefix) \ No newline at end of file +def render(path_t, path_c, quality): + map_t = SorterEngine.get_id_mapping(path_t) + map_c = SorterEngine.get_id_mapping(path_c) + common_ids = sorted(list(set(map_t.keys()) & set(map_c.keys()))) + + if common_ids: + curr_id = common_ids[0] + t_f, c_f = map_t[curr_id], map_c[curr_id] + t_p, c_p = os.path.join(path_t, t_f), os.path.join(path_c, c_f) + + st.subheader(f"Reviewing ID: {curr_id}") + col1, col2 = st.columns(2) + + img1 = SorterEngine.compress_for_web(t_p, quality) + img2 = SorterEngine.compress_for_web(c_p, quality) + + if img1: col1.image(img1, caption=t_f) + if img2: col2.image(img2, caption=c_f) + + if st.button("❌ Move Pair to Unused", use_container_width=True): + t_un = os.path.join(path_t, "unused", t_f) + c_un = os.path.join(path_c, "unused", c_f) + os.makedirs(os.path.dirname(t_un), exist_ok=True) + os.makedirs(os.path.dirname(c_un), exist_ok=True) + shutil.move(t_p, t_un) + shutil.move(c_p, c_un) + st.session_state.history.append({'type': 'unused', 't_src': t_p, 't_dst': t_un, 'c_src': c_p, 'c_dst': c_un}) + st.rerun() + else: + st.info("No existing ID matches found.") \ No newline at end of file