Spaces:
Sleeping
Sleeping
| # 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"] |