Spaces:
Running
on
A100
Running
on
A100
File size: 5,139 Bytes
ae238b3 |
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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# Frontend build stage
FROM node:18-alpine AS frontend-build
# Google Analytics build args
ARG VITE_ENABLE_ANALYTICS
ARG VITE_REACT_APP_GOOGLE_ANALYTICS_ID
ARG VITE_ALLOW_ALL_LANGUAGES
# Make build args available as environment variables during build
ENV VITE_ENABLE_ANALYTICS=${VITE_ENABLE_ANALYTICS}
ENV VITE_REACT_APP_GOOGLE_ANALYTICS_ID=${VITE_REACT_APP_GOOGLE_ANALYTICS_ID}
ENV VITE_ALLOW_ALL_LANGUAGES=${VITE_ALLOW_ALL_LANGUAGES}
WORKDIR /app/frontend
COPY frontend/package.json frontend/package-lock.json* ./
RUN npm install
COPY frontend/ ./
RUN npm run build
# Dockerfile to support Translations API Build - works locally and on Hugging Face Spaces
FROM nvidia/cuda:12.4.0-runtime-ubuntu22.04 as base
ENV PYTHON_VERSION=3.10 \
PYTHON_VERSION_SHORT=310
RUN apt-get update && apt-get upgrade -y
# Install system packages including audio processing libraries
RUN apt-get install -y \
build-essential \
wget \
python${PYTHON_VERSION} \
python3-pip \
libpq-dev
#Constants
ENV PYTHONUNBUFFERED TRUE
ARG DEBIAN_FRONTEND=noninteractive
# Set up user with UID 1000 for HF Spaces compatibility
RUN useradd -m -u 1000 user
# Install base utilities, linux packages, and audio processing libraries
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
fakeroot \
ca-certificates \
curl \
vim \
ssh \
wget \
gcc \
git \
ffmpeg \
libsndfile1 \
libsox-fmt-all \
sox \
libavcodec-extra && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Install miniconda
ENV CONDA_DIR /opt/conda
# Put conda in path and install
ENV PATH=$CONDA_DIR/bin:$PATH
RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh \
&& /bin/bash ~/miniconda.sh -b -p /opt/conda
RUN conda config --set auto_activate_base false && \
conda config --set channel_priority flexible && \
mkdir -p ~/.conda && \
echo "channel_priority: flexible" > ~/.condarc && \
conda config --add channels conda-forge && \
conda config --set remote_max_retries 5 && \
conda config --set remote_connect_timeout_secs 30 && \
conda config --set remote_read_timeout_secs 30 && \
conda config --set show_channel_urls True && \
conda config --set auto_update_conda False && \
conda config --set notify_outdated_conda False && \
conda config --set report_errors False && \
conda config --set always_yes True && \
conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/main && \
conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/r && \
conda clean -afy
RUN conda config --set channel_priority false && \
conda create -n transcriptions-api python=${PYTHON_VERSION} -y && \
conda install -n transcriptions-api -c conda-forge \
libsndfile=1.0.31 \
numpy \
scipy \
-y
# Enable conda
SHELL ["conda", "run", "-n", "transcriptions-api", "/bin/bash", "-c"]
# Set up working directory and environment for user
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH
WORKDIR $HOME/app
# Copy requirements.txt and wheel file before installing dependencies
COPY --chown=user server/requirements.txt ./
COPY --chown=user server/wheels/omnilingual_asr-0.1.0-py3-none-any.whl ./
# Install MMS library from local wheel file
RUN pip install omnilingual_asr-0.1.0-py3-none-any.whl
# Install Python dependencies with proper conda activation
RUN pip install -r requirements.txt
# Install debugpy for development debugging
RUN pip install debugpy
# Copy server code into the image with proper ownership
COPY --chown=user ./server $HOME/app/server
# Copy frontend build from the frontend-build stage
COPY --from=frontend-build --chown=user /app/frontend/dist $HOME/app/frontend/dist
# Make scripts executable and create directories with proper ownership
RUN chmod +x $HOME/app/server/run.sh $HOME/app/server/download_models.sh && \
mkdir -p $HOME/app/models && \
chown -R user:user $HOME/app && \
chmod -R 755 $HOME/app
# Switch to user for runtime
USER user
# Create /data/models and if possible (for HF Spaces)
RUN mkdir -p /data/models 2>/dev/null || true
# Set working directory to server
WORKDIR $HOME/app/server
# Expose port 7860 for HF Spaces (also works locally)
EXPOSE 7860
# For production: pre-download models into the image (optional)
# Uncomment the following lines if you want models baked into the production image
# RUN mkdir -p $HOME/app/models
# RUN cd $HOME/app/models && \
# wget -O ctc_alignment_mling_uroman_model_dict.txt https://dl.fbaipublicfiles.com/mms/torchaudio/ctc_alignment_mling_uroman/dictionary.txt && \
# wget -O ctc_alignment_mling_uroman_model.pt https://dl.fbaipublicfiles.com/mms/torchaudio/ctc_alignment_mling_uroman/model.pt && \
# wget https://dl.fbaipublicfiles.com/mms/mms_1143_langs_tokenizer_spm.model && \
# wget https://dl.fbaipublicfiles.com/mms/mms_XRI.pt
# Default command - works for both local and HF Spaces
CMD ["conda", "run", "--no-capture-output", "-n", "transcriptions-api", "./run.sh"]
|