Skip to content

09 — Running the app step-by-step

Duration: 15 min (excluding the 4.9 GB model download) Prerequisites: chapters 03 and 08.

Terminal window
# 1. Clone the two needed repos side-by-side (skip if already done)
mkdir project-1
cd project-1
git clone https://github.com/inskillflow/csv-llm-shared.git
git clone https://github.com/inskillflow/csv-llm-ollama.git
# 2. Install dependencies (still from project-1/)
pip install -r csv-llm-shared/requirements.txt
pip install -r csv-llm-ollama/requirements.txt
# 3. Start Ollama in a separate window (keep it open)
ollama serve
# 4. Pull the model (ONCE, ~4.9 GB)
ollama pull llama3.1:8b
ollama list # verify
# 5. Launch the Streamlit app (port 8504)
cd csv-llm-ollama
.\start.ps1
# or
streamlit run app.py --server.port 8504

The app opens at http://127.0.0.1:8504.

On first load, the app says:

No transactions for this profile. Load a CSV from the sidebar.

In the left sidebar:

  1. CSV path is pre-filled with data/data1-anonymized.csv.
  2. Profile name is data1.
  3. Click 📥 (Re)load this CSV.

You’ll see:

734 transactions loaded into data1.

The Dashboards tab now shows 4 KPIs and 4 figures.

Contains:

  • 4 KPIs at the top:

  • 4 charts:

    • Spending by month (bar) — clear November peak.
    • Breakdown by category (doughnut) — Housing dominates.
    • Top 10 merchants (horizontal bar) — Rent + StorageBox lead.
    • Recurring merchants (≥ 3 active months) — Coastal Spoon Cafe, Harbor Noodle House, etc.
  • Filters above the charts:

    • Multi-select on categories.
    • Date range.

An interactive st.dataframe with all 734 rows sorted by date desc. You can sort any column by clicking the header, and filter in the top-right (search icon).

Click the 💬 Chat tab. You see:

Model: llama3.1:8b (read-only SQL tool calling on csv-llm-ollama.sqlite, profile data1)

💡 Sample questions:

  • How much did I spend on groceries last month?
  • What is my biggest spending category?
  • How many times did I visit Coastal Spoon Cafe this year and how much did I spend?
  • List my top 5 merchants.

Type Q2: What is my biggest spending category?

After ~5 to 15 seconds (latency depends on your CPU/GPU) you see:

⏳ The model is thinking…

Then:

Your biggest spending category is Housing with a total of $30,895.29.

⏱️ 6.2 s · 1 SQL call

And a 🔧 SQL #1 expander you can open to see:

SELECT category, SUM(amount) AS total
FROM transactions
WHERE profile = 'data1' AND amount > 0
GROUP BY category
ORDER BY total DESC
LIMIT 1

With the tabular result:

categorytotal
Housing30895.29

Typical latency (CPU only) and expected SQL pattern:

#QuestionLatencyExpected answer
Q1Groceries last month?7 sFilter by category='Groceries' + last-month date range
Q2Biggest category?5 sHousing with $30,895.29
Q3Coastal Spoon Cafe this year?6 s19 times, total $1,221.34
Q4Top 5 merchants?10 sRent Payment Willow Street, StorageBox Monthly, GardenCare Subscription, Postbox Rental, Queenstown Path Pass

Two things to verify if you don’t get these results:

  1. You loaded data/data1-anonymized.csv (734 rows), not something else.
  2. Your model is llama3.1:8b (and not llama3.2:3b which can’t tool-call reliably).

Three lines of defense in this app:

db.safe_query() (chapter 05) rejects anything that isn’t a SELECT, contains forbidden keywords, or chains statements with ;.

The SQL_TOOL spec mentions “read-only” + “SELECT” explicitly. The model does not see an INSERT/UPDATE tool, so it has nothing to call.

The database lives at csv-llm-ollama/.cache/csv-llm-ollama.sqlite. No network exposure. The Streamlit server binds to 127.0.0.1 only — your firewall doesn’t even need a rule.

ErrorLikely causeFix
ConnectionError: Failed to connect to Ollamaollama serve not runningOpen a window, run ollama serve
model "llama3.1:8b" not foundNot pulledollama pull llama3.1:8b
Answer like “I cannot compute…”Model doesn’t tool-callVerify: must be llama3.1:8b, not llama3.2:3b
SQL refused: only SELECT statements allowedModel tried INSERT/UPDATERephrase, or enrich the system prompt
Port 8504 already in usePrevious Streamlit crashed.\stop.ps1 then relaunch
Terminal window
.\csv-llm-ollama\stop.ps1

Frees port 8504 (handy if Streamlit died ungracefully).

  • Try the cloud variant: same UI, 5× faster — Project 2 — csv-llm-openai.
  • Deep-dive the shared library: extend ingest.py for your own bank — Project 3 — csv-llm-shared.
  • Add a forecasting tool: a second tool forecast_month(category) that uses a simple moving average — the LLM picks when to call which.
  • Swap the model: ollama pull qwen2.5:7b then change the default in the sidebar. Compare answer quality and latency.
  • All commands fit in 6 lines (clone, install, serve, pull, run).
  • The app loads data1-anonymized.csv in one click and shows 4 dashboards + a chat.
  • Each question shows the generated SQL and tabular result in an expander.
  • Latency: 5–15 s per question on CPU. Faster with a GPU.
  • 100% local — your spending data never leaves your machine.

Back to the Project 1 overview