Spaces:
Sleeping
Sleeping
File size: 1,529 Bytes
459923e |
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 56 57 58 59 |
# 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"] |