sreepathi-ravikumar commited on
Commit
55f66b9
·
verified ·
1 Parent(s): 7f12dea

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +23 -17
Dockerfile CHANGED
@@ -1,29 +1,35 @@
1
- # Use lightweight Python image
2
- FROM python:3.9-slim
 
 
 
3
 
4
- # Install system dependencies for transformers
5
  RUN apt-get update && \
6
  apt-get install -y --no-install-recommends gcc python3-dev && \
7
- rm -rf /var/lib/apt/lists/*
 
 
 
 
8
 
9
- # Set working directory
10
  WORKDIR /app
11
 
12
- # Install Python dependencies
13
- COPY requirements.txt .
14
- RUN pip install --no-cache-dir -r requirements.txt
15
 
16
- # Cache the AI model (Falcon-7B)
17
- RUN python -c """
18
- from transformers import pipeline
19
- pipeline('text-generation', model='tiiuae/falcon-7b-instruct')
20
- """
21
 
22
- # Copy application files
23
  COPY app.py text2generation.py ./
24
 
25
- # Expose Hugging Face's default port
26
  EXPOSE 7860
 
 
27
 
28
- # Run the application with Gunicorn for production
29
- CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--workers", "2", "app:app"]
 
1
+ # Stage 1: Builder for model caching
2
+ FROM python:3.9-slim as builder
3
+
4
+ WORKDIR /app
5
+ COPY requirements.txt .
6
 
 
7
  RUN apt-get update && \
8
  apt-get install -y --no-install-recommends gcc python3-dev && \
9
+ pip install --user -r requirements.txt && \
10
+ python -c "from transformers import pipeline; pipeline('text-generation', model='tiiuae/falcon-7b-instruct')"
11
+
12
+ # Stage 2: Runtime image
13
+ FROM python:3.9-slim
14
 
 
15
  WORKDIR /app
16
 
17
+ # Copy only necessary files from builder
18
+ COPY --from=builder /root/.cache /root/.cache
19
+ COPY --from=builder /usr/local/lib/python3.9/site-packages /usr/local/lib/python3.9/site-packages
20
 
21
+ # Install runtime dependencies
22
+ RUN apt-get update && \
23
+ apt-get install -y --no-install-recommends libgomp1 && \
24
+ rm -rf /var/lib/apt/lists/*
 
25
 
26
+ # Copy application code
27
  COPY app.py text2generation.py ./
28
 
29
+ # Configure production server
30
  EXPOSE 7860
31
+ HEALTHCHECK --interval=30s --timeout=30s --start-period=120s --retries=3 \
32
+ CMD curl -f http://localhost:7860/health || exit 1
33
 
34
+ # Use gunicorn with 2 workers (optimal for HF Spaces)
35
+ CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--workers", "2", "--timeout", "120", "app:app"]