-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
200 lines (173 loc) · 7.07 KB
/
Makefile
File metadata and controls
200 lines (173 loc) · 7.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
.PHONY: build shell test clean help logs ocr excalidraw stop watch-build watch-start watch-stop watch-restart watch-logs watch-status watch-clean watch-shell
IMAGE_NAME := ghcr.io/cloonix/excalidraw-ocr:latest
# Docker Compose command (auto-detect v1 or v2)
DOCKER_COMPOSE := $(shell command -v docker-compose 2>/dev/null && echo docker-compose || echo "docker compose")
# Colors for output
GREEN := \033[0;32m
YELLOW := \033[0;33m
BLUE := \033[0;34m
NC := \033[0m # No Color
help:
@echo "$(BLUE)OCR Docker Commands:$(NC)"
@echo ""
@echo "$(GREEN)Setup:$(NC)"
@echo " make build - Build Docker image"
@echo " make setup - Create input/output directories and copy .env.example"
@echo ""
@echo "$(GREEN)One-shot Processing:$(NC)"
@echo " make shell - Open interactive shell in container"
@echo " make ocr - Run OCR on image (IMAGE=data/file.png)"
@echo " make excalidraw - Run Excalidraw OCR (FILE=data/drawing.excalidraw.md)"
@echo ""
@echo "$(GREEN)Watch Mode (docker compose):$(NC)"
@echo " make watch-build - Build watch mode container"
@echo " make watch-start - Start watch mode in background"
@echo " make watch-stop - Stop watch mode"
@echo " make watch-restart- Restart watch mode"
@echo " make watch-logs - View watch mode logs"
@echo " make watch-status - Show watch mode status"
@echo " make watch-shell - Open shell in running watch container"
@echo " make watch-clean - Remove watch mode container and volumes"
@echo ""
@echo "$(GREEN)Testing:$(NC)"
@echo " make test - Test installation and dependencies"
@echo " make list-models - List available OCR models"
@echo ""
@echo "$(GREEN)Maintenance:$(NC)"
@echo " make logs - View container logs"
@echo " make stop - Stop running containers"
@echo " make clean - Remove containers and volumes"
@echo " make clean-all - Remove containers, volumes, and images"
@echo ""
@echo "$(YELLOW)Examples:$(NC)"
@echo " make ocr IMAGE=data/handwriting.jpg"
@echo " make excalidraw FILE=data/drawing.excalidraw.md"
@echo " make watch-start # Monitors ./watch folder continuously"
build:
@echo "$(GREEN)Building Docker image...$(NC)"
$(DOCKER_COMPOSE) build watch
@echo "$(GREEN)✓ Build complete$(NC)"
setup:
@echo "$(GREEN)Setting up directories...$(NC)"
mkdir -p data watch
@if [ ! -f .env ]; then \
cp .env.example .env; \
echo "$(YELLOW)Created .env file from .env.example$(NC)"; \
echo "$(YELLOW)⚠️ Please edit .env and add your OPENROUTER_API_KEY$(NC)"; \
else \
echo "$(GREEN)✓ .env already exists$(NC)"; \
fi
@echo "$(GREEN)✓ Setup complete$(NC)"
@echo ""
@echo "Next steps:"
@echo " 1. Edit .env and add your API key"
@echo " 2. Run 'make build' to build the image"
@echo " 3. Place images in ./data/"
@echo " 4. Run 'make ocr IMAGE=/data/yourimage.png'"
shell:
@echo "$(GREEN)Opening shell in container...$(NC)"
docker run --rm -it -v ./data:/data --env-file .env $(IMAGE_NAME) /bin/bash
test:
@echo "$(GREEN)Testing Docker setup...$(NC)"
@echo "\n$(BLUE)Python version:$(NC)"
@docker run --rm $(IMAGE_NAME) python --version
@echo "\n$(BLUE)Node.js version:$(NC)"
@docker run --rm $(IMAGE_NAME) node --version
@echo "\n$(BLUE)Testing cairosvg import:$(NC)"
@docker run --rm $(IMAGE_NAME) python -c "import cairosvg; print('✓ cairosvg OK')"
@echo "\n$(BLUE)Testing lz-string:$(NC)"
@docker run --rm $(IMAGE_NAME) node -e "const lz = require('lz-string'); console.log('✓ lz-string OK')"
@echo "\n$(GREEN)✓ All tests passed$(NC)"
list-models:
@echo "$(GREEN)Listing available OCR models...$(NC)"
@docker run --rm --env-file .env $(IMAGE_NAME) python ocr.py --list-models
ocr:
@if [ -z "$(IMAGE)" ]; then \
echo "$(YELLOW)Usage: make ocr IMAGE=data/yourimage.png [OUTPUT=data/result.txt]$(NC)"; \
exit 1; \
fi
@if [ -n "$(OUTPUT)" ]; then \
docker run --rm -v ./data:/data --env-file .env $(IMAGE_NAME) python ocr.py /$(IMAGE) -o /$(OUTPUT); \
else \
docker run --rm -v ./data:/data --env-file .env $(IMAGE_NAME) python ocr.py /$(IMAGE); \
fi
excalidraw:
@if [ -z "$(FILE)" ]; then \
echo "$(YELLOW)Usage: make excalidraw FILE=data/drawing.excalidraw.md$(NC)"; \
exit 1; \
fi
@docker run --rm -v ./data:/data --env-file .env $(IMAGE_NAME) python excalidraw_ocr.py /$(FILE)
logs:
@echo "$(GREEN)Showing container logs...$(NC)"
$(DOCKER_COMPOSE) logs -f
stop:
@echo "$(GREEN)Stopping containers...$(NC)"
$(DOCKER_COMPOSE) down
@echo "$(GREEN)✓ Stopped$(NC)"
clean:
@echo "$(YELLOW)Removing containers and volumes...$(NC)"
$(DOCKER_COMPOSE) down -v
@echo "$(GREEN)✓ Cleaned$(NC)"
clean-all: clean
@echo "$(YELLOW)Removing Docker images...$(NC)"
docker rmi $(IMAGE_NAME) 2>/dev/null || true
@echo "$(GREEN)✓ All cleaned$(NC)"
# Development helpers
dev-build:
@echo "$(GREEN)Building without cache...$(NC)"
$(DOCKER_COMPOSE) build --no-cache watch
dev-logs:
@echo "$(GREEN)Showing detailed logs...$(NC)"
$(DOCKER_COMPOSE) logs --tail=100 -f
# Batch processing
batch-ocr:
@echo "$(GREEN)Batch processing all images in ./data/...$(NC)"
@for img in data/*.{png,jpg,jpeg,PNG,JPG,JPEG}; do \
if [ -f "$$img" ]; then \
echo "Processing $$img..."; \
docker run --rm -v ./data:/data --env-file .env $(IMAGE_NAME) python ocr.py "/$$img" -o "/data/$$(basename $$img .png).txt" 2>/dev/null || \
docker run --rm -v ./data:/data --env-file .env $(IMAGE_NAME) python ocr.py "/$$img" -o "/data/$$(basename $$img .jpg).txt" 2>/dev/null || \
docker run --rm -v ./data:/data --env-file .env $(IMAGE_NAME) python ocr.py "/$$img" -o "/data/$$(basename $$img .jpeg).txt" 2>/dev/null; \
fi; \
done
@echo "$(GREEN)✓ Batch processing complete$(NC)"
batch-excalidraw:
@echo "$(GREEN)Batch processing all Excalidraw files in ./data/...$(NC)"
@docker run --rm -v ./data:/data --env-file .env $(IMAGE_NAME) python excalidraw_ocr.py /data/
@echo "$(GREEN)✓ Batch processing complete$(NC)"
# Watch mode targets
watch-build:
@echo "$(GREEN)Building watch mode container...$(NC)"
$(DOCKER_COMPOSE) build watch
@echo "$(GREEN)✓ Build complete$(NC)"
watch-start:
@echo "$(GREEN)Starting watch mode...$(NC)"
@if [ ! -d watch ]; then \
mkdir -p watch; \
echo "$(YELLOW)Created ./watch directory$(NC)"; \
fi
$(DOCKER_COMPOSE) up -d watch
@echo "$(GREEN)✓ Watch mode started$(NC)"
@echo "$(BLUE)Monitor with: make watch-logs$(NC)"
@echo "$(BLUE)Place .excalidraw.md files in ./watch folder$(NC)"
watch-stop:
@echo "$(GREEN)Stopping watch mode...$(NC)"
$(DOCKER_COMPOSE) stop watch
@echo "$(GREEN)✓ Watch mode stopped$(NC)"
watch-restart:
@echo "$(GREEN)Restarting watch mode...$(NC)"
$(DOCKER_COMPOSE) restart watch
@echo "$(GREEN)✓ Watch mode restarted$(NC)"
watch-logs:
@echo "$(GREEN)Showing watch mode logs (Ctrl+C to exit)...$(NC)"
$(DOCKER_COMPOSE) logs -f --tail=50 watch
watch-status:
@echo "$(GREEN)Watch mode status:$(NC)"
$(DOCKER_COMPOSE) ps watch
watch-clean:
@echo "$(YELLOW)Removing watch mode container and volumes...$(NC)"
$(DOCKER_COMPOSE) down -v
@echo "$(GREEN)✓ Cleaned$(NC)"
watch-shell:
@echo "$(GREEN)Opening shell in watch container...$(NC)"
$(DOCKER_COMPOSE) exec watch /bin/bash