DEV Community

VOID
VOID

Posted on

# The Haunted Document: A Ghost That Reads My PDFs Locally

Hacktoberfest Open-Source AI Challenge: Ghost in the Machine Submission 👻🌼

This is a submission for the Hacktoberfest Open-Source AI Challenge Week 4: Ghost in the Machine.

What I Built

Some documents sit forgotten in folders for months or years. They contain schedules, reports, plans, and useful information—but finding the right detail can mean opening a file and searching through pages again.

For Ghost in the Machine, I built The Haunted Document: a ghostly librarian that reads a PDF and answers questions about it using a locally running AI model.

The idea is simple: upload a PDF, ask the ghost a question, and let it search the document for relevant passages. It then sends those passages to an Ollama model running on the same computer to generate an answer.

My interpretation of the theme was to give old documents a voice. The ghost lives inside my machine, waiting to bring information back from forgotten files. đź‘»

The app runs in a browser on my computer. In my test, I uploaded a two-page training schedule and asked, “What’s this about?” The ghost identified it as a safety-related training schedule covering topics such as emergency response and soft skills.

The interface also lets me open “View passages sent to the model” to inspect the text used to create the answer.

Screenshot:

Code

GitHub repository: https://github.com/VOID1454/haunted-document

The project is built with Python and Streamlit. It uses pypdf to extract text and Ollama to run the language model locally.

How I Built It

The app follows a straightforward process:

  1. Upload a PDF: The user selects a text-based PDF in the app.
  2. Extract and divide the text: pypdf reads the document page by page, and the app divides the text into smaller passages.
  3. Find relevant passages: A keyword-based search selects passages related to the user’s question.
  4. Ask the ghost: The selected passages and question are sent to a local Ollama model. I tested it with Llama 3.2.
  5. Show the answer and evidence: The model generates an answer, and the user can expand the selected passages to see what it was given.

The prompt asks the model to answer from the supplied excerpts, cite page numbers, and say when it cannot find an answer. It also tells the model to treat the PDF text as document content rather than instructions.

For the visual design, I used a dark purple interface, a ghostly librarian theme, and a chat layout. A Windows launcher helps start the app and install its Python dependencies.

The current version has limitations: scanned PDFs need OCR before they can be read, keyword search can miss relevant passages, and the model may produce an incorrect answer or omit a citation. Users should check important information against the original PDF.

Why Does Open Innovation Matter?

Documents can contain sensitive information. With this project, the PDF is processed on my computer, and the selected passages and questions are sent to Ollama on the same machine.

Once the app, dependencies, and a compatible local model have been installed, the app can be used without an internet connection. That gives me a way to ask questions about my documents without relying on a hosted AI API.

Open tools also make the project easier to change. I can inspect and modify the Python code, experiment with the prompts, and switch to another compatible model available in Ollama. I’m not tied to one model or a single hosted service.

The Spirit of It

The first time I tested the app, I uploaded a training schedule and asked the ghost what it was about. Within moments, it turned two pages of dates, trainers, and topics into a short explanation.

It wasn’t a supernatural encounter—but it did feel like bringing a quiet document to life.

The ghost lives on my laptop. The stories stay there too. đź‘»

Top comments (0)