End-to-end handwriting synthesis: train → package → serve → web.
Built on PyTorch with an LSTM + attention model trained on the IAM On‑Line Handwriting Database. Based on Alex Graves' "Generating Sequences With Recurrent Neural Networks" (https://arxiv.org/abs/1308.0850).
- Train LSTM + attention with GMM output on IAM
- Multi‑GPU training (DDP) and resumable checkpoints
- Weights & Biases logging (optional)
- FastAPI inference service + React frontend
- HuggingFace Space deployment template
scriptify/
├── ml/ # Training pipeline (PyTorch)
│ ├── src/ # models/, data/, training/, utils/
│ ├── config/ # config.yaml (paths, hyperparams)
│ ├── scripts/ # run.sh, run_ddp.sh
│ ├── outputs/ # runs/, checkpoints/, logs
│ └── packaged_models/ # packaged artifacts for serving
├── api/ # FastAPI inference service
│ └── src/
│ ├── main.py # API entry
│ └── inference_utils.py
└── frontend/ # React + TypeScript app
└── src/ # components/, services/, App.tsx
- Python 3.9+, Conda, Node 18+, CUDA GPU recommended
- Obtain IAM On‑Line Handwriting (ascii/ and lineStrokes/)
cd ml
# Edit config/config.yaml → set:
# paths.raw_data_root (contains ascii/ and lineStrokes/)
# paths.processed_data_dir (write location for .npy files)
conda env create -f environment.yml && conda activate scriptify_ml_env
python -m src.data.dataset # writes processed arrays to paths.processed_data_dircd ml
wandb login # optional
bash scripts/run.sh # single GPU (torchrun)
# Multi-node/GPU (requires ml/.env with DISTRIBUTED settings)
# Save this as ml/.env (example values):
# SCRIPTIFY_DIST_MASTER_ADDR=10.0.0.1
# SCRIPTIFY_DIST_MASTER_PORT=29500
# SCRIPTIFY_DIST_NNODES=2
# SCRIPTIFY_DIST_NPROC_PER_NODE=2
bash scripts/run_ddp.sh 0 # node rank 0The API loads from ml/packaged_models and expects these filenames:
handwriting_model.pthandwriting_model.scripted.pt
Generate matching files with:
cd ml
python -m src.package_model --pkg_name handwriting_modelOr specify paths explicitly:
python -m src.package_model \
--checkpoint <path/to/checkpoint> \
--config <path/to/config.yaml> \
--pkg_name handwriting_modelIf you change names or locations, update api/src/main.py constants (MODEL_DIR, SCRIPTED_MODEL_NAME, METADATA_MODEL_NAME) or rename the files accordingly.
cd api
pip install -r requirements.txt
cd src
python main.py # http://localhost:8000 (see /docs)
# Alternatively: uvicorn main:app --reloadcd frontend
npm install
npm run dev # http://localhost:5173- 3‑layer LSTM with soft attention over characters
- GMM output for (dx, dy, pen‑up) stroke prediction
- Tunable via
ml/config/config.yaml
Edit ml/config/config.yaml (or set SCRIPTIFY_CONFIG_PATH). Key fields:
paths.raw_data_root— IAM dataset root (containsascii/andlineStrokes/)paths.processed_data_dir— where processed.npyare savedpaths.outputs_dir— training runs and checkpointsdataset.max_stroke_len,dataset.max_text_len,dataset.alphabet_stringwandb.enabled,wandb.project_name
- Frontend: Vercel — https://scriptify-web.vercel.app
- Backend: HuggingFace Spaces — https://huggingface.co/spaces/h3nock/scriptify-api