#!/bin/bash

# VLMEvalKit dependency installer for evaluation
# Installs all packages required by third_party/VLMEvalKit into the active conda env.
#
# Usage:
#   bash chengyue_script/dvlm/utils/install_vlmeval_deps.sh
#
# If PROJECT_ROOT is not set, auto-detect from script location:
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="${PROJECT_ROOT:-$(cd "${SCRIPT_DIR}/../../.." && pwd)}"

set -euo pipefail

# Activate target conda env safely under set -u
set +u
source "${PROJECT_ROOT}/scripts/cluster_env.sh"
lmflow_activate_conda
set -u

python3 - <<'PY'
import sys
print("Python:", sys.version)
PY

echo "Upgrading pip/setuptools/wheel..."
python3 -m pip install -U pip setuptools wheel

# ---------- Core VLMEvalKit deps ----------
echo "Installing VLMEvalKit core deps..."
python3 -m pip install -U \
  validators \
  sty \
  rich \
  json_repair \
  pylatexenc==2.10 \
  portalocker \
  timeout-decorator \
  xlsxwriter \
  openpyxl \
  tabulate \
  dotenv \
  python-dotenv \
  qwen-vl-utils

# ---------- Image / Video ----------
echo "Installing image/video deps..."
python3 -m pip install -U \
  imageio \
  imageio-ffmpeg \
  opencv-python-headless \
  decord \
  pdf2image

# ---------- NLP / Eval metrics ----------
echo "Installing NLP/eval deps..."
python3 -m pip install -U \
  math-verify \
  apted \
  colormath \
  distance \
  lxml \
  zss \
  polygon3 \
  levenshtein \
  jieba \
  editdistance \
  anls

# ---------- ML / Torch extras ----------
echo "Installing ML extras..."
python3 -m pip install -U \
  torchmetrics \
  scikit-image \
  lpips \
  openai-clip \
  sentence_transformers \
  bert_score

# ---------- Misc ----------
echo "Installing misc deps..."
python3 -m pip install -U \
  cairosvg \
  gradio \
  ipdb \
  google-genai

echo ""
echo "✓ VLMEvalKit deps installed successfully."
echo "  Verify: python3 -c 'import vlmeval; print(vlmeval.__file__)'"


