#!/bin/sh set -e echo "[entrypoint] Starting entrypoint script..." # If a hf_token.txt file is present in the repo, export it as HF_TOKEN so # the container can download models at runtime. HF Spaces can also set the # HF_TOKEN secret in the UI which will override this. if [ -f /app/hf_token.txt ]; then export HF_TOKEN="$(cat /app/hf_token.txt)" echo "[entrypoint] HF_TOKEN loaded from /app/hf_token.txt" fi # Default bind settings for Gradio/Spaces export GRADIO_SERVER_NAME=${GRADIO_SERVER_NAME:-0.0.0.0} export GRADIO_SERVER_PORT=${GRADIO_SERVER_PORT:-7860} # Ensure application writable directories exist and are world-writable so # the app (possibly running as non-root inside Spaces) can create caches, # temp files and matplotlib config without permission errors. mkdir -p /app/app_cache /app/app_tmp /app/speechbrain_cache /app/.cache/matplotlib chmod 0777 /app/app_cache /app/app_tmp /app/speechbrain_cache /app/.cache/matplotlib || true # Point Matplotlib config to a writable directory to avoid attempts to write to /.config export MPLCONFIGDIR=${MPLCONFIGDIR:-/app/.cache/matplotlib} # Optional pre-download step: run scripts/download_models.py if present if [ -f /app/scripts/download_models.py ]; then echo "[entrypoint] Found scripts/download_models.py — attempting to run it" python /app/scripts/download_models.py || echo "[entrypoint] download_models.py failed or exited non-zero — continuing" fi echo "[entrypoint] Launching application (python /app/app.py)" exec python -u /app/app.py