#!/bin/sh # MiniCPM-OCR-1.0 on AX8860 (llama.cpp + ggml-axera). # ./run.sh -i ["prompt"] [n] OCR one image (greedy) # ./run.sh -b ["prompt"] [n] OCR every PNG in a directory through the HTTP server # ./run.sh -s [port] OpenAI-compatible server # ./run.sh "" [n] text completion (greedy) set -u H=$(cd "$(dirname "$0")" && pwd) export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:-/opt/lib} export GGML_AXERA_KERNEL_DIR=${GGML_AXERA_KERNEL_DIR:-$H/kernels} G=${GGUF:-$H/gguf/minicpm-ocr-1.0-bf16.gguf} P=${MMPROJ:-$H/gguf/mmproj-minicpm-ocr-1.0-bf16.gguf} CTX=${CTX:-4096} chmod +x "$H"/bin/* 2>/dev/null case "${1:-}" in -i) img=${2:?image path}; shift 2 prompt=${1:-Text Recognition:}; [ $# -gt 0 ] && shift exec "$H/bin/llama-mtmd-cli" -m "$G" --mmproj "$P" -ngl 99 -c "$CTX" -b 256 -ub 256 \ --image "$img" --image-max-tokens 4096 -p "$prompt" -n "${1:-256}" --temp 0 -t 8 --jinja ;; -b) dir=${2:?image directory}; shift 2 prompt=${1:-Text Recognition:}; [ $# -gt 0 ] && shift port=${PORT:-18258} mkdir -p "$H/slots" "$H/bin/llama-server" -m "$G" --mmproj "$P" -ngl 99 -c "$CTX" -b 256 -ub 256 -np 1 \ -ctxcp 8 --cache-ram 0 --slot-save-path "$H/slots" --jinja \ --chat-template-file "$H/chat_template.jinja" --reasoning off --image-max-tokens 4096 \ --host 127.0.0.1 --port "$port" --temp 0 --top-k 1 --seed 1 > "$H/run-server.log" 2>&1 & srv=$! i=0 while [ "$i" -lt 300 ]; do curl -fsS "http://127.0.0.1:$port/health" >/dev/null 2>&1 && break; i=$((i + 1)); sleep 1; done python3 "$H/scripts/ocr_client.py" --port "$port" --images "$dir" --prompt "$prompt" --max-tokens "${1:-256}" rc=$? kill -TERM "$srv" 2>/dev/null i=0; while [ -d "/proc/$srv" ] && [ "$i" -lt 120 ]; do sleep 1; i=$((i + 1)); done exit $rc ;; -s) exec "$H/bin/llama-server" -m "$G" --mmproj "$P" -ngl 99 -c "$CTX" -b 256 -ub 256 -np 1 \ -ctxcp 8 --cache-ram 4096 --jinja --chat-template-file "$H/chat_template.jinja" --reasoning off \ --image-max-tokens 4096 --host 0.0.0.0 --port "${2:-8080}" --temp 0 --top-k 1 --seed 1 ;; *) exec "$H/bin/llama-completion" -m "$G" -ngl 99 -c "$CTX" -b 256 -ub 256 \ -p "${1:-Text Recognition:}" -n "${2:-256}" --temp 0 -no-cnv ;; esac