Spaces:
Sleeping
Sleeping
Senum2001 commited on
Commit ·
eba5a08
1
Parent(s): 3b2a8b5
Fix: Add python-dotenv dependency and fix matplotlib permissions with non-root user
Browse files- Dockerfile +15 -8
- requirements.txt +1 -0
Dockerfile
CHANGED
|
@@ -1,6 +1,9 @@
|
|
| 1 |
# Optimized Dockerfile for Hugging Face Spaces - Reduced size
|
| 2 |
FROM python:3.10-slim
|
| 3 |
|
|
|
|
|
|
|
|
|
|
| 4 |
# Set working directory
|
| 5 |
WORKDIR /app
|
| 6 |
|
|
@@ -13,23 +16,26 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
| 13 |
&& apt-get clean
|
| 14 |
|
| 15 |
# Copy requirements first for better caching
|
| 16 |
-
COPY requirements.txt ./
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
# Install Python dependencies with optimizations
|
| 19 |
RUN pip install --no-cache-dir -r requirements.txt && \
|
| 20 |
-
pip cache purge
|
| 21 |
-
rm -rf /root/.cache/pip
|
| 22 |
|
| 23 |
# Download model checkpoint from Google Drive
|
| 24 |
RUN pip install --no-cache-dir gdown && \
|
| 25 |
gdown --id 1ftzxTJUnlxpQFqPlaUozG_JUbl1Qi5tQ -O /app/model_checkpoint.ckpt && \
|
| 26 |
pip uninstall -y gdown && \
|
| 27 |
-
|
| 28 |
|
| 29 |
# Copy application files
|
| 30 |
-
COPY app.py inference_core.py ./
|
| 31 |
-
COPY scripts/ ./scripts/
|
| 32 |
-
COPY configs/ ./configs/
|
| 33 |
|
| 34 |
# Create output directories
|
| 35 |
RUN mkdir -p api_inference_pred_masks_pipeline \
|
|
@@ -42,7 +48,8 @@ EXPOSE 7860
|
|
| 42 |
# Set environment variables
|
| 43 |
ENV PYTHONUNBUFFERED=1 \
|
| 44 |
PORT=7860 \
|
| 45 |
-
PYTHONDONTWRITEBYTECODE=1
|
|
|
|
| 46 |
|
| 47 |
# Start Flask app
|
| 48 |
CMD ["python", "app.py"]
|
|
|
|
| 1 |
# Optimized Dockerfile for Hugging Face Spaces - Reduced size
|
| 2 |
FROM python:3.10-slim
|
| 3 |
|
| 4 |
+
# Create non-root user
|
| 5 |
+
RUN useradd -m -u 1000 user
|
| 6 |
+
|
| 7 |
# Set working directory
|
| 8 |
WORKDIR /app
|
| 9 |
|
|
|
|
| 16 |
&& apt-get clean
|
| 17 |
|
| 18 |
# Copy requirements first for better caching
|
| 19 |
+
COPY --chown=user:user requirements.txt ./
|
| 20 |
+
|
| 21 |
+
# Switch to user before installing Python packages
|
| 22 |
+
USER user
|
| 23 |
+
ENV PATH="/home/user/.local/bin:$PATH"
|
| 24 |
|
| 25 |
# Install Python dependencies with optimizations
|
| 26 |
RUN pip install --no-cache-dir -r requirements.txt && \
|
| 27 |
+
pip cache purge
|
|
|
|
| 28 |
|
| 29 |
# Download model checkpoint from Google Drive
|
| 30 |
RUN pip install --no-cache-dir gdown && \
|
| 31 |
gdown --id 1ftzxTJUnlxpQFqPlaUozG_JUbl1Qi5tQ -O /app/model_checkpoint.ckpt && \
|
| 32 |
pip uninstall -y gdown && \
|
| 33 |
+
pip cache purge
|
| 34 |
|
| 35 |
# Copy application files
|
| 36 |
+
COPY --chown=user:user app.py inference_core.py ./
|
| 37 |
+
COPY --chown=user:user scripts/ ./scripts/
|
| 38 |
+
COPY --chown=user:user configs/ ./configs/
|
| 39 |
|
| 40 |
# Create output directories
|
| 41 |
RUN mkdir -p api_inference_pred_masks_pipeline \
|
|
|
|
| 48 |
# Set environment variables
|
| 49 |
ENV PYTHONUNBUFFERED=1 \
|
| 50 |
PORT=7860 \
|
| 51 |
+
PYTHONDONTWRITEBYTECODE=1 \
|
| 52 |
+
MPLCONFIGDIR=/tmp/matplotlib
|
| 53 |
|
| 54 |
# Start Flask app
|
| 55 |
CMD ["python", "app.py"]
|
requirements.txt
CHANGED
|
@@ -23,6 +23,7 @@ cloudinary
|
|
| 23 |
# Configuration
|
| 24 |
omegaconf
|
| 25 |
pyyaml
|
|
|
|
| 26 |
|
| 27 |
# Utilities
|
| 28 |
requests
|
|
|
|
| 23 |
# Configuration
|
| 24 |
omegaconf
|
| 25 |
pyyaml
|
| 26 |
+
python-dotenv
|
| 27 |
|
| 28 |
# Utilities
|
| 29 |
requests
|