File size: 1,233 Bytes
98ea022
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Use official python slim image
FROM python:3.10-slim

# Install system dependencies (ffmpeg is required for Whisper!)
RUN apt-get update && apt-get install -y \
    ffmpeg \
    git \
    && rm -rf /var/lib/apt/lists/*

# Set up user with UID 1000 (recommended by Hugging Face)
RUN useradd -m -u 1000 user
WORKDIR /app

# Copy requirements and install dependencies
COPY --chown=user requirements.txt /app/
RUN pip install --no-cache-dir -r requirements.txt

# Copy the rest of the application files
COPY --chown=user . /app/

# Create folders for history and cached models
RUN mkdir -p /app/data /app/static/audio && chown -R user:user /app

# Switch to the non-root user
USER user

# Set env variables
ENV PORT=7860
ENV HOME=/home/user
ENV TRANSFORMERS_CACHE=/home/user/.cache/huggingface

# Pre-download the Whisper base model and NLLB model/tokenizer to ensure instant startup
RUN python -c "import whisper; whisper.load_model('base')"
RUN python -c "from transformers import AutoTokenizer, AutoModelForSeq2SeqLM; AutoTokenizer.from_pretrained('facebook/nllb-200-distilled-600M'); AutoModelForSeq2SeqLM.from_pretrained('facebook/nllb-200-distilled-600M')"

# Expose port 7860
EXPOSE 7860

# Run the app
CMD ["python", "app.py"]