dots-ocr-idcard / Makefile
tommulder's picture
chore(test): commit Makefile and testing scripts
34c6057
.PHONY: help install dev test lint format clean run
help: ## Show this help message
@echo "KYB Tech Dots.OCR - Development Commands"
@echo "=========================================="
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
install: ## Install the package
uv pip install -e .
dev: ## Install development dependencies
uv pip install -e .[dev]
test: ## Run tests
pytest
test-verbose: ## Run tests with verbose output
pytest -v
lint: ## Run linting
ruff check .
mypy src/
format: ## Format code
black .
ruff check --fix .
clean: ## Clean up build artifacts
rm -rf build/
rm -rf dist/
rm -rf *.egg-info/
rm -rf .pytest_cache/
rm -rf .mypy_cache/
rm -rf .ruff_cache/
find . -type d -name __pycache__ -exec rm -rf {} +
find . -type f -name "*.pyc" -delete
run: ## Run the application
python main.py
run-dev: ## Run the application in development mode
uvicorn src.kybtech_dots_ocr.app:app --host 0.0.0.0 --port 7860 --reload
setup: ## Set up development environment
python setup_dev.py
check: ## Run all checks (lint, format, test)
$(MAKE) lint
$(MAKE) test
build: ## Build the Docker image
docker build -t kybtech-dots-ocr .
# Build for Hugging Face Spaces GPU (CUDA, optional flash-attn)
build-spaces-gpu: ## Build Docker image for HF Spaces GPU
# Use CUDA runtime base; leave flash-attn on by default (can disable with ARGS)
docker build \
--build-arg BASE_IMAGE=pytorch/pytorch:2.7.0-cuda12.6-cudnn9-runtime \
--build-arg INSTALL_FLASH_ATTN=true \
-t kybtech-dots-ocr:spaces-gpu .
# Build for local Apple Silicon CPU (no CUDA, no flash-attn)
build-local-cpu: ## Build Docker image for local CPU (arm64)
docker build \
--platform=linux/arm64 \
--build-arg BASE_IMAGE=python:3.12-slim \
--build-arg INSTALL_FLASH_ATTN=false \
-t kybtech-dots-ocr:cpu .
run-docker: ## Run the Docker container locally
docker run -p 7860:7860 kybtech-dots-ocr
deploy-staging: ## Deploy to staging (requires HF CLI)
@echo "Deploying to staging..."
@echo "Make sure you have HF CLI installed and are logged in"
@echo "Then push to your staging space repository"
deploy-production: ## Deploy to production (requires HF CLI)
@echo "Deploying to production..."
@echo "Make sure you have HF CLI installed and are logged in"
@echo "Then push to your production space repository"
test-local: ## Test the local API endpoint
cd scripts && ./run_tests.sh -e local
test-production: ## Test the production API endpoint
cd scripts && ./run_tests.sh -e production
test-staging: ## Test the staging API endpoint
cd scripts && ./run_tests.sh -e staging
test-quick: ## Quick test with curl (no Python dependencies)
cd scripts && ./test_production_curl.sh
logs: ## Show application logs (if running in Docker)
docker logs -f kybtech-dots-ocr
stop: ## Stop the Docker container
docker stop kybtech-dots-ocr || true
clean-docker: ## Clean up Docker images and containers
docker stop kybtech-dots-ocr || true
docker rm kybtech-dots-ocr || true
docker rmi kybtech-dots-ocr || true
# -----------------------------
# Debug testing helpers
# -----------------------------
.PHONY: debug-test-local debug-test-hf debug-test
debug-test-local: ## Run debug curl test against local server
./scripts/test_debug_ocr.sh -u http://localhost:7860 -f scripts/tom_id_card_front.jpg -d
debug-test-hf: ## Run debug curl test against HF Space (set HF_URL var)
@if [ -z "$(HF_URL)" ]; then echo "HF_URL not set. Example: make debug-test-hf HF_URL=https://your-space.hf.space"; exit 1; fi
./scripts/test_debug_ocr.sh -u $(HF_URL) -f scripts/tom_id_card_front.jpg -d
# debug-test allows overriding URL/FILE/ROI/DEBUG via envs
# Example:
# make debug-test URL=https://space.hf.space FILE=scripts/tom_id_card_front.jpg ROI='{"x1":0,"y1":0,"x2":1,"y2":0.5}' DEBUG=1
debug-test: ## Run debug curl test with overrides: URL, FILE, ROI, DEBUG
@URL=${URL:-http://localhost:7860} \
FILE=${FILE:-scripts/tom_id_card_front.jpg} \
ROI=${ROI:-} \
DBG=${DEBUG:-0} \
sh -c '\
CMD="./scripts/test_debug_ocr.sh -u $$URL -f $$FILE"; \
if [ "$$DBG" = "1" ]; then CMD="$$CMD -d"; fi; \
if [ -n "$$ROI" ]; then CMD="$$CMD -r '$$ROI'"; fi; \
echo "Running: $$CMD"; \
eval $$CMD \
'