File size: 3,472 Bytes
5bacc9d
3b528f9
5bacc9d
77cd9f4
 
aca25cc
 
 
 
 
 
6252089
 
 
7eff467
5bacc9d
7eff467
5bacc9d
77cd9f4
 
 
 
 
 
 
6f0cad3
 
 
 
77cd9f4
3b528f9
 
aca25cc
6252089
 
aca25cc
 
6252089
 
1b3a125
5bacc9d
 
1b3a125
5bacc9d
77cd9f4
bb36a56
77cd9f4
5bacc9d
6ba5ea6
 
3b528f9
 
cca2050
 
 
 
 
 
6252089
 
cca2050
6252089
cca2050
 
 
 
 
 
 
 
 
 
 
 
 
 
aca25cc
3b528f9
5bacc9d
3b528f9
 
5bacc9d
3b528f9
 
5bacc9d
 
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
FROM python:3.9-slim

# Set environment variables
ENV PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    MPLCONFIGDIR=/tmp/matplotlib \
    TRANSFORMERS_CACHE=/app/.cache/huggingface \
    HF_HOME=/app/.cache/huggingface \
    XDG_CACHE_HOME=/app/.cache \
    PYTHONIOENCODING=utf-8 \
    TOKENIZERS_PARALLELISM=false \
    HF_HUB_DISABLE_SYMLINKS_WARNING=1 \
    STREAMLIT_SERVER_MAX_UPLOAD_SIZE=150 \
    STREAMLIT_CLIENT_TOOLCHAIN=vite

WORKDIR /app

# Install system dependencies
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
    build-essential \
    curl \
    git \
    ffmpeg \
    libsndfile1 \
    libgl1-mesa-glx \
    python3-tk \
    libavcodec-extra \
    libavformat-dev \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# Create necessary directories with proper permissions
RUN mkdir -p /app/tmp_model /tmp/matplotlib /app/uploads /app/.cache/huggingface /app/.streamlit /app/.config /root/.cache/huggingface /tmp/streamlit_uploads
RUN chmod -R 777 /app/uploads /app/tmp_model /tmp/matplotlib /app/.cache /app/.streamlit /app/.config /root/.cache /tmp/streamlit_uploads
# Create symbolic link to ensure both user and root can access cache
RUN ln -sf /app/.cache/huggingface /root/.cache/huggingface
# Use alternative uploads directory with guaranteed permissions
ENV STREAMLIT_UPLOADS_PATH=/tmp/streamlit_uploads

# Copy requirements first (for better caching)
COPY requirements.txt .

# Install Python dependencies with specific order for compatibility
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir torch==2.0.1 torchaudio==2.0.2 torchvision==0.15.2 && \
    pip install --no-cache-dir -r requirements.txt && \
    pip install --no-cache-dir git+https://github.com/speechbrain/speechbrain.git@v0.5.14

# Copy source code
COPY src/ ./src/

# Create Streamlit configuration directly in the container
RUN mkdir -p .streamlit && \
    echo '[server]' > .streamlit/config.toml && \
    echo 'port = 8501' >> .streamlit/config.toml && \
    echo 'address = "0.0.0.0"' >> .streamlit/config.toml && \
    echo 'headless = true' >> .streamlit/config.toml && \
    echo 'enableCORS = true' >> .streamlit/config.toml && \
    echo 'maxUploadSize = 150' >> .streamlit/config.toml && \
    echo 'enableXsrfProtection = false' >> .streamlit/config.toml && \
    echo 'enableWebsocketCompression = false' >> .streamlit/config.toml && \
    echo '' >> .streamlit/config.toml && \
    echo '[browser]' >> .streamlit/config.toml && \
    echo 'gatherUsageStats = false' >> .streamlit/config.toml && \
    echo '' >> .streamlit/config.toml && \
    echo '[runner]' >> .streamlit/config.toml && \
    echo 'fastReruns = true' >> .streamlit/config.toml && \
    echo '' >> .streamlit/config.toml && \
    echo '[theme]' >> .streamlit/config.toml && \
    echo 'primaryColor = "#2196F3"' >> .streamlit/config.toml && \
    echo 'backgroundColor = "#FFFFFF"' >> .streamlit/config.toml && \
    echo 'secondaryBackgroundColor = "#F0F2F6"' >> .streamlit/config.toml && \
    echo 'textColor = "#262730"' >> .streamlit/config.toml && \
    echo 'font = "sans serif"' >> .streamlit/config.toml && \
    chmod -R 755 ./.streamlit && \
    chmod 644 ./.streamlit/config.toml

# Expose port
EXPOSE 8501

# Health check
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health

# Run the app
ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]