# Base image FROM python:3.11 as base RUN apt-get update && apt-get install git -y RUN useradd -m -u 1000 user USER user # Set home to the user's home directory ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH # Set the working directory WORKDIR $HOME/app # =========================== # Stage 1: Install Dependencies # =========================== FROM base as dependencies # Copy only requirements.txt COPY --chown=user:user requirements.txt $HOME/app/ # Install CUDA-enabled PyTorch, torchvision, and torchaudio RUN pip install --user torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 # Install Python dependencies in a cacheable layer RUN pip install --user -r requirements.txt \ && pip install --user git+https://github.com/openai/CLIP.git # Copy requirements file and app files #COPY --chown=user:user requirements.txt $HOME/app/ #COPY --chown=user:user . $HOME/app/ #RUN chown -R user:user /app # Install dependencies # RUN pip install -r requirements.txt # RUN pip install git+https://github.com/openai/CLIP.git # =========================== # Stage 2: Final Build # =========================== FROM base as final # Copy the Python dependencies from the previous stage COPY --from=dependencies /home/user/.local /home/user/.local # Copy the rest of the application files COPY --chown=user:user . $HOME/app # Expose the application port EXPOSE 7860 # Run the application CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--reload"]