diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 66e0b012..ecfd8317 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -113,6 +113,7 @@ jobs: if: ${{ matrix.skip_pytests != 'true' }} env: ML_BACKEND: ${{ matrix.backend_dir_name }} + TEST_ENV: "true" run: | docker compose -f label_studio_ml/examples/${{ matrix.backend_dir_name }}/docker-compose.yml exec -T ${{ matrix.backend_dir_name }} pytest -vvv --cov --cov-report=xml:/tmp/coverage.xml diff --git a/label_studio_ml/examples/deepgram/Dockerfile b/label_studio_ml/examples/deepgram/Dockerfile new file mode 100644 index 00000000..c7ff2c5c --- /dev/null +++ b/label_studio_ml/examples/deepgram/Dockerfile @@ -0,0 +1,48 @@ +# syntax=docker/dockerfile:1 +ARG PYTHON_VERSION=3.13 + +FROM python:${PYTHON_VERSION}-slim AS python-base +ARG TEST_ENV + +WORKDIR /app + +ENV PYTHONUNBUFFERED=1 \ + PYTHONDONTWRITEBYTECODE=1 \ + PORT=${PORT:-9090} \ + PIP_CACHE_DIR=/.cache \ + WORKERS=1 \ + THREADS=8 + +# Update the base OS +RUN --mount=type=cache,target="/var/cache/apt",sharing=locked \ + --mount=type=cache,target="/var/lib/apt/lists",sharing=locked \ + set -eux; \ + apt-get update; \ + apt-get upgrade -y; \ + apt install --no-install-recommends -y \ + git; \ + apt-get autoremove -y + +# install base requirements +COPY requirements-base.txt . +RUN --mount=type=cache,target=${PIP_CACHE_DIR},sharing=locked \ + pip install -r requirements-base.txt + +# install custom requirements +COPY requirements.txt . +RUN --mount=type=cache,target=${PIP_CACHE_DIR},sharing=locked \ + pip install -r requirements.txt + +# install test requirements if needed +COPY requirements-test.txt . +# build only when TEST_ENV="true" +RUN --mount=type=cache,target=${PIP_CACHE_DIR},sharing=locked \ + if [ "$TEST_ENV" = "true" ]; then \ + pip install -r requirements-test.txt; \ + fi + +COPY . . + +EXPOSE 9090 +CMD gunicorn --preload --bind :$PORT --workers $WORKERS --threads $THREADS --timeout 0 _wsgi:app + diff --git a/label_studio_ml/examples/deepgram/README.md b/label_studio_ml/examples/deepgram/README.md new file mode 100644 index 00000000..a7b89248 --- /dev/null +++ b/label_studio_ml/examples/deepgram/README.md @@ -0,0 +1,35 @@ + +# Using Deepgram with Label Studio for Text to Speech annotation + +This backend uses the Deepgram API to take the input text from the user, do text to speech, and return the output audio for annotation in Label Studio. + +https://github.com/user-attachments/assets/9569a955-0baf-4a95-9e8a-d08250a0a298 + + +IMPORTANT NOTE: YOU MUST REFRESH THE PAGE AFTER SUBMITTING THE TEXT TO SEE THE AUDIO APPEAR. + +## Prerequistes +1. [Deepgram API Key](https://deepgram.com/) -- create an account and follow the instructions to get an api key with default permissions. Store this key as `DEEPGRAM_API_KEY` in `docker_compose.yml` +2. AWS Storage -- make sure you configure the following parameters in `docker_compose.yml`: + - `AWS_ACCESS_KEY_ID` -- your AWS access key id + - `AWS_SECRET_ACCESS_KEY` -- your AWS secret access key + - `AWS_SESSION_TOKEN` -- your AWS session token + - `AWS_DEFAULT_REGION` - the region you want to use for S3 + - `S3_BUCKET` -- the name of the bucket where you'd like to store the created audio files + - `S3_FOLDER` -- the name of the folder within the specified bucket where you'd like to store the audio files. +3. Label Studio -- make sure you set your `LABEL_STUDIO_URL` and your `LABEL_STUDIO_API_KEY` in `docker_compose.yml`. As of 11/12/25, you must use the LEGACY TOKEN. + +## Labeling Config +This is the base labeling config to be used with this backend. Note that you may add additional annotations to the document after the audio without breaking anything! +``` + +
+