kocr/script/deploy.sh

61 lines
2.1 KiB
Bash
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# KOCR v4 — 一键部署脚本
# 用法: bash script/deploy.sh
set -e
PROJECT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
echo "📦 KOCR v4 部署脚本"
echo " 路径: $PROJECT_DIR"
echo ""
# 1. 安装系统依赖
echo "📥 安装系统依赖..."
if command -v apt &>/dev/null; then
sudo apt install -y python3-pip python3-opencv > /dev/null 2>&1 || true
fi
# 2. 安装 Python 依赖
echo "📥 安装 Python 依赖..."
cd "$PROJECT_DIR"
pip install -r requirements.txt -q 2>&1 | tail -1 || {
echo "⚠️ pip install 失败,尝试 conda 或手动安装"
echo " 核心依赖: opencv-python, paddlepaddle, paddleocr, pyyaml, xlrd, xlwt"
}
# 3. 测试 GPU
echo "🔍 检测 GPU..."
if python3 -c "import subprocess; r=subprocess.run(['nvidia-smi'],capture_output=True); exit(0 if r.returncode==0 else 1)" 2>/dev/null; then
echo " ✅ NVIDIA GPU 可用"
nvidia-smi --query-gpu=name,memory.total --format=csv,noheader 2>/dev/null | head -1
# 检查是否已装 GPU 版 paddle
if python3 -c "import paddle; print(paddle.is_compiled_with_cuda())" 2>/dev/null | grep -q True; then
echo " ✅ PaddlePaddle GPU 版已安装"
else
echo " ⚠️ PaddlePaddle 当前为 CPU 版"
echo " 如需 GPU 加速,手动执行:"
echo " pip install paddlepaddle-gpu==2.6.1 -f https://www.paddlepaddle.org.cn/whl/linux/mkl/avx/stable.html"
fi
else
echo " 未检测到 NVIDIA GPU使用 CPU 模式"
fi
# 4. 创建目录
echo "📁 创建目录..."
mkdir -p "$PROJECT_DIR/input" "$PROJECT_DIR/input/done" "$PROJECT_DIR/output"
# 5. 检查模板
TEMPLATE="${HOME}/.hermes/cache/documents/doc_704eac18442d_凭证模板.xls"
if [ -f "$TEMPLATE" ]; then
echo "✅ 模板文件存在: $TEMPLATE"
else
echo "⚠️ 模板文件不存在: $TEMPLATE"
echo " 请将金蝶 K3 导入模板放到该路径,或修改 config.yaml 中 paths.template"
fi
echo ""
echo "✅ KOCR v4 部署完成!"
echo " 运行: cd $PROJECT_DIR && python3 kocr.py --status"
echo " 处理: python3 kocr.py --merge --review"