Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +22 -23
Dockerfile
CHANGED
|
@@ -1,35 +1,34 @@
|
|
| 1 |
-
#
|
| 2 |
-
FROM python:3.
|
| 3 |
|
| 4 |
-
# Set
|
| 5 |
-
WORKDIR /
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
# Update the package list and install 'build-essential'
|
| 12 |
-
# build-essential includes gcc and other necessary C/C++ compilers
|
| 13 |
-
RUN apt-get update && \
|
| 14 |
-
apt-get install -y build-essential && \
|
| 15 |
-
rm -rf /var/lib/apt/lists/*
|
| 16 |
-
# === END OF FIX ===
|
| 17 |
-
|
| 18 |
-
# Copy the requirements file first for layer caching
|
| 19 |
COPY requirements.txt .
|
| 20 |
|
| 21 |
# Install Python dependencies
|
| 22 |
-
#
|
| 23 |
-
|
| 24 |
-
RUN pip install --no-cache-dir --prefer-binary -r requirements.txt
|
| 25 |
|
| 26 |
-
# Copy the
|
| 27 |
-
# This includes app.py and classifier.pkl (which you must upload)
|
| 28 |
COPY . .
|
| 29 |
|
| 30 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
EXPOSE 7860
|
| 32 |
|
| 33 |
-
# Command to run the
|
| 34 |
-
# --host 0.0.0.0 makes it accessible from outside the container
|
| 35 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 1 |
+
# Use a lightweight Python base image
|
| 2 |
+
FROM python:3.9-slim
|
| 3 |
|
| 4 |
+
# Set working directory
|
| 5 |
+
WORKDIR /code
|
| 6 |
|
| 7 |
+
# Install system dependencies required for OpenCV
|
| 8 |
+
# libgl1-mesa-glx and libglib2.0-0 are critical for cv2 to work in Docker
|
| 9 |
+
RUN apt-get update && apt-get install -y \
|
| 10 |
+
libgl1-mesa-glx \
|
| 11 |
+
libglib2.0-0 \
|
| 12 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 13 |
|
| 14 |
+
# Copy requirements file first to leverage Docker caching
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
COPY requirements.txt .
|
| 16 |
|
| 17 |
# Install Python dependencies
|
| 18 |
+
# We use the CPU version of PyTorch to keep the image size small for deployment
|
| 19 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
|
|
|
| 20 |
|
| 21 |
+
# Copy the application code and the model
|
|
|
|
| 22 |
COPY . .
|
| 23 |
|
| 24 |
+
# Create a non-root user (Hugging Face security requirement)
|
| 25 |
+
RUN useradd -m -u 1000 user
|
| 26 |
+
USER user
|
| 27 |
+
ENV HOME=/home/user \
|
| 28 |
+
PATH=/home/user/.local/bin:$PATH
|
| 29 |
+
|
| 30 |
+
# Expose the port Hugging Face expects
|
| 31 |
EXPOSE 7860
|
| 32 |
|
| 33 |
+
# Command to run the application
|
|
|
|
| 34 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|