Fix caption cache timing, commit path tracking, and clean up start script
- Move caption cache refresh before UI render so indicators show on load - Return actual dest paths from commit_batch/commit_global to fix caption-on-apply silently failing when files are renamed on collision - Simplify start.sh to only run NiceGUI (remove Streamlit) - Add requests to requirements.txt Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
16
engine.py
16
engine.py
@@ -450,8 +450,10 @@ class SorterEngine:
|
||||
|
||||
@staticmethod
|
||||
def commit_global(output_root, cleanup_mode, operation="Copy", source_root=None, profile=None):
|
||||
"""Commits ALL staged files and fixes permissions."""
|
||||
"""Commits ALL staged files and fixes permissions.
|
||||
Returns dict mapping original_path -> {dest, cat} for committed files."""
|
||||
data = SorterEngine.get_staged_data()
|
||||
committed = {}
|
||||
|
||||
# Save folder tags BEFORE processing (so we can restore them later)
|
||||
if source_root:
|
||||
@@ -482,6 +484,9 @@ class SorterEngine:
|
||||
# --- FIX PERMISSIONS ---
|
||||
SorterEngine.fix_permissions(final_dst)
|
||||
|
||||
# Track actual destination
|
||||
committed[old_p] = {"dest": final_dst, "cat": info['cat']}
|
||||
|
||||
# Log History
|
||||
cursor.execute("INSERT OR REPLACE INTO processed_log VALUES (?, ?, ?)",
|
||||
(old_p, info['cat'], operation))
|
||||
@@ -505,6 +510,7 @@ class SorterEngine:
|
||||
cursor.execute("DELETE FROM staging_area")
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return committed
|
||||
|
||||
# --- 6. CORE UTILITIES (SYNC & UNDO) ---
|
||||
@staticmethod
|
||||
@@ -616,10 +622,12 @@ class SorterEngine:
|
||||
|
||||
@staticmethod
|
||||
def commit_batch(file_list, output_root, cleanup_mode, operation="Copy"):
|
||||
"""Commits files and fixes permissions."""
|
||||
"""Commits files and fixes permissions.
|
||||
Returns dict mapping original_path -> actual_dest_path for committed files."""
|
||||
data = SorterEngine.get_staged_data()
|
||||
conn = sqlite3.connect(SorterEngine.DB_PATH)
|
||||
cursor = conn.cursor()
|
||||
committed = {}
|
||||
|
||||
if not os.path.exists(output_root): os.makedirs(output_root, exist_ok=True)
|
||||
|
||||
@@ -648,6 +656,9 @@ class SorterEngine:
|
||||
# --- FIX PERMISSIONS ---
|
||||
SorterEngine.fix_permissions(final_dst)
|
||||
|
||||
# Track actual destination
|
||||
committed[file_path] = {"dest": final_dst, "cat": info['cat']}
|
||||
|
||||
# Update DB
|
||||
cursor.execute("DELETE FROM staging_area WHERE original_path = ?", (file_path,))
|
||||
cursor.execute("INSERT OR REPLACE INTO processed_log VALUES (?, ?, ?)",
|
||||
@@ -668,6 +679,7 @@ class SorterEngine:
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return committed
|
||||
|
||||
@staticmethod
|
||||
def rename_category(old_name, new_name):
|
||||
|
||||
@@ -273,10 +273,10 @@ def load_images():
|
||||
state.page = 0
|
||||
|
||||
refresh_staged_info()
|
||||
refresh_ui()
|
||||
# Refresh caption cache in background (non-blocking)
|
||||
# Load caption data before rendering so indicators appear on cards
|
||||
state.refresh_caption_cache()
|
||||
state.load_caption_settings()
|
||||
refresh_ui()
|
||||
|
||||
# ==========================================
|
||||
# PAIRING MODE FUNCTIONS
|
||||
@@ -715,24 +715,16 @@ async def action_apply_page():
|
||||
ui.notify("No images on current page", type='warning')
|
||||
return
|
||||
|
||||
# Get tagged images and their categories before commit (they'll be moved/copied)
|
||||
tagged_batch = []
|
||||
for img_path in batch:
|
||||
if img_path in state.staged_data:
|
||||
info = state.staged_data[img_path]
|
||||
# Calculate destination path
|
||||
dest_path = os.path.join(state.output_dir, info['name'])
|
||||
tagged_batch.append((img_path, info['cat'], dest_path))
|
||||
committed = SorterEngine.commit_batch(batch, state.output_dir, state.cleanup_mode, state.batch_mode)
|
||||
|
||||
SorterEngine.commit_batch(batch, state.output_dir, state.cleanup_mode, state.batch_mode)
|
||||
|
||||
# Caption on apply if enabled
|
||||
if state.caption_on_apply and tagged_batch:
|
||||
# Caption on apply if enabled - uses actual dest paths from commit
|
||||
if state.caption_on_apply and committed:
|
||||
state.load_caption_settings()
|
||||
caption_count = 0
|
||||
for orig_path, category, dest_path in tagged_batch:
|
||||
for orig_path, info in committed.items():
|
||||
dest_path = info['dest']
|
||||
if os.path.exists(dest_path):
|
||||
prompt = SorterEngine.get_category_prompt(state.profile_name, category)
|
||||
prompt = SorterEngine.get_category_prompt(state.profile_name, info['cat'])
|
||||
caption, error = await run.io_bound(
|
||||
SorterEngine.caption_image_vllm,
|
||||
dest_path, prompt, state.caption_settings
|
||||
@@ -753,14 +745,7 @@ async def action_apply_global():
|
||||
"""Apply all staged changes globally."""
|
||||
ui.notify("Starting global apply... This may take a while.", type='info')
|
||||
|
||||
# Capture staged data before commit for captioning
|
||||
staged_before_commit = {}
|
||||
if state.caption_on_apply:
|
||||
for img_path, info in state.staged_data.items():
|
||||
dest_path = os.path.join(state.output_dir, info['name'])
|
||||
staged_before_commit[img_path] = {'cat': info['cat'], 'dest': dest_path}
|
||||
|
||||
await run.io_bound(
|
||||
committed = await run.io_bound(
|
||||
SorterEngine.commit_global,
|
||||
state.output_dir,
|
||||
state.cleanup_mode,
|
||||
@@ -769,13 +754,13 @@ async def action_apply_global():
|
||||
state.profile_name
|
||||
)
|
||||
|
||||
# Caption on apply if enabled
|
||||
if state.caption_on_apply and staged_before_commit:
|
||||
# Caption on apply if enabled - uses actual dest paths from commit
|
||||
if state.caption_on_apply and committed:
|
||||
state.load_caption_settings()
|
||||
ui.notify(f"Captioning {len(staged_before_commit)} images...", type='info')
|
||||
ui.notify(f"Captioning {len(committed)} images...", type='info')
|
||||
|
||||
caption_count = 0
|
||||
for orig_path, info in staged_before_commit.items():
|
||||
for orig_path, info in committed.items():
|
||||
dest_path = info['dest']
|
||||
if os.path.exists(dest_path):
|
||||
prompt = SorterEngine.get_category_prompt(state.profile_name, info['cat'])
|
||||
|
||||
31
start.sh
Normal file → Executable file
31
start.sh
Normal file → Executable file
@@ -1,18 +1,25 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 1. Navigate to app directory
|
||||
# NiceSorter - Start Script
|
||||
# Runs the NiceGUI gallery interface on port 8080
|
||||
|
||||
set -e
|
||||
|
||||
# Navigate to app directory if running in container
|
||||
if [ -d "/app" ]; then
|
||||
cd /app
|
||||
fi
|
||||
|
||||
# 2. Install dependencies (Including NiceGUI if missing)
|
||||
# This checks your requirements.txt AND ensures nicegui is present
|
||||
pip install --no-cache-dir -r requirements.txt
|
||||
# Install dependencies if requirements.txt exists
|
||||
if [ -f "requirements.txt" ]; then
|
||||
echo "📦 Installing dependencies..."
|
||||
pip install --no-cache-dir -q -r requirements.txt
|
||||
fi
|
||||
|
||||
# 3. Start NiceGUI in the Background (&)
|
||||
# This runs silently while the script continues
|
||||
echo "🚀 Starting NiceGUI on Port 8080..."
|
||||
python3 gallery_app.py &
|
||||
# Initialize database
|
||||
echo "🗄️ Initializing database..."
|
||||
python3 -c "from engine import SorterEngine; SorterEngine.init_db()"
|
||||
|
||||
# 4. Start Streamlit in the Foreground
|
||||
# This keeps the container running
|
||||
echo "🚀 Starting Streamlit on Port 8501..."
|
||||
streamlit run app.py --server.port=8501 --server.address=0.0.0.0
|
||||
# Start NiceGUI
|
||||
echo "🚀 Starting NiceSorter on http://0.0.0.0:8080"
|
||||
exec python3 gallery_app.py
|
||||
|
||||
Reference in New Issue
Block a user