# Use a solid Python base (HF Spaces supports 3.10+) FROM python:3.11-slim # Environment variables for Python behavior ENV PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ PIP_NO_CACHE_DIR=1 \ HF_HOME="/huggingface" \ STREAMLIT_SERVER_ADDRESS=0.0.0.0 \ STREAMLIT_SERVER_PORT=7860 # Set workspace WORKDIR /app # System dependencies RUN apt-get update && apt-get install -y \ build-essential \ curl \ git \ && rm -rf /var/lib/apt/lists/* # Copy requirements first (to use Docker layer caching) COPY requirements.txt ./ # Install Python dependencies RUN pip install --upgrade pip && \ pip install --no-cache-dir -r requirements.txt && \ pip install --no-cache-dir "httpx<0.28" # Copy the rest of the application COPY . . # Create necessary directories RUN mkdir -p /app/.streamlit /app/db # Hugging Face Spaces uses port 7860 EXPOSE 7860 # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \ CMD curl -f http://localhost:7860/_stcore/health || exit 1 # Launch Streamlit on Spaces' port (7860) CMD ["streamlit", "run", "main.py", \ "--server.port=7860", \ "--server.address=0.0.0.0", \ "--server.headless=true", \ "--server.enableCORS=false", \ "--server.enableXsrfProtection=false", \ "--browser.gatherUsageStats=false"]