# ============================================================ # Math Search Engine — Hugging Face Spaces (Gradio SDK) # # This runs as a Python app. The React frontend is pre-built # and served as static files from FastAPI. # ============================================================ FROM python:3.11-slim # Install Node.js for building React frontend RUN apt-get update && \ apt-get install -y --no-install-recommends curl && \ curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \ apt-get install -y --no-install-recommends nodejs && \ apt-get clean && rm -rf /var/lib/apt/lists/* # Create non-root user (required by HF Spaces) RUN useradd -m -u 1000 appuser WORKDIR /app # ── Python backend dependencies ──────────────────────────── COPY Backend/requirements.txt /app/Backend/requirements.txt RUN pip install --no-cache-dir -r /app/Backend/requirements.txt # Download NLTK data RUN python -c "import nltk; nltk.download('punkt'); nltk.download('punkt_tab'); nltk.download('wordnet'); nltk.download('stopwords'); nltk.download('omw-1.4')" # ── Build React frontend ─────────────────────────────────── COPY Frontend/package.json Frontend/package-lock.json /app/Frontend/ RUN cd /app/Frontend && npm ci COPY Frontend/ /app/Frontend/ RUN cd /app/Frontend && npm run build # Clean up node_modules to save image size (~200 MB) RUN rm -rf /app/Frontend/node_modules # ── Copy backend source ──────────────────────────────────── COPY Backend/ /app/Backend/ # ── Copy datasets ────────────────────────────────────────── COPY Documents/ /app/Documents/ # ── Copy entry point ─────────────────────────────────────── COPY app.py /app/app.py # Give appuser ownership RUN chown -R appuser:appuser /app USER appuser # HF Spaces expects port 7860 EXPOSE 7860 CMD ["python", "app.py"]