Download src/utils/db_connection.py from dahutapea/Topic-Modeling-Tokopedia-Reviews: direct link, hf CLI and curl.
- Browser
- Download file 662 Bytes
-
https://huggingface.co/spaces/dahutapea/Topic-Modeling-Tokopedia-Reviews/resolve/main/src/utils/db_connection.py
- Command line
-
hf download hf://spaces/dahutapea/Topic-Modeling-Tokopedia-Reviews/src/utils/db_connection.py
-
curl -L -o db_connection.py https://huggingface.co/spaces/dahutapea/Topic-Modeling-Tokopedia-Reviews/resolve/main/src/utils/db_connection.py
662 Bytes
| import os | |
| import streamlit as st | |
| def get_connection(): | |
| """Supabase Postgres connection. | |
| - On Hugging Face: set a Space Secret named SUPABASE_DB_URL (a full SQLAlchemy URL, | |
| e.g. postgresql+psycopg2://USER:PASSWORD@HOST:5432/postgres). It is read here as an | |
| environment variable, so the password never lives in the repo. | |
| - Locally: if SUPABASE_DB_URL is not set, this falls back to the [connections.supabase] | |
| block in .streamlit/secrets.toml (gitignored). | |
| """ | |
| url = os.environ.get("SUPABASE_DB_URL") | |
| if url: | |
| return st.connection("supabase", type="sql", url=url) | |
| return st.connection("supabase", type="sql") | |