Spooky Machine:以本機 Qwen 生成鬼故事
Spooky Machine: A Local Qwen Ghost Story Generator
Spooky Machine 是一款以本機開放權重模型 Qwen3 4B 生成鬼故事的工具,用戶可輸入故事構想,或直接要求生成故事。它透過 Ollama 在本機推理,構想不會傳送至雲端 AI API;程式以 MIT 授權發佈。
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
Spooky Machine is a small ghost story generator. Give it a premise—like a locked bedroom door opening at midnight—and it asks a locally running open-weight model to turn that idea into an atmospheric story.
I started with the challenge’s smart-home-sensor prompt, then pared the project back to one thing: telling scary ghost stories. No sensors, accounts, saved stories, or extra controls—just an idea and a story.
Demo
The MVP runs locally. To try it on a computer with Ollama and Qwen3 4B installed:
ollama create spooky-qwen3 -f Modelfile
python server.py
Then open http://127.0.0.1:8000, optionally enter a story idea, and click Tell me a ghost story.
Code
Spooky Machine
A tiny ghost story generator powered by a local open-weight model.
Run
Install Python 3.11+ and Ollama, then run:
ollama create spooky-qwen3 -f Modelfile python server.py
The Modelfile makes a small spooky-qwen3 variant from your already-installed Qwen3 model and disables its reasoning prefix, so the app gets the story instead of the model's planning text. Open http://127.0.0.1:8000, optionally add a story idea, and ask for a ghost story. Your idea stays on this computer.
If you don't have qwen3:4b yet, run ollama pull qwen3:4b first. Run the tests with:
python -m unittest discover -s tests -v
How I Built It
The interface is plain HTML, CSS, and JavaScript. A small Python standard-library server sends the prompt to Ollama’s local generation endpoint and returns the finished story. Qwen3 4B provides the writing; the custom Ollama Modelfile keeps the setup reproducible. The server removes a completed Qwen <think> block before showing the story and refuses an incomplete response rather than displaying planning text.
The app accepts a short, optional idea, limits its length, and renders the model response as text. It has no database or cloud AI dependency. The project is released under the MIT license.
Why Open Innovation Matters
A ghost-story prompt is personal and creative. Running Qwen locally means the idea can stay on my own computer instead of being sent to a hosted AI API. An open-weight model and a small, readable app also make the experience easier to inspect, adapt, and keep running without depending on a particular writing service.
For this MVP, local inference is not an optional add-on: it is the thing that makes the generator private and self-contained.
The Spirit of It
The first version asked the house what happened while everyone slept. The smaller version asks a simpler question: what if the thing in the dark could tell its own story?
來源:DEV Community · dev.to