#!/usr/bin/env bash
set -euo pipefail

source "$(cd "$(dirname "$0")" && pwd)/_common.sh"
require_venv
require_curl
cd_nanogpt

# Prefer a github.com URL (some networks block raw.githubusercontent.com).
# This writes the input file where nanoGPT's prepare script expects it.
INPUT_TXT="data/shakespeare_char/input.txt"
if [[ ! -f "${INPUT_TXT}" ]]; then
	mkdir -p "$(dirname "${INPUT_TXT}")"
	echo "Downloading tiny Shakespeare to ${INPUT_TXT}" >&2
	curl -fL --retry 3 --retry-delay 1 \
		-o "${INPUT_TXT}" \
		"https://github.com/karpathy/char-rnn/raw/master/data/tinyshakespeare/input.txt"
fi

"${VENV_PY}" data/shakespeare_char/prepare.py
