abdullahalioo commited on
Commit
868d51b
·
verified ·
1 Parent(s): 7d0f4d3

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +21 -3
Dockerfile CHANGED
@@ -2,12 +2,30 @@ FROM python:3.9-slim
2
 
3
  WORKDIR /app
4
 
5
- # 1. Install dependencies
 
 
 
 
 
6
  COPY requirements.txt .
7
  RUN pip install --no-cache-dir -r requirements.txt
8
 
 
 
 
 
 
 
 
 
9
 
 
10
  COPY . .
11
 
12
- # 5. Run FastAPI (HF Spaces expects port 7860)
13
- CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
 
 
 
 
 
2
 
3
  WORKDIR /app
4
 
5
+ # 1. Install system dependencies first (better caching)
6
+ RUN apt-get update && \
7
+ apt-get install -y --no-install-recommends gcc python3-dev && \
8
+ rm -rf /var/lib/apt/lists/*
9
+
10
+ # 2. Install Python dependencies
11
  COPY requirements.txt .
12
  RUN pip install --no-cache-dir -r requirements.txt
13
 
14
+ # 3. Configure cache locations (using Hugging Face's recommended paths)
15
+ ENV TRANSFORMERS_CACHE=/tmp/model_cache \
16
+ HF_HOME=/tmp/huggingface \
17
+ XDG_CACHE_HOME=/tmp/xdg_cache
18
+
19
+ # 4. Create cache directories with correct permissions
20
+ RUN mkdir -p ${TRANSFORMERS_CACHE} ${HF_HOME} ${XDG_CACHE_HOME} && \
21
+ chmod -R 777 /tmp
22
 
23
+ # 5. Copy application files
24
  COPY . .
25
 
26
+ # 6. Health check (recommended for HF Spaces)
27
+ HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
28
+ CMD curl -f http://localhost:7860/health || exit 1
29
+
30
+ # 7. Run with optimized Uvicorn settings
31
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]