Update tab_category_sorter.py
This commit is contained in:
@@ -9,46 +9,29 @@ def render(path_t, path_out, quality, naming_mode):
|
|||||||
if st.session_state.idx_cat < len(images):
|
if st.session_state.idx_cat < len(images):
|
||||||
curr_p = os.path.join(path_t, images[st.session_state.idx_cat])
|
curr_p = os.path.join(path_t, images[st.session_state.idx_cat])
|
||||||
|
|
||||||
# Filmstrip (Current + Next 6)
|
# Filmstrip
|
||||||
st.write("### 🎞️ Filmstrip")
|
st.write("### 🎞️ Filmstrip")
|
||||||
fs_cols = st.columns(7)
|
fs_cols = st.columns(7)
|
||||||
for i, img_name in enumerate(images[st.session_state.idx_cat : st.session_state.idx_cat + 7]):
|
for i, img_name in enumerate(images[st.session_state.idx_cat : st.session_state.idx_cat + 7]):
|
||||||
fs_cols[i].image(SorterEngine.compress_for_web(os.path.join(path_t, img_name), 10))
|
fs_cols[i].image(SorterEngine.compress_for_web(os.path.join(path_t, img_name), 10))
|
||||||
|
|
||||||
st.divider()
|
|
||||||
|
|
||||||
col_img, col_btns = st.columns([2, 1])
|
col_img, col_btns = st.columns([2, 1])
|
||||||
col_img.image(SorterEngine.compress_for_web(curr_p, quality), caption=images[st.session_state.idx_cat])
|
col_img.image(SorterEngine.compress_for_web(curr_p, quality))
|
||||||
|
|
||||||
with col_btns:
|
with col_btns:
|
||||||
fid = SorterEngine.get_folder_id(path_t)
|
fid = SorterEngine.get_folder_id(path_t)
|
||||||
st.write(f"**Current Folder ID:** {fid}")
|
st.write(f"**Folder ID:** {fid}")
|
||||||
|
|
||||||
# Category Management
|
|
||||||
new_cat = st.text_input("➕ New Category")
|
|
||||||
if st.button("Add"): SorterEngine.add_category(new_cat); st.rerun()
|
|
||||||
|
|
||||||
# Dynamic Category Buttons
|
|
||||||
for cat in categories:
|
for cat in categories:
|
||||||
if st.button(cat, use_container_width=True):
|
if st.button(cat, use_container_width=True):
|
||||||
# Naming Logic from script
|
|
||||||
_, ext = os.path.splitext(curr_p)
|
_, ext = os.path.splitext(curr_p)
|
||||||
name = images[st.session_state.idx_cat] if naming_mode == "original" else f"{fid}{ext}"
|
name = images[st.session_state.idx_cat] if naming_mode == "original" else f"{fid}{ext}"
|
||||||
|
|
||||||
dst_dir = os.path.join(path_out, cat)
|
dst_dir = os.path.join(path_out, cat)
|
||||||
os.makedirs(dst_dir, exist_ok=True)
|
os.makedirs(dst_dir, exist_ok=True)
|
||||||
dst_p = os.path.join(dst_dir, name)
|
dst_p = os.path.join(dst_dir, name)
|
||||||
|
|
||||||
# Collision check
|
|
||||||
count = 2
|
|
||||||
while os.path.exists(dst_p):
|
|
||||||
root, ext = os.path.splitext(name)
|
|
||||||
dst_p = os.path.join(dst_dir, f"{root}_{count}{ext}")
|
|
||||||
count += 1
|
|
||||||
|
|
||||||
shutil.move(curr_p, dst_p)
|
shutil.move(curr_p, dst_p)
|
||||||
st.toast(f"Moved to {cat}")
|
st.session_state.history.append({'type': 'cat_move', 't_src': curr_p, 't_dst': dst_p})
|
||||||
st.rerun()
|
st.rerun()
|
||||||
|
if st.button("SKIP"):
|
||||||
if st.button("⏭️ SKIP", type="secondary", use_container_width=True):
|
st.session_state.idx_cat += 1
|
||||||
st.session_state.idx_cat += 1; st.rerun()
|
st.rerun()
|
||||||
|
else: st.success("Finished Categorizing.")
|
||||||
Reference in New Issue
Block a user