File size: 2,424 Bytes
f0b73e2
 
806f191
c68d774
8176759
89fcea9
 
8176759
4733482
806f191
 
4733482
806f191
 
 
 
 
 
 
 
 
 
 
89fcea9
806f191
 
4733482
806f191
 
89fcea9
 
 
 
 
 
806f191
89fcea9
 
 
806f191
2326eea
c68d774
 
 
 
89fcea9
 
c68d774
806f191
f0b73e2
806f191
4733482
89fcea9
 
f0b73e2
89fcea9
 
f0b73e2
2326eea
806f191
89fcea9
 
806f191
 
89fcea9
c68d774
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
# 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"]