The code in this repository is proudly and entirely written using AI
PlotKing is an interactive AI Book Generator that helps writers generate, validate, refine, and export novels. The application takes a short plot description and transforms it into a complete book using local or cloud LLM deployments.
PlotKing follows a structured pipeline to ensure high-quality output:
- Refine: You define the core idea, genre, and structure. You can refine this manually, use AI refine to automatically expand and enhance your plot, or have a conversation with Plot King AI to brainstorm and detail your story concept.
- Create: Using the refined input from the previous step, the AI expands this into a detailed plot, chapter overview, and full chapters.
- Edit: You review the generated content. You can rewrite sections with AI, chat with the AI for suggestions, or manually edit text. The unique Validation System ensures your changes don't break the story's continuity.
- Export: Once satisfied, you export your novel to a formatted EPUB file, ready for reading or publishing.
Before creating your book, refine your story idea through multiple approaches:
- Manual Input: Directly write and edit your plot description, genre, and structure.
- AI Refine: Use the AI refine button to automatically expand and enhance your plot with creative details, proper structure, and genre-appropriate elements.
- Chat with Plot King: Have a conversation with Plot King AI to brainstorm ideas, discuss characters, settings, conflicts, and narrative details. The AI helps you explore different aspects of your story and fills in gaps.
The creation process uses your refined input and is broken down into logical steps to maintain coherence:
- Plot Expansion: Turn your refined idea into a rich, multi-paragraph synopsis.
- Chapter Outline: The system generates an outline of chapters based on the expanded plot.
- Full Generation: Each chapter is written individually, with the AI referencing the plot and previous chapters to maintain context.
- Automatic Validation: After generating a chapter, a separate AI agent reads it to ensure it matches the outline. If it fails, it auto-regenerates until it passes.
The Editor tab is where the magic happens. It's not just a text box; it's a suite of tools:
- View: Read-only mode to browse your story.
- Manual: Standard text editor for direct changes.
- Rewrite: Select text and give instructions (e.g., "Make this dialogue more intense", "Describe the setting in more detail").
- Chat: Converse with "Plot King" to brainstorm ideas or request changes for the current section.
When you make changes (manually or via AI), PlotKing doesn't just overwrite your work. It creates Drafts.
- Impact Analysis: The system analyzes how your change affects future chapters.
- Auto-Generated Drafts: If your change alters the plot significantly, the AI suggests updates for subsequent chapters to maintain continuity.
- Draft Review: You can compare the Checkpoint (original) vs. Draft (new) using the comparison view ⚖️.
- Selective Apply: You choose which AI suggestions to keep and which to discard or regenerate.
Turn your project into a finished product:
- EPUB Generation: Creates a professional e-book file compatible with most readers.
- Metadata Fetching: AI can suggest a title based on your story content.
- Customization: Choose fonts (Georgia, Palatino, etc.) and set font sizes for the output file.
- Cover Art: Upload a custom cover image or generate one using AI, to be embedded in the EPUB.
Keep your stories organized:
- Save: Persist your current progress, including plot and chapters.
- Load: Switch between different story projects easily.
- New: Start a fresh project from scratch.
- Delete: Remove unwanted projects.
- Models: Support for multiple providers (LM Studio, OpenAI, Gemini, xAI for LLM tasks; Automatic1111 and OpenAI for image generation) with configurable local endpoints, API keys, and provider-specific settings.
- Tasks: Assign different models to specific tasks for optimal performance and easy switching.
The application requires:
- Python 3.6+
- Gradio for the UI
- Access to an LLM API (default:
http://localhost:1234/v1/chat/completionsfor local deployments, but configurable) - Additional dependencies listed in
requirements.txt
- Install dependencies:
pip install -r requirements.txt - Run the application:
python main.pyor./run.baton Windows. - Access the UI through your browser at
http://localhost:7860
PlotKing is designed to work seamlessly with local LLM deployments, and LM Studio provides an easy way to run models locally without internet dependency.
- Download and install LM Studio for your operating system: 👉 https://lmstudio.ai/
- Launch LM Studio after installation.
- Open the Models tab in LM Studio.
- Search for and download a model suitable for long context and creative writing. For local development, I'm using
gpt-oss 20b. - Once downloaded, load the model in memory.
💡 Tip: For long-form book generation, prefer models that support at least 128K context windows.
- In LM Studio, open the Developer tab (top-right gear icon).
- Toggle "Start Server".
- The default address is
http://127.0.0.1:1234/v1/chat/completions(this works out of the box), but you can configure a different endpoint in PlotKing's Settings tab if needed.
If your GPU supports it (NVIDIA RTX 30xx, 40xx, or newer), you can enable FlashAttention for significant performance improvements, especially when working with long context windows.
In LM Studio while the model is loaded:
- Open the model's Settings, the gear on the left of the loaded model.
- Enable “FlashAttention”
- Restart the model to apply changes.
PlotKing supports Stable Diffusion for generating book covers via the Automatic1111 WebUI.
Follow the installation instructions for your OS: 👉 https://github.com/AUTOMATIC1111/stable-diffusion-webui
To allow PlotKing to communicate with Stable Diffusion, you must enable the API and set the port.
- Open the
webui-user.batfile (Windows) orwebui-user.sh(Linux/Mac) in a text editor. - Add the following arguments to the
COMMANDLINE_ARGSvariable (port 6969 is suggested to match PlotKing's default configuration, but you can use any port and configure it in PlotKing's Settings tab):set COMMANDLINE_ARGS=--api --port 6969 - Save the file and run it to start the server.
We would love your help building PlotKing! To make collaboration effective, please adhere to the following:
- Keep Pull Requests Focused: Each Pull Request should address a single issue or add one specific feature. Please do not mix bug fixes, new features, and code refactoring in the same PR.
- Target the develop Branch: All Pull Requests must be opened against the
devbranch. PRs opened against themasterbranch will be closed.
PlotKing is an evolving project. Upcoming features, experimental ideas, and long-term development milestones are documented in the Roadmap.
Check it out to see what’s planned next — from interactive editing tools and story infill/outfill features to multi-model support and visual story generation.
