Ghostlight:由本地開放權重 AI 驅動的幽靈物件收藏櫃
Ghostlight: a cabinet of haunted objects powered by local, open-weight AI
Ghostlight 以瀏覽器內運行的 Qwen2.5-0.5B-Instruct,按物件、場景和情緒生成恐怖故事片段。首次生成需下載約 550 MB 的模型及執行環境,生成上限為 220 tokens,無須帳戶、API 金鑰或付費推理服務。物件名稱和生成文字不會傳送至推理服務,但模型下載仍會連接 Hugging Face/CDN 主機。
This is a submission for the Hacktoberfest Open-Source AI Challenge Week 4: Ghost in the Machine
What I Built
Ghostlight gives ordinary objects a fictional afterlife. Name an object, choose a setting and a feeling, and a small language model writes a spooky story fragment in your browser. Keep it in a local cabinet or export it as Markdown.
The interpretation of “Ghost in the Machine” is literal: the machine invents the ghost, while a familiar object gives the story somewhere to live. The interface is a midnight-green museum desk with an illuminated bell jar and paper-like story cards. These are invented stories, not historical accounts or simulations of real people.
Demo
For a quick look, try the clearly labeled sample. It does not run the model. For actual generation, enter an object, choose the setting and mood, then awaken its story.
First generation downloads roughly 550 MB of model and runtime files. A capable desktop is recommended. Loading and generation can take a few minutes, and mobile performance has not been verified. No account, API key or paid inference service is required.
Code
The application code is MIT licensed. The model and dependencies keep their own licenses.
How I Built It
The generation path uses Qwen2.5-0.5B-Instruct, with 8-bit ONNX weights, through Transformers.js and ONNX Runtime Web. Inference runs in a dedicated browser worker on CPU/WebAssembly, so WebGPU is not required.
The rest is a static JavaScript/Vite app deployed on GitHub Pages:
- A bounded prompt supplies the object, setting and mood to the model.
- The worker handles loading and generation; cancellation terminates it.
- Saved stories stay in this browser’s localStorage, with Markdown export for a separate copy.
- Model output is rendered as text, not executable HTML.
- A sample is kept separate from generated results and never silently substitutes for failed inference.
The small model is a real constraint. It can repeat itself or ignore details. A live desktop test produced a coherent station story but left out the requested brass key. Generation is limited to 220 tokens; a trailing unfinished sentence is dropped rather than completed with fabricated fallback text. That is why the app calls its output a story fragment.
Verification included 21 automated core tests, type checking, a production build, and live desktop checks of real model generation, cancellation, save, reload, export and deletion. These checks do not establish reliability on every browser or phone.
Why Does Open Innovation Matter?
Open weights make the story engine inspectable and replaceable. The prompt, worker and model choice are visible in the repository instead of hidden behind an inference endpoint. Someone can change the tone or try another compatible model without depending on a hosted text-generation API.
Local execution also changes where the story goes. Object names and generated text are not sent to an inference service. Model downloads still contact Hugging Face/CDN hosts, and the page uses Google Fonts, so this is not a claim of zero network contact. Saved stories are not encrypted, and clearing site data removes them.
There is no per-story API bill, but the cost moves to download size, memory and CPU time on the reader’s device. Offline availability is not guaranteed: the app has no service worker, and browser caches can be evicted. Those tradeoffs are part of the project rather than hidden behind the demo.
AI Disclosure
An AI coding assistant developed the project and generated this write-up. The included sample was written during that assisted build, not by the on-device model. This post uses DEV’s Fully Autonomous disclosure.
來源:DEV Community · dev.to