Skip to content

About

Local-first AI learning application: Flask, Ollama, RAG, spaced repetition, algorithm visualisation and Docker. Public source edition.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Local AI Tutor

A local-first learning application combining a Flask web interface, Ollama language models and retrieval-augmented generation (RAG). Built by Cheng Wui Sum (Wilson Cheng) as a university group project.

Engineering and AI

  • Flask application with separate database, language-model and document-retrieval services.
  • Browser interface for conversations, algorithm visualisation and spaced repetition.
  • Local model integration, document chunking and semantic retrieval.
  • Docker configuration and a pytest suite covering application and service behaviour.

Public source edition

This repository contains application source and tests. Course slides, exam papers, student documents, training checkpoints, local databases and agent settings are excluded. The original project history is retained privately. The bundled model prompt is a generic tutoring prompt.

Use only documents you own or have permission to process. Set COURSE_DATA_DIR to your own document directory; the default is course_data/.

Local setup

Install Python and Ollama, then:

python -m venv .venv
# Activate the environment for your shell.
pip install -r requirements.txt
cp .env.example .env
ollama pull llama3
ollama pull nomic-embed-text
python app.py

Open the tutor. On Windows, use .venv\Scripts\Activate.ps1 and Copy-Item .env.example .env. Select an installed Ollama model in the sidebar; explicit tags such as gemma2:2b are preserved. The optional Modelfile contains an original generic tutor prompt; no custom model is required.

The server binds to loopback with debugging disabled. PORT and FLASK_HOST can be configured explicitly. Conversations are separated by browser session; a server restart creates a new session key. Documents are shared within this single-user local installation. This application has no multi-user authentication and should be used locally. The former --public tunnel option is disabled to prevent accidental exposure of this shared document workspace.

Document retrieval

Upload a PDF, or a ZIP containing PDFs, then ask about its contents. Files stay in the ignored uploads/ directory; SQLite history stays in the ignored tutor.db. Delete a document in the sidebar to remove both its file and indexed text. Archives are limited to 100 entries and 10 MB expanded size. Use original material or documents you have permission to process.

The copied .env.example selects the recommended, runtime-tested Ollama backend with EMBEDDING_BACKEND=ollama and EMBEDDING_MODEL=nomic-embed-text. The setup commands explicitly install this embedding model; startup does not download it automatically. Chat model inference was tested with gemma2:2b; other installed chat models can be selected in the sidebar.

As an alternative, set EMBEDDING_BACKEND=sentence-transformers to load all-MiniLM-L6-v2 on first document use. This code-level fallback also applies when no backend is configured. It requires an initial model download and a working PyTorch/SciPy installation, and was not runtime-verified on the validation machine because application-control policy blocked a SciPy DLL. Chat and built-in study tools do not load that model. Delete and re-upload documents when changing embedding models. An unavailable model produces an error rather than a fabricated answer.

Study tools

  • Socratic chat, exam practice, answer feedback, multiple perspectives and optional vision support.
  • Algorithm visualizations and a Python Code Lab that run in the browser.
  • Flashcard generation from uploaded notes, spaced review, concept map and learning progress.

Browser CSS and the Skulpt Python runtime are served locally; upstream licenses are in static/vendor/. To rebuild utility CSS after changing Tailwind classes, run npx tailwindcss@3.4.17 -i static/tailwind.input.css -o static/utilities.css --minify. No Node runtime is required to run the tutor.

Docker

docker compose up --build -d starts the app and Ollama. Install the configured model explicitly with docker compose exec ollama ollama pull llama3; vision needs its own model. Startup does not silently download several models. The published application port is bound to 127.0.0.1. Docker configuration is provided but was not runtime-tested in this validation environment.

Validation

Run python -m pytest. The full suite passes 231 tests in a fresh Python 3.12 environment. Automated tests mock model inference and embedding dependencies; these counts alone do not establish model quality.

A separate live HTTP check exercised an actual installed gemma2:2b model, original synthetic PDF extraction, nomic-embed-text ingestion through Ollama, retrieval-backed streaming, browser-session separation, document/index deletion and history clearing. Real model-backed MCQ generation/answering, answer feedback, three-perspective responses, flashcard generation and spaced review also passed. Missing-model errors returned an honest failure. Browser checks exercised streaming chat, Python execution and algorithm controls. The alternative sentence-transformers backend could not run on that Windows machine because its application-control policy blocked a SciPy DLL; the explicitly configured Ollama backend was used for the live RAG check. Learning quality, vision inference, and long-running concurrent usage have not been benchmarked. This remains a local project portfolio rather than a hosted production service.

Author

Cheng Wui Sum (Wilson Cheng) · LinkedIn

About

Local-first AI learning application: Flask, Ollama, RAG, spaced repetition, algorithm visualisation and Docker. Public source edition.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages