math-engine / Dockerfile
rabie54654's picture
Deploy Math Search Engine
169aba7
Raw History Blame Contribute Delete
2.2 kB
# ============================================================
# 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"]