File size: 2,761 Bytes
c7e434a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2195b13
5395cd1
c7e434a
5395cd1
c7e434a
5395cd1
c7e434a
 
 
 
 
 
 
 
 
2195b13
c7e434a
897c408
 
 
 
 
c7e434a
 
 
 
 
2195b13
c7e434a
 
 
 
 
2195b13
c7e434a
 
 
 
 
2195b13
 
 
c7e434a
 
 
 
 
 
 
 
 
 
 
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
# Hugging Face Spaces - Single Container Dockerfile
FROM python:3.10-slim

WORKDIR /app

# Install system dependencies including Redis
RUN apt-get update && apt-get install -y \
    ffmpeg \
    libsndfile1 \
    git \
    redis-server \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Copy requirements
COPY requirements.txt .

# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Create cache directory for models BEFORE copying code
# This ensures model downloads are cached even when code changes
RUN mkdir -p /.cache && chmod -R 777 /.cache
RUN mkdir -p /data/.cache && chmod -R 777 /data/.cache
ENV HF_HOME=/.cache
ENV TORCH_HOME=/data/.cache
ENV XDG_CACHE_HOME=/.cache
ENV WHISPER_CACHE=/data/.cache

# Pre-download models during build (HF Pro with persistent storage)
# These layers will be CACHED and won't rebuild when only code changes

# 1. Download Structure Model from HF Hub (~475MB)
RUN python -c "from transformers import AutoTokenizer, AutoModelForSequenceClassification; \
    print('πŸ“₯ Downloading Structure Model from HF Hub...'); \
    AutoTokenizer.from_pretrained('Cyberlace/swara-structure-model', cache_dir='/.cache'); \
    AutoModelForSequenceClassification.from_pretrained('Cyberlace/swara-structure-model', cache_dir='/.cache'); \
    print('βœ… Structure Model cached!')" && chmod -R 777 /.cache

# 2. Whisper medium: LAZY LOADING on first request
# Build OOM - HF Space build container has RAM limit
# Will download to /data/.cache on FIRST REQUEST (~2-3 min)
# With HF Pro persistent storage, download persists across restarts
# Subsequent requests will be fast using cached model

# 3. Download Sentence Transformer for Keywords (~420MB)
RUN python -c "from sentence_transformers import SentenceTransformer; \
    print('πŸ“₯ Downloading Sentence Transformer...'); \
    SentenceTransformer('paraphrase-multilingual-MiniLM-L12-v2', cache_folder='/.cache'); \
    print('βœ… Sentence Transformer cached!')" && chmod -R 777 /.cache

# 4. Download Silero VAD (~10MB)
RUN python -c "import torch; \
    print('πŸ“₯ Downloading Silero VAD model...'); \
    torch.hub.load(repo_or_dir='snakers4/silero-vad', model='silero_vad', force_reload=False); \
    print('βœ… Silero VAD cached!')" && chmod -R 777 /.cache

# Copy application code LAST (after model downloads)
# This way, code changes don't invalidate model cache layers
COPY . .

# Fix all cache permissions after code copy (in case any new cache created)
RUN chmod -R 777 /.cache || true

# Create uploads directory with proper permissions
RUN mkdir -p uploads && chmod 777 uploads

# Make start script executable
RUN chmod +x start.sh

# Expose Hugging Face Spaces port
EXPOSE 7860

# Start script (Redis + Worker + API)
CMD ["./start.sh"]