viskav commited on
Commit
94ebfe7
·
verified ·
1 Parent(s): ac11563

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +22 -10
Dockerfile CHANGED
@@ -2,10 +2,11 @@ FROM python:3.10-slim
2
 
3
  WORKDIR /code
4
 
5
- # Install minimal system dependencies
6
  RUN apt-get update && apt-get install -y \
7
  build-essential \
8
  curl \
 
9
  && rm -rf /var/lib/apt/lists/*
10
 
11
  # Copy requirements first for better caching
@@ -14,18 +15,29 @@ COPY requirements.txt .
14
  # Install Python dependencies
15
  RUN pip install --no-cache-dir -r requirements.txt
16
 
17
- # Copy application
 
 
 
 
 
 
 
 
 
 
 
18
  COPY app.py .
19
 
20
- # Download model (will happen automatically at runtime)
21
- # Or you can download it here if you want:
22
- # RUN pip install huggingface-hub && \
23
- # python -c "from huggingface_hub import hf_hub_download; \
24
- # hf_hub_download(repo_id='bartowski/Phi-3.1-mini-4k-instruct-GGUF', \
25
- # filename='Phi-3.1-mini-4k-instruct-IQ2_M.gguf', local_dir='/code')"
26
 
27
- # Expose port
28
  EXPOSE 7860
29
 
 
 
 
 
30
  # Run the app
31
- CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]
 
2
 
3
  WORKDIR /code
4
 
5
+ # Install system dependencies
6
  RUN apt-get update && apt-get install -y \
7
  build-essential \
8
  curl \
9
+ git \
10
  && rm -rf /var/lib/apt/lists/*
11
 
12
  # Copy requirements first for better caching
 
15
  # Install Python dependencies
16
  RUN pip install --no-cache-dir -r requirements.txt
17
 
18
+ # Download model during build (optional - can also download at runtime)
19
+ ARG HF_TOKEN=""
20
+ RUN if [ -n "$HF_TOKEN" ]; then \
21
+ python -c "from huggingface_hub import hf_hub_download; \
22
+ hf_hub_download(repo_id='bartowski/Phi-3.1-mini-4k-instruct-GGUF', \
23
+ filename='Phi-3.1-mini-4k-instruct-IQ2_M.gguf', \
24
+ local_dir='/code', token='$HF_TOKEN')"; \
25
+ else \
26
+ echo "HF_TOKEN not provided, model will download at runtime"; \
27
+ fi
28
+
29
+ # Copy application code
30
  COPY app.py .
31
 
32
+ # Create a directory for models if it doesn't exist
33
+ RUN mkdir -p /code
 
 
 
 
34
 
35
+ # Expose port (Hugging Face Spaces uses 7860)
36
  EXPOSE 7860
37
 
38
+ # Health check
39
+ HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
40
+ CMD curl -f http://localhost:7860/health || exit 1
41
+
42
  # Run the app
43
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]