hizuk commited on
Commit
4d7c9e3
·
verified ·
1 Parent(s): b65e80c

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +16 -11
Dockerfile CHANGED
@@ -2,28 +2,33 @@
2
  FROM python:3.10-slim
3
 
4
  # Set environment variables
5
- ENV PYTHONDONTWRITEBYTECODE 1
6
- ENV PYTHONUNBUFFERED 1
7
- ENV PORT 7860
8
 
9
  # Set the working directory to the root where files are uploaded
10
  WORKDIR /code
11
 
12
- # Install system dependencies
13
  RUN apt-get update && apt-get install -y --no-install-recommends \
14
  build-essential \
15
  && rm -rf /var/lib/apt/lists/*
16
 
17
- # Copy everything from the Space root into the container /code
18
- # This assumes requirements.txt, app.py, and all routers are at the root
19
- COPY . .
 
 
 
20
 
21
  # Install dependencies from the copied requirements.txt
22
- RUN pip install --no-cache-dir --upgrade -r requirements.txt
 
 
 
23
 
24
  # Expose the HF Spaces default port
25
  EXPOSE 7860
26
 
27
- # Start the application
28
- # Since app.py is at the root of /code, we use app:app
29
- CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
2
  FROM python:3.10-slim
3
 
4
  # Set environment variables
5
+ ENV PYTHONDONTWRITEBYTECODE=1
6
+ ENV PYTHONUNBUFFERED=1
7
+ ENV PORT=7860
8
 
9
  # Set the working directory to the root where files are uploaded
10
  WORKDIR /code
11
 
12
+ # Install system dependencies required for compiling certain Python packages
13
  RUN apt-get update && apt-get install -y --no-install-recommends \
14
  build-essential \
15
  && rm -rf /var/lib/apt/lists/*
16
 
17
+ # PRO-MOVE: Copy ONLY requirements.txt first to leverage Docker caching.
18
+ # This prevents PyTorch from re-downloading every time you change your Python code.
19
+ COPY requirements.txt .
20
+
21
+ # Upgrade pip FIRST to break the filelock backtracking loop
22
+ RUN pip install --no-cache-dir --upgrade pip
23
 
24
  # Install dependencies from the copied requirements.txt
25
+ RUN pip install --no-cache-dir -r requirements.txt
26
+
27
+ # Now copy the rest of your application code
28
+ COPY . .
29
 
30
  # Expose the HF Spaces default port
31
  EXPOSE 7860
32
 
33
+ # Start the application using Uvicorn
34
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]