# Dockerfile for Hugging Face Spaces FROM python:3.10-slim # Add metadata for Hugging Face Spaces LABEL maintainer="AR Collection Agent Demo" LABEL description="Educational AI agent demonstration for accounts receivable collections" # Install system dependencies and clean up in one layer RUN apt-get update && apt-get install -y \ curl \ && rm -rf /var/lib/apt/lists/* \ && apt-get clean # Create user for Hugging Face Spaces RUN useradd -m -u 1000 user USER user # Set up environment ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH \ PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 WORKDIR $HOME/app # Copy requirements first for better layer caching COPY --chown=user requirements.txt . # Install Python dependencies with optimized flags RUN pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir --prefer-binary -r requirements.txt # Copy application files (excluding credentials via .dockerignore) COPY --chown=user . . # Set Gradio environment variables for Hugging Face Spaces ENV GRADIO_SERVER_NAME="0.0.0.0" \ GRADIO_SERVER_PORT="7860" \ GRADIO_THEME_CACHE_DIR="/tmp/gradio_cache" # Create necessary directories RUN mkdir -p /tmp/gradio_cache # Add health check for Hugging Face infrastructure HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ CMD curl -f http://localhost:7860/health || exit 1 # Expose port for Hugging Face Spaces EXPOSE 7860 # Run the application with proper signal handling CMD ["python", "-u", "app.py"]