Add dataset card with download script
Browse files
README.md
CHANGED
|
@@ -127,6 +127,54 @@ if __name__ == "__main__":
|
|
| 127 |
|
| 128 |
Requires `pip install -U huggingface_hub`. If the repo is private, run `hf auth login` first or set `HF_TOKEN`.
|
| 129 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
## Load
|
| 131 |
|
| 132 |
```python
|
|
|
|
| 127 |
|
| 128 |
Requires `pip install -U huggingface_hub`. If the repo is private, run `hf auth login` first or set `HF_TOKEN`.
|
| 129 |
|
| 130 |
+
### Retry / keep in sync (`rerun.sh`)
|
| 131 |
+
|
| 132 |
+
Long downloads can fail on network errors. `snapshot_download` resumes and skips files that are already complete, so re-running the script is safe. `rerun.sh` runs a Python script in a loop: it waits `success_wait` seconds after a success and `fail_wait` seconds after a failure, and stops after `max_runs` runs (0 = never stop).
|
| 133 |
+
|
| 134 |
+
```bash
|
| 135 |
+
chmod +x rerun.sh
|
| 136 |
+
# retry every 5 min on failure, re-sync every hour after success; give all three numbers before `--`
|
| 137 |
+
nohup ./rerun.sh download_lpr.py 3600 300 0 -- --out data/crops > rerun.log 2>&1 &
|
| 138 |
+
# one country: 3 runs total, 5 min apart (later runs only fetch what's missing or new)
|
| 139 |
+
./rerun.sh download_lpr.py 300 300 3 -- --out data/crops --countries BY
|
| 140 |
+
```
|
| 141 |
+
|
| 142 |
+
Save as `rerun.sh`:
|
| 143 |
+
|
| 144 |
+
```bash
|
| 145 |
+
#!/usr/bin/env bash
|
| 146 |
+
# Re-run a Python script forever: wait SUCCESS_WAIT after success, FAIL_WAIT after failure.
|
| 147 |
+
# Usage: ./rerun.sh script.py [success_wait_sec] [fail_wait_sec] [max_runs] [-- script args...]
|
| 148 |
+
# ./rerun.sh /home/jovyan/test.py 3600 300
|
| 149 |
+
# ./rerun.sh test.py 3600 300 0 -- --country VN # max_runs 0 = unlimited
|
| 150 |
+
# nohup ./rerun.sh test.py 3600 300 > rerun.log 2>&1 &
|
| 151 |
+
|
| 152 |
+
set -u
|
| 153 |
+
SCRIPT="${1:?usage: $0 script.py [success_wait] [fail_wait] [max_runs] [-- args]}"
|
| 154 |
+
SUCCESS_WAIT="${2:-3600}"
|
| 155 |
+
FAIL_WAIT="${3:-300}"
|
| 156 |
+
MAX_RUNS="${4:-0}"
|
| 157 |
+
shift $(( $# < 4 ? $# : 4 ))
|
| 158 |
+
[ "${1:-}" = "--" ] && shift
|
| 159 |
+
ARGS=("$@")
|
| 160 |
+
|
| 161 |
+
PYTHON="${PYTHON:-python}"
|
| 162 |
+
trap 'echo "$(date "+%F %T") stopped"; exit 0' INT TERM
|
| 163 |
+
|
| 164 |
+
run=0
|
| 165 |
+
while true; do
|
| 166 |
+
run=$((run + 1))
|
| 167 |
+
echo "$(date '+%F %T') run #$run: $PYTHON $SCRIPT ${ARGS[*]:-}"
|
| 168 |
+
"$PYTHON" "$SCRIPT" "${ARGS[@]}"
|
| 169 |
+
code=$?
|
| 170 |
+
if [ "$code" -eq 0 ]; then wait_s=$SUCCESS_WAIT; status=OK; else wait_s=$FAIL_WAIT; status="FAILED(exit $code)"; fi
|
| 171 |
+
echo "$(date '+%F %T') run #$run $status; next run in ${wait_s}s"
|
| 172 |
+
if [ "$MAX_RUNS" -gt 0 ] && [ "$run" -ge "$MAX_RUNS" ]; then echo "reached max_runs=$MAX_RUNS"; exit "$code"; fi
|
| 173 |
+
sleep "$wait_s" &
|
| 174 |
+
wait $!
|
| 175 |
+
done
|
| 176 |
+
```
|
| 177 |
+
|
| 178 |
## Load
|
| 179 |
|
| 180 |
```python
|