#!/usr/bin/env bash# Cotton Albums' face model for Android: HyperFace-50k as LiteRT, made from the iPhone's pinned archive# (apps/cotton/App/Flavours/albums/face-model.json) into $COTTON_MODELS_DIR (default ~/.cache/cottondb/models),# where the albums flavour's build takes it by the pin's `android.sha256` (AlbumsFaceModel in app/build.gradle.kts).## The archive must be there already with its pinned hash (scripts/albums-face-model.sh says where it comes from).# The conversion runs in a venv of its own beside the models (numpy, flatbuffers, tflite), never the repo's tooling.# A result whose hash is not the pinned one is deleted and FAILS: the converter or its inputs changed.set -euo pipefailhere="$(cd "$(dirname "$0")" && pwd)"pin="$here/../../apps/cotton/App/Flavours/albums/face-model.json"read_pin() { /usr/bin/python3 -c "import json,sys; d=json.load(open(sys.argv[1])); [d := d[k] for k in sys.argv[2].split('.')]; print(d)""$pin""$1"; }dir="${COTTON_MODELS_DIR:-$HOME/.cache/cottondb/models}"archive="$dir/$(read_pin file)"out="$dir/$(read_pin android.file)"fail() { echo "error: Cotton Albums face model (Android): $*" >&2; exit1; }[ -f "$archive" ] || fail "$archive is absent: put the pinned archive (sha256 $(read_pin sha256)) there first."[ "$(shasum -a 256 "$archive" | cut -d' ' -f1)" = "$(read_pin sha256)" ] || fail "$archive is not the pinned archive."venv="$dir/.venv-convert"if [ ! -x "$venv/bin/python" ]; thenif command -v uv >/dev/null; then uv venv -q --python 3.12"$venv" && VIRTUAL_ENV="$venv" uv pip install -q numpy flatbuffers tfliteelse python3 -m venv "$venv" && "$venv/bin/pip" install -q numpy flatbuffers tflite; fifi"$venv/bin/python" -I "$here/convert.py" hyperface "$archive""$out.part"got="$(shasum -a 256 "$out.part" | cut -d' ' -f1)"want="$(read_pin android.sha256)"[ "$got" = "$want" ] || { rm -f "$out.part"; fail "made sha256 $got; face-model.json pins $want."; }mv "$out.part""$out"echo "Cotton Albums face model (Android): $out ($got)"