File size: 1,219 Bytes
a10a6c0
 
 
d3c87d2
a10a6c0
d3c87d2
a10a6c0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Stage 1: Build React frontend
FROM node:20-alpine AS build
WORKDIR /app/frontend
COPY frontend/package.json ./
RUN npm install

COPY frontend/ ./
RUN npm run build

# Stage 2: Create Python runtime image
FROM python:3.11-slim

# Create a non-root user with UID 1000 as required by Hugging Face Spaces
RUN useradd -m -u 1000 user
WORKDIR /home/user/app

# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    && rm -rf /var/lib/apt/lists/*

# Install python requirements
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy application files
COPY server.py socratic_graph.py ingest.py ingested_files.json ./
COPY utils/ ./utils/
COPY chroma_db/ ./chroma_db/
COPY data/ ./data/

# Copy React build artifacts
COPY --from=build /app/frontend/dist ./frontend/dist

# Set correct ownership for writing files (eval_logs.jsonl, data uploads, chromadb write operations)
RUN chown -R user:user /home/user/app

USER user

# Set environmental variables
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH

# Expose the port HF Spaces expects
EXPOSE 7860

CMD ["uvicorn", "server:app", "--host", "0.0.0.0", "--port", "7860"]