File size: 1,498 Bytes
be36ee7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
733c0c5
be36ee7
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
FROM python:3.11-slim

ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    DEBIAN_FRONTEND=noninteractive

WORKDIR /app

# Install system dependencies (minimal set)
RUN apt-get update && apt-get install -y --no-install-recommends \
    tesseract-ocr \
    poppler-utils \
    ffmpeg \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Copy and install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt uvicorn[standard]

# Copy application code
COPY . .

# Set environment for HF Spaces with minimal resource usage
ENV PYTHONPATH=/app/services/ai-service/src:$PYTHONPATH \
    HF_SPACES=true \
    FAST_MODE=true \
    PRELOAD_SMALL_MODELS=false \
    PRELOAD_GGUF=false \
    HF_HOME=/tmp/huggingface \
    TORCH_HOME=/tmp/torch \
    WHISPER_CACHE=/tmp/whisper \
    MODEL_CACHE_DIR=/tmp/models \
    TRANSFORMERS_CACHE=/tmp/huggingface/transformers \
    PYTORCH_CUDA_ALLOC_CONF=max_split_size_mb:128 \
    TOKENIZERS_PARALLELISM=false \
    OMP_NUM_THREADS=1 \
    MKL_NUM_THREADS=1

# Create necessary directories
RUN mkdir -p /tmp/uploads /tmp/huggingface /tmp/models && \
    chmod -R 777 /tmp

EXPOSE 7860

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
    CMD curl -f http://localhost:7860/health || exit 1

# Start application with single worker for minimal memory footprint
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1", "--timeout-keep-alive", "1200"]