This guide walks through deploying the Analytics Copilot Streamlit UI to Streamlit Community Cloud using this repository as the source of truth.
The Streamlit app is UI-only and lives at:
app/streamlit_app.py
It talks to remote inference backends (Hugging Face Inference + optional OpenAI fallback) and does not require a GPU on the Streamlit side.
Before creating the app on Streamlit Community Cloud:
-
Push this repository to GitHub (public or private, depending on your plan).
-
Ensure the app runs locally:
# Create a virtualenv and install dependencies (see README for details) python -m venv .venv source .venv/bin/activate # Windows: .venv\Scripts\activate python -m pip install --upgrade pip python -m pip install -r requirements.txt # Optional but recommended: check runtime config python scripts/check_runtime_config.py # Start the Streamlit app streamlit run app/streamlit_app.py
-
Confirm the UI loads and you can see the input fields (schema + question).
For more background on Streamlit secrets and secrets.toml, see the official
Streamlit docs:
- Secrets management on Community Cloud
(seeSecrets managementin the Streamlit docs) - Local
secrets.tomlfile format
(seesecrets.tomlreference)
-
Sign in to Streamlit Community Cloud.
-
Click New app and choose From existing repo.
-
Select the GitHub repository that contains this project.
-
Choose the branch you want to deploy from (typically
mainor a feature branch). -
Set the Main file path (entrypoint) to:
app/streamlit_app.py -
Click Deploy. The app will build and start, but it will show configuration errors until secrets are provided.
The Streamlit app expects configuration via Streamlit secrets (with environment variables as a secondary fallback). On Community Cloud, secrets are managed entirely through the web UI.
Locally, secrets are stored in:
.streamlit/secrets.toml
This file is ignored by git (see .gitignore) and should never be
committed. The repository provides an example template:
.streamlit/secrets.toml.example
You can copy it locally:
cp .streamlit/secrets.toml.example .streamlit/secrets.tomlThen edit .streamlit/secrets.toml and fill in the values for your environment.
The same keys and values are what you will paste into the Streamlit Cloud
Secrets UI.
Recommended for production-like usage:
HF_TOKEN = "hf_your_access_token_here"
# Dedicated Inference Endpoint / TGI URL
HF_ENDPOINT_URL = "https://your-endpoint-1234.us-east-1.aws.endpoints.huggingface.cloud"
# Adapter identifier configured in your endpoint's LORA_ADAPTERS
HF_ADAPTER_ID = "text2sql-qlora"Notes:
HF_TOKENshould be a token with permission to call your Inference Endpoint.HF_ENDPOINT_URLpoints at a dedicated Text Generation Inference (TGI) endpoint (often with Multi-LoRA configured).HF_ADAPTER_IDmust match the adapteridyou configured in the endpointLORA_ADAPTERSsetting.
The app also understands HF_INFERENCE_BASE_URL as an alias for
HF_ENDPOINT_URL. If both are set, HF_ENDPOINT_URL takes precedence.
If you prefer to call a provider-managed merged model via the HF router (no adapters), you can configure:
HF_TOKEN = "hf_your_access_token_here"
HF_MODEL_ID = "your-username/your-merged-text2sql-model"
HF_PROVIDER = "auto" # optional provider hintNotes:
- Do not point
HF_MODEL_IDat a pure adapter repo; most providers will respond withmodel_not_supportedin that case. - For adapter-based inference, use the dedicated endpoint pattern above
(
HF_ENDPOINT_URL+HF_ADAPTER_ID).
When HF inference fails (for example, endpoint paused or network issues), the app can automatically fall back to a cheap OpenAI model.
To enable this, add:
OPENAI_API_KEY = "sk_..." # required to use the fallback
OPENAI_FALLBACK_MODEL = "gpt-5-nano" # default if omitted
OPENAI_FALLBACK_STRICT_JSON = "false" # or "true" to request structured JSON- If
OPENAI_API_KEYis missing, the OpenAI fallback is disabled. OPENAI_FALLBACK_MODELdefaults to"gpt-5-nano"when not set, matching the app’s internal default.- When
OPENAI_FALLBACK_STRICT_JSONis a truthy value ("true","1","yes","on"), the app asks for a JSON object of the form{"sql": "SELECT ..."}and tries to parse thesqlfield.
In the Streamlit Cloud UI:
- Open your deployed app.
- Go to the app’s Settings → Secrets section.
- Copy the contents of your local
.streamlit/secrets.toml(or build it from the example) and paste it into the secrets editor. - Save the secrets and restart the app if necessary.
The format is exactly the same TOML syntax as
.streamlit/secrets.toml.example.
Before relying on the deployed app, you can validate your configuration locally using the runtime config checker:
python scripts/check_runtime_config.pyThis script:
- Looks for
.streamlit/secrets.tomlin the project root (if present). - Checks environment variables as a fallback.
- Prints which keys are configured (masking sensitive values).
- Exits with a non-zero status if neither:
- a usable Hugging Face configuration (
HF_TOKENplus eitherHF_ENDPOINT_URL/HF_INFERENCE_BASE_URLorHF_MODEL_ID), nor - an
OPENAI_API_KEYis set.
- a usable Hugging Face configuration (
A successful run will report that at least one provider (HF and/or OpenAI) is configured.
Once the app is deployed and secrets are configured:
- Trigger a generation by providing a schema and question and clicking Generate SQL.
- Open the Diagnostics section in the sidebar.
The Diagnostics panel shows:
- Which provider handled the last request (
HFvsOpenAI fallback). - Whether the last HF call reported that the endpoint is paused (with a hint to resume it from the Hugging Face Inference Endpoint Overview page).
- The request duration (in milliseconds).
- The
max_new_tokensvalue used for the last request.
The diagnostics are intentionally lightweight and do not show stack traces or detailed exception internals, to keep the UI clean and safe for end users.
To deploy this app on Streamlit Community Cloud:
- Push the repository to GitHub.
- Create a new Streamlit app from that repo and set the main file to
app/streamlit_app.py. - Configure secrets in the Streamlit Cloud Secrets editor, using the keys
from
.streamlit/secrets.toml.example. - (Optional) Run
python scripts/check_runtime_config.pylocally to validate configuration before pushing changes. - Deploy and use the Diagnostics panel to verify which provider is serving requests and whether your Hugging Face endpoint is healthy.
With these steps, there should be no guesswork required to get a working deployment on Streamlit Community Cloud.