File size: 1,614 Bytes
49aea4b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58f623a
fb45033
49aea4b
58f623a
fb45033
49aea4b
58f623a
 
fb45033
58f623a
49aea4b
 
 
 
 
 
 
 
 
 
 
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
# Use a lightweight Python 3.10 base image
FROM python:3.10-slim

# Hugging Face Spaces requires running as a non-root user (UID 1000)
RUN useradd -m -u 1000 user

# Set working directory and change ownership to the non-root user
WORKDIR /app
RUN chown user:user /app

# Switch to the non-root user
USER user
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH \
    PYTHONPATH=/app

# Install system dependencies (must switch to root temporarily)
USER root
RUN apt-get update && apt-get install -y \
    build-essential \
    libgdal-dev \
    git \
    git-lfs \
    && rm -rf /var/lib/apt/lists/*
USER user

# 1. Install PyTorch FIRST (Required for PyG C++ extensions)
RUN pip install --no-cache-dir --user torch==2.10.0 torchvision==0.25.0 --extra-index-url https://download.pytorch.org/whl/cpu

# 2. Install PyTorch Geometric dependencies (Sparse/Scatter) natively from PyG wheel index
RUN pip install --no-cache-dir --user torch-scatter torch-sparse -f https://data.pyg.org/whl/torch-2.10.0+cpu.html

# 3. Copy requirements and install the rest (It will skip torch and torch-scatter since they are already installed)
COPY --chown=user:user requirements.txt .
RUN pip install --no-cache-dir --user -r requirements.txt -f https://data.pyg.org/whl/torch-2.10.0+cpu.html

# Copy the rest of the application
COPY --chown=user:user . .

# Ensure correct permissions for the Pyoxigraph Knowledge Graph storage
RUN chmod -R 777 /app || true

# Expose port for Hugging Face Spaces
EXPOSE 7860

# Command to run the FastAPI server
CMD ["python", "chatbot/chat_server.py", "--host", "0.0.0.0", "--port", "7860"]