A Streamlit application for local document summarisation, grounded question answering, and comprehension-question generation. Users can upload a PDF or TXT file and interact with it through an Ollama-hosted language model.
- Uploads PDF and UTF-8 TXT documents.
- Extracts document text and basic metadata.
- Produces a concise summary.
- Answers questions using selected passages from the uploaded document.
- Generates logic/comprehension challenges with answers and evidence.
- Uses lazy model initialisation, clear error messages, environment-based configuration, and automated tests for the deterministic utilities.
PDF/TXT upload
│
▼
Document loader
- validates extension and size
- extracts text and metadata
│
▼
Context selector
- chunks document text
- ranks chunks by query-term overlap
│
▼
Ollama LLM
├── summary prompt
├── grounded Q&A prompt
└── JSON challenge prompt
│
▼
Streamlit interface
.
├── app.py
├── src/document_assistant/
│ ├── document_loader.py
│ ├── llm.py
│ ├── service.py
│ └── text_utils.py
├── tests/
├── .env.example
├── requirements.txt
└── .streamlit/config.toml
- Python 3.10 or newer
- Ollama installed and running
- A locally available model, defaulting to
gemma:2b
python -m venv .venvWindows:
.venv\Scripts\activatemacOS/Linux:
source .venv/bin/activateInstall dependencies:
pip install -r requirements.txtPrepare the local model:
ollama pull gemma:2bCopy .env.example to .env and change the model or Ollama URL when needed.
Run the application:
streamlit run app.pyThe application splits the document into overlapping chunks and ranks them using query-term overlap. Only the highest-ranked passages are sent to the model for Q&A. The prompt instructs the model to state when the answer is not supported by the supplied context.
This is a lightweight retrieval approach rather than a production retrieval-augmented generation system. It does not use embeddings, a vector database, citations with page coordinates, or formal answer-quality evaluation.
pip install -r requirements-dev.txt
pytestThe tests cover text chunking, context selection, JSON extraction, and challenge validation without requiring Ollama.
- Do not commit uploaded documents,
.env, or Streamlit secrets. - Local inference can keep prompts on the machine running Ollama, but actual privacy depends on how Ollama and the host environment are configured.
- Do not use this prototype for confidential, regulated, medical, or legal documents without an appropriate security review.
- Add embeddings and a vector store for semantic retrieval.
- Preserve page-level references during extraction.
- Add OCR for scanned PDFs.
- Add evaluation datasets for faithfulness and answer relevance.
- Add model and response caching.
Govardhan Reddy — MSc Big Data Analytics candidate
MIT