Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
FROM python:3.10
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim AS base

FROM base AS model-downloader

# Pre-download Whisper model using ADD
ARG WHISPER_MODEL_URL=https://openaipublic.azureedge.net/main/whisper/models/345ae4da62f9b3d59415adc60127b97c714f32e89e936602e85993674d08dcb1/medium.pt
ARG WHISPER_MODEL=medium
RUN mkdir -p /root/.cache/whisper
ADD ${WHISPER_MODEL_URL} /root/.cache/whisper/${WHISPER_MODEL}.pt
RUN uv pip install --system faster-whisper
RUN python -c "from faster_whisper import WhisperModel; model = WhisperModel('${WHISPER_MODEL}', device='cpu')"

# Remove apt auto-clean hook to preserve cache
RUN rm -f /etc/apt/apt.conf.d/docker-clean
FROM base

# Install system dependencies with cache mount
RUN --mount=type=cache,target=/var/cache/apt \
--mount=type=cache,target=/var/lib/apt/lists \
apt update && apt install -y --no-install-recommends ffmpeg
# Copy model cache from first stage
COPY --from=model-downloader /root/.cache /root/.cache

# Copy uv binary
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv
Expand Down
30 changes: 22 additions & 8 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@

import dash
import dash_bootstrap_components as dbc
import torch
import whisper
from dash import Input, Output, State, dcc, html
from faster_whisper import WhisperModel

UPLOAD_FOLDER = tempfile.mkdtemp(dir=os.getcwd())

Expand Down Expand Up @@ -65,12 +64,27 @@ def write_srt(transcript: Iterator[dict], file: TextIO):


def translate_transcribe_file(file_path):
try:
model = whisper.load_model("medium")
except torch.OutOfMemoryError: # fallback
model = whisper.load_model("tiny", device="cpu")
translation = model.transcribe(file_path, language="no", task="translate")
transcription = model.transcribe(file_path, language="no")
model = WhisperModel("medium")

# Get translation segments
translation_segments, _ = model.transcribe(
file_path, language="no", task="translate"
)
translation = {
"segments": [
{"start": seg.start, "end": seg.end, "text": seg.text}
for seg in translation_segments
]
}

# Get transcription segments
transcription_segments, _ = model.transcribe(file_path, language="no")
transcription = {
"segments": [
{"start": seg.start, "end": seg.end, "text": seg.text}
for seg in transcription_segments
]
}

# Create temporary files for translation and transcription
with tempfile.NamedTemporaryFile(
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ requires-python = ">=3.8"
dependencies = [
"dash==2.14.0",
"dash-bootstrap-components>=1.5.0",
"openai-whisper>=20250625",
"faster-whisper>=1.1.0",
]

21 changes: 0 additions & 21 deletions utils/get_model_url.py

This file was deleted.

Loading