Skip to content

SnobbishFish40/StatementAssist

 
 

Repository files navigation

Review Assignment Due Date

StatementAssist

AI-powered police witness statement collection app. A chatbot interviews witnesses, extracts structured data, and produces formal MG11-style statements.

Architecture

backend/                  FastAPI + Kokoro TTS + SQLite
├── docker-compose.yml       Runs API + Ollama together
└── src/
StatementAssist/          Flutter app (witness-facing)
PolicePortal/             Flutter app (officer-facing)

The backend serves both apps — StatementAssist for witness interviews and PolicePortal for officers reviewing completed statements.

Prerequisites

  • Docker with the Compose plugin
  • Flutter SDK
  • NVIDIA GPU (recommended): Install the NVIDIA Container Toolkit to enable GPU passthrough for faster LLM inference:
    curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg
    curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
    sudo apt-get update && sudo apt-get install -y nvidia-container-toolkit
    sudo nvidia-ctk runtime configure --runtime=docker
    sudo systemctl restart docker
    Without this, the backend will still run but Ollama will use CPU only (significantly slower).

Quick Start

1. Start the backend (Docker)

cd backend
./start.sh

start.sh automatically detects whether an NVIDIA GPU is available and enables GPU passthrough if so, falling back to CPU-only otherwise.

This starts three containers (use ./start.sh -d to run in the background):

  • api — FastAPI server on localhost:8000 (includes Kokoro TTS)
  • ollama — Local LLM server (pulls qwen3:4b-instruct on first run)
  • ngrok — Public tunnel so physical devices can reach the API

First run takes a few minutes to pull images and the model (~2.5GB).

Set your ngrok credentials in backend/.env:

NGROK_AUTHTOKEN=your_token_here
NGROK_DOMAIN=your-domain.ngrok-free.dev

2. Run the Flutter app

cd StatementAssist
flutter pub get

# Default (connects via ngrok — works on physical devices)
flutter run

# Debug mode (connects to localhost:8000 — simulators/desktop only)
flutter run --dart-define=LOCAL=true

3. Run PolicePortal

cd PolicePortal
flutter pub get

# Default (connects via ngrok)
flutter run

# Debug mode (connects to localhost:8000)
flutter run --dart-define=LOCAL=true

Connects to the same backend to view and manage completed statements.

Local Development (without Docker)

If you prefer running the backend directly:

cd backend
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt

# Start Ollama separately (must be running on port 11434)
cd src
python main.py

Requires:

  • Python 3.12+
  • Ollama running at http://localhost:11434
  • espeak-ng installed (brew install espeak-ng on macOS, apt install espeak-ng on Ubuntu)

Tech Stack

  • Frontend: Flutter (Dart) with Material Design 3
  • Backend: FastAPI (Python) with Peewee ORM (SQLite)
  • LLM: Ollama (local, qwen3:4b-instruct)
  • TTS: Kokoro ONNX (en-GB, bm_fable voice)
  • STT: speech_to_text package (on-device)
  • PDF: ReportLab for MG11 statement generation

App Flow

Landing → Form → Interview → Review → Submit

Witnesses provide their details, answer AI-guided interview questions via voice or text, then review and sign a generated MG11 statement. Officers access completed statements through PolicePortal.

Data Persistence

When using Docker, all persistent data lives in backend/data/ (git-ignored):

  • witness_statements.db — SQLite database
  • statements/ — generated MG11 PDFs
  • models/ — Kokoro ONNX model files (~80MB, auto-downloaded)

Ollama models persist in a Docker named volume (ollama-models).

Project Structure

backend/
├── docker-compose.yml           # API + Ollama + ngrok containers
├── Dockerfile
├── docker-entrypoint.sh         # Waits for Ollama, pulls model, starts app
├── start.sh                     # GPU-aware launcher
├── requirements.txt
└── src/
    ├── main.py                  # FastAPI app, CORS, health check, /tts
    ├── routes.py                # /sessions endpoints (auth-protected)
    ├── police_routes.py         # /police endpoints
    ├── auth.py                  # Per-session bearer token auth
    ├── llm.py                   # Ollama chat with tool-calling loop
    ├── tools.py                 # Structured data extraction tools
    ├── tts.py                   # Kokoro ONNX TTS (streaming)
    ├── mg11.py                  # MG11 PDF generation (ReportLab)
    └── database/
        └── database.py          # Peewee models: Session, Message

StatementAssist/
└── lib/
    ├── main.dart                # AppShell navigation state machine
    ├── screens/
    │   ├── landing_page.dart    # Welcome screen
    │   ├── landing_form.dart    # Witness details input
    │   ├── interview_chat.dart  # Chat interface (voice + text)
    │   ├── review_statement.dart# MG11 review, edit, sign
    │   └── sessions_list.dart   # Resume paused sessions
    ├── services/
    │   ├── llm_service.dart     # HTTP client for backend API
    │   └── speech_service.dart  # STT + TTS (Kokoro via backend)
    ├── models/
    │   ├── chat_message.dart
    │   ├── witness_details.dart
    │   └── statement_draft.dart
    └── widgets/
        ├── chat_bubble.dart
        ├── voice_visualizer.dart
        ├── input_mode_toggle.dart
        └── feature_card.dart

PolicePortal/
└── lib/
    ├── main.dart
    └── screens/
        └── police_portal.dart   # Statement list, view, URN assignment, PDF download

Running Tests

# StatementAssist Flutter tests
cd StatementAssist
flutter test

# PolicePortal Flutter tests
cd PolicePortal
flutter test

# Backend tests
cd backend
source venv/bin/activate
pytest

About

AI-Assisted Witness Statement Generation Application (Software Engineering Group Project)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Dart 56.1%
  • Python 30.2%
  • C++ 6.2%
  • CMake 4.8%
  • HTML 0.7%
  • Ruby 0.7%
  • Other 1.3%