File size: 1,144 Bytes
126d7e9
 
 
 
 
ff44ef4
 
 
 
 
 
 
85c1ab3
 
ff44ef4
 
 
 
 
 
 
 
 
 
126d7e9
 
 
ff44ef4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126d7e9
ff44ef4
85c1ab3
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
# Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
# you will also find guides on how best to write your Dockerfile

FROM python:3.9

# Stage 1: Build the React application
FROM node:20-slim AS builder

WORKDIR /app

# Copy package files and install dependencies
COPY package.json ./
# COPY package-lock.json ./ 
# Uncomment above if you have a lock file
RUN npm install

# Copy the rest of the application code
COPY . .

# Build the application (creates the 'dist' folder)
RUN npm run build

# Stage 2: Serve with Python FastAPI
FROM python:3.9-slim

WORKDIR /app

# Copy the build artifacts from the previous stage
COPY --from=builder /app/dist /app/dist

# Copy Python requirements and install them
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy the server script
COPY app.py .

# Create a user to run the application (standard for HF Spaces)
RUN useradd -m -u 1000 user
USER user
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH

# Expose the port (Hugging Face Spaces uses 7860)
EXPOSE 7860

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