| # Use NVIDIA CUDA base image for GPU support on HuggingFace Spaces | |
| FROM nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu22.04 | |
| # Set environment variables | |
| ENV DEBIAN_FRONTEND=noninteractive \ | |
| PYTHONUNBUFFERED=1 \ | |
| GRADIO_SERVER_NAME=0.0.0.0 \ | |
| GRADIO_SERVER_PORT=7860 | |
| # Install system dependencies | |
| RUN apt-get update && apt-get install -y \ | |
| python3.10 \ | |
| python3-pip \ | |
| git \ | |
| curl \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Create symbolic link for python | |
| RUN ln -s /usr/bin/python3.10 /usr/bin/python | |
| # Set up user with ID 1000 (required by HuggingFace Spaces) | |
| RUN useradd -m -u 1000 user | |
| # Switch to user | |
| USER user | |
| # Set home and path | |
| ENV HOME=/home/user \ | |
| PATH=/home/user/.local/bin:$PATH | |
| # Set working directory | |
| WORKDIR $HOME/app | |
| # Upgrade pip | |
| RUN pip3 install --no-cache-dir --upgrade pip | |
| # Copy requirements and install (fix NumPy version first) | |
| COPY --chown=user requirements.txt . | |
| RUN pip3 install --no-cache-dir "numpy<2" && \ | |
| pip3 install --no-cache-dir -r requirements.txt | |
| # Copy application files | |
| COPY --chown=user app.py . | |
| COPY --chown=user README.md . | |
| # Create data directory for persistent storage | |
| RUN mkdir -p $HOME/app/data | |
| # Expose Gradio port | |
| EXPOSE 7860 | |
| # Health check | |
| HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ | |
| CMD curl -f http://localhost:7860/ || exit 1 | |
| # Run the Gradio application | |
| CMD ["python3", "app.py"] | |