Update tab_id_review.py
This commit is contained in:
@@ -2,63 +2,33 @@ import streamlit as st
|
|||||||
import os, shutil
|
import os, shutil
|
||||||
from engine import SorterEngine
|
from engine import SorterEngine
|
||||||
|
|
||||||
def render(path_t, quality):
|
def render(path_rv_t, path_rv_c, quality):
|
||||||
# 1. Detect all sibling folders (just like the original script)
|
# Only scan the two paths provided manually
|
||||||
control_folders = SorterEngine.get_sibling_controls(path_t)
|
map_t = SorterEngine.get_id_mapping(path_rv_t)
|
||||||
|
map_c = SorterEngine.get_id_mapping(path_rv_c)
|
||||||
|
|
||||||
# 2. Get ID mapping for Target
|
# Find common IDs between these two specific folders
|
||||||
# We check the root and the 'selected_target' subfolder
|
|
||||||
target_search_paths = [path_t, os.path.join(path_t, "selected_target")]
|
|
||||||
map_t = {}
|
|
||||||
for p in target_search_paths:
|
|
||||||
map_t.update(SorterEngine.get_id_mapping(p))
|
|
||||||
|
|
||||||
# 3. Get ID mapping for all Sibling Controls
|
|
||||||
map_c = {}
|
|
||||||
for folder in control_folders:
|
|
||||||
control_search_paths = [folder, os.path.join(path_t, "selected_control")]
|
|
||||||
for p in control_search_paths:
|
|
||||||
if os.path.exists(p):
|
|
||||||
# Update map_c with found IDs, keeping track of their full paths
|
|
||||||
images = SorterEngine.get_images(p)
|
|
||||||
for f in images:
|
|
||||||
if f.startswith("id") and "_" in f:
|
|
||||||
prefix = f.split('_')[0]
|
|
||||||
map_c[prefix] = os.path.join(p, f)
|
|
||||||
|
|
||||||
# 4. Find Common IDs
|
|
||||||
common_ids = sorted(list(set(map_t.keys()) & set(map_c.keys())))
|
common_ids = sorted(list(set(map_t.keys()) & set(map_c.keys())))
|
||||||
|
|
||||||
if st.session_state.idx_id < len(common_ids):
|
if st.session_state.idx_id < len(common_ids):
|
||||||
curr_id = common_ids[st.session_state.idx_id]
|
curr_id = common_ids[st.session_state.idx_id]
|
||||||
|
|
||||||
# Determine full paths for display
|
t_p = os.path.join(path_rv_t, map_t[curr_id])
|
||||||
# map_t stores just the filename, map_c stores the full path
|
c_p = os.path.join(path_rv_c, map_c[curr_id])
|
||||||
t_filename = map_t[curr_id]
|
|
||||||
# Find which target path the file is actually in
|
|
||||||
t_p = ""
|
|
||||||
for p in target_search_paths:
|
|
||||||
potential_p = os.path.join(p, t_filename)
|
|
||||||
if os.path.exists(potential_p):
|
|
||||||
t_p = potential_p
|
|
||||||
break
|
|
||||||
|
|
||||||
c_p = map_c[curr_id]
|
|
||||||
|
|
||||||
st.subheader(f"Reviewing Match: {curr_id} ({st.session_state.idx_id + 1}/{len(common_ids)})")
|
|
||||||
|
|
||||||
|
st.subheader(f"Reviewing ID: {curr_id} ({st.session_state.idx_id + 1}/{len(common_ids)})")
|
||||||
col1, col2 = st.columns(2)
|
col1, col2 = st.columns(2)
|
||||||
|
|
||||||
img1 = SorterEngine.compress_for_web(t_p, quality)
|
img1 = SorterEngine.compress_for_web(t_p, quality)
|
||||||
img2 = SorterEngine.compress_for_web(c_p, quality)
|
img2 = SorterEngine.compress_for_web(c_p, quality)
|
||||||
|
|
||||||
if img1: col1.image(img1, caption=f"Target: {os.path.basename(t_p)}")
|
if img1: col1.image(img1, caption=f"Target: {map_t[curr_id]}")
|
||||||
if img2: col2.image(img2, caption=f"Control: {os.path.basename(c_p)}")
|
if img2: col2.image(img2, caption=f"Control: {map_c[curr_id]}")
|
||||||
|
|
||||||
# Actions
|
btn_col1, btn_col2 = st.columns(2)
|
||||||
btn1, btn2 = st.columns(2)
|
if btn_col1.button("❌ Move Pair to Unused", use_container_width=True, type="primary"):
|
||||||
if btn1.button("❌ Move Pair to Unused", use_container_width=True, type="primary"):
|
# Move both to unused folders relative to their current review path
|
||||||
# Use the synced renaming logic from engine.py
|
t_un, c_un = SorterEngine.move_to_unused_synced(t_p, c_p, path_rv_t, path_rv_c)
|
||||||
t_un, c_un = SorterEngine.move_to_unused_synced(t_p, c_p, path_t, os.path.dirname(c_p))
|
|
||||||
st.session_state.history.append({
|
st.session_state.history.append({
|
||||||
'type': 'unused',
|
'type': 'unused',
|
||||||
't_src': t_p, 't_dst': t_un,
|
't_src': t_p, 't_dst': t_un,
|
||||||
@@ -67,11 +37,11 @@ def render(path_t, quality):
|
|||||||
st.session_state.idx_id += 1
|
st.session_state.idx_id += 1
|
||||||
st.rerun()
|
st.rerun()
|
||||||
|
|
||||||
if btn2.button("✅ Keep Both / Next", use_container_width=True):
|
if btn_col2.button("✅ Keep Both / Next", use_container_width=True):
|
||||||
st.session_state.idx_id += 1
|
st.session_state.idx_id += 1
|
||||||
st.rerun()
|
st.rerun()
|
||||||
else:
|
else:
|
||||||
st.info("No more matching ID pairs found in the target or sibling folders.")
|
st.info(f"No ID matches found between:\n\nTarget: `{path_rv_t}`\n\nControl: `{path_rv_c}`")
|
||||||
if st.button("Reset Review Progress"):
|
if st.button("Reset Review Progress"):
|
||||||
st.session_state.idx_id = 0
|
st.session_state.idx_id = 0
|
||||||
st.rerun()
|
st.rerun()
|
||||||
Reference in New Issue
Block a user