File size: 2,410 Bytes
ab1b928
 
 
 
 
 
 
 
 
 
 
 
 
f88dfcd
ab1b928
974325b
f88dfcd
 
ab1b928
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
974325b
bdef142
 
 
ab1b928
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0e56bd7
 
 
ab1b928
 
 
 
 
 
 
 
 
 
 
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
70
71
72
73
74
75
76
77
78
79
# ==========================================
# Builder Stage: Compile React Frontend
# ==========================================
FROM oven/bun:1-alpine AS frontend-builder
WORKDIR /app

# Monorepo — bun workspace with lockfile at repo root. Copy manifests first
# so `bun install` caches independently of source edits.
COPY package.json bun.lock ./
COPY frontend/package.json ./frontend/

RUN bun install --frozen-lockfile

# Copy frontend source (already patched for Docker same-origin serving)
COPY frontend/ ./frontend/

# Build static files (output lands in /app/frontend/dist)
RUN bun run --cwd frontend build

# ==========================================
# Runtime Stage: Python & PyTorch Backend
# ==========================================
FROM pytorch/pytorch:2.8.0-cuda12.8-cudnn9-runtime AS runtime
# Create a non-root user (Hugging Face Spaces requirement)
RUN useradd -m -u 1000 user
ENV HOME=/home/user
WORKDIR $HOME/app

# Enable unbuffered logs and optimizations
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV UV_SYSTEM_PYTHON=1
ENV HF_HOME=$HOME/app/omnivoice_data/huggingface
# Allow bare imports
ENV PYTHONPATH=$HOME/app/backend
# Allow all origins (HF Spaces iframe embedding)
ENV OMNIVOICE_ALLOWED_ORIGINS="*"
# Bind to 0.0.0.0 for Docker networking
ENV OMNIVOICE_BIND_HOST="0.0.0.0"

# Install system dependencies (FFmpeg is critical for torchaudio/scene splitting)
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    ffmpeg \
    libsndfile1 \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Install `uv` for blazing-fast reliable pip resolution
RUN pip install --no-cache-dir uv

# Copy python packaging specs
COPY pyproject.toml uv.lock README.md ./

# Install the project
RUN uv pip install --system --no-cache .  

# Copy application source
COPY backend/ ./backend/
COPY omnivoice/ ./omnivoice/

# Copy the pre-built React frontend from the builder stage
COPY --from=frontend-builder /app/frontend/dist ./frontend/dist

# Pre-create the data directory so it is owned by the non-root user
RUN mkdir -p $HOME/app/omnivoice_data/huggingface

# Set ownership to the non-root user
RUN chown -R user:user $HOME/app

# Switch to the non-root user
USER user

# Expose the single unified API and UI port
EXPOSE 3900

# Bind to 0.0.0.0 for external access
ENTRYPOINT ["uvicorn", "backend.main:app", "--host", "0.0.0.0", "--port", "3900"]