#!/usr/bin/env bash # # Deploy the backend to the Hugging Face Space. # # Why this script: HF Spaces require a YAML config frontmatter in README.md # (sdk: docker, app_port: 7860, ...). But GitHub renders that frontmatter as an # ugly key/value table at the top of the README. So we keep the GitHub README # CLEAN (no frontmatter) and inject the frontmatter ONLY into the orphan branch # we push to the Space. The React UI is Vercel-only, so the disposable backend # branch strips every frontend directory as well as unrelated binary assets. # # Prereqs (once): # git remote add space https://huggingface.co/spaces//themis # (HF write token cached in your git credential helper) # # Usage: bash scripts/deploy-space.sh set -euo pipefail ROOT="$(cd "$(dirname "$0")/.." && pwd)" cd "$ROOT" BASE_BRANCH="$(git rev-parse --abbrev-ref HEAD)" git branch -D hf-space 2>/dev/null || true git checkout --orphan hf-space git rm -r --cached frontend vercel-frontend assets >/dev/null 2>&1 || true # Living documentation contains generated PDFs that are useful in GitHub but are # not runtime inputs. HF rejects those binaries unless they use Xet, so leave the # entire documentation tree out of the disposable Space branch. git rm -r --cached documentation >/dev/null 2>&1 || true # Court templates live in a pinned private dataset. Keep the source PDFs out of # the public Space repository; start_private_space.py downloads them at boot. git rm -r --cached phase1/drafting/templates >/dev/null 2>&1 || true # statute_vectors.npy is a binary — HF Spaces reject binaries in git (Xet). It rides in the # themis-escr-artifacts dataset instead and the Dockerfile places it beside the statute JSONs. git rm --cached "statute corpus/statute_vectors.npy" >/dev/null 2>&1 || true # themis-handoff ships gzipped corpus inputs (HF pre-receive rejects git binaries) git rm -r --cached themis-handoff >/dev/null 2>&1 || true # Prepend the HF Spaces config frontmatter to README.md (orphan/Space branch only). # Built with explicit newlines so the closing '---' stays on its own line. { printf -- '---\n' printf 'title: Moonley API\n' printf 'sdk: docker\n' printf 'app_port: 7860\n' printf 'pinned: false\n' printf -- '---\n\n' cat README.md } > README.hf && mv README.hf README.md git -c user.name="vg15o2" -c user.email="vaishu1521.g@gmail.com" \ commit -q -am "Moonley backend (HF Space build)" git push space hf-space:main --force git checkout -f "$BASE_BRANCH" git branch -D hf-space echo "Deployed backend to the HF Space from '$BASE_BRANCH'."