File size: 2,031 Bytes
c562596 ce9fbaa cb4d881 c562596 cb4d881 ce9fbaa 7d8d72d ce9fbaa c562596 ce9fbaa 7d8d72d c562596 7d8d72d ce9fbaa 7d8d72d c562596 0b083c6 7d8d72d cb4d881 0b083c6 7d8d72d 0b083c6 c562596 cb4d881 7d8d72d c562596 7d8d72d cb4d881 ce9fbaa cb4d881 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | # Multi-stage Dockerfile for Hugging Face Spaces (with model pre-caching)
# =============================================================================
# Stage 1: Frontend build (Node + Vite)
# =============================================================================
FROM node:20-alpine AS frontend-build
WORKDIR /frontend
COPY frontend/package.json frontend/package-lock.json* ./
RUN npm ci
COPY frontend/ ./
ARG VITE_API_BASE_URL=/api
ENV VITE_API_BASE_URL=$VITE_API_BASE_URL
RUN npm run build
# =============================================================================
# Stage 2: Python backend (FastAPI + static files + pre-cached models)
# =============================================================================
FROM python:3.12-slim-bookworm
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PYTHONPATH=/app \
HF_HOME=/app/.cache/huggingface \
TRANSFORMERS_CACHE=/app/.cache/huggingface \
HF_HUB_CACHE=/app/.cache/huggingface/hub \
PIP_NO_CACHE_DIR=1
WORKDIR /app
# System dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
build-essential \
ffmpeg \
libsndfile1 \
curl \
&& rm -rf /var/lib/apt/lists/*
# Install Python dependencies
COPY backend/requirements.txt ./backend/requirements.txt
RUN pip install --no-cache-dir -r backend/requirements.txt
# Copy backend code
COPY backend ./backend
COPY app ./app
COPY constants ./constants
# Pre-download the Diac model into the image cache (avoids first-boot download issues on HF)
RUN mkdir -p /app/.cache/huggingface/hub && \
python -c "from huggingface_hub import snapshot_download; \
snapshot_download('rufaelfekadu/diac-transformer-text-asr-tashkeela-clartts', \
cache_dir='/app/.cache/huggingface/hub')"
# Copy built frontend from Stage 1
COPY --from=frontend-build /frontend/dist ./static
# Make cache writable
RUN chmod -R 777 /app/.cache
EXPOSE 7860
CMD ["uvicorn", "backend.app.main:app", "--host", "0.0.0.0", "--port", "7860"]
|