Update Dockerfile
Browse files- Dockerfile +23 -19
Dockerfile
CHANGED
@@ -6,15 +6,17 @@ ENV PYTHONUNBUFFERED=1 \
|
|
6 |
MDR_DEVICE=cpu \
|
7 |
MDR_TABLE_FORMAT=MARKDOWN \
|
8 |
LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH \
|
9 |
-
# --- ADDED: Point config/cache dirs to writable locations within /app ---
|
10 |
MPLCONFIGDIR=/app/.cache/matplotlib \
|
11 |
-
YOLO_CONFIG_DIR=/app/.config/Ultralytics
|
12 |
-
|
|
|
|
|
|
|
13 |
|
14 |
# Set the working directory in the container
|
15 |
WORKDIR /app
|
16 |
|
17 |
-
#
|
18 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
19 |
libgl1-mesa-glx \
|
20 |
libglib2.0-0 \
|
@@ -25,33 +27,35 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
25 |
libfreetype6-dev && \
|
26 |
rm -rf /var/lib/apt/lists/*
|
27 |
|
28 |
-
#
|
29 |
-
|
|
|
|
|
|
|
30 |
|
31 |
-
# Install
|
32 |
-
RUN python -m pip install --no-cache-dir --
|
33 |
-
&& python -m pip install --no-cache-dir -r requirements.txt
|
34 |
|
|
|
|
|
35 |
RUN python -c "import torch; print('PyTorch version during build: ' + torch.__version__); print('Has get_default_device: ' + str(hasattr(torch, 'get_default_device')))"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
# Copy the application code into the container
|
38 |
COPY mdr_pdf_parser.py .
|
39 |
COPY main.py .
|
40 |
|
41 |
-
# Create
|
42 |
-
# --- MODIFIED: Added creation of the new cache/config dirs ---
|
43 |
RUN mkdir -p ${MDR_MODEL_DIR} /app/temp_uploads /app/.cache/matplotlib /app/.config/Ultralytics && \
|
44 |
chmod -R 777 ${MDR_MODEL_DIR} /app/temp_uploads /app/.cache /app/.config
|
45 |
-
# Note: chmod 777 is very permissive, but often necessary/easiest in restricted environments like HF Spaces.
|
46 |
-
# It ensures the directories are writable by the user running the application.
|
47 |
-
# --- END MODIFIED ---
|
48 |
|
49 |
-
# Expose the port the app runs on
|
50 |
ENV PORT 7860
|
51 |
EXPOSE 7860
|
52 |
-
|
53 |
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
54 |
-
|
55 |
-
|
56 |
-
# This allows mounting a host directory for persistent models
|
57 |
VOLUME ${MDR_MODEL_DIR}
|
|
|
6 |
MDR_DEVICE=cpu \
|
7 |
MDR_TABLE_FORMAT=MARKDOWN \
|
8 |
LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH \
|
|
|
9 |
MPLCONFIGDIR=/app/.cache/matplotlib \
|
10 |
+
YOLO_CONFIG_DIR=/app/.config/Ultralytics \
|
11 |
+
PIP_NO_CACHE_DIR=off \
|
12 |
+
PIP_DISABLE_PIP_VERSION_CHECK=on \
|
13 |
+
# Ensure pip uses the official PyTorch CPU index for torch related packages
|
14 |
+
PIP_EXTRA_INDEX_URL=https://download.pytorch.org/whl/cpu
|
15 |
|
16 |
# Set the working directory in the container
|
17 |
WORKDIR /app
|
18 |
|
19 |
+
# System libs
|
20 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
21 |
libgl1-mesa-glx \
|
22 |
libglib2.0-0 \
|
|
|
27 |
libfreetype6-dev && \
|
28 |
rm -rf /var/lib/apt/lists/*
|
29 |
|
30 |
+
# Upgrade pip first
|
31 |
+
RUN python -m pip install --upgrade pip
|
32 |
+
|
33 |
+
# --- MODIFIED AND MORE AGGRESSIVE PYTORCH INSTALLATION ---
|
34 |
+
RUN python -m pip uninstall -y torch torchvision torchaudio
|
35 |
|
36 |
+
# 2. Install the specific CPU-only PyTorch version using the --index-url for PyTorch's CPU wheelhouse.
|
37 |
+
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
|
|
|
38 |
|
39 |
+
|
40 |
+
# 3. Verify PyTorch installation during build (same as before)
|
41 |
RUN python -c "import torch; print('PyTorch version during build: ' + torch.__version__); print('Has get_default_device: ' + str(hasattr(torch, 'get_default_device')))"
|
42 |
+
# --- END MODIFICATION ---
|
43 |
+
|
44 |
+
# Copy the requirements file into the container
|
45 |
+
COPY requirements.txt .
|
46 |
+
|
47 |
+
# Install other Python dependencies from requirements.txt
|
48 |
+
RUN python -m pip install --no-cache-dir -r requirements.txt
|
49 |
|
50 |
# Copy the application code into the container
|
51 |
COPY mdr_pdf_parser.py .
|
52 |
COPY main.py .
|
53 |
|
54 |
+
# Create directories
|
|
|
55 |
RUN mkdir -p ${MDR_MODEL_DIR} /app/temp_uploads /app/.cache/matplotlib /app/.config/Ultralytics && \
|
56 |
chmod -R 777 ${MDR_MODEL_DIR} /app/temp_uploads /app/.cache /app/.config
|
|
|
|
|
|
|
57 |
|
|
|
58 |
ENV PORT 7860
|
59 |
EXPOSE 7860
|
|
|
60 |
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
|
|
|
61 |
VOLUME ${MDR_MODEL_DIR}
|