File size: 1,910 Bytes
88a679b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Use a lightweight python base image
FROM python:3.10-slim

# Set environment variables
ENV PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    DEBIAN_FRONTEND=noninteractive \
    PORT=7860

# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    ffmpeg \
    libsndfile1 \
    git \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Create a non-root user with UID 1000 (required for Hugging Face Spaces)
RUN useradd -m -u 1000 user

# Set up work directory and set ownership
WORKDIR /app
RUN chown user:user /app

# Switch to the non-root user
USER user
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH

# Copy requirements file first for caching
COPY --chown=user:user requirements-docker.txt /app/requirements-docker.txt

# Upgrade pip to ensure correct wheel tag resolution
RUN pip3 install --no-cache-dir --user --upgrade pip

# Install PyTorch CPU-only package (saves ~1.5GB of image size)
RUN pip3 install --no-cache-dir --user torch==2.5.1 torchaudio==2.5.1 --index-url https://download.pytorch.org/whl/cpu

# Install all other python requirements
RUN pip3 install --no-cache-dir --user -r /app/requirements-docker.txt

# Pre-download NLTK resources and ASR model weights to avoid runtime downloads/timeouts
RUN python3 -c "import nltk; nltk.download('averaged_perceptron_tagger_eng'); nltk.download('cmudict')"
RUN python3 -c "from transformers import Wav2Vec2Processor, Wav2Vec2ForCTC; Wav2Vec2Processor.from_pretrained('MihirRPatil/nptel-asr-phoneme-v3'); Wav2Vec2ForCTC.from_pretrained('MihirRPatil/nptel-asr-phoneme-v3')"

# Copy the entire project codebase
COPY --chown=user:user . /app

# Generate the Prisma client for Python
RUN prisma generate --schema=/app/product/backend/prisma/schema.prisma

# Expose the default Hugging Face Spaces port
EXPOSE 7860

# Command to run the application
CMD ["python3", "product/backend/app.py"]