pgits commited on
Commit
0d732a6
·
verified ·
1 Parent(s): 6986168

Upload Dockerfile with huggingface_hub

Browse files
Files changed (1) hide show
  1. Dockerfile +64 -0
Dockerfile ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM nvidia/cuda:11.8-devel-ubuntu22.04
2
+
3
+ # Set environment variables
4
+ ENV DEBIAN_FRONTEND=noninteractive
5
+ ENV PYTHONUNBUFFERED=1
6
+ ENV TRANSFORMERS_CACHE=/app/model_cache
7
+ ENV HF_HOME=/app/model_cache
8
+
9
+ # Install system dependencies
10
+ RUN apt-get update && apt-get install -y \
11
+ python3 \
12
+ python3-pip \
13
+ python3-dev \
14
+ ffmpeg \
15
+ portaudio19-dev \
16
+ libasound2-dev \
17
+ libsndfile1 \
18
+ git \
19
+ curl \
20
+ && rm -rf /var/lib/apt/lists/*
21
+
22
+ # Create app directory and model cache directory
23
+ WORKDIR /app
24
+ RUN mkdir -p /app/model_cache
25
+
26
+ # Copy requirements first for better Docker layer caching
27
+ COPY requirements.txt .
28
+
29
+ # Install Python dependencies
30
+ RUN pip3 install --no-cache-dir --upgrade pip
31
+ RUN pip3 install --no-cache-dir -r requirements.txt
32
+
33
+ # Pre-download and cache the model during build
34
+ RUN python3 -c "
35
+ import os
36
+ os.environ['TRANSFORMERS_CACHE'] = '/app/model_cache'
37
+ os.environ['HF_HOME'] = '/app/model_cache'
38
+
39
+ from transformers import KyutaiSpeechToTextProcessor, KyutaiSpeechToTextForConditionalGeneration
40
+ print('Downloading and caching model...')
41
+
42
+ model_id = 'kyutai/stt-1b-en_fr'
43
+ processor = KyutaiSpeechToTextProcessor.from_pretrained(model_id, cache_dir='/app/model_cache')
44
+ model = KyutaiSpeechToTextForConditionalGeneration.from_pretrained(model_id, cache_dir='/app/model_cache')
45
+
46
+ print('Model cached successfully at /app/model_cache')
47
+ print('Processor cached successfully')
48
+ "
49
+
50
+ # Copy application files
51
+ COPY app.py .
52
+
53
+ # Set permissions for model cache
54
+ RUN chmod -R 755 /app/model_cache
55
+
56
+ # Expose port
57
+ EXPOSE 7860
58
+
59
+ # Health check
60
+ HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
61
+ CMD curl -f http://localhost:7860/health || exit 1
62
+
63
+ # Run the application
64
+ CMD ["python3", "app.py"]