Ravindra BagaleCourses & study guides Track your progress
AI CODING · KEEP DATA AT YOURSELF

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

WHY

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

WHAT
  • 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

1 · Install Ollama + a coding model qwen2.5-coder, local 2 · Generate ~10 lakh rows locally gen_data.py -> sales.csv 3 · Ask local AI to write app.py pandas + Plotly + Streamlit 4 · Run the dashboard offline streamlit run app.py 5 · Tweak by chatting to local AI no data leaves your PC

Setup — install everything (once)

SETUP · INSTALL
  1. Install Python 3 and these libraries:
    pip install pandas plotly streamlit
  2. 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
  3. Pick a size for your machine (see the hardware card below). Bigger = smarter but needs more memory.
Settings / config: the 7B model's default context can be small. For bigger files or longer chats raise it: ollama run qwen2.5-coder --parameter num_ctx 8192 (more context needs more RAM).
REVISION CARDAI Coding

Hardware for a local coding model

8 GB RAM / 4 GB VRAM: use qwen2.5-coder:3b or :1.5b — fast, simple tasks.
16 GB RAM / 8 GB VRAM: qwen2.5-coder:7b — best all-rounder for this project.
16 GB+ VRAM: :14b for stronger code; 24 GB+ VRAM: :32b, near top quality.
CPU only: :3b works but is slow (a few tokens/second).
Ravindra Bagale · ravindrabagale.com/ai-coding

Step 1 — make the data locally (no internet)

HOW

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.)

gen_data.py
"""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")
Run it: 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.

COPY THIS PROMPT (to your local model)

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).

app.py
"""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)

  1. Start the app: streamlit run app.py
  2. Open the browser at http://localhost:8501 (Streamlit opens it for you).
  3. Use the Year filter in the sidebar; the KPIs and charts update.

Step 5 — tweak by chatting (still local)

  1. "Add a line chart of monthly sales."
  2. "Make the pies show percent labels and one colour theme."
  3. "Add a Region filter next to the Year filter."
Keep data at yourself: every step here runs on your machine. The data file, the AI model and the dashboard never touch the internet. This is the safest way to use AI on private business data. See the cloud Excel version if your data is not sensitive.

How to check the numbers

  1. In Python: df['sales'].sum() must match the Total Sales KPI.
  2. len(df) must equal your row count (10,00,000).
  3. Ask the AI to show each KPI formula and read it once.
Rule: local AI can still make mistakes. Always run and check the numbers before trusting a chart.

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

SMART AI USE

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.

Save these cards

INTERVIEW CARDAI Coding

How do you build a dashboard without sending data to the cloud?

Answer: run a local model with Ollama (e.g. qwen2.5-coder), keep the CSV on disk, and let it write a pandas + Plotly + Streamlit app you run offline.
Key line: data and model both stay on your machine.
Ravindra Bagale · ravindrabagale.com/ai-coding
REVISION CARDAI Coding

Local dashboard in 3 ideas

1 Data: gen_data.py -> sales.csv (10 lakh rows), all local.
2 Code: local AI writes app.py (pandas + Plotly + Streamlit).
3 Run: streamlit run app.py -> private dashboard at localhost:8501.
Ravindra Bagale · ravindrabagale.com/ai-coding