rodrigomasini's picture
Update Dockerfile
d615b7b verified
FROM python:3.11-slim
# Set environment variables
ENV PYTHONUNBUFFERED=1 \
MDR_MODEL_DIR=/models \
MDR_DEVICE=cpu \
MDR_TABLE_FORMAT=MARKDOWN \
LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH \
MPLCONFIGDIR=/app/.cache/matplotlib \
YOLO_CONFIG_DIR=/app/.config/Ultralytics \
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
# Ensure pip uses the official PyTorch CPU index for torch related packages
PIP_EXTRA_INDEX_URL=https://download.pytorch.org/whl/cpu
# Set the working directory in the container
WORKDIR /app
# System libs
RUN apt-get update && apt-get install -y --no-install-recommends \
libgl1-mesa-glx \
libglib2.0-0 \
libopenblas0-pthread \
libgomp1 \
libxext6 \
libxrender-dev \
libfreetype6-dev && \
rm -rf /var/lib/apt/lists/*
# Upgrade pip first
RUN python -m pip install --upgrade pip
# --- MODIFIED AND MORE AGGRESSIVE PYTORCH INSTALLATION ---
RUN python -m pip uninstall -y torch torchvision torchaudio
# 2. Install the specific CPU-only PyTorch version using the --index-url for PyTorch's CPU wheelhouse.
RUN python -m pip install --no-cache-dir torch==2.1.2 torchvision==0.16.2 torchaudio==2.1.2 --index-url https://download.pytorch.org/whl/cpu
# 3. Verify PyTorch installation during build (same as before)
RUN python -c "import torch; print('PyTorch version during build: ' + torch.__version__); print('Has get_default_device: ' + str(hasattr(torch, 'get_default_device')))"
# --- END MODIFICATION ---
# Copy the requirements file into the container
COPY requirements.txt .
# Install other Python dependencies from requirements.txt
RUN python -m pip install --no-cache-dir -r requirements.txt
# Copy the application code into the container
COPY mdr_pdf_parser.py .
COPY main.py .
# Create directories
RUN mkdir -p ${MDR_MODEL_DIR} /app/temp_uploads /app/.cache/matplotlib /app/.config/Ultralytics && \
chmod -R 777 ${MDR_MODEL_DIR} /app/temp_uploads /app/.cache /app/.config
ENV PORT 7860
EXPOSE 7860
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
VOLUME ${MDR_MODEL_DIR}