RoAr777 commited on
Commit
6324c73
·
verified ·
1 Parent(s): 8b61522

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +22 -23
Dockerfile CHANGED
@@ -1,35 +1,34 @@
1
- # Start from a stable, slim Python base image
2
- FROM python:3.13-slim
3
 
4
- # Set the working directory inside the container
5
- WORKDIR /app
6
 
7
- # Switch to root user to install system packages
8
- USER root
 
 
 
 
9
 
10
- # === THIS IS THE FIX ===
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
- # --no-cache-dir reduces image size
23
- # --prefer-binary to speed up install if possible
24
- RUN pip install --no-cache-dir --prefer-binary -r requirements.txt
25
 
26
- # Copy the rest of the application code
27
- # This includes app.py and classifier.pkl (which you must upload)
28
  COPY . .
29
 
30
- # Hugging Face Spaces requires the app to listen on port 7860
 
 
 
 
 
 
31
  EXPOSE 7860
32
 
33
- # Command to run the FastAPI server using uvicorn
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"]