-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
117 lines (99 loc) · 2.96 KB
/
Copy pathDockerfile
File metadata and controls
117 lines (99 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# Multi-stage Dockerfile for Video OCR & Transcription Service
# Optimized for CPU-based processing
FROM ubuntu:22.04 as base
# Prevent interactive prompts during build
ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
# Set working directory
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
# Core tools
python3 \
python3-pip \
python3-venv \
cmake \
make \
g++ \
git \
wget \
curl \
# Media processing
ffmpeg \
# OCR
tesseract-ocr \
tesseract-ocr-eng \
# OpenCV dependencies
libgl1-mesa-glx \
libglib2.0-0 \
libsm6 \
libxext6 \
libxrender-dev \
libgomp1 \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# Clone and build whisper.cpp
RUN git clone --depth 1 https://github.com/ggerganov/whisper.cpp.git /opt/whisper.cpp && \
cd /opt/whisper.cpp && \
cmake -B build \
-DBUILD_SHARED_LIBS=OFF \
-DWHISPER_BUILD_TESTS=OFF \
-DWHISPER_BUILD_EXAMPLES=ON \
-DCMAKE_BUILD_TYPE=Release && \
cmake --build build -j$(nproc) --target whisper-cli && \
# Download tiny model
bash models/download-ggml-model.sh tiny && \
# Cleanup to reduce image size
rm -rf build/examples build/tests .git
# Create virtual environment
RUN python3 -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Install Python dependencies
COPY requirements.txt /app/
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r requirements.txt
# Runtime stage
FROM ubuntu:22.04 as runtime
ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
ENV WHISPER_BIN=/opt/whisper.cpp/build/bin/whisper-cli
ENV WHISPER_MODEL=/opt/whisper.cpp/models/ggml-tiny.bin
ENV OPENAI_API_KEY=""
ENV OPENAI_BASE_URL="https://api.openai.com/v1"
ENV OPENAI_MODEL="gpt-4o-mini"
WORKDIR /app
# Install runtime dependencies only
RUN apt-get update && apt-get install -y --no-install-recommends \
python3 \
ffmpeg \
tesseract-ocr \
tesseract-ocr-eng \
libgl1-mesa-glx \
libglib2.0-0 \
libsm6 \
libxext6 \
libxrender-dev \
libgomp1 \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# Copy whisper.cpp from builder
COPY --from=base /opt/whisper.cpp /opt/whisper.cpp
# Copy virtual environment from builder
COPY --from=base /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Copy application files
COPY main.py /app/
COPY ocr_service.py /app/
COPY local_analyzer.py /app/
# Create temp directory
RUN mkdir -p /tmp/whisper_transcriptions /tmp/video_ocr && \
chmod 777 /tmp/whisper_transcriptions /tmp/video_ocr
# Expose port
EXPOSE 8000
# Health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8000/api/health || exit 1
# Run the application
CMD ["python3", "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "1"]