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 WORKDIR /app # Install system dependencies RUN apt-get update && \ apt-get install -y --no-install-recommends \ build-essential \ curl \ git \ ffmpeg \ libsndfile1 \ && 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 RUN chmod -R 777 /app/uploads /app/tmp_model /tmp/matplotlib /app/.cache /app/.streamlit /app/.config /root/.cache # Create symbolic link to ensure both user and root can access cache RUN ln -sf /app/.cache/huggingface /root/.cache/huggingface # 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 && \ 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 = false' >> .streamlit/config.toml && \ echo 'maxUploadSize = 200' >> .streamlit/config.toml && \ echo 'enableXsrfProtection = 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"]