sriharshini2901's picture
Upload 4 files
ccd968b verified
|
Raw
History Blame Contribute Delete
12.5 kB

<<<<<<< HEAD

Local AI β€” Offline Multi-Modal Document Intelligence System

Turn images, PDFs, plain text, audio, and video into structured JSON β€” 100% offline, CPU-only. No cloud APIs, no API keys, no telemetry, no internet dependency after setup.

Built with Streamlit (not React/FastAPI β€” swapped per project requirements for a single-process, easy-to-run app), Tesseract OCR, and a lightweight rule-based local extraction engine, with an optional upgrade path to a real local LLM via llama-cpp-python.


βœ… What's fully working out of the box (zero extra downloads)

  • Images β†’ OCR β†’ JSON (Tesseract, native)
  • PDFs β†’ text/OCR β†’ JSON (pdfplumber, with automatic OCR fallback for scanned pages)
  • Plain text β†’ JSON
  • Automatic document type classification (invoice, resume, receipt, meeting notes, contract, medical report, letter, research paper, certificate, general)
  • Rule-based entity extraction: people, emails, phones, dates, amounts, organizations, invoice numbers, keywords, tags, summary, confidence score
  • SQLite storage, full History view, Search, Dashboard with charts
  • Export to JSON / CSV / Excel
  • Duplicate detection via SHA-256 file hashing
  • Demo Mode (one click, no upload needed)

This mode (rules in Settings) is what the app uses by default and what was tested end-to-end while building this β€” see "What was tested" below.

πŸ”Œ Optional upgrades (require one-time internet access on your machine)

Feature Install Notes
Real local LLM extraction pip install llama-cpp-python + a .gguf model in models/ Switch to "llm" mode in Settings. See backend/llm_local.py for model recommendations (TinyLlama, Phi-3-mini, Qwen2.5-3B).
Audio transcription pip install openai-whisper + ffmpeg on PATH Powers .mp3/.wav/.m4a uploads
Video transcription same as above Extracts audio via ffmpeg, then transcribes

Once installed, these still run entirely locally / CPU-only β€” the "offline" install step is a one-time download of the model file, not a runtime API call.


Quickstart

git clone <this-repo>
cd local-ai
python -m venv venv && source venv/bin/activate   # optional but recommended
pip install -r requirements.txt

# Tesseract binary (required for OCR):
#   Ubuntu/Debian:  sudo apt install tesseract-ocr
#   macOS:          brew install tesseract
#   Windows:        https://github.com/UB-Mannheim/tesseract/wiki

streamlit run app.py

Open the URL Streamlit prints (usually http://localhost:8501). Try Home β†’ Run Demo Mode, or upload a file from sample_docs/.


Architecture

Input (image/pdf/text/audio/video)
        β”‚
        β–Ό
   OCR / Transcription      (Tesseract / pdfplumber / Whisper)
        β”‚
        β–Ό
   Text Cleaning
        β”‚
        β–Ό
   Local AI Extraction      (rule-based engine, or local LLM via llama.cpp)
        β”‚
        β–Ό
   Structured JSON
        β”‚
        β–Ό
   SQLite Storage  ──►  Dashboard / History / Search / Export

Folder structure

local-ai/
β”œβ”€β”€ app.py                # Streamlit UI (Home, Upload, Dashboard, History, Search, Settings)
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ ocr.py             # Tesseract image OCR
β”‚   β”œβ”€β”€ pdf_extract.py     # PDF text extraction + OCR fallback for scans
β”‚   β”œβ”€β”€ extractor.py       # Document classification + rule-based JSON extraction
β”‚   β”œβ”€β”€ llm_local.py       # Optional llama-cpp-python local LLM extraction
β”‚   β”œβ”€β”€ audio.py           # Optional Whisper transcription
β”‚   β”œβ”€β”€ video.py           # Optional ffmpeg audio extraction + Whisper
β”‚   β”œβ”€β”€ pipeline.py         # Orchestrates the full flow + status updates
β”‚   β”œβ”€β”€ db.py               # SQLite storage (stdlib sqlite3, no ORM dependency)
β”‚   └── exporters.py        # JSON / CSV / Excel export
β”œβ”€β”€ prompts/
β”‚   └── templates.py        # Prompt templates per document type (used in LLM mode)
β”œβ”€β”€ sample_docs/            # Sample files for quick testing / Demo Mode
β”œβ”€β”€ models/                 # Drop a .gguf model here to enable LLM mode
β”œβ”€β”€ data/                   # SQLite database lives here (created at runtime)
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ LICENSE                 # GPLv3
└── README.md

API surface (internal, called by the Streamlit UI)

These are plain Python functions, not HTTP endpoints (no separate backend server is needed since Streamlit handles both UI and processing in one process):

  • pipeline.process_file(filename, bytes, mode, model_path, ocr_lang, status_callback)
  • db.list_documents(), db.search_documents(query), db.get_document(id), db.delete_document(id), db.stats()
  • exporters.to_json_bytes(rows), to_csv_bytes(rows), to_excel_bytes(rows)

If you specifically need a separate REST API (e.g. to call from another app), the same backend/ modules can be wrapped in FastAPI with a thin main.py β€” they have no Streamlit dependency themselves.

What was tested while building this (in a sandboxed, no-internet environment)

  • Image OCR on a generated test image βœ…
  • PDF native-text extraction on a generated test PDF βœ…
  • Document classification across invoice/resume/meeting-notes samples βœ…
  • Full entity extraction (emails, phones, dates, amounts, orgs, names) βœ…
  • SQLite insert/list/search/stats/delete βœ…
  • Duplicate detection via hashing βœ…
  • JSON/CSV/Excel export βœ…

Not testable in that environment (no internet to install/download): the Streamlit UI render itself, llama-cpp-python LLM mode, and Whisper audio/video transcription. The code for all three is complete and follows each library's standard, stable API β€” install the optional dependencies above to light them up.

Security & privacy

No cloud calls, no telemetry, no analytics, no external API keys anywhere in this codebase. All processing and storage stays on the machine running streamlit run app.py.

License

GPLv3 β€” see LICENSE.

Future improvements

  • Folder-watch mode for auto-processing new files
  • Custom JSON schema builder in Settings
  • Batch processing queue with pause/resume/retry
  • Side-by-side original-document + JSON viewer with click-to-highlight
  • Multi-user auth if deployed beyond a single local user

offline notes analyser

Getting started

To make it easy for you to get started with GitLab, here's a list of recommended next steps.

Already a pro? Just edit this README.md and make it your own. Want to make it easy? Use the template at the bottom!

Add your files

cd existing_repo
git remote add origin https://code.swecha.org/sriharshini2901/offline-notes-analyser.git
git branch -M main
git push -uf origin main

Integrate with your tools

Collaborate with your team

Test and Deploy

Use the built-in continuous integration in GitLab.


Editing this README

When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to makeareadme.com for this template.

Suggestions for a good README

Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.

Name

Choose a self-explaining name for your project.

Description

Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.

Badges

On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.

Visuals

Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.

Installation

Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.

Usage

Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.

Support

Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.

Roadmap

If you have ideas for releases in the future, it is a good idea to list them in the README.

Contributing

State if you are open to contributions and what your requirements are for accepting them.

For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.

You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.

Authors and acknowledgment

Show your appreciation to those who have contributed to the project.

License

For open source projects, say how it is licensed.

Project status

If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.

5198c728ba5184d464aecc5842b792739ae0ed27