Spaces:
Build error
Build error
# Use a specific Python 3.10 base image for better stability with faiss-cpu. | |
FROM python:3.10-slim-bookworm | |
# Set environment variables for non-buffered Python output and explicit Python path. | |
ENV PYTHONUNBUFFERED=1 | |
# Set the default Python executable for consistency. | |
ENV PATH="/usr/local/bin:${PATH}" | |
# Set the working directory inside the container. | |
WORKDIR /app | |
# Install essential system dependencies. | |
RUN apt-get update && apt-get install -y --no-install-recommends \ | |
git \ | |
git-lfs \ | |
ffmpeg \ | |
libsm6 \ | |
libxext6 \ | |
cmake \ | |
rsync \ | |
libgl1-mesa-glx \ | |
curl \ | |
&& rm -rf /var/lib/apt/lists/* \ | |
&& apt-get clean \ | |
&& git lfs install | |
# Install Node.js, which Gradio requires. | |
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \ | |
&& apt-get install -y nodejs \ | |
&& rm -rf /var/lib/apt/lists/* | |
# Create a non-root user and switch to it. | |
# This is a best practice for security and can resolve some permission-related issues. | |
RUN useradd -m -u 1000 user | |
USER user | |
# Copy requirements.txt and install Python dependencies. | |
# This is done before copying the rest of the app to leverage Docker layer caching. | |
COPY --chown=user:user requirements.txt . | |
# --- START OF CRITICAL INSTALLATION BLOCK --- | |
# Upgrade pip to the latest version. | |
RUN pip install --no-cache-dir --upgrade pip | |
# Install core deep learning and Gradio packages. | |
# Using --break-system-packages (if needed for pip 23.x+) to avoid default Python conflicts. | |
# The --target flag explicitly installs into site-packages, which should be on PYTHONPATH. | |
RUN pip install --no-cache-dir \ | |
torch==2.0.0 \ | |
sentence-transformers==2.5.1 \ | |
faiss-cpu==1.7.4 \ | |
gradio==4.28.3 \ | |
--index-url https://download.pytorch.org/whl/cpu && \ | |
pip install --no-cache-dir -r requirements.txt | |
# Verify installation with pip check and direct import. | |
RUN pip check || echo "pip check found issues!" | |
RUN python3 -c "try: import sentence_transformers; print('sentence_transformers imported successfully in build step!')\nexcept ImportError as e: print(f'Failed to import sentence_transformers in build step: {e}'); exit(1)" | |
# --- END OF CRITICAL INSTALLATION BLOCK --- | |
# Copy all your application files into the container, owned by the 'user'. | |
COPY --chown=user:user . . | |
# Define the command that will run your application when the Space starts. | |
# Using 'python3' explicitly. | |
CMD ["python3", "app.py"] |