Spaces:
Sleeping
Sleeping
File size: 1,776 Bytes
832e106 | 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 69 | # ================================
# PrecisionVoice Dockerfile
# Optimized for performance and size
# ================================
# Stage 1: Builder
FROM python:3.10-slim-bullseye AS builder
WORKDIR /app
# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
git \
ffmpeg \
libsndfile1-dev \
&& rm -rf /var/lib/apt/lists/*
# Copy requirements and install dependencies
# Using --user to keep packages in /root/.local
COPY requirements.txt .
RUN pip install --no-cache-dir --user -r requirements.txt
# ================================
# Stage 2: Runtime
# ================================
FROM python:3.10-slim-bullseye
WORKDIR /app
# Install runtime dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
ffmpeg \
libsndfile1 \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# Copy Python packages from builder
COPY --from=builder /root/.local /root/.local
# Ensure scripts in .local are available
ENV PATH=/root/.local/bin:$PATH
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
# Model cache directories
ENV HF_HOME=/root/.cache/huggingface
ENV TORCH_HOME=/root/.cache/torch
ENV TRANSFORMERS_CACHE=/root/.cache/huggingface
# Copy application code
COPY app/ ./app/
COPY data/ ./data/
# Create necessary directories
RUN mkdir -p /app/data/uploads /app/data/processed
# Port configuration
ARG PORT=7860
ENV PORT=${PORT}
EXPOSE ${PORT}
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:${PORT}/api/health')" || exit 1
# Run the application
CMD ["sh", "-c", "uvicorn app.main:app --host 0.0.0.0 --port ${PORT}"]
|