Skip to content

Commit 7d86fdb

Browse files
committed
fix: initial commit
1 parent 7dd141f commit 7d86fdb

File tree

7 files changed

+223
-0
lines changed

7 files changed

+223
-0
lines changed

Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ARG CUDA_VERSION=12.3.0
2+
FROM docker.io/nvidia/cuda:${CUDA_VERSION}-devel-ubuntu22.04
3+
4+
WORKDIR /usr/local/src
5+
RUN apt-get update && \
6+
apt-get install --no-install-recommends -y bash git make vim wget g++ ffmpeg curl
7+
RUN git clone https://github.com/ggerganov/whisper.cpp.git -b v1.4.0 --depth 1
8+
9+
# whisper.cpp setup
10+
WORKDIR /usr/local/src/whisper.cpp
11+
12+
RUN make clean
13+
RUN WHISPER_CUBLAS=1 make -j
14+
15+
ENTRYPOINT [ "./volume/transcribe.sh" ]

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
https://github.com/ggerganov/whisper.cpp
3+
4+
## TLDR
5+
```
6+
docker compose up
7+
```
8+
or
9+
```
10+
MODEL=large-v2 LANGUAGE=ru docker compose up
11+
```
12+
13+
## Step by step
14+
#### 1. Build CUDA image (single run)
15+
```
16+
docker compose build --progress=plain
17+
```
18+
19+
#### 2. Download models (single run)
20+
You may want to do it manually in order to see the progress
21+
```
22+
./models/download.sh large-v2
23+
```
24+
This script is a plain copy of [download-ggml-model.sh](https://github.com/ggerganov/whisper.cpp/blob/master/models/download-ggml-model.sh)
25+
You may find additional information and configurations [here](https://github.com/ggerganov/whisper.cpp/tree/master/models)
26+
27+
#### 3. Prepare your files
28+
Place all the files in the ```./volume/input/``` directory
29+
30+
#### 4. Run the docker compose
31+
```
32+
docker compose up
33+
```
34+
Configure defaults
35+
```
36+
MODEL=large-v2 \
37+
LANGUAGE=ru \
38+
docker compose up
39+
```
40+
| Argument | Values | Defaults |
41+
| -------- | ------- |------- |
42+
| model | base, medium, large, [other options](https://github.com/ggerganov/whisper.cpp/blob/master/models/download-ggml-model.sh#L25) | large-v3
43+
| language | rn, ru, fr, etc. (depends on the model) | ru
44+
45+
#### 5. Result
46+
You can find the result in the ```./volume/output/``` directory

docker-compose.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
version: "3.3"
2+
3+
services:
4+
whisper-cpp:
5+
build:
6+
context: .
7+
stdin_open: true
8+
tty: true
9+
environment:
10+
- MODEL=${MODEL:-ggml-large-v3.bin}
11+
- LANGUAGE=${LANGUAGE:-ru}
12+
volumes:
13+
- ./models:/usr/local/src/whisper.cpp/models
14+
- ./volume:/usr/local/src/whisper.cpp/volume
15+
deploy:
16+
resources:
17+
reservations:
18+
devices:
19+
- driver: nvidia
20+
device_ids: ['0']
21+
capabilities: [gpu]
22+

models/download.sh

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#!/bin/bash
2+
3+
# This script downloads Whisper model files that have already been converted to ggml format.
4+
# This way you don't have to convert them yourself.
5+
6+
#src="https://ggml.ggerganov.com"
7+
#pfx="ggml-model-whisper"
8+
9+
src="https://huggingface.co/ggerganov/whisper.cpp"
10+
pfx="resolve/main/ggml"
11+
12+
# get the path of this script
13+
function get_script_path() {
14+
if [ -x "$(command -v realpath)" ]; then
15+
echo "$(dirname "$(realpath "$0")")"
16+
else
17+
local ret="$(cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P)"
18+
echo "$ret"
19+
fi
20+
}
21+
22+
models_path="$(get_script_path)"
23+
24+
# Whisper models
25+
models=(
26+
"tiny.en"
27+
"tiny"
28+
"tiny-q5_1"
29+
"tiny.en-q5_1"
30+
"base.en"
31+
"base"
32+
"base-q5_1"
33+
"base.en-q5_1"
34+
"small.en"
35+
"small.en-tdrz"
36+
"small"
37+
"small-q5_1"
38+
"small.en-q5_1"
39+
"medium"
40+
"medium.en"
41+
"medium-q5_0"
42+
"medium.en-q5_0"
43+
"large-v1"
44+
"large-v2"
45+
"large-v3"
46+
"large-q5_0"
47+
)
48+
49+
# list available models
50+
function list_models {
51+
printf "\n"
52+
printf " Available models:"
53+
for model in "${models[@]}"; do
54+
printf " $model"
55+
done
56+
printf "\n\n"
57+
}
58+
59+
if [ "$#" -ne 1 ]; then
60+
printf "Usage: $0 <model>\n"
61+
list_models
62+
63+
exit 1
64+
fi
65+
66+
model=$1
67+
68+
if [[ ! " ${models[@]} " =~ " ${model} " ]]; then
69+
printf "Invalid model: $model\n"
70+
list_models
71+
72+
exit 1
73+
fi
74+
75+
# check if model contains `tdrz` and update the src and pfx accordingly
76+
if [[ $model == *"tdrz"* ]]; then
77+
src="https://huggingface.co/akashmjn/tinydiarize-whisper.cpp"
78+
pfx="resolve/main/ggml"
79+
fi
80+
81+
# download ggml model
82+
83+
printf "Downloading ggml model $model from '$src' ...\n"
84+
85+
cd "$models_path"
86+
87+
if [ -f "ggml-$model.bin" ]; then
88+
printf "Model $model already exists. Skipping download.\n"
89+
exit 0
90+
fi
91+
92+
if [ -x "$(command -v curl)" ]; then
93+
curl -L --output ggml-$model.bin $src/$pfx-$model.bin
94+
elif [ -x "$(command -v wget)" ]; then
95+
wget --no-config --quiet --show-progress -O ggml-$model.bin $src/$pfx-$model.bin
96+
else
97+
printf "Either wget or curl is required to download models.\n"
98+
exit 1
99+
fi
100+
101+
102+
if [ $? -ne 0 ]; then
103+
printf "Failed to download ggml model $model \n"
104+
printf "Please try again later or download the original Whisper model files and convert them yourself.\n"
105+
exit 1
106+
fi
107+
108+
printf "Done! Model '$model' saved in 'models/ggml-$model.bin'\n"
109+
printf "You can now use it like this:\n\n"
110+
printf " $ ./main -m models/ggml-$model.bin -f samples/jfk.wav\n"
111+
printf "\n"

volume/input/.gitkeep

Whitespace-only changes.

volume/output/.gitkeep

Whitespace-only changes.

volume/transcribe.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
echo "[logger]: configuration"
3+
echo "${MODEL}"
4+
echo "${LANGUAGE}"
5+
6+
# Model verification
7+
echo "[logger]: model verification"
8+
if [ ! -f "./models/ggml-$MODEL.bin" ]; then
9+
echo "[logger]: model not found. downloading"
10+
./models/download.sh "$MODEL"
11+
else
12+
echo "[logger]: model found"
13+
fi
14+
15+
# Transcribe
16+
rm ./volume/output/*
17+
shopt -s nullglob
18+
for file in ./volume/input/*; do
19+
base_name=$(basename -- "$file")
20+
extension="${base_name##*.}"
21+
file_name="${base_name%.*}"
22+
echo "$file" "$file_name"
23+
24+
echo "[logger]: Covert to wav "$file_name""
25+
ffmpeg -i "$file" -ar 16000 "./volume/output/$file_name.wav"
26+
27+
echo "[logger]: Transcribe"
28+
./main -m "./models/ggml-$MODEL.bin" -f "./volume/output/$file_name.wav" --language "ru" -otxt -osrt
29+
done

0 commit comments

Comments
 (0)