# Ankui Kazakh forced-alignment service — Hugging Face Docker Space. FROM python:3.12-slim RUN apt-get update && apt-get install -y --no-install-recommends ffmpeg && rm -rf /var/lib/apt/lists/* # HF Spaces run the container as uid 1000. RUN useradd -m -u 1000 user ENV HOME=/home/user \ HF_HOME=/home/user/hf \ TORCH_HOME=/home/user/torch \ ANKUI_ALIGN_HOST=0.0.0.0 \ ANKUI_ALIGN_PORT=7860 \ PYTHONUNBUFFERED=1 WORKDIR /home/user/app # CPU-only torch — the default CUDA build is ~2 GB and useless on a CPU Space. RUN pip install --no-cache-dir torch==2.8.0 torchaudio==2.8.0 \ --index-url https://download.pytorch.org/whl/cpu COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Copy align.py + transcription helpers + bake models BEFORE serve.py so # iterating on serve.py doesn't invalidate the (slow) model-download layer. COPY align.py truecase.py kk_names.txt convert_kkturbo.py ./ RUN chown -R user:user /home/user USER user # kk-turbo Whisper lives in the image at a local path (converted here at # build time — see convert_kkturbo.py — rather than uploaded pre-converted). ENV ANKUI_KKTURBO_MODEL=/home/user/app/models/kk-turbo-ct2 # Bake all models into the image so a cold start (after the free Space # sleeps) loads from disk instead of re-downloading: # - kk-turbo: convert the KSC2 Whisper fine-tune to CTranslate2/int8 # - MMS-1b Kazakh aligner + HDEMUCS separator (forced alignment /align) # - validate the transcriber loads from the converted dir RUN python convert_kkturbo.py && \ python -c "import align; align.load_model('cpu'); align.load_separator('cpu'); align.load_transcriber('cpu')" # structure.py is pure Python with no model dependencies, so it is copied here # rather than above: editing it must not invalidate the (slow) model-bake layer. COPY --chown=user serve.py structure.py ./ EXPOSE 7860 CMD ["python", "serve.py"]