# 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"]