-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·222 lines (179 loc) · 8.33 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·222 lines (179 loc) · 8.33 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#!/usr/bin/env bash
set -euo pipefail
# First-time setup for idp-leaderboard-benchmarks
# Creates venv, installs dependencies, configures .env, and validates.
REPO_ROOT="$(cd "$(dirname "$0")" && pwd)"
cd "$REPO_ROOT"
VENV_DIR=".venv"
MIN_PYTHON_MAJOR=3
MIN_PYTHON_MINOR=10
# ── Colors ──────────────────────────────────────────────────────────────────
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
CYAN='\033[0;36m'
BOLD='\033[1m'
NC='\033[0m'
info() { echo -e "${CYAN}▸${NC} $*"; }
ok() { echo -e "${GREEN}✓${NC} $*"; }
warn() { echo -e "${YELLOW}⚠${NC} $*"; }
fail() { echo -e "${RED}✗${NC} $*"; }
# ── Find Python ─────────────────────────────────────────────────────────────
find_python() {
for cmd in python3 python; do
if command -v "$cmd" &>/dev/null; then
local ver
ver=$("$cmd" -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')" 2>/dev/null)
local major minor
major=$(echo "$ver" | cut -d. -f1)
minor=$(echo "$ver" | cut -d. -f2)
if [ "$major" -ge "$MIN_PYTHON_MAJOR" ] && [ "$minor" -ge "$MIN_PYTHON_MINOR" ]; then
echo "$cmd"
return 0
fi
fi
done
return 1
}
echo ""
echo -e "${BOLD}═══ idp-leaderboard-benchmarks setup ═══${NC}"
echo ""
# ── 1. Check Python ─────────────────────────────────────────────────────────
info "Checking Python version (need ${MIN_PYTHON_MAJOR}.${MIN_PYTHON_MINOR}+)..."
PYTHON=$(find_python) || {
fail "Python ${MIN_PYTHON_MAJOR}.${MIN_PYTHON_MINOR}+ not found."
echo " Install from https://www.python.org/downloads/"
exit 1
}
PY_VERSION=$("$PYTHON" --version 2>&1)
ok "$PY_VERSION ($(command -v "$PYTHON"))"
# ── 2. Create virtualenv ────────────────────────────────────────────────────
if [ -d "$VENV_DIR" ] && [ -f "$VENV_DIR/bin/activate" ]; then
ok "Virtual environment already exists at ${VENV_DIR}/"
else
info "Creating virtual environment in ${VENV_DIR}/..."
"$PYTHON" -m venv "$VENV_DIR"
ok "Virtual environment created"
fi
# shellcheck disable=SC1091
source "$VENV_DIR/bin/activate"
ok "Activated venv ($(python --version))"
# ── 3. Install core dependencies ────────────────────────────────────────────
info "Installing core dependencies from requirements.txt..."
pip install --upgrade pip --quiet
pip install -r requirements.txt --quiet
ok "Core dependencies installed"
# ── 4. Install Playwright (for olmocr evaluation) ───────────────────────────
info "Installing Playwright chromium (needed for olmOCR evaluation)..."
if python -m playwright install chromium 2>/dev/null; then
ok "Playwright chromium installed"
else
warn "Playwright chromium install failed (non-fatal — only needed for olmOCR eval)"
fi
# ── 5. Install docext (for IDP benchmark) ───────────────────────────────────
DOCEXT_DIR="$REPO_ROOT/../docext"
if [ ! -d "$DOCEXT_DIR" ]; then
info "Cloning docext into ${DOCEXT_DIR}..."
git clone https://github.com/NanoNets/docext.git "$DOCEXT_DIR"
ok "docext cloned"
else
ok "docext already present at ${DOCEXT_DIR}"
fi
info "Installing docext (editable)..."
pip install -e "$DOCEXT_DIR" --quiet
ok "docext installed"
# Comment out CLASSIFICATION task — not used by idp-leaderboard benchmarks
# and its dataset loading slows down startup.
DOCEXT_CFG="$DOCEXT_DIR/configs/benchmark.yaml"
if [ -f "$DOCEXT_CFG" ] && grep -q "^ - CLASSIFICATION" "$DOCEXT_CFG"; then
sed -i.bak 's/^ - CLASSIFICATION/ # - CLASSIFICATION/' "$DOCEXT_CFG" && rm -f "$DOCEXT_CFG.bak"
ok "Commented out CLASSIFICATION task in docext config"
fi
# ── 6. Install optional dependencies ────────────────────────────────────────
info "Installing optional dependencies (json_repair, pandas)..."
pip install json_repair pandas --quiet 2>/dev/null || true
ok "Optional dependencies installed"
# ── 7. Create .env template ─────────────────────────────────────────────────
if [ -f ".env" ]; then
ok ".env file already exists"
else
info "Creating .env template..."
cat > .env <<'ENVEOF'
# API keys — uncomment and fill in the ones you need
# For GPT models (via LiteLLM)
# OPENAI_API_KEY=sk-...
# For Gemini models (via LiteLLM)
# GOOGLE_API_KEY=AIza...
# For Claude models (via LiteLLM)
# ANTHROPIC_API_KEY=sk-ant-...
# For Nanonets model
# NANONETS_API_KEY=...
# For publishing results to HuggingFace
# HF_WRITE_TOKEN=hf_...
ENVEOF
ok ".env template created — edit it with your API keys"
fi
# ── 8. Create directories ───────────────────────────────────────────────────
mkdir -p caches ground_truth results
ok "Directories ready (caches/, ground_truth/, results/)"
# ── 9. Validate setup ───────────────────────────────────────────────────────
echo ""
echo -e "${BOLD}── Validation ──${NC}"
CHECKS_PASSED=0
CHECKS_TOTAL=0
check() {
CHECKS_TOTAL=$((CHECKS_TOTAL + 1))
if python -c "$1" 2>/dev/null; then
ok "$2"
CHECKS_PASSED=$((CHECKS_PASSED + 1))
else
fail "$2"
fi
}
check "import httpx" "httpx"
check "import fitz" "PyMuPDF"
check "import PIL" "Pillow"
check "import yaml" "PyYAML"
check "import litellm" "litellm"
check "from olmocr.bench.tests import load_tests" "olmocr[bench]"
CHECKS_TOTAL=$((CHECKS_TOTAL + 1))
if python -c "from docext.benchmark.benchmark import NanonetsIDPBenchmark" 2>/dev/null; then
ok "docext (IDP benchmark)"
CHECKS_PASSED=$((CHECKS_PASSED + 1))
else
warn "docext not available (IDP benchmark will not work)"
fi
# ── 10. Check for OmniDocBench data ─────────────────────────────────────────
OMNIDOC_DIR="$REPO_ROOT/../OmniDocBench"
CHECKS_TOTAL=$((CHECKS_TOTAL + 1))
OMNIDOC_FOUND=false
for candidate in "$OMNIDOC_DIR/OmniDocBench.json" "$REPO_ROOT/OmniDocBench/OmniDocBench.json"; do
if [ -f "$candidate" ]; then
ok "OmniDocBench.json found at $(dirname "$candidate")"
OMNIDOC_FOUND=true
CHECKS_PASSED=$((CHECKS_PASSED + 1))
break
fi
done
if [ "$OMNIDOC_FOUND" = false ]; then
info "Cloning OmniDocBench dataset into ${OMNIDOC_DIR}..."
if git clone https://huggingface.co/datasets/opendatalab/OmniDocBench "$OMNIDOC_DIR" 2>&1; then
ok "OmniDocBench cloned"
CHECKS_PASSED=$((CHECKS_PASSED + 1))
else
warn "OmniDocBench clone failed (non-fatal — only needed for OmniDocBench benchmark)"
echo " You can clone it manually later:"
echo " git clone https://huggingface.co/datasets/opendatalab/OmniDocBench ../OmniDocBench"
fi
fi
# ── Summary ─────────────────────────────────────────────────────────────────
echo ""
echo -e "${BOLD}═══ Setup complete (${CHECKS_PASSED}/${CHECKS_TOTAL} checks passed) ═══${NC}"
echo ""
echo " Activate the venv: source ${VENV_DIR}/bin/activate"
echo " Configure API keys: edit .env"
echo ""
echo " Quick test:"
echo " python benchmarks/olmocr/run.py --model test --provider litellm \\"
echo " --model-id openai/gpt-4.1-mini --workers 1 --categories arxiv_math"
echo ""