FROM python:3.9-slim # Set working directory WORKDIR /app # [cite_start]Install system dependencies needed for OpenCV and other libraries [cite: 2] RUN apt-get update && apt-get install -y \ libgl1-mesa-glx \ libglib2.0-0 \ libsm6 \ libxext6 \ libxrender-dev \ libgomp1 \ libgtk-3-0 \ && rm -rf /var/lib/apt/lists/* # Copy requirements first for better caching COPY requirements.txt . # [cite_start]Install Python dependencies [cite: 3] RUN pip install --no-cache-dir -r requirements.txt # Copy application files COPY . . # Set environment variables for optimization and fixing write permissions ENV OMP_NUM_THREADS=2 ENV OPENBLAS_NUM_THREADS=2 ENV MKL_NUM_THREADS=2 ENV PYTHONUNBUFFERED=1 ENV MPLCONFIGDIR=/tmp/matplotlib ENV YOLO_CONFIG_DIR=/tmp/yolo # Expose port EXPOSE 7860 # CMD gunicorn ... --threads 4 ... app:app // di ganti dengan # PERBAIKAN DEFINITIF: Menggunakan 1 worker DAN 1 thread untuk stabilitas maksimum pada hardware terbatas. # Ini memaksa server memproses satu request pada satu waktu, mencegah crash karena kehabisan memori/CPU. CMD gunicorn --bind 0.0.0.0:7860 --workers 1 --threads 1 --worker-class gthread --timeout 300 --keep-alive 5 --max-requests 2000 --max-requests-jitter 50 app:app # baru perbaikan