rmbg/Makefile
2026-05-16 18:22:26 -06:00

59 lines
1.6 KiB
Makefile

# BiRefNet background removal service — CLI shortcuts.
# Override defaults inline, e.g.: make test BG=white INPUT=photo.jpg
COMPOSE ?= docker compose
PYTHON ?= python3
PORT ?= 8000
INPUT ?= test.jpg
OUTPUT ?= output.png
BG ?= alpha
BLUR ?= 0
.DEFAULT_GOAL := help
.PHONY: help build run up stop down logs log ps test test-mask dev sync shell clean fmt
help: ## Show this help
@grep -E '^[a-zA-Z_-]+:.*?## ' $(MAKEFILE_LIST) \
| awk 'BEGIN{FS=":.*?## "}{printf " \033[36m%-12s\033[0m %s\n", $$1, $$2}'
build: ## Build the Docker image
$(COMPOSE) build
run up: ## Start the service (GPU) in the background
$(COMPOSE) up -d
stop down: ## Stop and remove the service container
$(COMPOSE) down
logs log: ## Follow service logs
$(COMPOSE) logs -f
ps: ## Show service status
$(COMPOSE) ps
test: ## Send INPUT to the running service, save OUTPUT
$(PYTHON) scripts/client.py --url http://localhost:$(PORT) \
--input $(INPUT) --output $(OUTPUT) --background $(BG) --mask-blur $(BLUR)
test-mask: ## Like 'test' but also save the raw mask (mask.png)
$(PYTHON) scripts/client.py --url http://localhost:$(PORT) \
--input $(INPUT) --output $(OUTPUT) --background $(BG) \
--mask-blur $(BLUR) --mask-output mask.png
sync: ## Install dependencies locally with uv
uv sync
dev: sync ## Run the service locally (no Docker; needs local CUDA)
uv run rmbg-as-a-service
shell: ## Open a shell inside a fresh container
$(COMPOSE) run --rm --entrypoint bash rmbg
fmt: ## Format code with ruff
uv run ruff format src scripts
clean: ## Stop the service and remove build artifacts
-$(COMPOSE) down
rm -f $(OUTPUT) mask.png