FROM python:3.11-slim # Set working directory WORKDIR /app # Install system dependencies RUN apt-get update && apt-get install -y \ gcc \ g++ \ && rm -rf /var/lib/apt/lists/* # Copy requirements first for better caching COPY requirements.txt . # Install Python packages RUN pip install --no-cache-dir -r requirements.txt # Copy the entire application COPY . . # Create necessary directories with write permissions RUN mkdir -p uploads saved_sessions .streamlit RUN chmod -R 777 uploads saved_sessions # Create Streamlit config to fix 403 error RUN echo '[server]' > .streamlit/config.toml && \ echo 'maxUploadSize = 200' >> .streamlit/config.toml && \ echo 'enableCORS = true' >> .streamlit/config.toml && \ echo 'enableXsrfProtection = false' >> .streamlit/config.toml && \ echo 'address = "0.0.0.0"' >> .streamlit/config.toml && \ echo 'port = 7860' >> .streamlit/config.toml && \ echo '' >> .streamlit/config.toml && \ echo '[browser]' >> .streamlit/config.toml && \ echo 'gatherUsageStats = false' >> .streamlit/config.toml && \ echo '' >> .streamlit/config.toml && \ echo '[theme]' >> .streamlit/config.toml && \ echo 'base = "dark"' >> .streamlit/config.toml && \ echo 'primaryColor = "#00ff9d"' >> .streamlit/config.toml && \ echo 'backgroundColor = "#0a0e17"' >> .streamlit/config.toml && \ echo 'secondaryBackgroundColor = "#111827"' >> .streamlit/config.toml && \ echo 'textColor = "#e8e8e8"' >> .streamlit/config.toml # Create a user for security RUN useradd -m -u 1000 user USER user # Set environment variables ENV HOME=/home/user ENV PATH=/home/user/.local/bin:$PATH ENV PYTHONUNBUFFERED=1 # Copy files with correct ownership WORKDIR $HOME/app COPY --chown=user . $HOME/app # Ensure directories exist and have correct permissions RUN mkdir -p uploads saved_sessions RUN chmod -R 777 uploads saved_sessions # Expose the port Hugging Face Spaces uses EXPOSE 7860 # Health check HEALTHCHECK CMD curl --fail http://localhost:7860/_stcore/health || exit 1 # Run the Streamlit app CMD ["streamlit", "run", "app/main.py", "--server.port=7860", "--server.address=0.0.0.0"]