You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on May 20, 2025. It is now read-only.
@@ -42,32 +47,29 @@ uv add openai-whisper --optional ml
42
47
We'll organize our project structure like so:
43
48
44
49
```text
45
-
+--src/
46
-
| +--__init__.py
47
-
| +--resources.py
48
-
| +--services/
49
-
| +--__init__.py
50
-
| +--main.py
51
-
| +--jobs/
52
-
| +--__init__.py
53
-
| +--api.pypy
54
-
+--nitric.yaml
55
-
+--docker/
56
-
| +-- transcribe.dockerfile
57
-
| +-- transcribe.dockerignore
58
-
| +-- python.dockerfile
59
-
| +-- python.dockerignore
50
+
+--common/
51
+
| +-- __init__.py
52
+
| +-- resources.py
53
+
+--batches/
54
+
| +-- transcribe.py
55
+
+--services/
56
+
| +-- api.py
60
57
+--.gitignore
61
58
+--.python-version
62
-
+--pyproject.toml
63
-
+--README.md
59
+
+-- pyproject.toml
60
+
+-- python.dockerfile
61
+
+-- python.dockerignore
62
+
+-- nitric.yaml
63
+
+-- transcribe.dockerfile
64
+
+-- transcribe.dockerignore
65
+
+-- README.md
64
66
```
65
67
66
68
## Define our resources
67
69
68
70
We'll start by creating a file to define our Nitric resources. For this project we'll need an API, Batch Job, and two buckets, one for the audio files to be transcribed and one for the resulting transcripts. The API will interface with the buckets, while the Batch Job will handle the transcription.
Now that we have defined resources, we can import our API and add some routes to access the buckets. Start by importing the resources and adding permissions to the resources.
from nitric.resources import BucketNotificationContext
89
91
from nitric.context import HttpContext
@@ -96,9 +98,9 @@ Nitric.run()
96
98
97
99
We'll then write a route for getting a file from the transcription bucket. These will get a signed download url and redirect the user to this url for downloading the text content.
We'll then read the audio file that is referenced in the `JobContext` data that was sent with the submit request. We'll write the podcast to a local file so that the model can read from it.
We'll then load our model and transcribe the audio. This is where we can choose the model based on balancing speed, size, and accuracy. We can turn off `FP16` with `fp16=False` which will use `FP32` instead. This will depend on what is supported on your CPU when testing locally, however, `FP16` and `FP32` are supported on Lambda.
With our code complete, we can write a dockerfile that our batch job will run in. Start with the base image that copies our application code and resolves the dependencies using `uv`.
295
297
296
-
```docker title:docker/transcribe.dockerfile
298
+
```docker title:transcribe.dockerfile
297
299
# The python version must match the version in .python-version
298
300
FROM ghcr.io/astral-sh/uv:python3.11-bookworm-slim AS builder
299
301
@@ -313,7 +315,7 @@ RUN --mount=type=cache,target=/root/.cache/uv \
313
315
314
316
The next stage is to build upon our base with another image with Nvidia drivers. We'll set some environment variables to enable GPU use and download Python 3.11 with apt.
315
317
316
-
```docker title:docker/transcribe.dockerfile
318
+
```docker title:transcribe.dockerfile
317
319
# !collapse(1:14) collapsed
318
320
FROM ghcr.io/astral-sh/uv:python3.11-bookworm-slim AS builder
319
321
@@ -350,7 +352,7 @@ RUN apt-get update -y && \
350
352
351
353
Finally, we'll get our application from the base image and run our application.
352
354
353
-
```docker title:docker/transcribe.dockerfile
355
+
```docker title:transcribe.dockerfile
354
356
# !collapse(1:31) collapsed
355
357
FROM ghcr.io/astral-sh/uv:python3.11-bookworm-slim AS builder
356
358
@@ -397,7 +399,7 @@ ENTRYPOINT python -u $HANDLER
397
399
398
400
We'll add a `dockerignore` to help reduce the size of the Docker Image that is being deployed.
399
401
400
-
```text title:docker/transcribe.dockerignore
402
+
```text title:transcribe.dockerignore
401
403
.mypy_cache/
402
404
.nitric/
403
405
.venv/
@@ -407,29 +409,23 @@ README.md
407
409
408
410
Finally, we can update the project file to point our batch job to our new dockerfile.
@@ -494,4 +490,4 @@ You can destroy the project once it is finished using `nitric down`.
494
490
495
491
In this guide, we've created a podcast transcription service using OpenAI Whisper and Nitric's Python SDK. We showed how to use batch jobs to run long-running workloads and connect these jobs to buckets to store generated transcripts. We also demonstrated how to expose buckets using simple CRUD routes on a cloud API. Finally, we were able to create dockerfiles with GPU support to optimize the generation speeds on the cloud.
496
492
497
-
For more information and advanced usage, refer to the [Nitric documentation](/docs).
493
+
For more information and advanced usage, refer to the [Nitric documentation](/).
0 commit comments