File size: 1,373 Bytes
e6660cd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env bash
# =============================================================================
# Container entrypoint (Hugging Face Spaces / Docker).
#
# Streamlit native auth reads its [auth] config from .streamlit/secrets.toml,
# which is gitignored (it holds the client secret). On HF there's no such file,
# so we materialise it here from Space secrets (injected as env vars) before
# launching Streamlit. Local dev doesn't use this script — it runs
# `streamlit run` directly against the local .streamlit/secrets.toml.
#
# Required HF Space secrets/variables:
#   AUTH_CLIENT_ID, AUTH_CLIENT_SECRET, AUTH_COOKIE_SECRET,
#   AUTH_REDIRECT_URI, AUTH_SERVER_METADATA_URL
# =============================================================================
set -e

if [ -n "$AUTH_CLIENT_ID" ]; then
    mkdir -p .streamlit
    cat > .streamlit/secrets.toml <<EOF
[auth]
redirect_uri = "${AUTH_REDIRECT_URI}"
cookie_secret = "${AUTH_COOKIE_SECRET}"
client_id = "${AUTH_CLIENT_ID}"
client_secret = "${AUTH_CLIENT_SECRET}"
server_metadata_url = "${AUTH_SERVER_METADATA_URL}"
EOF
    echo "[entrypoint] wrote .streamlit/secrets.toml from Space secrets"
else
    echo "[entrypoint] WARNING: AUTH_CLIENT_ID not set — sign-in will not work until the Space secrets are configured"
fi

exec streamlit run streamlit_app.py --server.port "${PORT:-7860}" --server.address 0.0.0.0