File size: 1,525 Bytes
a2d8544
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0ad7c1d
 
 
 
 
 
 
 
 
a2d8544
 
 
 
 
 
 
 
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
#!/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