# Use a lightweight Python image FROM python:3.9-slim # Install system dependencies including supervisor RUN apt-get update && apt-get install -y supervisor && rm -rf /var/lib/apt/lists/* # Set the working directory WORKDIR /app # Copy the requirements file from the root of the uploaded content COPY requirements.txt . # Install Python dependencies RUN pip install --no-cache-dir -r requirements.txt # Copy the application files and the model file from the root of the uploaded content COPY app.py . COPY streamlit_app.py . COPY best_model.joblib . # Copy the model file # Create the supervisord configuration files RUN mkdir -p /etc/supervisor/conf.d RUN echo "[supervisord]\n" > /etc/supervisor/supervisord.conf && \ echo "nodaemon=true\n" >> /etc/supervisor/supervisord.conf # Flask application configuration RUN echo "[program:flask_app]\n" >> /etc/supervisor/conf.d/flask_app.conf && \ echo "command=gunicorn --bind 0.0.0.0:5000 app:app\n" >> /etc/supervisor/conf.d/flask_app.conf && \ echo "directory=/app\n" >> /etc/supervisor/conf.d/flask_app.conf && \ echo "autostart=true\n" >> /etc/supervisor/conf.d/flask_app.conf && \ echo "autorestart=true\n" >> /etc/supervisor/conf.d/flask_app.conf && \ echo "stderr_logfile=/dev/stderr\n" >> /etc/supervisor/conf.d/flask_app.conf && \ echo "stdout_logfile=/dev/stdout\n" >> /etc/supervisor/conf.d/flask_app.conf # Streamlit application configuration RUN echo "[program:streamlit_app]\n" >> /etc/supervisor/conf.d/streamlit_app.conf && \ echo "command=streamlit run streamlit_app.py --server.port 7860 --server.address 0.0.0.0\n" >> /etc/supervisor/conf.d/streamlit_app.conf && \ echo "directory=/app\n" >> /etc/supervisor/conf.d/streamlit_app.conf && \ echo "autostart=true\n" >> /etc/supervisor/conf.d/streamlit_app.conf && \ echo "autorestart=true\n" >> /etc/supervisor/conf.d/streamlit_app.conf && \ echo "stderr_logfile=/dev/stderr\n" >> /etc/supervisor/conf.d/streamlit_app.conf && \ echo "stdout_logfile=/dev/stdout\n" >> /etc/supervisor/conf.d/streamlit_app.conf # Expose the Streamlit port (Hugging Face Spaces expects 7860 for Streamlit) EXPOSE 7860 # Expose the Flask port (used internally within Docker) EXPOSE 5000 # Command to run supervisord CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]