Skip to content

FaizarM/Local-AI-Data-Analyst

Repository files navigation

Local Private Data Analyst

Ask your business data questions in plain English and get back the answer, the SQL, and a chart in seconds. Everything runs on your own machine, so no data ever leaves your computer.

This is an agentic AI system that converts natural language into SQL, runs it against a local database, fixes its own failed queries, and visualizes the result, all powered by a local LLM through Ollama.

What Was the Problem?

In most companies, business teams cannot get answers from their own data without help. Every question, such as "which region is losing money", goes into a queue to a data analyst and comes back days later. The obvious shortcut of pasting data into ChatGPT or Claude is often not allowed, because sensitive financial and customer data cannot be sent to a third party cloud AI. The result is that the people who need answers are stuck waiting, while the data team drowns in repetitive ad hoc requests.

How Did I Solve It?

I built a self hosted analyst that anyone on the team can use, with no SQL knowledge required.

  1. The user asks a question in plain English.
  2. A local LLM (qwen2.5-coder:7b) receives the database schema and writes a SQL query.
  3. The query runs against a local SQLite database.
  4. If the SQL fails, the system feeds the error back to the model and retries automatically. This is the agentic self correction step.
  5. The result is shown as both a table and an interactive chart.

Because the model runs locally through Ollama and the database stays on the machine, no business data ever leaves the device. That directly removes the privacy blocker that stops teams from using cloud AI.

Architecture:

User question (English)
        |
        v
  Local LLM (Ollama, qwen2.5-coder:7b)   generates SQL from schema
        |
        v
  SQLite (superstore.db)   executes query
        |                        | on error
        |                        v
        |                 feed error back, LLM rewrites the SQL (auto retry)
        v
  Table plus interactive Plotly chart

What Happened After I Shipped It?

  1. Questions that would normally sit in an analyst queue for days are now answered in seconds, directly by the person who needs them.
  2. The whole system runs fully offline, so it works in exactly the environments where cloud AI is banned for compliance reasons.
  3. A failed query no longer blocks the user, because the agent rewrites broken SQL on its own before the user ever sees an error.
  4. The project is open sourced under MIT, so any team can clone it, point it at their own database, and run it without sending data anywhere. It is tested on the Sample Superstore dataset (9,994 rows).

Tech Stack

Layer Tool
LLM (local) Ollama, qwen2.5-coder:7b
Data SQLite (Sample Superstore, 9,994 rows)
App and UI Streamlit with custom CSS
Charts Plotly

Run It Locally

Prerequisites: Python 3.11 or newer, and Ollama installed (https://ollama.com/download).

# 1. Clone
git clone https://github.com/FaizarM/Local-AI-Data-Analyst.git
cd Local-AI-Data-Analyst

# 2. Install dependencies
pip install -r requirements.txt

# 3. Pull the local model
ollama pull qwen2.5-coder:7b

# 4. Build the database from the CSV
python load_data.py

# 5. Run the app
streamlit run app.py

Open the URL that Streamlit prints, usually http://localhost:8501.

Why I Built This

I am a data science student, and I keep seeing the same gap. Companies sit on data they cannot easily query, and the privacy rules around cloud AI make the easy shortcuts off limits. I wanted to prove that you can give a team a real, useful AI analyst without handing their data to anyone. This is my take on what an AI system that actually ships should look like: local, private, and solving a problem that someone actually has.

License

MIT

About

Privacy-first AI data analyst: natural language to SQL, fully local with Ollama + Streamlit.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages