From 5570a745f880c4e9a3423412fa7e24400d00b105 Mon Sep 17 00:00:00 2001 From: pluja Date: Fri, 27 Oct 2023 10:23:08 +0200 Subject: [PATCH] add support for GPU (cuda) --- backend/api/handlers.go | 7 +- docker-compose.ferret.yml | 3 +- docker-compose.gpu.yml | 119 ++++++++++++++++++ docker-compose.yml | 22 ++-- example.env | 7 +- .../components/ModalTranscriptionForm.svelte | 23 +++- frontend/src/lib/utils.js | 11 +- 7 files changed, 170 insertions(+), 22 deletions(-) create mode 100644 docker-compose.gpu.yml diff --git a/backend/api/handlers.go b/backend/api/handlers.go index 03b1ea9..ff877f1 100644 --- a/backend/api/handlers.go +++ b/backend/api/handlers.go @@ -87,8 +87,11 @@ func (s *Server) handlePostTranscription(c *fiber.Ctx) error { transcription.Status = models.TranscriptionStatusPending transcription.Task = "transcribe" transcription.SourceUrl = c.FormValue("sourceUrl") - // TODO: Implement other device types - transcription.Device = "cpu" + transcription.Device = c.FormValue("device") + if transcription.Device != "cpu" && transcription.Device != "cuda" { + log.Warn().Msgf("Device %v not supported, using cpu", transcription.Device) + transcription.Device = "cpu" + } log.Debug().Msgf("Transcription: %+v", transcription) // Save transcription to database diff --git a/docker-compose.ferret.yml b/docker-compose.ferret.yml index 98cc417..8be4eb3 100644 --- a/docker-compose.ferret.yml +++ b/docker-compose.ferret.yml @@ -90,7 +90,8 @@ services: environment: PUBLIC_INTERNAL_API_HOST: "http://nginx:80" PUBLIC_TRANSLATION_API_HOST: "" - PUBLIC_API_HOST: ${WHISHPER_PUBLIC_URL:-} + PUBLIC_API_HOST: ${WHISHPER_HOST:-} + PUBLIC_WHISHPER_GPU: ${WHISHPER_GPU:-false} depends_on: transcription-api: condition: service_healthy diff --git a/docker-compose.gpu.yml b/docker-compose.gpu.yml new file mode 100644 index 0000000..d2d9af2 --- /dev/null +++ b/docker-compose.gpu.yml @@ -0,0 +1,119 @@ +version: "3.9" + +services: + mongo: + image: mongo + env_file: + - .env + restart: unless-stopped + volumes: + - ./whishper_data/db_data:/data/db + - ./whishper_data/db_data/logs/:/var/log/mongodb/ + environment: + MONGO_INITDB_ROOT_USERNAME: ${DB_USER:-whishper} + MONGO_INITDB_ROOT_PASSWORD: ${DB_PASS:-whishper} + expose: + - 27017 + command: ['--logpath', '/var/log/mongodb/mongod.log'] + healthcheck: + test: mongosh --eval 'db.runCommand("ping").ok' --quiet + interval: 2s + timeout: 3s + retries: 5 + + translate: + container_name: whisper-libretranslate + image: libretranslate/libretranslate:latest + restart: unless-stopped + volumes: + - ./whishper_data/libretranslate/data:/home/libretranslate/.local/share + - ./whishper_data/libretranslate/cache:/home/libretranslate/.local/cache + env_file: + - .env + tty: true + environment: + LT_DISABLE_WEB_UI: True + #LT_UPDATE_MODELS: True + expose: + - 5000 + healthcheck: + test: ['CMD-SHELL', './venv/bin/python scripts/healthcheck.py'] + interval: 15s + timeout: 10s + start_period: 5s + retries: 5 + + transcription-api: + container_name: whisper-api + image: pluja/whishper-transcription-api:latest-gpu + env_file: + - .env + volumes: + - ./whishper_data/whisper_models:/app/models + - ./whishper_data/uploads:/app/uploads + environment: + - WHISPER_MODELS_DIR=/app/models + - UPLOAD_DIR=/app/uploads + restart: unless-stopped + expose: + - 8000 + deploy: + resources: + reservations: + devices: + - driver: nvidia + count: all + capabilities: [gpu] + + whishper-backend: + container_name: whishper-backend + image: pluja/whishper-backend:latest + env_file: + - .env + volumes: + - ./whishper_data/uploads:/app/uploads + restart: unless-stopped + environment: + - FERRETDB_MONGO_URL=mongodb://${DB_USER:-whishper}:${DB_PASS:-whishper}@mongo:27017/?authMechanism=PLAIN + depends_on: + translate: + condition: service_healthy + transcription-api: + condition: service_healthy + healthcheck: + test: curl --fail http://localhost:8080/api/transcriptions || exit 1 + interval: 15s + timeout: 10s + retries: 5 + start_period: 5s + expose: + - 8080 + + whishper-frontend: + container_name: whishper-web + image: pluja/whishper-frontend:latest + env_file: + - .env + restart: unless-stopped + environment: + PUBLIC_INTERNAL_API_HOST: "http://nginx:80" + PUBLIC_TRANSLATION_API_HOST: "" + PUBLIC_API_HOST: ${WHISHPER_HOST:-} + PUBLIC_WHISHPER_GPU: ${WHISHPER_GPU:-true} + depends_on: + transcription-api: + condition: service_healthy + expose: + - 3000 + + nginx: + image: nginx:1 + restart: unless-stopped + volumes: + - ./nginx.conf:/etc/nginx/nginx.conf + - ./whishper_data/uploads:/app/uploads + depends_on: + whishper-backend: + condition: service_healthy + ports: + - 8082:80 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 96800ac..09e06e4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,10 +17,9 @@ services: command: ['--logpath', '/var/log/mongodb/mongod.log'] healthcheck: test: mongosh --eval 'db.runCommand("ping").ok' --quiet - interval: 15s - timeout: 10s + interval: 2s + timeout: 3s retries: 5 - start_period: 5s translate: container_name: whisper-libretranslate @@ -39,9 +38,8 @@ services: - 5000 healthcheck: test: ['CMD-SHELL', './venv/bin/python scripts/healthcheck.py'] - interval: 15s - timeout: 10s - start_period: 5s + interval: 2s + timeout: 3s retries: 5 transcription-api: @@ -76,10 +74,9 @@ services: condition: service_healthy healthcheck: test: curl --fail http://localhost:8080/api/transcriptions || exit 1 - interval: 15s - timeout: 10s + interval: 2s + timeout: 2s retries: 5 - start_period: 5s expose: - 8080 @@ -90,9 +87,10 @@ services: - .env restart: unless-stopped environment: - INTERNAL_API_HOST: "http://nginx:80" - VITE_TRANSLATION_API_HOST: "" - VITE_API_HOST: ${WHISHPER_HOST:-} + PUBLIC_INTERNAL_API_HOST: "http://nginx:80" + PUBLIC_TRANSLATION_API_HOST: "" + PUBLIC_API_HOST: ${WHISHPER_HOST:-} + PUBLIC_WHISHPER_GPU: ${WHISHPER_GPU:-false} depends_on: transcription-api: condition: service_healthy diff --git a/example.env b/example.env index 95cee21..2790684 100644 --- a/example.env +++ b/example.env @@ -1,8 +1,11 @@ # Libretranslate Configuration -LT_LOAD_ONLY=es,en,fr +LT_LOAD_ONLY=es,ja,fr # Whisper Configuration WHISPER_MODELS=tiny,small -WHISHPER_HOST=localhost:8082 +WHISHPER_HOST=127.0.0.1:8082 +WHISHPER_GPU=false # true if you have cuda support, read https://whishper.net/guides/gpu + +# Database Configuration DB_USER=whishper DB_PASS=whishper \ No newline at end of file diff --git a/frontend/src/lib/components/ModalTranscriptionForm.svelte b/frontend/src/lib/components/ModalTranscriptionForm.svelte index 3a954f5..656acc8 100644 --- a/frontend/src/lib/components/ModalTranscriptionForm.svelte +++ b/frontend/src/lib/components/ModalTranscriptionForm.svelte @@ -1,5 +1,5 @@