An interactive Streamlit app for exploring store performance, inventory, and business policies, powered by Databricks and OpenAI agents SDK.
This app is a conversational assistant that helps users query and analyze:
- 📊 Store performance metrics
- 🔄 Return and business conduct policies
- 🛍️ BOPIS (Buy Online, Pick Up In Store) information
- 📦 Product inventory across stores
- 📈 Monthly Sales Forecasts for stores
It leverages Databricks-hosted resources, Databricks Genie rooms, and a large language model (LLM) to provide on-demand, context-aware answers. The repo also shows how to deploy this app to Databricks Apps.
The following is a quick demo of the working application:
The app uses Genie rooms to power its data tools. These Genie rooms are used by the app's tools to fetch live data and answer user questions.
-
Store Performance Genie Room: For revenue, BOPIS, forecasts, store performance metrics
-
Product Inventory Genie Room: For inventory snapshots, product details etc.
- Business Conduct Policy Table: For querying and finding out specific information about vendor conduct policy using a vector index
- The app uses a Databricks-hosted LLM, specified by the
DATABRICKS_MODEL
environment variable. - The LLM is accessed via the OpenAI-compatible API endpoint provided by Databricks Mosaic AI Gateway.
- All chat and tool responses are generated or orchestrated by this model.
- The app is built with Streamlit for a modern, interactive UI.
- User questions are routed to an agent, which can:
- Answer directly using the LLM
- Call specialized tools that query Genie rooms or Databricks tables for live data
- All Databricks credentials and resource IDs are managed via environment variables (see
.env
setup).
- get_store_performance_info:
- Queries the Store Performance Genie room for sales, location, and forecast data.
- get_product_inventory_info:
- Queries the Product Inventory Genie room for inventory snapshots and product data.
- get_business_conduct_policy_info:
- Queries a Databricks Vector Search Index for business conduct and return policies.
The vector search index was hydrated using the process highlighted in the vector_search_setup.png file in this repository.
- Clone this repo and install dependencies:
pip install -r requirements.txt
- Set up your
.env
file with Databricks credentials and model info. - Run the app:
streamlit run streamlit_multi_genie_tools.py
- Update the Genie room IDs or Databricks model in your
.env
file to point to your own resources. - The UI and agent instructions can be customized in
streamlit_multi_genie_tools.py
.
- Python 3.12
- Access to a Databricks workspace with Genie enabled
- A Databricks-hosted LLM (or compatible OpenAI endpoint)
- Set up a .env file with the following details
note: you only need the
MLFLOW_EXPERIMENT_ID
if you want to enable montioring or write to an existing external monitor
DATABRICKS_TOKEN=
DATABRICKS_HOST=
DATABRICKS_BASE_URL=
DATABRICKS_MODEL=
GENIE_SPACE_ID=
GENIE_SPACE_PRODUCT_INV_ID='
MLFLOW_EXPERIMENT_ID=
- Create a virtual env locally using uv
uv venv --python 3.12
- Then, install the requirements using
uv pip install -r requirements.txt
- Run the app
streamlit run streamlit_multi_genie_tools.py
- You might have to create a .streamlit folder on the root of the project to control the theme as you might see fit using a
config.toml file
Example config.toml
file
[theme]
base="light"
primaryColor="#FF4B4B"
backgroundColor="#FFFFFF"
secondaryBackgroundColor="#F0F2F6"
textColor="#31333F"
font="sans serif"
You can deploy this Streamlit app to your Databricks workspace as a Databricks App for secure, scalable access. Here's how:
- The app uses an
app.yaml
file to define how it runs and which environment variables it needs. - Best practice: Use Databricks secrets to store sensitive values (tokens, workspace URLs, model IDs, etc).
- In your Databricks workspace, add secrets for each required variable (see below).
Example app.yaml
:
command: ['streamlit', 'run', 'streamlit_multi_genie_tools.py']
env:
- name: 'DATABRICKS_TOKEN'
valueFrom: 'token' # Secret name in Databricks
- name: 'DATABRICKS_HOST'
valueFrom: 'DATABRICKS_HOST'
- name: 'DATABRICKS_BASE_URL'
valueFrom: 'DATABRICKS_BASE_URL'
- name: 'DATABRICKS_MODEL'
valueFrom: 'DATABRICKS_MODEL'
- name: 'GENIE_SPACE_ID'
valueFrom: 'GENIE_SPACE_ID'
- name: 'GENIE_SPACE_PRODUCT_INV_ID'
valueFrom: 'GENIE_SPACE_PRODUCT_INV_ID'
- name: 'MLFLOW_EXPERIMENT_ID'
valueFrom: 'MLFLOW_EXPERIMENT_ID'
- Each
valueFrom
should match the name of a secret you've configured in your Databricks workspace (see Databricks docs).
In your terminal, run:
databricks apps create <app-name>
Replace <app-name>
with your desired app name (e.g., store-intel-assistant
).
From your project directory, run:
databricks sync --watch . /Workspace/Users/<your-user-or-group>/<app-name>
- This will upload your code and watch for changes.
- Exclude files/folders using
.gitignore
if needed.
After syncing, deploy the app with:
databricks apps deploy <app-name> --source-code-path /Workspace/Users/<your-user-or-group>/<app-name>
- Replace
<app-name>
and the workspace path as appropriate.
- Go to your Databricks workspace, click Compute > Apps tab, and find your app.
- Click the app name to view deployment status and launch the Streamlit UI.
References: