Spaces:
Sleeping
Sleeping
# Multi-stage build for optimized Docker image | |
FROM python:3.10-slim AS builder | |
WORKDIR /app | |
# Install only essential build dependencies | |
RUN apt-get update && apt-get install -y \ | |
build-essential \ | |
libffi-dev \ | |
python3-dev \ | |
&& rm -rf /var/lib/apt/lists/* | |
# Copy and install Python dependencies | |
COPY requirements.optimized.txt . | |
RUN --mount=type=cache,target=/root/.cache/pip \ | |
pip install --no-cache-dir --upgrade pip && \ | |
pip install --no-cache-dir -r requirements.optimized.txt | |
# Production stage | |
FROM python:3.10-slim | |
WORKDIR /app | |
# Install only runtime dependencies (much smaller) | |
RUN apt-get update && apt-get install -y \ | |
poppler-utils \ | |
libgl1-mesa-glx \ | |
libglib2.0-0 \ | |
libsm6 \ | |
libxext6 \ | |
libxrender1 \ | |
&& rm -rf /var/lib/apt/lists/* \ | |
&& apt-get clean | |
# Copy Python packages and binaries from builder | |
COPY --from=builder /usr/local/lib/python3.10/site-packages/ /usr/local/lib/python3.10/site-packages/ | |
COPY --from=builder /usr/local/bin/ /usr/local/bin/ | |
# (Optional) Reinstall uvicorn in the final image to guarantee it's available | |
RUN pip install --no-cache-dir uvicorn | |
# Copy only necessary application files | |
COPY app.py . | |
COPY OCR.py . | |
COPY Feedback.py . | |
COPY PDFFeedbackGenerator.py . | |
COPY OCRAccuracyAnalyzer.py . | |
# Create necessary directories | |
RUN mkdir -p temp output | |
# Set environment variables | |
ENV POPPLER_PATH=/usr/bin | |
ENV PYTHONPATH=/app | |
ENV PYTHONUNBUFFERED=1 | |
EXPOSE 5000 | |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "5000"] |