FROM python:3.11-slim WORKDIR /services/app_service # System packages for video/image processing and OpenCV runtime RUN apt-get update && apt-get install -y \ ffmpeg \ curl \ git \ git-lfs \ libgl1 \ libglib2.0-0 \ && rm -rf /var/lib/apt/lists/* \ && git lfs install # Reduce build-time and run-time memory usage and set writable config dirs ENV PIP_NO_CACHE_DIR=1 \ PIP_ROOT_USER_ACTION=ignore \ OMP_NUM_THREADS=1 \ MKL_NUM_THREADS=1 \ HOME=/tmp \ XDG_CACHE_HOME=/tmp/.cache \ MPLCONFIGDIR=/tmp/matplotlib \ YOLO_CONFIG_DIR=/tmp/Ultralytics \ STREAMLIT_BROWSER_GATHER_USAGE_STATS=false # Create config/cache dirs to avoid permission issues RUN mkdir -p /tmp/.streamlit /tmp/.cache /tmp/matplotlib /tmp/Ultralytics \ && chmod -R 777 /tmp/.streamlit /tmp/.cache /tmp/matplotlib /tmp/Ultralytics # Python deps (CPU-only PyTorch wheels) RUN python -m pip install --upgrade pip setuptools wheel && \ pip install --no-cache-dir \ streamlit==1.49.1 \ moviepy==2.2.1 \ pillow>=10.0.0 \ ultralytics==8.0.196 \ torch==2.5.1 torchvision==0.20.1 --extra-index-url https://download.pytorch.org/whl/cpu # Copy entire repository and download script COPY . /tmp/repo WORKDIR /tmp/repo # Pull LFS files and copy app service RUN git lfs pull && cp -r services/app_service/* /services/app_service/ WORKDIR /services/app_service # Ensure app directory is writable at runtime RUN chmod -R 777 /services/app_service # Streamlit config via env ENV STREAMLIT_SERVER_ENABLECORS=false \ STREAMLIT_SERVER_ENABLE_XSRF_PROTECTION=false \ STREAMLIT_SERVER_ADDRESS=0.0.0.0 \ STREAMLIT_SERVER_HEADLESS=true \ STREAMLIT_SERVER_MAX_UPLOAD_SIZE=200 # Hugging Face Spaces will set $PORT (default 7860) — listen on that ENV PORT=7860 EXPOSE 7860 # Healthcheck should also use $PORT HEALTHCHECK CMD curl --fail http://localhost:${PORT}/_stcore/health || exit 1 # Use $PORT instead of hard-coding 8501 ENTRYPOINT ["sh", "-c", "streamlit run app.py --server.port=$PORT --server.address=0.0.0.0"]