# Dockerfile for Hugging Face Spaces - Streamlit App FROM python:3.9-slim # Create user for security RUN useradd -m -u 1000 user USER user # Set environment variables ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH \ PYTHONPATH=$HOME/app \ PYTHONUNBUFFERED=1 # Set working directory WORKDIR $HOME/app # Copy requirements first for better Docker layer caching COPY --chown=user:user requirements.txt . # Install Python dependencies RUN pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir --user -r requirements.txt # Copy the application files COPY --chown=user:user . . # Create necessary directories RUN mkdir -p $HOME/.streamlit # Create Streamlit config RUN echo "\ [general]\n\ email = \"\"\n\ " > $HOME/.streamlit/credentials.toml RUN echo "\ [server]\n\ headless = true\n\ enableCORS = false\n\ enableXsrfProtection = false\n\ port = 7860\n\ " > $HOME/.streamlit/config.toml # Expose the port that Hugging Face Spaces expects EXPOSE 7860 # Health check HEALTHCHECK CMD curl --fail http://localhost:7860/_stcore/health # Command to run the Streamlit app CMD ["streamlit", "run", "app.py", "--server.port=7860", "--server.address=0.0.0.0"]