Files
secondary-school-grade-archive/deploy/ocr-worker/install.sh
T

56 lines
1.9 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
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.
#!/usr/bin/env bash
# 在带 NVIDIA 显卡的 Linux 机器上安装 OCR Worker(由 deploy/install.sh 自动调用)
set -euo pipefail
ROOT="$(cd "$(dirname "$0")" && pwd)"
VENV="${ROOT}/.venv"
PORT="${OCR_PORT:-23567}"
PIP_MIRROR="${PIP_MIRROR:-https://pypi.tuna.tsinghua.edu.cn/simple}"
echo "==> OCR Worker 安装目录: ${ROOT}"
if ! command -v python3 >/dev/null; then
echo "错误: 请先安装 python3"
exit 1
fi
if [[ -d "${VENV}" ]]; then
echo "==> 已有虚拟环境,跳过 python3 -m venv"
else
python3 -m venv "${VENV}"
fi
# shellcheck disable=SC1091
source "${VENV}/bin/activate"
pip install -U pip wheel -i "${PIP_MIRROR}"
install_paddle() {
if command -v nvidia-smi >/dev/null 2>&1; then
local cuda_major
cuda_major="$(nvidia-smi 2>/dev/null | sed -n 's/.*CUDA Version: \([0-9]*\)\.[0-9]*/\1/p' | head -1)"
cuda_major="${cuda_major:-11}"
echo "==> 检测到 NVIDIA GPUCUDA 主版本: ${cuda_major}"
if [[ "${cuda_major}" -ge 12 ]]; then
echo "==> 安装 paddlepaddle-gpu (CUDA 12.x)…"
pip install paddlepaddle-gpu==2.6.2 -i https://www.paddlepaddle.org.cn/packages/stable/cu123/ \
|| pip install paddlepaddle-gpu==2.6.2 -i https://www.paddlepaddle.org.cn/packages/stable/cu118/
else
echo "==> 安装 paddlepaddle-gpu (CUDA 11.x)…"
pip install paddlepaddle-gpu==2.6.2 -i https://www.paddlepaddle.org.cn/packages/stable/cu118/
fi
else
echo "==> 未检测到 GPU,安装 CPU 版 paddlepaddle…"
pip install paddlepaddle==2.6.2 -i "${PIP_MIRROR}"
fi
}
install_paddle
pip install -r "${ROOT}/requirements.txt" -i "${PIP_MIRROR}"
chmod +x "${ROOT}/run.sh" "${ROOT}/start.sh" 2>/dev/null || true
echo ""
python3 -c "import fastapi, uvicorn, paddle; print('paddle', paddle.__version__, 'OK')"
echo ""
echo "==> OCR Worker 安装完成。由 deploy/install.sh 通过 screen 自动启动。"
echo " 手动管理: bash $(dirname "$ROOT")/ocr-screen.sh status"