From 7d75b9acd60aebd62a78cbc6223cfbac19a914dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sp=C3=B6ttel?= <1682504+fspoettel@users.noreply.github.com> Date: Tue, 27 Jun 2023 20:20:12 +0200 Subject: [PATCH] feat: simplify docker files --- .env.dev | 2 +- README.md | 17 ++++++++++------- docker-compose.base.yml | 2 ++ docker-compose.dev.yml | 13 ++----------- docker-compose.prod.yml | 9 +-------- worker.gpu.Dockerfile | 2 +- 6 files changed, 17 insertions(+), 28 deletions(-) diff --git a/.env.dev b/.env.dev index f525fed..7505d9d 100644 --- a/.env.dev +++ b/.env.dev @@ -1,5 +1,5 @@ API_SECRET="a_very_secret_token" -DOMAIN="whisperbox-transcribe.localhost" +TRAEFIK_DOMAIN="whisperbox-transcribe.localhost" WHISPER_MODEL="tiny" ENVIRONMENT="development" DATABASE_URI="sqlite:///./whisperbox-transcribe.sqlite" diff --git a/README.md b/README.md index efb7174..3c5051f 100644 --- a/README.md +++ b/README.md @@ -4,30 +4,33 @@ ## Overview -This project wraps OpenAI's `whisper` models with a simple HTTP API. It is assumed that the service is used by exactly one consumer, so a pre-shared API key is used as authentication. +This project wraps OpenAI's `whisper` speech-to-text models with a HTTP API. -The API design takes inspiration from the [rev.ai async speech-to-text API](https://docs.rev.ai/api/asynchronous/get-started/). Transcription jobs are submitted via a `HTTP POST`, returning an internal reference, which can later be used to retrieve the transcription results. Results are stored in an internal database until retrieved, and can optionally be deleted afterwards. +The API design takes inspiration from the [rev.ai async speech-to-text API](https://docs.rev.ai/api/asynchronous/get-started/). Transcription jobs are submitted via a HTTP `POST` request. After the job is accepted, an id is returned, which can later be used to retrieve the transcription results from the service. Results are stored in an internal database until retrieved, and can optionally be deleted afterwards. -OpenAPI documentation for the service is available at `/docs`. +It is assumed that the service is used by exactly one consumer, so a pre-shared API key is used as authentication method. OpenAPI documentation for the service is available at `/docs`. ## Deploy ### 0. Choose model & instance size -Whisper provides [several sizes](https://github.com/openai/whisper#available-models-and-languages) of their model, where model size is a trade-off between model accuracy, resource usage and transcription speed. Smaller models are generally faster and lighter, but more inaccurate, especially for certain languages and translation tasks. +Whisper provides [several sizes](https://github.com/openai/whisper#available-models-and-languages) of their model where size is a trade-off between model accuracy, resource usage and transcription speed. Smaller models are generally faster and lighter, but more inaccurate, especially for non-english languages and translation tasks. -Whisper inference can be run on both CPU and GPU, and this project supports both via slightly altered docker compose configuration. (see GPU support section) CPU inference is a lot slower, but easier to host. CPU inference generally scales well with CPU speed. +Whisper inference can be run on both CPU and GPU, and this project supports both via slightly altered docker compose configurations. CPU inference is slower, but easier and cheaper to host. CPU inference, while overall slower than the GPU, generally scales well with CPU speed. -Another consideration when choosing an instance is disk size. In order to transcribe audio, it needs to be downloaded to a temporary folder before processing, so the HDD needs to have enough free space to allow for that. For some hosting environments (e.g. Digital Ocean), it can make sense to mount an additional disk in the VM instead of choosing a larger instance. +Another consideration when choosing your instance is disk size. In order to transcribe media, it first needs to be downloaded to a temporary file, so the HDD needs to have enough free space to allow for that. For some hosting environments (e.g. Digital Ocean), it can make sense to mount an additional disk in the VM instead of choosing a larger instance. As a baseline, the `small` model can run on a `4GB` Digital Ocean droplet, achieving roughly a 1-2x speedup over original audio when transcribing. ### 1. Prepare host environment This project is intended to be run via [docker compose](https://docs.docker.com/compose/). To get started: - 1. [install](https://docs.docker.com/engine/install/) docker engine. + 1. [Install](https://docs.docker.com/engine/install/) docker engine. 2. Clone this repository to the machine. + > **Note** + > If you want to use the GPU, uncomment the sections tagged with __ in docker-compose.prod.yml + ### 2. Configure service 2. Create an `.env` file from `.env.example` and configure it: diff --git a/docker-compose.base.yml b/docker-compose.base.yml index 0e8be50..f82e962 100644 --- a/docker-compose.base.yml +++ b/docker-compose.base.yml @@ -22,6 +22,7 @@ services: memory: 128M worker: + env_file: .env build: context: . dockerfile: worker.Dockerfile @@ -39,6 +40,7 @@ services: retries: 5 web: + env_file: .env build: context: . dockerfile: web.Dockerfile diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 3fe12ed..7a27abf 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -1,22 +1,17 @@ version: "3.8" +name: whisperbox-transcribe-dev services: traefik: - container_name: whisperbox-transcribe_traefik_dev ports: - "80:80" command: - "--providers.docker=true" - "--providers.docker.exposedbydefault=false" - - "--providers.docker.network=whisperbox-transcribe_traefik" + - "--providers.docker.network=whisperbox-transcribe-dev_traefik" - "--entrypoints.web.address=:80" - redis: - container_name: whisperbox-transcribe_redis_dev - web: - container_name: whisperbox-transcribe_web_dev - env_file: .env command: bash -c "alembic upgrade head && uvicorn app.web.main:app --reload --host ${HOST:-0.0.0.0} --port ${PORT:-8000} --log-level info" volumes: - ./:/etc/whisperbox-transcribe/ @@ -27,14 +22,11 @@ services: - "traefik.http.routers.web.rule=(Host(`${TRAEFIK_DOMAIN}`))" worker: - container_name: whisperbox-transcribe_worker_dev - env_file: .env command: watchmedo auto-restart -d app/worker -p *.py --recursive celery -- --app=app.worker.main.celery worker --loglevel=info --concurrency=1 --pool solo volumes: - ./:/etc/whisperbox-transcribe/ flower: - container_name: whisperbox-transcribe_flower_dev image: mher/flower command: celery --broker redis://redis:6379/0 flower --port=5555 ports: @@ -44,4 +36,3 @@ services: condition: service_healthy networks: - app - diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index 3b00828..3cced44 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -1,8 +1,8 @@ version: "3.8" +name: whisperbox-transcribe services: traefik: - container_name: whisperbox-transcribe_traefik ports: - "80:80" - "443:443" @@ -22,12 +22,7 @@ services: - ./data/letsencrypt:/letsencrypt - /var/run/docker.sock:/var/run/docker.sock:ro - redis: - container_name: whisperbox-transcribe_redis - worker: - container_name: whisperbox-transcribe_worker - env_file: .env # # build: # dockerfile: worker.gpu.Dockerfile @@ -43,8 +38,6 @@ services: # capabilities: [gpu] web: - container_name: whisperbox-transcribe_web - env_file: .env volumes: - whisperbox-transcribe-data:/etc/whisperbox-transcribe/data/ labels: diff --git a/worker.gpu.Dockerfile b/worker.gpu.Dockerfile index 9aa7f02..022e0c7 100644 --- a/worker.gpu.Dockerfile +++ b/worker.gpu.Dockerfile @@ -1,4 +1,4 @@ -# TODO: clean up lol +# TODO: clean up FROM nvidia/cuda:11.8.0-base-ubuntu22.04 AS python-deploy ENV PYTHON_VERSION=3.10