How to Create a Dashboard from Local Data with AI
Your data never leaves your computer. A local AI model (Ollama) writes the code. You run a private Streamlit dashboard on about 10 lakh rows.
In short: run a coding AI on your own machine with Ollama, make a big local data file, let the AI write a Python dashboard, and open it in your browser — all offline.
Why keep it local
Cloud AI tools send your data to a server. For private business data that is a risk. A local model runs on your own PC, so the data and the AI both stay with you. Nothing is uploaded.
What these words mean
- Ollama: a free app that runs AI models on your own computer.
- qwen2.5-coder: a coding-focused open model you can pull in Ollama (sizes 0.5B to 32B).
- pandas: a Python tool to read and summarise tables.
- Streamlit: turns a Python file into a web dashboard with one command.
- Plotly: makes the charts (bars, pies).
- 10 lakh rows: 10,00,000 (one million) rows — a realistically big file.
The whole flow, top to bottom
Setup — install everything (once)
- Install Python 3 and these libraries:
pip install pandas plotly streamlit
- Install Ollama from ollama.com, then pull a coding model:
ollama pull qwen2.5-coder # default 7B, about 4.7 GB ollama run qwen2.5-coder # chat test; type /bye to exit
- Pick a size for your machine (see the hardware card below). Bigger = smarter but needs more memory.
ollama run qwen2.5-coder --parameter num_ctx 8192 (more context needs more RAM).Hardware for a local coding model
Step 1 — make the data locally (no internet)
Save this as gen_data.py and run python gen_data.py. It writes sales.csv with 10 lakh rows. (This script was run and tested.)
"""Make fake local sales data. No internet. Default 10 lakh (1,000,000) rows."""
import csv, random, datetime, sys
ROWS = int(sys.argv[1]) if len(sys.argv) > 1 else 1_000_000
random.seed(42)
regions = ["West", "South", "North", "East"]
cats = {"Appliances": ["Mixer", "Fan", "Iron"],
"Furniture": ["Chair", "Desk", "Table"],
"Electronics": ["Monitor", "Laptop", "Phone"]}
start = datetime.date(2023, 1, 1)
with open("sales.csv", "w", newline="") as f:
w = csv.writer(f)
w.writerow(["date", "region", "category", "product", "units", "sales"])
for _ in range(ROWS):
d = start + datetime.timedelta(days=random.randint(0, 1000))
cat = random.choice(list(cats))
prod = random.choice(cats[cat])
units = random.randint(1, 50)
price = random.choice([500, 1200, 3000, 8000, 15000])
w.writerow([d.isoformat(), random.choice(regions), cat, prod, units, units * price])
print(f"wrote sales.csv with {ROWS} rows")
python gen_data.py for 10 lakh rows, or python gen_data.py 5000 for a quick small test.Step 2 — ask the local AI to write the dashboard
Open the Ollama chat (or use it inside VS Code via the Continue extension) and paste this prompt. The AI replies with the full app.py.
I have a local file sales.csv with columns: date, region, category, product, units, sales (about 10 lakh rows). Write one Python file app.py using pandas, plotly.express and streamlit that shows: 4 KPIs (total sales, total units, average sale, best region), 2 bar charts (sales by year, sales by region), 2 pie charts (sales by category, units by region), and a sidebar Year filter. Cache the data load. Only return the code.
Step 3 — the dashboard code (tested, runnable)
Save the AI's answer as app.py. Below is a clean version that was actually run here (pandas + Plotly + Streamlit all built the 4 charts without error).
"""Local sales dashboard. Runs fully offline: streamlit run app.py"""
import pandas as pd
import plotly.express as px
import streamlit as st
st.set_page_config(page_title="Local Sales Dashboard", layout="wide")
st.title("Local Sales Dashboard")
@st.cache_data
def load():
df = pd.read_csv("sales.csv", parse_dates=["date"])
df["year"] = df["date"].dt.year
return df
df = load()
# sidebar filter
years = sorted(df["year"].unique())
pick = st.sidebar.multiselect("Year", years, default=years)
df = df[df["year"].isin(pick)]
# KPIs
c1, c2, c3, c4 = st.columns(4)
c1.metric("Total Sales", f"Rs {df['sales'].sum():,.0f}")
c2.metric("Total Units", f"{df['units'].sum():,.0f}")
c3.metric("Avg Sale", f"Rs {df['sales'].mean():,.0f}")
c4.metric("Best Region", df.groupby("region")["sales"].sum().idxmax())
# charts
a, b = st.columns(2)
a.plotly_chart(px.bar(df.groupby("year")["sales"].sum().reset_index(),
x="year", y="sales", title="Sales by Year"), use_container_width=True)
b.plotly_chart(px.bar(df.groupby("region")["sales"].sum().reset_index(),
x="region", y="sales", title="Sales by Region"), use_container_width=True)
c, d = st.columns(2)
c.plotly_chart(px.pie(df, names="category", values="sales", title="Sales by Category"),
use_container_width=True)
d.plotly_chart(px.pie(df, names="region", values="units", title="Units by Region"),
use_container_width=True)
Step 4 — run it (offline)
- Start the app:
streamlit run app.py - Open the browser at
http://localhost:8501(Streamlit opens it for you). - Use the Year filter in the sidebar; the KPIs and charts update.
Step 5 — tweak by chatting (still local)
- "Add a line chart of monthly sales."
- "Make the pies show percent labels and one colour theme."
- "Add a Region filter next to the Year filter."
How to check the numbers
- In Python:
df['sales'].sum()must match the Total Sales KPI. len(df)must equal your row count (10,00,000).- Ask the AI to show each KPI formula and read it once.
Quick quiz
1. Why use a local model for private data?
The data and the AI both stay on your computer. Nothing is uploaded.
2. Which command starts the dashboard?
streamlit run app.py, then open http://localhost:8501.
3. How do you handle a bigger file in the 7B model?
Raise the context: --parameter num_ctx 8192 (needs more RAM).
4. How do you confirm the Total Sales KPI is right?
Compare it with df['sales'].sum() in Python.
Save tokens and money
A local model is free to run, so "tokens" cost nothing — but a smaller model is faster. Use 7B for everyday code, only jump to 14B/32B when 7B struggles. Ask for "only the code" to get shorter, faster replies. See more AI Coding guides.