Spaces:
Sleeping
Sleeping
| # Build UI | |
| FROM node:20 AS ui-builder | |
| WORKDIR /app | |
| COPY package.json package-lock.json* ./ | |
| RUN npm install | |
| COPY . . | |
| RUN npm run build | |
| # Build AI | |
| FROM python:3.10-slim AS ai-builder | |
| WORKDIR /app | |
| COPY requirements.txt . | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| COPY app.py dataset.json ./ | |
| # Final image | |
| FROM nginx:latest | |
| # Install Python for backend and build tools for pip packages | |
| RUN apt-get update && \ | |
| apt-get install -y python3 python3-pip python3-venv build-essential pkg-config && \ | |
| rm -rf /var/lib/apt/lists/* | |
| # Copy UI build | |
| COPY --from=ui-builder /app/dist /usr/share/nginx/html | |
| # Copy AI app and requirements to /app BEFORE pip install | |
| COPY --from=ai-builder /app/app.py /app/dataset.json /app/ | |
| COPY requirements.txt /app/ | |
| # Custom Nginx config for reverse proxy | |
| COPY nginx.conf /etc/nginx/nginx.conf | |
| # Create and activate a virtual environment, then install requirements | |
| RUN python3 -m venv /venv | |
| ENV PATH="/venv/bin:$PATH" | |
| RUN pip install --no-cache-dir cython | |
| RUN pip install --no-cache-dir -r /app/requirements.txt | |
| # Expose port | |
| EXPOSE 7860 | |
| # Fix Nginx cache directory permissions | |
| RUN mkdir -p /var/cache/nginx && chmod 777 /var/cache/nginx | |
| # Start both Nginx and Flask | |
| CMD python /app/app.py & nginx -g 'daemon off;' | |