-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbatch-simple.sh
More file actions
executable file
·95 lines (81 loc) · 2.29 KB
/
batch-simple.sh
File metadata and controls
executable file
·95 lines (81 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env bash
# Simple portable batch runner for annotate_images_enhanced.py using uv
# Usage:
# ./batch-simple.sh -i <input_dir> -o <output_dir> [-c <categories.json>] [-m <model>] [-C <context>] [-n] [-v]
set -euo pipefail
INPUT_DIR=""
OUTPUT_DIR=""
CATEGORIES="image_categories_enhanced.json"
MODEL="qwen3-vl:30b"
CONTEXT_SIZE=500
VERBOSE=false
DRYRUN=false
usage() {
cat <<EOF
Usage: $(basename "$0") -i <input_dir> -o <output_dir> [options]
Options:
-i DIR Input directory containing .md files (required)
-o DIR Output directory for results (required)
-c FILE Categories JSON (default: ${CATEGORIES})
-m MODEL Ollama model (default: ${MODEL})
-C N Context size (default: ${CONTEXT_SIZE})
-n Dry run
-v Verbose (passes --verbose to Python and prints the command)
-h Help
EOF
}
while getopts ":i:o:c:m:C:nvh" opt; do
case "$opt" in
i) INPUT_DIR=$OPTARG ;;
o) OUTPUT_DIR=$OPTARG ;;
c) CATEGORIES=$OPTARG ;;
m) MODEL=$OPTARG ;;
C) CONTEXT_SIZE=$OPTARG ;;
n) DRYRUN=true ;;
v) VERBOSE=true ;;
h) usage; exit 0 ;;
\?) echo "Unknown option: -$OPTARG" >&2; usage; exit 2 ;;
:) echo "Option -$OPTARG requires an argument." >&2; usage; exit 2 ;;
esac
done
if [[ -z "$INPUT_DIR" || -z "$OUTPUT_DIR" ]]; then
echo "Error: -i and -o are required." >&2
usage
exit 2
fi
if [[ ! -d "$INPUT_DIR" ]]; then
echo "Error: input directory not found: $INPUT_DIR" >&2
exit 1
fi
mkdir -p "$OUTPUT_DIR"
found_any=false
while IFS= read -r -d '' file; do
found_any=true
base="$(basename "$file")"
stem="${base%.md}"
out_md="${OUTPUT_DIR}/${stem}_annotated.md"
sum_md="${OUTPUT_DIR}/${stem}_summary.md"
cmd=( uv run annotate_images_enhanced.py
--input "$file"
--output "$out_md"
--summary "$sum_md"
--categories "$CATEGORIES"
--model "$MODEL"
--context-size "$CONTEXT_SIZE" )
if $VERBOSE; then
cmd+=( --verbose )
fi
echo "📄 Processing: $base"
if $VERBOSE || $DRYRUN; then
printf '▶ '
for a in "${cmd[@]}"; do printf '%q ' "$a"; done
printf '\n'
fi
if $DRYRUN; then
continue
fi
"${cmd[@]}"
done < <(find "$INPUT_DIR" -maxdepth 1 -type f -name "*.md" -print0 2>/dev/null)
if ! $found_any; then
echo "No markdown files found in $INPUT_DIR"
fi