File size: 1,945 Bytes
a4bb334
 
 
 
 
 
 
 
 
 
1f6bb6b
0b65204
 
 
 
 
 
975eab2
0b65204
 
 
 
d30a2d9
89c3992
a4bb334
bd338cd
ef48146
3f23b61
 
0b65204
eb57b9f
bd338cd
 
eb57b9f
bd338cd
975eab2
eb57b9f
bd338cd
eb57b9f
 
bd338cd
0b65204
 
bd338cd
 
 
eb57b9f
bd338cd
 
975eab2
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
# Use a multi-stage build to handle uroman installation cleanly
# ---- Builder Stage for uroman ----
FROM python:3.10-slim as uroman-builder

# Install uroman via pip in a temporary stage
# This lets pip manage the download of the perl script
RUN pip install uroman==1.3.1.1

# ---- Final App Stage ----
FROM python:3.10-slim

# Set environment variables for caching to a writable directory
# These will be used by huggingface libraries to store models and other assets.
ENV HF_HOME=/data/huggingface
ENV TORCH_HOME=/data/torch
ENV TRANSFORMERS_CACHE=/data/huggingface/hub
ENV HF_DATASETS_CACHE=/data/huggingface/datasets

# Create the cache directories and make them writable by any user
RUN mkdir -p $TRANSFORMERS_CACHE $HF_DATASETS_CACHE $TORCH_HOME && \
    chmod -R 777 /data

# System deps for soundfile, audio encoding, and uroman
RUN apt-get update && apt-get install -y --no-install-recommends \
    libsndfile1 ffmpeg perl && \
    rm -rf /var/lib/apt/lists/*

# Copy the uroman script from the builder stage. It's placed in /usr/local/bin by pip.
COPY --from=uroman-builder /usr/local/bin/uroman /usr/local/bin/uroman

WORKDIR /app

# Install Python deps
COPY backend/requirements.txt /app/requirements.txt
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir -r /app/requirements.txt

# Copy app code
COPY backend/ /app/

# Optional: pre-cache the MMS model at build time to speed up first request
# This now uses the cache directory defined by the ENV variables.
RUN python -c "from transformers import VitsModel, AutoTokenizer; model_id = 'facebook/mms-tts-amh'; VitsModel.from_pretrained(model_id); AutoTokenizer.from_pretrained(model_id); print('Pre-cached MMS model')"

# Spaces expects the app to listen on $PORT (default 7860)
ENV PORT=7860
EXPOSE 7860

# Start the Flask app via gunicorn
CMD ["gunicorn", "app:app", "--bind", "0.0.0.0:7860", "--workers", "1", "--threads", "4", "--timeout", "300"]