-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
204 lines (171 loc) · 7.99 KB
/
Makefile
File metadata and controls
204 lines (171 loc) · 7.99 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
201
202
203
204
PYTHON := python3
VENV := .venv
PIP := $(VENV)/bin/pip
PY := $(VENV)/bin/python
# ── Default config/output ─────────────────────────────────────────────────────
CONFIG ?= config.json
BACKEND ?= faster_whisper
LANGUAGE ?= fr
WORKERS ?= 2
OUTPUT ?= ./output
FILE ?=
URL ?=
.DEFAULT_GOAL := help
# ── Setup ─────────────────────────────────────────────────────────────────────
.PHONY: install
install: ## Full installation (venv + deps + config)
bash install.sh
.PHONY: venv
venv: ## Create virtual environment only
$(PYTHON) -m venv $(VENV)
$(PIP) install --upgrade pip --quiet
.PHONY: deps
deps: venv ## Install core dependencies
$(PIP) install --quiet ffmpeg-python tqdm requests yt-dlp pydub
.PHONY: deps-faster-whisper
deps-faster-whisper: deps ## Install faster-whisper backend
$(PIP) install --quiet faster-whisper
.PHONY: deps-openai
deps-openai: deps ## Install OpenAI backend
$(PIP) install --quiet openai
.PHONY: deps-all
deps-all: deps deps-faster-whisper deps-openai ## Install all Python dependencies
# ── whisper.cpp ───────────────────────────────────────────────────────────────
WHISPER_CPP_DIR := whisper.cpp
WHISPER_MODEL ?= base
WHISPER_MODEL_BIN := $(WHISPER_CPP_DIR)/models/ggml-$(WHISPER_MODEL).bin
.PHONY: whisper-cpp-build
whisper-cpp-build: ## Clone and compile whisper.cpp
@if [ ! -d "$(WHISPER_CPP_DIR)" ]; then \
echo "[+] Cloning whisper.cpp..."; \
git clone --depth=1 https://github.com/ggerganov/whisper.cpp $(WHISPER_CPP_DIR); \
else \
echo "[+] whisper.cpp already cloned."; \
fi
@echo "[+] Compiling..."
$(MAKE) -C $(WHISPER_CPP_DIR) -j$$(nproc)
@echo "[+] Build complete."
@ls $(WHISPER_CPP_DIR)/main $(WHISPER_CPP_DIR)/build/bin/whisper-cli 2>/dev/null | head -1 | xargs -I{} echo "[+] Binary: {}"
.PHONY: whisper-cpp-model
whisper-cpp-model: ## Download whisper.cpp model (WHISPER_MODEL=base|tiny|small|medium|large-v2)
@if [ -f "$(WHISPER_MODEL_BIN)" ]; then \
echo "[+] Model already exists: $(WHISPER_MODEL_BIN)"; \
else \
echo "[+] Downloading model: $(WHISPER_MODEL)..."; \
bash $(WHISPER_CPP_DIR)/models/download-ggml-model.sh $(WHISPER_MODEL); \
fi
.PHONY: whisper-cpp-setup
whisper-cpp-setup: whisper-cpp-build whisper-cpp-model ## Full whisper.cpp setup (build + model)
# ── Run ───────────────────────────────────────────────────────────────────────
.PHONY: run
run: ## Transcribe FILE= or URL= (e.g. make run FILE=video.mp4)
ifndef FILE
ifndef URL
$(error Specify FILE=path/to/video.mp4 or URL=https://...)
endif
endif
ifdef FILE
$(PY) main.py --file "$(FILE)" --backend $(BACKEND) --language $(LANGUAGE) \
--workers $(WORKERS) --output-dir $(OUTPUT)
endif
ifdef URL
$(PY) main.py --url "$(URL)" --backend $(BACKEND) --language $(LANGUAGE) \
--workers $(WORKERS) --output-dir $(OUTPUT)
endif
.PHONY: run-config
run-config: ## Run using CONFIG= file (default: config.json)
$(PY) main.py --config $(CONFIG)
.PHONY: dry-run
dry-run: ## Dry-run — show what would be executed without running
ifdef FILE
$(PY) main.py --file "$(FILE)" --backend $(BACKEND) --dry-run
else ifdef URL
$(PY) main.py --url "$(URL)" --backend $(BACKEND) --dry-run
else
$(error Specify FILE= or URL=)
endif
.PHONY: run-whisper-cpp
run-whisper-cpp: ## Run with whisper_cpp backend (auto-detects binary and model)
$(eval WCPP_BIN := $(shell ls $(WHISPER_CPP_DIR)/build/bin/whisper-cli $(WHISPER_CPP_DIR)/main 2>/dev/null | head -1))
@if [ -z "$(WCPP_BIN)" ]; then echo "[x] whisper.cpp binary not found. Run: make whisper-cpp-setup"; exit 1; fi
@if [ ! -f "$(WHISPER_MODEL_BIN)" ]; then echo "[x] Model not found: $(WHISPER_MODEL_BIN). Run: make whisper-cpp-model"; exit 1; fi
ifdef FILE
$(PY) main.py --file "$(FILE)" --backend whisper_cpp \
--whisper-binary "$(WCPP_BIN)" --whisper-model "$(WHISPER_MODEL_BIN)" \
--language $(LANGUAGE) --workers $(WORKERS) --output-dir $(OUTPUT)
else ifdef URL
$(PY) main.py --url "$(URL)" --backend whisper_cpp \
--whisper-binary "$(WCPP_BIN)" --whisper-model "$(WHISPER_MODEL_BIN)" \
--language $(LANGUAGE) --workers $(WORKERS) --output-dir $(OUTPUT)
else
$(error Specify FILE= or URL=)
endif
.PHONY: run-faster-whisper
run-faster-whisper: ## Run with faster_whisper backend
$(MAKE) run BACKEND=faster_whisper
.PHONY: run-openai
run-openai: ## Run with OpenAI API backend
$(MAKE) run BACKEND=openai
# ── Output formats ────────────────────────────────────────────────────────────
.PHONY: run-srt
run-srt: ## Transcribe and output SRT subtitles
ifdef FILE
$(PY) main.py --file "$(FILE)" --backend $(BACKEND) --language $(LANGUAGE) \
--format srt --output-dir $(OUTPUT)
else
$(error Specify FILE=path/to/video.mp4)
endif
.PHONY: run-all-formats
run-all-formats: ## Transcribe and output txt + json + srt + vtt
ifdef FILE
$(PY) main.py --file "$(FILE)" --backend $(BACKEND) --language $(LANGUAGE) \
--format txt,json,srt,vtt --output-dir $(OUTPUT)
else
$(error Specify FILE=path/to/video.mp4)
endif
# ── Dev ───────────────────────────────────────────────────────────────────────
.PHONY: check
check: ## Validate all imports and CLI
$(PY) -c "from transcriber.config import TranscriptionConfig; print('config OK')"
$(PY) -c "from transcriber.backends.base import TranscriptionBackend; print('backends OK')"
$(PY) -c "from transcriber.managers.transcription import TranscriptionManager; print('manager OK')"
$(PY) -c "from transcriber.formatters.output import OutputFormatter; print('formatter OK')"
$(PY) main.py --help > /dev/null && echo "CLI OK"
.PHONY: clean
clean: ## Remove output files and temp dirs
rm -rf output/* __pycache__ transcriber/__pycache__
find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
find . -name "*.pyc" -delete
.PHONY: clean-all
clean-all: clean ## Remove venv and output
rm -rf $(VENV)
# ── Web interface ─────────────────────────────────────────────────────────────
.PHONY: web
web: ## Start web interface at http://localhost:8000
$(PIP) install --quiet fastapi "uvicorn[standard]" python-multipart
$(PY) -m uvicorn web.app:app --host 0.0.0.0 --port 8000 --reload
.PHONY: web-install
web-install: ## Install web dependencies only
$(PIP) install --quiet fastapi "uvicorn[standard]" python-multipart
# ── Help ──────────────────────────────────────────────────────────────────────
.PHONY: help
help: ## Show this help
@echo ""
@echo " Whisper Transcriber"
@echo ""
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
| awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-22s\033[0m %s\n", $$1, $$2}'
@echo ""
@echo " Variables (override with make VAR=value):"
@echo " BACKEND $(BACKEND)"
@echo " LANGUAGE $(LANGUAGE)"
@echo " WORKERS $(WORKERS)"
@echo " OUTPUT $(OUTPUT)"
@echo ""
@echo " Examples:"
@echo " make run FILE=video.mp4"
@echo " make run URL=https://youtube.com/... BACKEND=whisper_cpp LANGUAGE=en"
@echo " make run-all-formats FILE=video.mp4"
@echo " make dry-run URL=https://..."
@echo " make check"
@echo ""