File size: 1,824 Bytes
88adaa5 b398c5e a4ee93f 8e65651 b398c5e a4ee93f b398c5e 8e65651 2bc9380 88adaa5 b398c5e 88adaa5 b398c5e 88adaa5 b398c5e a4ee93f 88adaa5 2bc9380 a4ee93f 88adaa5 2bc9380 a4ee93f 88adaa5 8e65651 a4ee93f 88adaa5 8e65651 a4ee93f 88adaa5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | # 1. Base Image: Use a stable, slim Python image
FROM python:3.10-slim
# Set the environment variable for Python
ENV PYTHONUNBUFFERED=1
# 2. System Dependencies: Install essential libraries for image processing and OCR
RUN apt-get update && \
apt-get install -y --no-install-recommends \
libgl1 \
libgomp1 \
libsm6 libxext6 libxrender1 \
tesseract-ocr \
build-essential \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
# 3. Application Setup
WORKDIR /app
# 4. Copy dependency file and install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# 5. Copy ALL project files (This is where the .pkl and .h5 files arrive)
# This step MUST be done before applying permissions to model files.
COPY . .
# 6. Final Permissions and Directory Fixes (Executed AFTER COPY)
# -----------------------------------------------------------------
# Grant general access to /app so the non-root user can read/write
RUN chmod -R 777 /app
# Set up EASYOCR CACHE with permissions (Resolves PermissionError)
ENV EASYOCR_MODULE_PATH /app/easyocr_models
RUN mkdir -p /app/easyocr_models
RUN chmod -R 777 /app/easyocr_models
# CRITICAL FIX: Ensure individual model files are explicitly readable by the Gunicorn worker.
# This prevents the "Model files missing" error during Gunicorn startup.
RUN chmod 666 /app/cnn_model.h5
RUN chmod 666 /app/model.pkl
RUN chmod 666 /app/target_encoder.pkl
RUN chmod 666 /app/model_features.pkl
# Ensure the 'uploads' directory is writable for runtime file saving
RUN mkdir -p /app/uploads
RUN chmod -R 777 /app/uploads
# 7. Deployment Configuration
ENV PORT=7860
EXPOSE 7860
# 8. Start app using Gunicorn
CMD exec gunicorn --bind 0.0.0.0:$PORT --workers 1 --threads 8 app:app |