File size: 1,030 Bytes
1344296
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Unified Dockerfile for Hugging Face Spaces
# Stage 1: Build the frontend
FROM node:25-slim AS build-ui
WORKDIR /app/ui
COPY ui/package*.json ./
RUN npm install
COPY ui/ ./
RUN npm run build

# Stage 2: Final Image
FROM python:3.12-slim
WORKDIR /app

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

# Create a non-root user for Hugging Face (UID 1000)
RUN useradd -m -u 1000 user
USER user
ENV PATH="/home/user/.local/bin:$PATH"

# Install Python dependencies
COPY --chown=user api/requirements.txt .
RUN pip install --no-cache-dir --user -r requirements.txt

# Copy backend code
COPY --chown=user api/ ./

# Copy built frontend from Stage 1 to the 'dist' folder
COPY --from=build-ui --chown=user /app/ui/dist ./dist

# Hugging Face Spaces uses port 7860
EXPOSE 7860

# Run setup and start the API
# We ensure models are installed in user space
CMD ["sh", "-c", "python setup_models.py && uvicorn main:app --host 0.0.0.0 --port 7860"]