File size: 1,223 Bytes
7339046
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ba9111a
7339046
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
FROM python:3.11-slim

# Prevent Python from writing .pyc files and buffer stdout
ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    DEBIAN_FRONTEND=noninteractive

# Install system deps: libsndfile for soundfile, build-essential for torch
RUN apt-get update && apt-get install -y --no-install-recommends \
    libsndfile1 \
    build-essential \
    && rm -rf /var/lib/apt/lists/*

# Create non-root user (UID 1000 required by HF Spaces Dev Mode)
RUN useradd -m -u 1000 user

# Install uv for faster pip installs
RUN pip install --no-cache-dir uv

# Install PyTorch with CUDA support (GPU Space)
RUN uv pip install --system --no-cache-dir \
    torch \
    torchaudio \
    && uv cache clean

# Install app dependencies
WORKDIR /app
COPY --chown=user ./requirements.txt .
RUN uv pip install --system --no-cache-dir -r requirements.txt \
    && uv cache clean

# Copy application code and model files
COPY --chown=user . .

# Redirect HF/torch caches to /tmp (only writable directory on Spaces)
ENV HF_HOME=/tmp/hf_cache \
    TORCH_HOME=/tmp/hf_cache/torch

# Switch to non-root user
USER user

# Expose the expected HF Spaces port
EXPOSE 7860

CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]