Spaces:
Running
Running
File size: 2,774 Bytes
0fd155c db3eaec 04a15c5 d34af22 49e0db8 04a15c5 0fd155c c9da99d 7d5387e 0fd155c c9da99d 9dbf344 97913c4 51ba1cb 9dbf344 611584f 90553eb 611584f 00db72b 04a15c5 0fd155c 04a15c5 c9da99d 0fd155c db3eaec 04a15c5 0fd155c c9da99d 0fd155c 3c1c3de 0fd155c 04a15c5 0fd155c 9dbf344 04a15c5 0fd155c 9dbf344 0fd155c 51ba1cb 0fd155c 9dbf344 0fd155c 9dbf344 |
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 |
# Stage 1: Build dependencies and download models
FROM public.ecr.aws/docker/library/python:3.12.11-slim-trixie AS builder
# Install Lambda web adapter in case you want to run with with an AWS Lamba function URL (not essential if not using Lambda)
#COPY --from=public.ecr.aws/awsguru/aws-lambda-adapter:0.8.4 /lambda-adapter /opt/extensions/lambda-adapter
# Install system dependencies
RUN apt-get update && rm -rf /var/lib/apt/lists/*
# Create directories (if needed for model download script)
RUN mkdir -p /model/rep /model/embed /install
WORKDIR /src
# Copy requirements file and install dependencies. Sentence transformers and Bertopic are installed without dependencies so that torch is not reinstalled.
COPY requirements_aws.txt .
RUN pip install torch>=2.6.0+cpu --target=/install --index-url https://download.pytorch.org/whl/cpu \
&& pip install --no-cache-dir --target=/install sentence-transformers>=5.1.2 --no-deps \
&& pip install --no-cache-dir --target=/install bertopic==0.17.3 --no-deps \
&& pip install --no-cache-dir --target=/install -r requirements_aws.txt \
&& pip install --no-cache-dir --target=/install gradio==5.49.1
# Add /install to the PYTHONPATH
ENV PYTHONPATH="/install:${PYTHONPATH}"
# Download models (using your download_model.py script)
COPY download_model.py /src/download_model.py
RUN python /src/download_model.py
RUN rm requirements_aws.txt download_model.py
# Stage 2: Final runtime image
FROM public.ecr.aws/docker/library/python:3.12.1-slim-trixie
# Create a non-root user
RUN useradd -m -u 1000 user
# Copy installed packages from builder stage
COPY --from=builder /install /usr/local/lib/python3.11/site-packages/
# Create necessary directories and set ownership
RUN mkdir -p /home/user/app/output /home/user/.cache/huggingface/hub /home/user/.cache/matplotlib /home/user/app/cache \
&& chown -R user:user /home/user
# Copy models from the builder stage
COPY --from=builder /model/rep /home/user/app/model/rep
COPY --from=builder /model/embed /home/user/app/model/embed
# Switch to the non-root user
USER user
# Set environment variables
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH \
PYTHONPATH=/home/user/app \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
GRADIO_ALLOW_FLAGGING=never \
GRADIO_NUM_PORTS=1 \
GRADIO_SERVER_NAME=0.0.0.0 \
GRADIO_SERVER_PORT=7860 \
GRADIO_THEME=huggingface \
AWS_STS_REGIONAL_ENDPOINT=regional \
GRADIO_OUTPUT_FOLDER='output/' \
NUMBA_CACHE_DIR=/home/user/app/cache \
SYSTEM=spaces
# Set working directory and copy application code
WORKDIR $HOME/app
COPY --chown=user . $HOME/app
# Command to run your application
CMD ["python", "app.py"] |