rodrigomasini's picture
Update Dockerfile
af729d4 verified
raw
history blame
1.98 kB
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 \
# --- ADDED: Point config/cache dirs to writable locations within /app ---
MPLCONFIGDIR=/app/.cache/matplotlib \
YOLO_CONFIG_DIR=/app/.config/Ultralytics
# --- END ADDED ---
# Set the working directory in the container
WORKDIR /app
# system libs for OpenCV, Ultralytics & friends
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/*
# Copy the requirements file into the container
COPY requirements.txt .
# Install Python dependencies
RUN python -m pip install --no-cache-dir --upgrade pip \
&& python -m pip install --no-cache-dir -r requirements.txt
RUN python -c "import torch; print(f'PyTorch version during build: {torch.__version__}'); print(f'Has get_default_device: {hasattr(torch, \'get_default_device\')}')"
# Copy the application code into the container
COPY mdr_pdf_parser.py .
COPY main.py .
# Create the default model directory, temp directory, AND the config/cache dirs
# --- MODIFIED: Added creation of the new cache/config dirs ---
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
# Note: chmod 777 is very permissive, but often necessary/easiest in restricted environments like HF Spaces.
# It ensures the directories are writable by the user running the application.
# --- END MODIFIED ---
# Expose the port the app runs on
ENV PORT 7860
EXPOSE 7860
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
# This allows mounting a host directory for persistent models
VOLUME ${MDR_MODEL_DIR}